From ce2de462b0635c9bee2e2f19e8136e2389e6b18d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 24 Oct 2014 00:24:31 +1100 Subject: [PATCH 01/13] chat color support in flags --- .../com/intellectualcrafters/plot/Flag.java | 2 +- .../plot/database/DBFunc.java | 19 ------------------- .../plot/listeners/PlayerEvents.java | 1 - 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java index b153d0387..0e038a13b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java @@ -21,7 +21,7 @@ public class Flag { * if you provide inadequate inputs */ public Flag(AbstractFlag key, String value) { - if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value))) { + if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', value)))) { throw new IllegalArgumentException("Flag must be alphanumerical"); } if (value.length() > 48) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 478d7676e..9e06bd96e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -8,33 +8,14 @@ package com.intellectualcrafters.plot.database; -import static com.intellectualcrafters.plot.PlotMain.connection; - -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import org.bukkit.block.Biome; - -import sun.security.pkcs11.Secmod.DbMode; - import com.intellectualcrafters.plot.Flag; -import com.intellectualcrafters.plot.FlagManager; -import com.intellectualcrafters.plot.Logger; -import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotHomePosition; import com.intellectualcrafters.plot.PlotId; -import com.intellectualcrafters.plot.PlotMain; /** * @author Citymonstret diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 8bbcf8ce2..d68f210a0 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -451,7 +451,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (event.getEntity() instanceof Player) { return; } - System.out.print(event.getEntityType().getName()); if (!isInPlot(event.getLocation())) { event.setCancelled(true); } From 2ffb2d08a66e65ba67bceb4b7ba29b8359cd8a80 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 24 Oct 2014 00:41:57 +1100 Subject: [PATCH 02/13] should be fixed now. --- PlotSquared/src/com/intellectualcrafters/plot/Flag.java | 5 ++++- .../src/com/intellectualcrafters/plot/commands/Set.java | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java index 0e038a13b..310f1f720 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java @@ -28,7 +28,10 @@ public class Flag { throw new IllegalArgumentException("Value must be <= 48 characters"); } this.key = key; - this.value = value; + this.value = key.parseValue(value); + if (this.value==null) { + throw new IllegalArgumentException(key.getValueDesc()); + } } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 6b788fca1..fa2f82e24 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -91,13 +91,13 @@ public class Set extends SubCommand { return false; } - AbstractFlag af = new AbstractFlag(""); + AbstractFlag af; try { - af = new AbstractFlag(args[1].toLowerCase()); + af = FlagManager.getFlag(args[1].toLowerCase()); } catch (Exception e) { - + af = new AbstractFlag(args[1].toLowerCase()); } if (!FlagManager.getFlags().contains(af) && ((PlotMain.worldGuardListener == null) || !PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase()))) { @@ -141,7 +141,6 @@ public class Set extends SubCommand { try { String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); value = af.parseValue(value); - if (value==null) { PlayerFunctions.sendMessage(plr, af.getValueDesc()); return false; From a67e03fec44a2e4a3042c1ecf0df06cb95318a0e Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 24 Oct 2014 11:29:18 +1100 Subject: [PATCH 03/13] Added percentage support for block lists (untested) e.g. (I put block names instead of Ids as I can't remember what they are) floor - 90%stone - 5%gravel - 1%diamond - 4%tnt It doesn't need to add up to 100%, they are just ratios. so there is 1 part diamond to 90 parts stone. People's brains just work better when using percentages. --- .../plot/Configuration.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java index 2bbb26e7a..50dbff7eb 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java @@ -147,12 +147,29 @@ public class Configuration { return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data; } }; + + public static int gcd(int a, int b) { + if (b==0) return a; + return gcd(b,a%b); + } + private static int gcd(int[] a) + { + int result = a[0]; + for(int i = 1; i < a.length; i++) + result = gcd(result, a[i]); + return result; + } public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { @Override public boolean validateValue(String string) { try { for (String block : string.split(",")) { + if (block.contains("%")) { + String[] split = block.split("%"); + Integer.parseInt(split[0]); + block = split[1]; + } if (block.contains(":")) { String[] split = block.split(":"); Short.parseShort(split[0]); @@ -172,8 +189,28 @@ public class Configuration { @Override public Object parseString(String string) { String[] blocks = string.split(","); + ArrayList parsedvalues = new ArrayList(); + + PlotBlock[] values = new PlotBlock[blocks.length]; + int[] counts = new int[blocks.length]; + int min = 100; for (int i = 0; i < blocks.length; i++) { + if (blocks[i].contains("%")) { + String[] split = blocks[i].split("%"); + blocks[i] = split[1]; + int value = Integer.parseInt(split[0]); + counts[i] = value; + if (value Date: Fri, 24 Oct 2014 14:12:07 +1100 Subject: [PATCH 04/13] worldguard regions now support owner changes --- .../plot/Configuration.java | 1 + .../plot/commands/SetOwner.java | 5 +++++ .../plot/listeners/WorldGuardListener.java | 22 +++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java index 50dbff7eb..53b9c4482 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java @@ -3,6 +3,7 @@ package com.intellectualcrafters.plot; import java.util.ArrayList; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.block.Biome; public class Configuration { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java index dd25ee01b..6b08e9f7c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java @@ -51,6 +51,11 @@ public class SetOwner extends SubCommand { PlotMain.updatePlot(plot); DBFunc.setOwner(plot, plot.owner); PlayerFunctions.sendMessage(plr, C.SET_OWNER); + + if (PlotMain.worldGuardListener!=null) { + PlotMain.worldGuardListener.changeOwner(plr, plot.owner, plr.getWorld(), plot); + } + return true; } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java index aa6f4221b..7c49688f2 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java @@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.listeners; import java.util.ArrayList; import java.util.Map; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -15,6 +16,7 @@ import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.UUIDHandler; import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.events.PlotMergeEvent; @@ -41,6 +43,22 @@ public class WorldGuardListener implements Listener { this.flags.add(flag); } } + public void changeOwner(Player requester, UUID owner, World world, Plot plot) { + boolean op = requester.isOp(); + requester.setOp(true); + try { + RegionManager manager = PlotMain.worldGuard.getRegionManager(world); + manager.getRegion(plot.id.x + "-" + plot.id.y); + requester.performCommand("region setowner " + (plot.id.x + "-" + plot.id.y) + " " + UUIDHandler.getName(owner)); + requester.performCommand("region removeowner " + (plot.id.x + "-" + plot.id.y) + " " + UUIDHandler.getName(plot.getOwner())); + } + catch (Exception e) { + requester.setOp(op); + } + finally { + requester.setOp(op); + } + } public void removeFlag(Player requester, World world, Plot plot, String key) { boolean op = requester.isOp(); @@ -48,7 +66,7 @@ public class WorldGuardListener implements Listener { try { RegionManager manager = PlotMain.worldGuard.getRegionManager(world); manager.getRegion(plot.id.x + "-" + plot.id.y); - for (Flag flag : this.flags) { + for (Flag flag : this.flags) { if (flag.getName().equalsIgnoreCase(key)) { requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key); } @@ -68,7 +86,7 @@ public class WorldGuardListener implements Listener { try { RegionManager manager = PlotMain.worldGuard.getRegionManager(world); manager.getRegion(plot.id.x + "-" + plot.id.y); - for (Flag flag : this.flags) { + for (Flag flag : this.flags) { if (flag.getName().equalsIgnoreCase(key)) { requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key + " " + value); } From c367dfa510845167a2f5805758f08beb59c4bd6a Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 24 Oct 2014 16:50:48 +1100 Subject: [PATCH 05/13] Added plot info categories. --- .../jnbt/ByteArrayTag.java | 19 --- .../intellectualcrafters/jnbt/ByteTag.java | 19 --- .../jnbt/CompoundTag.java | 19 --- .../jnbt/CompoundTagBuilder.java | 19 --- .../intellectualcrafters/jnbt/DoubleTag.java | 19 --- .../com/intellectualcrafters/jnbt/EndTag.java | 19 --- .../intellectualcrafters/jnbt/FloatTag.java | 19 --- .../jnbt/IntArrayTag.java | 19 --- .../com/intellectualcrafters/jnbt/IntTag.java | 19 --- .../intellectualcrafters/jnbt/ListTag.java | 19 --- .../jnbt/ListTagBuilder.java | 19 --- .../intellectualcrafters/jnbt/LongTag.java | 19 --- .../jnbt/NBTConstants.java | 19 --- .../jnbt/NBTInputStream.java | 19 --- .../jnbt/NBTOutputStream.java | 19 --- .../intellectualcrafters/jnbt/NBTUtils.java | 29 +---- .../intellectualcrafters/jnbt/ShortTag.java | 19 --- .../intellectualcrafters/jnbt/StringTag.java | 19 --- .../com/intellectualcrafters/jnbt/Tag.java | 19 --- .../src/com/intellectualcrafters/plot/C.java | 14 ++- .../plot/commands/Info.java | 112 ++++++++++++++---- .../plot/commands/list.java | 2 +- 22 files changed, 108 insertions(+), 391 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ByteArrayTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ByteArrayTag.java index c6efbd9cb..4d0d89322 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/ByteArrayTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ByteArrayTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java index 65e86ec84..46e247e63 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java index 13dad7121..2052d65b3 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import java.util.Collections; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTagBuilder.java b/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTagBuilder.java index 8f1edf183..bdca78428 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTagBuilder.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTagBuilder.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import java.util.HashMap; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/DoubleTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/DoubleTag.java index e3c9028d6..b660eb681 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/DoubleTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/DoubleTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java index f4a6b49e4..408206b1b 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java index 9d75964c0..ad333dad1 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/IntArrayTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/IntArrayTag.java index 3359b393a..4c80b1cf7 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/IntArrayTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/IntArrayTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/IntTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/IntTag.java index d272cfa15..bea176238 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/IntTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/IntTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java index 8d36aea43..bea5d8158 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import javax.annotation.Nullable; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ListTagBuilder.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTagBuilder.java index 711e5629e..758bc52eb 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/ListTagBuilder.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTagBuilder.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import java.util.ArrayList; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/LongTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/LongTag.java index 839b0f0cf..19ab6b44f 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/LongTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/LongTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java index d8b5544f9..f1bef6d4f 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import java.nio.charset.Charset; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTInputStream.java b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTInputStream.java index a412a4d74..fc6609f35 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTInputStream.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTInputStream.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import java.io.Closeable; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java index c982d7817..dc915bcf4 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import java.io.Closeable; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java index 19a62bfb6..611f109df 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java @@ -1,30 +1,7 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import java.util.Map; -import com.sun.media.sound.InvalidFormatException; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * A class which contains NBT-related utility methods. * @@ -160,13 +137,13 @@ public final class NBTUtils { * @return child tag * @throws InvalidFormatException */ - public static T getChildTag(Map items, String key, Class expected) throws InvalidFormatException { + public static T getChildTag(Map items, String key, Class expected) throws IllegalArgumentException { if (!items.containsKey(key)) { - throw new InvalidFormatException("Missing a \"" + key + "\" tag"); + throw new IllegalArgumentException("Missing a \"" + key + "\" tag"); } Tag tag = items.get(key); if (!expected.isInstance(tag)) { - throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName()); + throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName()); } return expected.cast(tag); } diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ShortTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ShortTag.java index c48e4198b..e488968d1 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/ShortTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ShortTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java index 1e5c06a98..6a66458eb 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java index a1ea70e83..2fab21bd2 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java @@ -1,22 +1,3 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.intellectualcrafters.jnbt; /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 41be88e8b..271b0404c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -207,7 +207,19 @@ public enum C { * Info */ PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), - PLOT_INFO("ID: &6%id%&c, Alias: &6%alias%&c, Owner: &6%owner%&c, Biome: &6%biome%&c, Helpers:&6%helpers%&c, Trusted:&6%trusted%&c, Denied:&6%denied%&c, Rating: &6%rating%&c, Flags: &6%flags%"), + PLOT_INFO("&6ID&7: &a%id%&7\n&6Alias&7: &a%alias%\n&6Owner&7: &a%owner%\n&6Description&7: &a%desc%\n&6Rating&7: &a%rating%&7/&a10\n&6Can build&7: &a%build%"), + + PLOT_INFO_HELPERS("&6Helpers&7: %helpers%"), + PLOT_INFO_TRUSTED("&6Trusted&7: %trusted%"), + PLOT_INFO_DENIED("&6DENIED&7: %denied%"), + PLOT_INFO_FLAGS("&6Flags&7: %flags%"), + PLOT_INFO_BIOME("&6Biome&7: %biome%"), + PLOT_INFO_RATING("&6Rating&7: %rating%"), + PLOT_INFO_OWNER("&6Owner&7: %owner%"), + PLOT_INFO_ID("&6ID&7: %id%"), + PLOT_INFO_ALIAS("&6Alias&7: %alias%"), + PLOT_INFO_SIZE("&6Size&7: %size%"), + PLOT_USER_LIST(" &6%user%&c,"), INFO_SYNTAX_CONSOLE("/plot info X;Y"), /* diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index caf3f5189..eea11751a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -10,7 +10,9 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.database.DBFunc; + import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -31,9 +33,10 @@ public class Info extends SubCommand { @Override public boolean execute(Player player, String... args) { - + World world; Plot plot; if (player!=null) { + world = player.getWorld(); if (!PlayerFunctions.isInPlot(player)) { PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT); return false; @@ -41,7 +44,7 @@ public class Info extends SubCommand { plot = PlayerFunctions.getCurrentPlot(player); } else { - if (args.length!=2) { + if (args.length<2) { PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE); return false; } @@ -56,6 +59,14 @@ public class Info extends SubCommand { plot = PlotHelper.getPlot(Bukkit.getWorld(plotworld.worldname), id); if (plot==null) { PlayerFunctions.sendMessage(player, C.NOT_VALID_PLOT_ID); + return false; + } + world = Bukkit.getWorld(args[0]); + if (args.length==3) { + args = new String[] {args[2]}; + } + else { + args = new String[0]; } } catch (Exception e) { @@ -90,8 +101,6 @@ public class Info extends SubCommand { return true; } - new StringBuilder(); - String owner = "none"; if (plot.owner != null) { owner = Bukkit.getOfflinePlayer(plot.owner).getName(); @@ -99,27 +108,88 @@ public class Info extends SubCommand { if (owner == null) { owner = plot.owner.toString(); } - String info = C.PLOT_INFO.s(); - info = info.replaceAll("%alias%", plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none"); - info = info.replaceAll("%id%", plot.id.toString()); - info = info.replaceAll("%biome%", getBiomeAt(plot).toString()); - info = info.replaceAll("%owner%", owner); - info = info.replaceAll("%helpers%", getPlayerList(plot.helpers)); - info = info.replaceAll("%trusted%", getPlayerList(plot.trusted)); - info = info.replaceAll("%denied%", getPlayerList(plot.denied)); - info = info.replaceAll("%rating%", "" + DBFunc.getRatings(plot)); - info = - info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(), "").length() > 0 - ? StringUtils.join(plot.settings.getFlags(), ",") : "none"); - // PlayerFunctions.sendMessage(player, - // PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString()); - // PlayerFunctions.sendMessage(player, - // PlayerFunctions.getBottomPlot(player.getWorld(), - // plot).id.toString()); + + if (args.length==1) { + info = getCaption(args[0].toLowerCase()); + if (info==null) { + PlayerFunctions.sendMessage(player, "&6Categories&7: &ahelpers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating"); + return false; + } + } + + info = format(info, world, plot, player); + PlayerFunctions.sendMessage(player, info); return true; } + + private String getCaption(String string) { + switch (string) { + case "helpers": + return C.PLOT_INFO_HELPERS.s(); + case "alias": + return C.PLOT_INFO_ALIAS.s(); + case "biome": + return C.PLOT_INFO_BIOME.s(); + case "denied": + return C.PLOT_INFO_DENIED.s(); + case "flags": + return C.PLOT_INFO_FLAGS.s(); + case "id": + return C.PLOT_INFO_ID.s(); + case "size": + return C.PLOT_INFO_SIZE.s(); + case "trusted": + return C.PLOT_INFO_TRUSTED.s(); + case "owner": + return C.PLOT_INFO_OWNER.s(); + case "rating": + return C.PLOT_INFO_RATING.s(); + default: + return null; + } + } + + private String format(String info, World world, Plot plot, Player player) { + + PlotId id = plot.id; + PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id; + int num = PlayerFunctions.getPlotSelectionIds(world, id, id2).size(); + String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none"; + String biome = getBiomeAt(plot).toString(); + String helpers = getPlayerList(plot.helpers); + String trusted = getPlayerList(plot.trusted); + String denied = getPlayerList(plot.denied); + String rating = String.format("%.1f", DBFunc.getRatings(plot)); + String flags = StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none"; + boolean build = player==null ? true : plot.hasRights(player); + + String owner = "none"; + if (plot.owner != null) { + owner = Bukkit.getOfflinePlayer(plot.owner).getName(); + } + if (owner == null) { + owner = plot.owner.toString(); + } + + info = info.replaceAll("%alias%", alias); + info = info.replaceAll("%id%", id.toString()); + info = info.replaceAll("%id2%", id2.toString()); + info = info.replaceAll("%num%", num+""); + info = info.replaceAll("%biome%", biome); + info = info.replaceAll("%owner%", owner); + info = info.replaceAll("%helpers%", helpers); + info = info.replaceAll("%trusted%", trusted); + info = info.replaceAll("%denied%", denied); + info = info.replaceAll("%rating%", rating); + info = info.replaceAll("%flags%", flags); + info = info.replaceAll("%build%", build+""); + info = info.replaceAll("%desc%", "No description set."); + + + return info; + } private String getPlayerList(ArrayList l) { if ((l == null) || (l.size() < 1)) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java index f60431414..df09855e6 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java @@ -72,7 +72,7 @@ public class list extends SubCommand { + "\n"); } } - string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlots().size() + string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There are").replaceAll("%num%", PlotMain.getPlots().size() + "").replaceAll("%plot%", PlotMain.getPlots().size() == 1 ? "plot" : "plots")); PlayerFunctions.sendMessage(plr, string.toString()); return true; From eb35ba5fb015cb467da650cb943d484ce28da8cc Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 00:08:21 +1100 Subject: [PATCH 06/13] fixes --- .../com/intellectualcrafters/plot/PlayerFunctions.java | 9 ++++++++- PlotSquared/src/com/intellectualcrafters/plot/Plot.java | 1 + .../src/com/intellectualcrafters/plot/PlotSettings.java | 2 ++ .../src/com/intellectualcrafters/plot/commands/Info.java | 4 ++-- .../intellectualcrafters/plot/database/SQLManager.java | 7 ++++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index ce0e10ed7..97bec2db9 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -182,7 +182,14 @@ public class PlayerFunctions { * @return */ public static int getPlayerPlotCount(World world, Player plr) { - return getPlayerPlots(world, plr).size(); + UUID uuid = plr.getUniqueId(); + int count = 0; + for (Plot plot: PlotMain.getPlots(world).values()) { + if (plot.hasOwner() && plot.owner.equals(uuid) && plot.countsTowardsMax) { + count++; + } + } + return count; } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index ddcf159f0..8a7d3bcd2 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -65,6 +65,7 @@ public class Plot implements Cloneable { * Has the plot changed since the last save cycle? */ public boolean hasChanged = false; + public boolean countsTowardsMax = false; /** * Primary constructor diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java index 6fdd88f9d..d61617a92 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java @@ -10,6 +10,8 @@ package com.intellectualcrafters.plot; import org.bukkit.block.Biome; +import com.intellectualcrafters.plot.database.DBFunc; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index eea11751a..fb3189988 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -97,7 +97,7 @@ public class Info extends SubCommand { // Unclaimed? if (!hasOwner && !containsEveryone && !trustedEveryone) { - PlayerFunctions.sendMessage(player, C.PLOT_INFO_UNCLAIMED, plot.id.x + ";" + plot.id.y); + PlayerFunctions.sendMessage(player, C.PLOT_INFO_UNCLAIMED, (plot.id.x + ";" + plot.id.y)); return true; } @@ -162,7 +162,7 @@ public class Info extends SubCommand { String trusted = getPlayerList(plot.trusted); String denied = getPlayerList(plot.denied); String rating = String.format("%.1f", DBFunc.getRatings(plot)); - String flags = StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none"; + String flags = "&3"+ (StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), "&7, &3") : "none"); boolean build = player==null ? true : plot.hasRights(player); String owner = "none"; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java index b813adf8e..14b2e6f2b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java @@ -435,7 +435,12 @@ public class SQLManager extends AbstractDB { for (int i = 0; i < flags.length; i++) { if (flags_string[i].contains(":")) { String[] split = flags_string[i].split(":"); - flags[i] = new Flag(FlagManager.getFlag(split[0], true), split[1]); + try { + flags[i] = new Flag(FlagManager.getFlag(split[0], true), split[1]); + } + catch (Exception e) { + // invalid flag... ignoring it for now. + } } else { flags[i] = new Flag(FlagManager.getFlag(flags_string[i], true), ""); From 90d327d80c341e47fd5efce6171a9b3962527d17 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 00:12:20 +1100 Subject: [PATCH 07/13] whoops. --- PlotSquared/src/com/intellectualcrafters/plot/Plot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index 8a7d3bcd2..1a0bf09d6 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -65,7 +65,7 @@ public class Plot implements Cloneable { * Has the plot changed since the last save cycle? */ public boolean hasChanged = false; - public boolean countsTowardsMax = false; + public boolean countsTowardsMax = true; /** * Primary constructor From 1a9f10951dd6cc6bf10238d034daf9b21b5e3895 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 11:16:15 +1100 Subject: [PATCH 08/13] flag fixes. --- .../com/intellectualcrafters/plot/Plot.java | 2 +- .../plot/database/SQLManager.java | 46 ++++++++++++++++--- .../plot/listeners/PlotListener.java | 18 ++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index 1a0bf09d6..f4a5af227 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -65,7 +65,7 @@ public class Plot implements Cloneable { * Has the plot changed since the last save cycle? */ public boolean hasChanged = false; - public boolean countsTowardsMax = true; + public boolean countsTowardsMax = true ; /** * Primary constructor diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java index 14b2e6f2b..04eeebe79 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.block.Biome; @@ -431,21 +432,28 @@ public class SQLManager extends AbstractDB { else { flags_string = ((String) settings.get("flags")).split(","); } - Flag[] flags = new Flag[flags_string.length]; - for (int i = 0; i < flags.length; i++) { + ArrayList flags = new ArrayList(); + boolean exception = false; + for (int i = 0; i < flags_string.length; i++) { if (flags_string[i].contains(":")) { String[] split = flags_string[i].split(":"); try { - flags[i] = new Flag(FlagManager.getFlag(split[0], true), split[1]); + flags.add(new Flag(FlagManager.getFlag(split[0], true), split[1])); } catch (Exception e) { + exception = true; // invalid flag... ignoring it for now. } } else { - flags[i] = new Flag(FlagManager.getFlag(flags_string[i], true), ""); + flags.add(new Flag(FlagManager.getFlag(flags_string[i], true), "")); } } + + if (exception) { + setFlags(worldname, id, flags.toArray(new Flag[0])); + } + ArrayList helpers = plotHelpers(id); ArrayList trusted = plotTrusted(id); ArrayList denied = plotDenied(id); @@ -473,8 +481,7 @@ public class SQLManager extends AbstractDB { for (int i = 0; i < 4; i++) { merged[3 - i] = (merged_int & (1 << i)) != 0; } - p = - new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags, worldname, merged); + p = new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags.toArray(new Flag[0]), worldname, merged); if (plots.containsKey(worldname)) { plots.get(worldname).put((plot_id), p); } @@ -561,6 +568,33 @@ public class SQLManager extends AbstractDB { } }); } + + public void setFlags(final String world, final int id, final Flag[] flags) { + ArrayList newflags = new ArrayList(); + for (Flag flag : flags) { + if (flag!=null && flag.getKey()!=null && !flag.getKey().equals("")) { + newflags.add(flag); + } + } + final String flag_string = StringUtils.join(newflags,","); + runTask(new Runnable() { + @Override + public void run() { + try { + PreparedStatement stmt = + connection.prepareStatement("UPDATE `plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?"); + stmt.setString(1, flag_string); + stmt.setInt(2, id); + stmt.execute(); + stmt.close(); + } + catch (SQLException e) { + e.printStackTrace(); + Logger.add(LogLevel.WARNING, "Could not set flag for plot " + id); + } + } + }); + } /** * @param plot diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java index 65653e041..7b1b9f21b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -3,9 +3,12 @@ package com.intellectualcrafters.plot.listeners; import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; + import org.bukkit.*; import org.bukkit.block.Biome; +import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import java.util.ArrayList; import java.util.Arrays; @@ -45,6 +48,21 @@ public class PlotListener { public static UUID getUUID(String name) { return UUIDHandler.getUUID(name); } + + // unused + public static void blockChange(Block block, Cancellable event) { + Location loc = block.getLocation(); + String world = loc.getWorld().getName(); + PlotManager manager = PlotMain.getPlotManager(world); + if (manager!=null) { + PlotWorld plotworld = PlotMain.getWorldSettings(world); + PlotId id = manager.getPlotId(plotworld, loc); + if (id==null) { + event.setCancelled(true); + } + } + return; + } public static boolean enteredPlot(Location l1, Location l2) { PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ())); From 20554f7ed1a1ce44d72999dc21185e1f53849915 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 15:27:12 +1100 Subject: [PATCH 09/13] Added command to save a schematic. --- .../src/com/intellectualcrafters/plot/C.java | 1 + .../intellectualcrafters/plot/PlotMain.java | 2 + .../plot/SchematicHandler.java | 28 ++++---- .../intellectualcrafters/plot/Settings.java | 1 + .../plot/commands/Schematic.java | 71 ++++++++++++++++++- PlotSquared/src/plugin.yml | 2 +- 6 files changed, 88 insertions(+), 17 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 271b0404c..2f84a004d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -69,6 +69,7 @@ public enum C { * Schematic Stuff */ SCHEMATIC_MISSING_ARG("&cYou need to specify an argument. Possible values: &6test "), + SCHEMATIC_MISSING_ARG2("&cYou need to specify an argument. Possible values: &6save"), SCHEMATIC_INVALID("&cThat is not a valid schematic. Reason: &c%s"), SCHEMATIC_VALID("&cThat is a valid schematic"), SCHEMATIC_PASTE_FAILED("&cFailed to paste the schematic"), diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 18636934c..12e53a0ce 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -1078,6 +1078,7 @@ public class PlotMain extends JavaPlugin { options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT); options.put("web.enabled", Web.ENABLED); + options.put("web.directory", "/var/www"); options.put("web.port", Web.PORT); options.put("metrics", true); options.put("debug", true); @@ -1097,6 +1098,7 @@ public class PlotMain extends JavaPlugin { } Web.ENABLED = config.getBoolean("web.enabled"); Web.PORT = config.getInt("web.port"); + Web.PATH = config.getString("web.directory"); Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs"); Settings.WORLDGUARD = config.getBoolean("worldguard.enabled"); Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding"); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java index 3fa4a1e5a..a3b0ccce6 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java @@ -23,7 +23,7 @@ import java.util.zip.GZIPInputStream; */ public class SchematicHandler { - public boolean paste(Location location, Schematic schematic, Plot plot) { + public static boolean paste(Location location, Schematic schematic, Plot plot) { if (schematic == null) { PlotMain.sendConsoleSenderMessage("Schematic == null :|"); return false; @@ -71,7 +71,7 @@ public class SchematicHandler { return true; } - public Schematic getSchematic(String name) { + public static Schematic getSchematic(String name) { { File parent = new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics"); @@ -163,7 +163,7 @@ public class SchematicHandler { } } - public class Dimension { + public static class Dimension { private int x; private int y; private int z; @@ -193,7 +193,7 @@ public class SchematicHandler { * @param path * @return */ - public boolean save(CompoundTag tag, String path) { + public static boolean save(CompoundTag tag, String path) { if (tag==null) { PlotMain.sendConsoleSenderMessage("&cCannot save empty tag"); @@ -219,16 +219,16 @@ public class SchematicHandler { * @param plot * @return */ - public CompoundTag getCompoundTag(World world, Plot plot) { + public static CompoundTag getCompoundTag(World world, PlotId id) { - if (!PlotMain.getPlots(world).containsKey(plot.id)) { + if (!PlotMain.getPlots(world).containsKey(id)) { return null; // Plot is empty } // loading chunks - final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1); - final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id); + final Location pos1 = PlotHelper.getPlotBottomLoc(world, id).add(1, 0, 1); + final Location pos2 = PlotHelper.getPlotTopLoc(world, id); for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) { for (int j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) { Chunk chunk = world.getChunkAt(i, j); @@ -268,19 +268,19 @@ public class SchematicHandler { Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, 0 + y, pos1.getBlockZ() + z)); - int id = block.getTypeId(); + int id2 = block.getTypeId(); - if (id > 255) { + if (id2 > 255) { if (addBlocks == null) { addBlocks = new byte[(blocks.length >> 1) + 1]; } addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? - addBlocks[index >> 1] & 0xF0 | (id >> 8) & 0xF - : addBlocks[index >> 1] & 0xF | ((id >> 8) & 0xF) << 4); + addBlocks[index >> 1] & 0xF0 | (id2 >> 8) & 0xF + : addBlocks[index >> 1] & 0xF | ((id2 >> 8) & 0xF) << 4); } - blocks[index] = (byte) id; + blocks[index] = (byte) id2; blockData[index] = (byte) block.getData(); @@ -300,7 +300,7 @@ public class SchematicHandler { return schematicTag; } - public class DataCollection { + public static class DataCollection { private short block; private byte data; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java index dd302a1c7..29ff27347 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java @@ -73,6 +73,7 @@ public class Settings { public static class Web { public static boolean ENABLED = false; public static int PORT = 9000; + public static String PATH = "/var/www"; } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index f5b64e951..5fab31869 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -1,12 +1,19 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.entity.Player; +import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotId; +import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.SchematicHandler; +import com.intellectualcrafters.plot.Settings; +import com.intellectualcrafters.plot.database.DBFunc; public class Schematic extends SubCommand { @@ -17,12 +24,12 @@ public class Schematic extends SubCommand { } @Override - public boolean execute(Player plr, String... args) { + public boolean execute(final Player plr, String... args) { if (args.length < 1) { sendMessage(plr, C.SCHEMATIC_MISSING_ARG); return true; } - String arg = args[0]; + String arg = args[0].toLowerCase(); String file; SchematicHandler.Schematic schematic; switch (arg) { @@ -69,6 +76,66 @@ public class Schematic extends SubCommand { } sendMessage(plr, C.SCHEMATIC_VALID); break; + case "save": + final PlotId i; + final String world; + if (plr!=null) { + if(!PlayerFunctions.isInPlot(plr)) { + sendMessage(plr, C.NOT_IN_PLOT); + return false; + } + Plot myplot = PlayerFunctions.getCurrentPlot(plr); + if(!myplot.hasRights(plr)) { + sendMessage(plr, C.NO_PLOT_PERMS); + return false; + } + i = myplot.id; + world = plr.getWorld().getName(); + } + else { + if (args.length==3) { + try { + world = args[0]; + String[] split = args[2].split(";"); + i = new PlotId(Integer.parseInt(split[0]),Integer.parseInt(split[1])); + if (PlotMain.getPlots(world)==null || PlotMain.getPlots(world).get(i) == null) { + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save "); + return false; + } + + } + catch (Exception e) { + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save "); + return false; + } + } + else { + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save "); + return false; + } + } + + + + Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { + @Override + public void run() { + CompoundTag schematic = SchematicHandler.getCompoundTag(Bukkit.getWorld(world), i); + if (schematic==null) { + PlayerFunctions.sendMessage(plr, "&cInvalid plot"); + return; + } + boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+i.x+"-"+i.y+"-"+world+".schematic"); + + if (!result) { + PlayerFunctions.sendMessage(plr, "&cFailed to save schematic"); + return; + } + PlayerFunctions.sendMessage(plr, "&aSuccessfully saved schematic!"); + } + }); + + break; default: sendMessage(plr, C.SCHEMATIC_MISSING_ARG); break; diff --git a/PlotSquared/src/plugin.yml b/PlotSquared/src/plugin.yml index 1a27cbd72..ed8bc74e6 100644 --- a/PlotSquared/src/plugin.yml +++ b/PlotSquared/src/plugin.yml @@ -1,6 +1,6 @@ name: PlotSquared main: com.intellectualcrafters.plot.PlotMain -version: 2.1.1 +version: 2.1.2 load: STARTUP description: > Easy, yet powerful Plot World generation and management. From 760921a43bae9bc7e891227d7d35af9727e2ba4c Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 15:37:45 +1100 Subject: [PATCH 10/13] Added exportall command --- .../plot/commands/Schematic.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index 5fab31869..3d47ff06e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -1,5 +1,8 @@ package com.intellectualcrafters.plot.commands; +import java.util.Collection; +import java.util.HashMap; + import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -14,6 +17,7 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.SchematicHandler; import com.intellectualcrafters.plot.Settings; import com.intellectualcrafters.plot.database.DBFunc; +import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore; public class Schematic extends SubCommand { @@ -34,6 +38,10 @@ public class Schematic extends SubCommand { SchematicHandler.Schematic schematic; switch (arg) { case "paste": + if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste"); + return false; + } if (args.length < 2) { sendMessage(plr, C.SCHEMATIC_MISSING_ARG); break; @@ -53,6 +61,10 @@ public class Schematic extends SubCommand { } break; case "test": + if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test"); + return false; + } if (args.length < 2) { sendMessage(plr, C.SCHEMATIC_MISSING_ARG); break; @@ -76,7 +88,52 @@ public class Schematic extends SubCommand { } sendMessage(plr, C.SCHEMATIC_VALID); break; + case "saveall": + case "exportall": + if (plr!=null) { + PlayerFunctions.sendMessage(plr, C.NOT_CONSOLE); + return false; + } + if (args.length!=2) { + PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots schem exportall "); + return false; + } + HashMap plotmap = PlotMain.getPlots(args[1]); + if (plotmap==null || plotmap.size()==0) { + PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots schem exportall "); + return false; + } + + PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while."); + PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Found &c"+plotmap.size()+"&7 plots..."); + final Collection plots = plotmap.values(); + final World worldname = Bukkit.getWorld(args[1]); + Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { + @Override + public void run() { + + for (Plot plot:plots) { + CompoundTag schematic = SchematicHandler.getCompoundTag(worldname, plot.id); + if (schematic==null) { + PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id); + return; + } + boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+plot.id.x+"-"+plot.id.y+"-"+worldname+".schematic"); + + if (!result) { + PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id); + return; + } + PlayerFunctions.sendMessage(plr, "&7 - &aExport success: "+plot.id); + } + } + }); + case "export": case "save": + if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save"); + return false; + } final PlotId i; final String world; if (plr!=null) { From ed3003a2f669bb011b602111038a3c28b79cb673 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 16:34:06 +1100 Subject: [PATCH 11/13] Fixed exportall command (spigot would attempt to restart because of lag) --- .../src/com/intellectualcrafters/plot/C.java | 3 +- .../plot/SchematicHandler.java | 12 +- .../plot/commands/Schematic.java | 103 +++++++++++++----- 3 files changed, 84 insertions(+), 34 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 2f84a004d..e02ee649e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -68,8 +68,7 @@ public enum C { /* * Schematic Stuff */ - SCHEMATIC_MISSING_ARG("&cYou need to specify an argument. Possible values: &6test "), - SCHEMATIC_MISSING_ARG2("&cYou need to specify an argument. Possible values: &6save"), + SCHEMATIC_MISSING_ARG("&cYou need to specify an argument. Possible values: &6test &7 , &6save&7 , &6paste &7, &6exportall"), SCHEMATIC_INVALID("&cThat is not a valid schematic. Reason: &c%s"), SCHEMATIC_VALID("&cThat is a valid schematic"), SCHEMATIC_PASTE_FAILED("&cFailed to paste the schematic"), diff --git a/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java index a3b0ccce6..2280d0e8d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java @@ -229,8 +229,11 @@ public class SchematicHandler { // loading chunks final Location pos1 = PlotHelper.getPlotBottomLoc(world, id).add(1, 0, 1); final Location pos2 = PlotHelper.getPlotTopLoc(world, id); - for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) { - for (int j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) { + int i = 0; + int j = 0; + try { + for (i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) { + for (j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) { Chunk chunk = world.getChunkAt(i, j); boolean result = chunk.load(false); if (!result) { @@ -241,6 +244,11 @@ public class SchematicHandler { } } } + } + catch (Exception e) { + PlotMain.sendConsoleSenderMessage("&7 - Cannot save: corrupt chunk at "+(i/16)+", "+(j/16)); + return null; + } int width = pos2.getBlockX()-pos1.getBlockX(); int height = 256; int length = pos2.getBlockZ()-pos1.getBlockZ(); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index 3d47ff06e..00655b860 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -1,11 +1,13 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.C; @@ -22,11 +24,19 @@ import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore; public class Schematic extends SubCommand { public Schematic() { - super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, true); + super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false); // TODO command to fetch schematic from worldedit directory } - + + private int counter = 0; + private boolean running = false; + private Plot[] plots; + private int task; + + + + @Override public boolean execute(final Player plr, String... args) { if (args.length < 1) { @@ -38,6 +48,10 @@ public class Schematic extends SubCommand { SchematicHandler.Schematic schematic; switch (arg) { case "paste": + if (plr==null) { + PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE); + return false; + } if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste"); return false; @@ -51,8 +65,8 @@ public class Schematic extends SubCommand { break; } file = args[1]; - schematic = new SchematicHandler().getSchematic(file); - boolean s = new SchematicHandler().paste(plr.getLocation(), schematic, PlayerFunctions.getCurrentPlot(plr)); + schematic = SchematicHandler.getSchematic(file); + boolean s = SchematicHandler.paste(plr.getLocation(), schematic, PlayerFunctions.getCurrentPlot(plr)); if (s) { sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); } @@ -61,6 +75,10 @@ public class Schematic extends SubCommand { } break; case "test": + if (plr==null) { + PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE); + return false; + } if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test"); return false; @@ -70,7 +88,7 @@ public class Schematic extends SubCommand { break; } file = args[1]; - schematic = new SchematicHandler().getSchematic(file); + schematic = SchematicHandler.getSchematic(file); if (schematic == null) { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent"); break; @@ -95,39 +113,65 @@ public class Schematic extends SubCommand { return false; } if (args.length!=2) { - PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots schem exportall "); + PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall "); return false; } HashMap plotmap = PlotMain.getPlots(args[1]); if (plotmap==null || plotmap.size()==0) { - PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots schem exportall "); + PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); + return false; + } + if (running) { + PlayerFunctions.sendMessage(plr, "&cTask is already running."); return false; } PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while."); PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Found &c"+plotmap.size()+"&7 plots..."); - final Collection plots = plotmap.values(); - final World worldname = Bukkit.getWorld(args[1]); - Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { + final World worldObj = Bukkit.getWorld(args[1]); + final String worldname = Bukkit.getWorld(args[1]).getName(); + + final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); + + + this.plots = plotmap.values().toArray(new Plot[0]); + this.running = true; + this.counter = 0; + + task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { - - for (Plot plot:plots) { - CompoundTag schematic = SchematicHandler.getCompoundTag(worldname, plot.id); - if (schematic==null) { - PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id); - return; - } - boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+plot.id.x+"-"+plot.id.y+"-"+worldname+".schematic"); - - if (!result) { - PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id); - return; - } - PlayerFunctions.sendMessage(plr, "&7 - &aExport success: "+plot.id); + if (counter>=plots.length) { + PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &aFinished!"); + Bukkit.getScheduler().cancelTask(task); + return; } + final Plot plot = plots[counter]; + final CompoundTag sch = SchematicHandler.getCompoundTag(worldObj, plot.id); + if (sch==null) { + PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id); + } + else { + Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { + @Override + public void run() { + counter++; + PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); + boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+".schematic"); + + if (!result) { + PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id); + } + else { + PlayerFunctions.sendMessage(plr, "&7 - &aExport success: "+plot.id); + } + } + }); + } + counter++; } - }); + }, 20, 20); + break; case "export": case "save": if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { @@ -156,18 +200,18 @@ public class Schematic extends SubCommand { String[] split = args[2].split(";"); i = new PlotId(Integer.parseInt(split[0]),Integer.parseInt(split[1])); if (PlotMain.getPlots(world)==null || PlotMain.getPlots(world).get(i) == null) { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save "); + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); return false; } } catch (Exception e) { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save "); + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); return false; } } else { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots schem save "); + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); return false; } } @@ -182,7 +226,7 @@ public class Schematic extends SubCommand { PlayerFunctions.sendMessage(plr, "&cInvalid plot"); return; } - boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+i.x+"-"+i.y+"-"+world+".schematic"); + boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+i.x+","+i.y+","+world+".schematic"); if (!result) { PlayerFunctions.sendMessage(plr, "&cFailed to save schematic"); @@ -191,7 +235,6 @@ public class Schematic extends SubCommand { PlayerFunctions.sendMessage(plr, "&aSuccessfully saved schematic!"); } }); - break; default: sendMessage(plr, C.SCHEMATIC_MISSING_ARG); From 33acc95d92510ebf89b055610a6ae172b009a9a8 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 16:40:21 +1100 Subject: [PATCH 12/13] more fixes. --- .../plot/commands/Schematic.java | 73 +++++++++++++------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index 00655b860..23be122ee 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -143,6 +143,7 @@ public class Schematic extends SubCommand { public void run() { if (counter>=plots.length) { PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &aFinished!"); + running = false; Bukkit.getScheduler().cancelTask(task); return; } @@ -178,8 +179,12 @@ public class Schematic extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save"); return false; } - final PlotId i; + if (running) { + PlayerFunctions.sendMessage(plr, "&cTask is already running."); + return false; + } final String world; + final Plot p2; if (plr!=null) { if(!PlayerFunctions.isInPlot(plr)) { sendMessage(plr, C.NOT_IN_PLOT); @@ -190,7 +195,7 @@ public class Schematic extends SubCommand { sendMessage(plr, C.NO_PLOT_PERMS); return false; } - i = myplot.id; + p2 = myplot; world = plr.getWorld().getName(); } else { @@ -198,12 +203,12 @@ public class Schematic extends SubCommand { try { world = args[0]; String[] split = args[2].split(";"); - i = new PlotId(Integer.parseInt(split[0]),Integer.parseInt(split[1])); + PlotId i = new PlotId(Integer.parseInt(split[0]),Integer.parseInt(split[1])); if (PlotMain.getPlots(world)==null || PlotMain.getPlots(world).get(i) == null) { PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); return false; } - + p2 = PlotMain.getPlots(world).get(i); } catch (Exception e) { PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); @@ -216,25 +221,47 @@ public class Schematic extends SubCommand { } } - - - Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { - @Override - public void run() { - CompoundTag schematic = SchematicHandler.getCompoundTag(Bukkit.getWorld(world), i); - if (schematic==null) { - PlayerFunctions.sendMessage(plr, "&cInvalid plot"); - return; - } - boolean result = SchematicHandler.save(schematic, Settings.Web.PATH+"/"+i.x+","+i.y+","+world+".schematic"); - - if (!result) { - PlayerFunctions.sendMessage(plr, "&cFailed to save schematic"); - return; - } - PlayerFunctions.sendMessage(plr, "&aSuccessfully saved schematic!"); - } - }); + final Plugin plugin2 = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); + + + this.plots = new Plot[] {p2} ; + this.running = true; + this.counter = 0; + + task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin2, new Runnable() { + @Override + public void run() { + if (counter>=plots.length) { + PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &aFinished!"); + running = false; + Bukkit.getScheduler().cancelTask(task); + return; + } + final Plot plot = plots[counter]; + final CompoundTag sch = SchematicHandler.getCompoundTag(Bukkit.getWorld(world), plot.id); + if (sch==null) { + PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id); + } + else { + Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { + @Override + public void run() { + counter++; + PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); + boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+".schematic"); + + if (!result) { + PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id); + } + else { + PlayerFunctions.sendMessage(plr, "&7 - &aExport success: "+plot.id); + } + } + }); + } + counter++; + } + }, 20, 60); break; default: sendMessage(plr, C.SCHEMATIC_MISSING_ARG); From 768cb8b29339f46d818f8551bf023c7d1714d76d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 20:09:26 +1100 Subject: [PATCH 13/13] updated schematic format --- .../intellectualcrafters/plot/commands/Schematic.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index 23be122ee..981dbb663 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -18,6 +18,7 @@ import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.SchematicHandler; import com.intellectualcrafters.plot.Settings; +import com.intellectualcrafters.plot.UUIDHandler; import com.intellectualcrafters.plot.database.DBFunc; import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore; @@ -149,6 +150,8 @@ public class Schematic extends SubCommand { } final Plot plot = plots[counter]; final CompoundTag sch = SchematicHandler.getCompoundTag(worldObj, plot.id); + String o = UUIDHandler.getName(plot.owner); + final String owner = o==null ? "unknown" : o ; if (sch==null) { PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id); } @@ -158,7 +161,7 @@ public class Schematic extends SubCommand { public void run() { counter++; PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); - boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+".schematic"); + boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+","+owner+".schematic"); if (!result) { PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id); @@ -239,6 +242,8 @@ public class Schematic extends SubCommand { } final Plot plot = plots[counter]; final CompoundTag sch = SchematicHandler.getCompoundTag(Bukkit.getWorld(world), plot.id); + String o = UUIDHandler.getName(plot.owner); + final String owner = o==null ? "unknown" : o ; if (sch==null) { PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c"+plot.id); } @@ -248,7 +253,7 @@ public class Schematic extends SubCommand { public void run() { counter++; PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); - boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+".schematic"); + boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+world+","+owner+".schematic"); if (!result) { PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id);