From 4dddf35f625f2fa5cf8d50cd731fdfbb3729fece Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Fri, 9 Jan 2015 01:43:51 -0500 Subject: [PATCH] =?UTF-8?q?Gestion=20des=20regions=20=C3=A0=20priorit?= =?UTF-8?q?=C3=A9=20n=C3=A9gative=20+=20correction=20de=20bug=20d'affichag?= =?UTF-8?q?e=20des=20dimensions=20d'un=20cubo=20+=20Ajout=20de=20la=20comm?= =?UTF-8?q?ande=20/cubo=20convert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survival_cuboid/CommandCubo.java | 171 ++++++++++++++++-- 1 file changed, 159 insertions(+), 12 deletions(-) diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandCubo.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandCubo.java index a6eea43..c8ff361 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandCubo.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/survival_cuboid/CommandCubo.java @@ -2,8 +2,6 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Random; @@ -115,11 +113,15 @@ public class CommandCubo implements CommandExecutor { // on crée un cubo factice (qui ne sera pas enregistré) ProtectedCuboidRegion cubo = new ProtectedCuboidRegion("null", selection.getNativeMinimumPoint().toBlockVector(), selection.getNativeMaximumPoint().toBlockVector()); // on récupère les cubos de la map pour les comparer - Collection regions = wgPlugin.getRegionManager(selection.getWorld()).getRegions().values(); + List regions = new ArrayList(wgPlugin.getRegionManager(selection.getWorld()).getRegions().values()); boolean intersect = true; + for (ProtectedRegion reg : regions.toArray(new ProtectedRegion[regions.size()])) { + if (reg.getPriority() < 0) + regions.remove(reg); + } List intersect_region = null; 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; } catch (UnsupportedIntersectionException e) { } @@ -234,11 +236,16 @@ public class CommandCubo implements CommandExecutor { // on récupère les cubos de la map pour les comparer - Collection regions = wgPlugin.getRegionManager(selection.getWorld()).getRegions().values(); + + List regions = new ArrayList(wgPlugin.getRegionManager(selection.getWorld()).getRegions().values()); boolean intersect = true; + for (ProtectedRegion reg : regions.toArray(new ProtectedRegion[regions.size()])) { + if (reg.getPriority() < 0) + regions.remove(reg); + } List intersect_region = null; 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; } catch (UnsupportedIntersectionException e) { } @@ -290,7 +297,6 @@ public class CommandCubo implements CommandExecutor { try { wgPlugin.getRegionManager(selection.getWorld()).save(); } catch (ProtectionDatabaseException e) { - // TODO Auto-generated catch block e.printStackTrace(); } @@ -386,10 +392,10 @@ public class CommandCubo implements CommandExecutor { player.sendMessage(ChatColor.RED+"Vous ne vous trouvez dans aucun cubo"); return true; } - - int dim_x = inside_cubo.getMinimumPoint().getBlockX() + inside_cubo.getMaximumPoint().getBlockX() + 1; - int dim_y = inside_cubo.getMinimumPoint().getBlockY() + inside_cubo.getMaximumPoint().getBlockY() + 1; - int dim_z = inside_cubo.getMinimumPoint().getBlockZ() + inside_cubo.getMaximumPoint().getBlockZ() + 1; + + int dim_x = Math.abs(inside_cubo.getMinimumPoint().getBlockX() - inside_cubo.getMaximumPoint().getBlockX()) + 1; + int dim_y = Math.abs(inside_cubo.getMinimumPoint().getBlockY() - inside_cubo.getMaximumPoint().getBlockY()) + 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()); String proprio = inside_cubo.getOwners().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(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; @@ -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 regions_to_convert = new ArrayList(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 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 regions_to_compare_with = new ArrayList(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