Gestion des regions à priorité négative + correction de bug d'affichage des dimensions d'un cubo + Ajout de la commande /cubo convert
This commit is contained in:
parent
ef5cc23748
commit
4dddf35f62
@ -2,8 +2,6 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -115,11 +113,15 @@ public class CommandCubo implements CommandExecutor {
|
|||||||
// on crée un cubo factice (qui ne sera pas enregistré)
|
// on crée un cubo factice (qui ne sera pas enregistré)
|
||||||
ProtectedCuboidRegion cubo = new ProtectedCuboidRegion("null", selection.getNativeMinimumPoint().toBlockVector(), selection.getNativeMaximumPoint().toBlockVector());
|
ProtectedCuboidRegion cubo = new ProtectedCuboidRegion("null", selection.getNativeMinimumPoint().toBlockVector(), selection.getNativeMaximumPoint().toBlockVector());
|
||||||
// on récupère les cubos de la map pour les comparer
|
// on récupère les cubos de la map pour les comparer
|
||||||
Collection<ProtectedRegion> regions = wgPlugin.getRegionManager(selection.getWorld()).getRegions().values();
|
List<ProtectedRegion> regions = new ArrayList<ProtectedRegion>(wgPlugin.getRegionManager(selection.getWorld()).getRegions().values());
|
||||||
boolean intersect = true;
|
boolean intersect = true;
|
||||||
|
for (ProtectedRegion reg : regions.toArray(new ProtectedRegion[regions.size()])) {
|
||||||
|
if (reg.getPriority() < 0)
|
||||||
|
regions.remove(reg);
|
||||||
|
}
|
||||||
List<ProtectedRegion> intersect_region = null;
|
List<ProtectedRegion> intersect_region = null;
|
||||||
try {
|
try {
|
||||||
intersect_region = ((ProtectedRegion)cubo).getIntersectingRegions(Arrays.asList(regions.toArray(new ProtectedRegion[1])));
|
intersect_region = ((ProtectedRegion)cubo).getIntersectingRegions(regions);
|
||||||
if (intersect_region.size()==0) intersect = false;
|
if (intersect_region.size()==0) intersect = false;
|
||||||
} catch (UnsupportedIntersectionException e) { }
|
} catch (UnsupportedIntersectionException e) { }
|
||||||
|
|
||||||
@ -234,11 +236,16 @@ public class CommandCubo implements CommandExecutor {
|
|||||||
|
|
||||||
|
|
||||||
// on récupère les cubos de la map pour les comparer
|
// on récupère les cubos de la map pour les comparer
|
||||||
Collection<ProtectedRegion> regions = wgPlugin.getRegionManager(selection.getWorld()).getRegions().values();
|
|
||||||
|
List<ProtectedRegion> regions = new ArrayList<ProtectedRegion>(wgPlugin.getRegionManager(selection.getWorld()).getRegions().values());
|
||||||
boolean intersect = true;
|
boolean intersect = true;
|
||||||
|
for (ProtectedRegion reg : regions.toArray(new ProtectedRegion[regions.size()])) {
|
||||||
|
if (reg.getPriority() < 0)
|
||||||
|
regions.remove(reg);
|
||||||
|
}
|
||||||
List<ProtectedRegion> intersect_region = null;
|
List<ProtectedRegion> intersect_region = null;
|
||||||
try {
|
try {
|
||||||
intersect_region = ((ProtectedRegion)cubo).getIntersectingRegions(Arrays.asList(regions.toArray(new ProtectedRegion[1])));
|
intersect_region = ((ProtectedRegion)cubo).getIntersectingRegions(regions);
|
||||||
if (intersect_region.size()==0) intersect = false;
|
if (intersect_region.size()==0) intersect = false;
|
||||||
} catch (UnsupportedIntersectionException e) { }
|
} catch (UnsupportedIntersectionException e) { }
|
||||||
|
|
||||||
@ -290,7 +297,6 @@ public class CommandCubo implements CommandExecutor {
|
|||||||
try {
|
try {
|
||||||
wgPlugin.getRegionManager(selection.getWorld()).save();
|
wgPlugin.getRegionManager(selection.getWorld()).save();
|
||||||
} catch (ProtectionDatabaseException e) {
|
} catch (ProtectionDatabaseException e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,10 +392,10 @@ public class CommandCubo implements CommandExecutor {
|
|||||||
player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo");
|
player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dim_x = inside_cubo.getMinimumPoint().getBlockX() + inside_cubo.getMaximumPoint().getBlockX() + 1;
|
int dim_x = Math.abs(inside_cubo.getMinimumPoint().getBlockX() - inside_cubo.getMaximumPoint().getBlockX()) + 1;
|
||||||
int dim_y = inside_cubo.getMinimumPoint().getBlockY() + inside_cubo.getMaximumPoint().getBlockY() + 1;
|
int dim_y = Math.abs(inside_cubo.getMinimumPoint().getBlockY() - inside_cubo.getMaximumPoint().getBlockY()) + 1;
|
||||||
int dim_z = inside_cubo.getMinimumPoint().getBlockZ() + inside_cubo.getMaximumPoint().getBlockZ() + 1;
|
int dim_z = Math.abs(inside_cubo.getMinimumPoint().getBlockZ() - inside_cubo.getMaximumPoint().getBlockZ()) + 1;
|
||||||
Vector midpoint = Vector.getMidpoint(inside_cubo.getMinimumPoint(), inside_cubo.getMaximumPoint());
|
Vector midpoint = Vector.getMidpoint(inside_cubo.getMinimumPoint(), inside_cubo.getMaximumPoint());
|
||||||
String proprio = inside_cubo.getOwners().toUserFriendlyString();
|
String proprio = inside_cubo.getOwners().toUserFriendlyString();
|
||||||
String membres = inside_cubo.getMembers().toUserFriendlyString();
|
String membres = inside_cubo.getMembers().toUserFriendlyString();
|
||||||
@ -595,7 +601,7 @@ public class CommandCubo implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage(ChatColor.GREEN+"Vous venez de donner la parcelle courante à "+ChatColor.RESET+new_proprio.getDisplayName());
|
player.sendMessage(ChatColor.GREEN+"Vous venez de donner la parcelle courante à "+ChatColor.RESET+new_proprio.getDisplayName());
|
||||||
player.sendMessage(player.getDisplayName()+ChatColor.GREEN+" viens de vous donner la parcelle "+ChatColor.GRAY+inside_cubo.getId());
|
new_proprio.sendMessage(player.getDisplayName()+ChatColor.GREEN+" viens de vous donner la parcelle "+ChatColor.GRAY+inside_cubo.getId());
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -603,6 +609,147 @@ public class CommandCubo implements CommandExecutor {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("convert"))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!hasStaffPermission(player))
|
||||||
|
{
|
||||||
|
player.sendMessage(ChatColor.RED+"Vous n'avez pas la permission de faire cette action");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getLogger().info(ChatColor.BOLD+"Conversion des protections de la map survie en cours...");
|
||||||
|
|
||||||
|
List<ProtectedRegion> regions_to_convert = new ArrayList<ProtectedRegion>(wgPlugin.getRegionManager(player.getWorld()).getRegions().values());
|
||||||
|
|
||||||
|
int nb_converted = 0;
|
||||||
|
int nb_new_converted = 0;
|
||||||
|
int nb_concerned = regions_to_convert.size();
|
||||||
|
|
||||||
|
|
||||||
|
for (ProtectedRegion region_to_convert : regions_to_convert)
|
||||||
|
{
|
||||||
|
// on vérifie si c'est un cuboide (ne doit pas être un autre type de protection)
|
||||||
|
if (!(region_to_convert instanceof ProtectedCuboidRegion))
|
||||||
|
{
|
||||||
|
nb_concerned--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (region_to_convert.getPriority() < 0)
|
||||||
|
{
|
||||||
|
nb_concerned--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// on ignore les cubos dans le bon format
|
||||||
|
if (region_to_convert.getId().matches(regex_cubo_id))
|
||||||
|
{
|
||||||
|
nb_converted++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// on cherche le propriétaire
|
||||||
|
String id = region_to_convert.getId();
|
||||||
|
Set<String> owners = region_to_convert.getOwners().getPlayers();
|
||||||
|
|
||||||
|
|
||||||
|
if (owners.size() == 0){
|
||||||
|
plugin.getLogger().warning("cubo conversion : "+region_to_convert.getId()+" has no owner");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultDomain real_owners = new DefaultDomain();
|
||||||
|
DefaultDomain real_members = new DefaultDomain();
|
||||||
|
|
||||||
|
for (String p : owners)
|
||||||
|
{
|
||||||
|
if (id.toLowerCase().contains(p.toLowerCase()))
|
||||||
|
real_owners.addPlayer(p);
|
||||||
|
else
|
||||||
|
real_members.addPlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (real_owners.size() == 0 && owners.size() == 1)
|
||||||
|
real_owners.addPlayer(owners.toArray(new String[1])[0]);
|
||||||
|
|
||||||
|
if (real_owners.size() == 0 && owners.size() > 1){
|
||||||
|
plugin.getLogger().warning("cubo conversion : "+region_to_convert.getId()+" : has multiple owner but nobody is in region ID");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (real_owners.size() > 1){
|
||||||
|
plugin.getLogger().warning("cubo conversion : "+region_to_convert.getId()+" : has multiple owner in region ID");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String unique_owner = real_owners.getPlayers().toArray(new String[1])[0];
|
||||||
|
String cubo_name = id.replace(unique_owner, "").trim();
|
||||||
|
if (!cubo_name.matches("[0-9a-zA-Z_]+")){
|
||||||
|
plugin.getLogger().warning("cubo conversion : "+region_to_convert.getId()+" : new name '"+cubo_name+"' is not a valid name");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// on vérifie les intersections
|
||||||
|
try {
|
||||||
|
List<ProtectedRegion> regions_to_compare_with = new ArrayList<ProtectedRegion>(regions_to_convert);
|
||||||
|
regions_to_compare_with.remove(region_to_convert);
|
||||||
|
// on ne prends pas en compte les régions donc la priorité est négative (villes groupement de cubos)
|
||||||
|
for (ProtectedRegion reg : regions_to_convert) {
|
||||||
|
if (reg.getPriority() < 0)
|
||||||
|
regions_to_compare_with.remove(reg);
|
||||||
|
}
|
||||||
|
int nb_inter = region_to_convert.getIntersectingRegions(regions_to_compare_with).size();
|
||||||
|
if (nb_inter > 0)
|
||||||
|
{
|
||||||
|
plugin.getLogger().warning("cubo conversion : "+region_to_convert.getId()+" intersect with "+nb_inter+" other(s) regions");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (UnsupportedIntersectionException e) {
|
||||||
|
plugin.getLogger().warning("cubo conversion : "+region_to_convert.getId()+" throw a UnsupportedIntersectionException");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// création du cubo quiva remplacer l'ancien
|
||||||
|
String id_cubo;
|
||||||
|
do
|
||||||
|
id_cubo = "cubo"+(new Random()).nextInt(1000000000)+"-"+unique_owner+"-"+cubo_name;
|
||||||
|
while(wgPlugin.getRegionManager(player.getWorld()).hasRegion(id_cubo));
|
||||||
|
|
||||||
|
ProtectedCuboidRegion new_region = new ProtectedCuboidRegion(id_cubo, region_to_convert.getMinimumPoint(), region_to_convert.getMaximumPoint());
|
||||||
|
new_region.setMembers(real_members);
|
||||||
|
new_region.setOwners(real_owners);
|
||||||
|
new_region.setFlags(region_to_convert.getFlags());
|
||||||
|
new_region.setPriority(region_to_convert.getPriority());
|
||||||
|
|
||||||
|
wgPlugin.getRegionManager(player.getWorld()).removeRegion(region_to_convert.getId());
|
||||||
|
wgPlugin.getRegionManager(player.getWorld()).addRegion(new_region);
|
||||||
|
|
||||||
|
try {
|
||||||
|
wgPlugin.getRegionManager(player.getWorld()).save();
|
||||||
|
} catch (ProtectionDatabaseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nb_converted++;
|
||||||
|
nb_new_converted++;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getLogger().info(ChatColor.GREEN+""+nb_converted+"/"+nb_concerned+" régions converties ("+nb_new_converted+" nouvelles)");
|
||||||
|
player.sendMessage(ChatColor.GREEN+""+nb_converted+"/"+nb_concerned+" régions converties ("+nb_new_converted+" nouvelles). Voir la console pour les régions non converties");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// on arrive ici si aucune des sous commandes correspond à celle tapée
|
// on arrive ici si aucune des sous commandes correspond à celle tapée
|
||||||
|
Loading…
Reference in New Issue
Block a user