From f0e6e853a631a585e778acc68d070d6c6aa4fe73 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Tue, 20 Nov 2012 09:09:16 +0100 Subject: [PATCH 1/8] v1.4.0b: - Fix: CmdBlocker not active in survival mode --- plugin.yml | 2 +- pom.xml | 2 +- .../cmdblock/CommandBlocker.java | 25 +++++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/plugin.yml b/plugin.yml index e21f593..16d6cff 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.Core -version: 1.4.0a +version: 1.4.0b softdepend: [WorldGuard, WorldEdit, MultiInv] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: diff --git a/pom.xml b/pom.xml index a1c06d0..5d20281 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.jaschastarke LimitedCreative LimitedCreative - 1.4.0a + 1.4.0b https://github.com/possi/LimitedCreative scm:git:git://github.com/possi/LimitedCreative.git diff --git a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java index 3c90e3b..5cc0986 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java @@ -2,6 +2,7 @@ package de.jaschastarke.minecraft.limitedcreative.cmdblock; import static de.jaschastarke.minecraft.utils.Locale.L; +import org.bukkit.GameMode; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -22,17 +23,19 @@ public class CommandBlocker { class Listener implements org.bukkit.event.Listener { @EventHandler public void onPreCommand(PlayerCommandPreprocessEvent event) { - String cmd = event.getMessage(); - if (cmd.startsWith("/")) { // just to be sure ;) - cmd = cmd.substring(1); - for (ICmdBlockEntry blockentry : plugin.config.getCommandBlockList()) { - if (blockentry.test(cmd)) { - LCPlayer player = Players.get(event.getPlayer()); - if (!player.hasPermission(Perms.CmdBlock.ALL)) { - Core.debug("CmdBlock: "+event.getPlayer().getName()+": '/"+cmd+"' blocked by rule '"+blockentry.toString()+"'"); - event.setCancelled(true); - event.getPlayer().sendMessage(L("cmdblock.blocked")); - return; + if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { + String cmd = event.getMessage(); + if (cmd.startsWith("/")) { // just to be sure ;) + cmd = cmd.substring(1); + for (ICmdBlockEntry blockentry : plugin.config.getCommandBlockList()) { + if (blockentry.test(cmd)) { + LCPlayer player = Players.get(event.getPlayer()); + if (!player.hasPermission(Perms.CmdBlock.ALL)) { + Core.debug("CmdBlock: "+event.getPlayer().getName()+": '/"+cmd+"' blocked by rule '"+blockentry.toString()+"'"); + event.setCancelled(true); + event.getPlayer().sendMessage(L("cmdblock.blocked")); + return; + } } } } From e726509472bebee3729413eb3dd5b572f927797c Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Fri, 7 Dec 2012 18:29:03 +0100 Subject: [PATCH 2/8] Tag Serialization: - Store and restore names (only in Unsafe save) --- .../limitedcreative/store/InvConfStorage.java | 14 +++- .../store/NBTagSerializer.java | 75 +++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java diff --git a/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java b/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java index f81d49c..f94318d 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java @@ -78,8 +78,14 @@ abstract public class InvConfStorage extends PlayerInventoryStorage { } protected Object serialize(ItemStack is) { - if (Core.plugin.config.getUnsafeStorage()) - return is.serialize(); + if (Core.plugin.config.getUnsafeStorage()) { + Map serialized = is.serialize(); + Map tagData = NBTagSerializer.serializeTags(is); + if (tagData != null) { + serialized.put("tag", tagData); + } + return serialized; + } return is; } @@ -100,6 +106,10 @@ abstract public class InvConfStorage extends PlayerInventoryStorage { } } } + if (sect.contains("tag")) { + Map map = sect.getConfigurationSection("tag").getValues(false); + result = NBTagSerializer.unserializeTags(result, map); + } return result; } else if (is instanceof Map) { return ItemStack.deserialize((Map) is); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java b/src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java new file mode 100644 index 0000000..51e005d --- /dev/null +++ b/src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java @@ -0,0 +1,75 @@ +package de.jaschastarke.minecraft.limitedcreative.store; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.server.NBTTagCompound; + +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; + +public class NBTagSerializer { + + public static Map serializeTags(ItemStack cis) { + Map map = null; + NBTTagCompound tag = getTag(cis); + if (tag != null && tag.getCompound("display") != null) { + NBTTagCompound display = tag.getCompound("display"); + if (display.hasKey("Name")) { + map = new HashMap(); + map.put("name", display.getString("Name")); + } + } + return map; + } + + public static ItemStack unserializeTags(ItemStack cis, Map data) { + if (data.size() > 0) { + if (!(cis instanceof CraftItemStack)) { + cis = new CraftItemStack(cis); + } + NBTTagCompound nbt = getTag(cis, true); + + if (data.containsKey("name")) { + NBTTagCompound display; + if (nbt.hasKey("display")) { + display = nbt.getCompound("display"); + } else { + display = new NBTTagCompound("display"); + nbt.setCompound("display", display); + } + display.setString("Name", (String) data.get("name")); + } + } + return cis; + } + + private static NBTTagCompound getTag(ItemStack stack, boolean force) { + NBTTagCompound nbt = getTag(stack); + if (nbt == null && force) { + nbt = new NBTTagCompound(); + getMCItemStack(stack).setTag(nbt); + } + return nbt; + } + + private static NBTTagCompound getTag(ItemStack stack) { + net.minecraft.server.ItemStack is = getMCItemStack(stack); + if (is != null) { + return is.getTag(); + } else { + return null; + } + } + + private static net.minecraft.server.ItemStack getMCItemStack(ItemStack stack) { + if (stack instanceof CraftItemStack) { + return getMCItemStack((CraftItemStack) stack); + } else { + return null; + } + } + private static net.minecraft.server.ItemStack getMCItemStack(CraftItemStack stack) { + return stack.getHandle(); + } +} From 679978a56117df672284d8a1d1d93c292e3d4171 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Fri, 7 Dec 2012 20:03:15 +0100 Subject: [PATCH 3/8] v1.4.5b: - fixed localization encoding (again) - Bench-Block now also blocks Villagers and Anvils - Interacting with specific blocks is now also blocked cross regions --- config.yml | 2 +- lang/de_DE.yml | 12 +++--- lang/en_US.yml | 2 + plugin.yml | 2 +- pom.xml | 9 +++- .../minecraft/limitedcreative/LCPlayer.java | 8 ++++ .../listeners/LimitListener.java | 6 ++- .../regions/RegionListener.java | 41 +++++++++++++++++++ 8 files changed, 72 insertions(+), 10 deletions(-) diff --git a/config.yml b/config.yml index ba5498f..dc2bcf1 100644 --- a/config.yml +++ b/config.yml @@ -90,7 +90,7 @@ limit: button: false # BlockWorkbenches - # When enabled also blocks usage of workbenches like chests (so the creative player never can see his inventar). + # When enabled also blocks usage of workbenches, anvils and vendor-villagers like chests. # default: false workbench: false diff --git a/lang/de_DE.yml b/lang/de_DE.yml index 2b63eac..ca1fafe 100644 --- a/lang/de_DE.yml +++ b/lang/de_DE.yml @@ -13,9 +13,9 @@ basic: command: player: Spieler switch: - survival: ÿndert den Spiel-Modus des Charakters zu ÿberleben - creative: ÿndert den Spiel-Modus des Charakters zu Kreativ - adventure: ÿndert den Spiel-Modus des Charakters zu Abenteuer + survival: Ändert den Spiel-Modus des Charakters zu Überleben + creative: Ändert den Spiel-Modus des Charakters zu Kreativ + adventure: Ändert den Spiel-Modus des Charakters zu Abenteuer config: overview: "[Einstellung] - liste durch weglassen" settings: "Verfügbare Einstellungen: " @@ -57,10 +57,12 @@ blocked: button: Im Kreativ-Modus kann nicht mit Buttons interagiert werden lever: Im Kreativ-Modus kann nicht mit Schaltern interagiert werden survival_flying: Du solltest auf dem Boden stehen wenn du Kreativ-Regionen verlässt - outside_place: Du kannst keine Blöcke auÿerhalb von Spiel-Modus-Regionen setzen - outside_break: Du kannst keine Blöcke auÿerhalb von Spiel-Modus-Regionen zerstören + outside_place: Du kannst keine Blöcke außerhalb von Spiel-Modus-Regionen setzen + outside_break: Du kannst keine Blöcke außerhalb von Spiel-Modus-Regionen zerstören + outside_interact: Du kannst nicht mit Blöcken außerhalb von Spiel-Modus-Regionen interagieren inside_place: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen setzen inside_break: Du kannst keine Blöcke innerhalb von Spiel-Modus-Regionen zerstören + inside_interact: Du kannst nicht mit Blöcken innerhalb von Spiel-Modus-Regionen interagieren use: Du darfst diese Art von Gegenständen im Kreativ-Modus verwenden place: Du darfst diese Art von Blöcken im Kreativ-Modus nicht setzen break: Du darfst diese Art von Blöcken im Kreativ-Modus nicht zerstören diff --git a/lang/en_US.yml b/lang/en_US.yml index ad4779a..63a4f4e 100644 --- a/lang/en_US.yml +++ b/lang/en_US.yml @@ -59,8 +59,10 @@ blocked: survival_flying: You should stay on ground, when leaving a creative-area outside_place: You can not place blocks outside of the gamemode-area outside_break: You can not destroy blocks outside of the gamemode-area + outside_interact: You can not interact with blocks outside of the gamemode-area inside_place: You can not place blocks inside of the gamemode-area inside_break: You can not destroy blocks inside of the gamemode-area + inside_interact: You can not interact with blocks inside of the gamemode-area use: You are not allowed to use this type of item place: You are not allowed to place this type of block break: You are not allowed to break this type of block diff --git a/plugin.yml b/plugin.yml index 16d6cff..41fed30 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.Core -version: 1.4.0b +version: 1.4.5a softdepend: [WorldGuard, WorldEdit, MultiInv] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: diff --git a/pom.xml b/pom.xml index 5d20281..16a8953 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.jaschastarke LimitedCreative LimitedCreative - 1.4.0b + 1.4.5a https://github.com/possi/LimitedCreative scm:git:git://github.com/possi/LimitedCreative.git @@ -72,8 +72,13 @@ org.bukkit bukkit - 1.4.2-R0.2 + 1.4.5-R0.2 + + org.bukkit + craftbukkit + 1.4.5-R0.2 + com.sk89q worldguard diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java index 8b45d9e..0b2bf3a 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java @@ -356,6 +356,14 @@ public class LCPlayer { event.getPlayer().sendMessage(L("blocked.chest")); event.setCancelled(true); } + public void onBenchAccess(PlayerInteractEntityEvent event) { + if (!plugin.config.getBenchBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE) + return; + if (hasPermission(Perms.NoLimit.CHEST)) + return; + event.getPlayer().sendMessage(L("blocked.chest")); + event.setCancelled(true); + } public void onSignAccess(PlayerInteractEvent event) { if (!plugin.config.getSignBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE) return; diff --git a/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java b/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java index 61b347b..aa5700a 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java @@ -29,6 +29,7 @@ import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.StorageMinecart; +import org.bukkit.entity.Villager; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; @@ -98,7 +99,7 @@ public class LimitListener implements Listener { player.onSignAccess(event); } else if (block.getState() instanceof Lever || block.getState() instanceof Button) { player.onButtonAccess(event); - } else if (block.getType() == Material.WORKBENCH) { + } else if (block.getType() == Material.WORKBENCH || block.getType() == Material.ANVIL) { player.onBenchAccess(event); } } @@ -120,6 +121,7 @@ public class LimitListener implements Listener { // Temporary Solution: While dropping of Items is prevented we don't allow Interaction with ItemFrames, so no // Items can be "placed" anywhere. + // TODO: Improve Configuration if (!player.hasPermission(Perms.NoLimit.DROP)) { if (entity instanceof ItemFrame && plugin.config.getRemoveDrop()) { event.setCancelled(true); @@ -130,6 +132,8 @@ public class LimitListener implements Listener { if (entity instanceof StorageMinecart) { player.onChestAccess(event); + } else if (entity instanceof Villager) { + player.onBenchAccess(event); } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java index 6144a66..a8b6b49 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java @@ -6,21 +6,28 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.Sign; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.material.Button; +import org.bukkit.material.Lever; import de.jaschastarke.minecraft.limitedcreative.Core; import de.jaschastarke.minecraft.limitedcreative.LCPlayer; import de.jaschastarke.minecraft.limitedcreative.Players; +import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener; import de.jaschastarke.minecraft.utils.Util; import de.jaschastarke.minecraft.worldguard.ApplicableRegions; import de.jaschastarke.minecraft.worldguard.CRegionManager; @@ -56,6 +63,40 @@ public class RegionListener implements Listener { whenBlockBreak(event, event.getEntity().getLocation().getBlock(), eventPlayer); } } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (MainListener.isCancelled(event)) + return; + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + + Block block = event.getClickedBlock(); + + if (block.getState() instanceof InventoryHolder || block.getType() == Material.ENDER_CHEST || // Workaround, Bukkit not recognize a Enderchest + block.getState() instanceof Sign || + block.getState() instanceof Lever || block.getState() instanceof Button || + block.getType() == Material.WORKBENCH || block.getType() == Material.ANVIL) { + + LCPlayer player = Players.get(event.getPlayer()); + boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), block.getLocation()); + + if (player.isActiveRegionGameMode() && diffrent_region) { + // do not break outside of "gamemod-change-region" when in the region + if (rm.getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != player.getActiveRegionGameMode()) { + event.getPlayer().sendMessage(L("blocked.outside_interact")); + event.setCancelled(true); + } + } else if (diffrent_region) { + // do not break inside of "survial-region in creative world" when outside + if (rm.getRegionSet(block).getFlag(Flags.GAMEMODE) != null) { + event.getPlayer().sendMessage(L("blocked.inside_interact")); + event.setCancelled(true); + } + } + } + } private void whenBlockBreak(Cancellable event, Block block, Player eventPlayer) { LCPlayer player = Players.get(eventPlayer); From a53962804f86c6ed1a7c235b8b9576568fa899c2 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 15 Dec 2012 12:21:15 +0100 Subject: [PATCH 4/8] Fixes missing dep. for maven clean build with jenkins --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 16a8953..b05cc59 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,12 @@ https://github.com/possi/LimitedCreative/tree/master + opt-dep @@ -78,6 +84,12 @@ org.bukkit craftbukkit 1.4.5-R0.2 + + + com.sk89q + worldedit + 5.4.4 + compile com.sk89q From 7a471ea05e7f39dde3c630bbcf1576e60005e014 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 15 Dec 2012 14:34:56 +0100 Subject: [PATCH 5/8] Fixed a java backward compatibility issue, to use jenkins maven build --- .../minecraft/worldguard/ApplicableRegions.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/de/jaschastarke/minecraft/worldguard/ApplicableRegions.java b/src/de/jaschastarke/minecraft/worldguard/ApplicableRegions.java index 80e563c..c74ab3f 100644 --- a/src/de/jaschastarke/minecraft/worldguard/ApplicableRegions.java +++ b/src/de/jaschastarke/minecraft/worldguard/ApplicableRegions.java @@ -65,33 +65,34 @@ public class ApplicableRegions { } @SuppressWarnings("unchecked") - private , V> void extendRegionFlags() { + private void extendRegionFlags() { for (ProtectedRegion pr : regions) { for (FlagValue data : mgr.region(pr).getFlags()) { - T flag = (T) data.getFlag(); - V value = (V) data.getValue(); + Flag flag = (Flag) data.getFlag(); + Object value = data.getValue(); pr.setFlag(flag, value); } } if (mgr.getGlobalRegion() != null) { for (FlagValue data : mgr.region(mgr.getGlobalRegion()).getFlags()) { - T flag = (T) data.getFlag(); - V value = (V) data.getValue(); + Flag flag = (Flag) data.getFlag(); + Object value = data.getValue(); mgr.getGlobalRegion().setFlag(flag, value); } } } + @SuppressWarnings("unchecked") - private , V> void contractRegionFlags() { + private void contractRegionFlags() { for (ProtectedRegion pr : regions) { for (FlagValue data : mgr.region(pr).getFlags()) { - T flag = (T) data.getFlag(); + Flag flag = (Flag) data.getFlag(); pr.setFlag(flag, null); } } if (mgr.getGlobalRegion() != null) { for (FlagValue data : mgr.region(mgr.getGlobalRegion()).getFlags()) { - T flag = (T) data.getFlag(); + Flag flag = (Flag) data.getFlag(); mgr.getGlobalRegion().setFlag(flag, null); } } From 4bbc6a38c4ad69181bab425c080e9e681a85d175 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 22 Dec 2012 23:14:14 +0100 Subject: [PATCH 6/8] v1.4.6a: - Moved Maven repository to automatic jenkin-build-repo by cloudbees (free hosting) - Removed Unsafe storage item serialization as it is now more complex than i'd like to manage manually * (restoring should still work, so no inventory loss) --- config.yml | 7 -- plugin.yml | 2 +- pom.xml | 33 ++++---- .../limitedcreative/Configuration.java | 4 +- .../minecraft/limitedcreative/Inventory.java | 11 +-- .../limitedcreative/store/Fallback.java | 8 +- .../limitedcreative/store/InvConfStorage.java | 39 ++++++---- .../store/NBTagSerializer.java | 75 ------------------- 8 files changed, 52 insertions(+), 127 deletions(-) delete mode 100644 src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java diff --git a/config.yml b/config.yml index dc2bcf1..6dddd84 100644 --- a/config.yml +++ b/config.yml @@ -18,13 +18,6 @@ store: # default: true creative: true - # UnsafeStore (for storing invalid enchants) - # By default the new and upgrade-safe storage method for items is used. This method doesn't allow the use - # of "invalid" enchants, like given by different plugins. Enable it, to allow invalid enchants (not recommended). - # (May be removed with 1.2, as bukkit then allows unsafed enchants by default) - # default: false - unsafe: false - # CreativeArmor # When set, all creative Player automatically wears the given items as Armor. So they are better seen by other # Players. diff --git a/plugin.yml b/plugin.yml index 41fed30..ffdaacb 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.Core -version: 1.4.5a +version: 1.4.6a softdepend: [WorldGuard, WorldEdit, MultiInv] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: diff --git a/pom.xml b/pom.xml index b05cc59..ade8e9c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.jaschastarke LimitedCreative LimitedCreative - 1.4.5a + 1.4.6a https://github.com/possi/LimitedCreative scm:git:git://github.com/possi/LimitedCreative.git @@ -11,17 +11,14 @@ https://github.com/possi/LimitedCreative/tree/master - - de-jaschastarke + de-jas-mvn https://repository-possi.forge.cloudbees.com/release - --> - - - opt-dep - http://dl.dropbox.com/u/5023975/mvn-repo - + bukkit-repo @@ -37,10 +34,16 @@ onarandombox http://repo.onarandombox.com/content/groups/public + vault-repo http://ci.herocraftonline.com/plugin/repository/everything + ${basedir}/src @@ -78,28 +81,28 @@ org.bukkit bukkit - 1.4.5-R0.2 + 1.4.6-R0.1 org.bukkit craftbukkit - 1.4.5-R0.2 + 1.4.6-R0.1 com.sk89q worldedit - 5.4.4 + 5.4.5 compile com.sk89q worldguard - 5.6.3 + 5.6.6-SNAPSHOT uk.org.whoami authme - 2.6.7b5 + 2.7.0b2 com.onarandombox.multiversecore @@ -109,7 +112,7 @@ com.cypherx xauth - 2.0.20 + 2.0.26 diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java index 92b901f..2c2ede7 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java @@ -122,9 +122,9 @@ public class Configuration { public boolean getStoreCreative() { return this.getBoolean(Option.STORECREATIVE); } - public boolean getUnsafeStorage() { + /*public boolean getUnsafeStorage() { return c.getBoolean("store.unsafe", false); - } + }*/ public String getInventoryFolder() { return c.getString("store.folder", "inventories"); } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java b/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java index cf881f9..702bd60 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java @@ -17,9 +17,6 @@ */ package de.jaschastarke.minecraft.limitedcreative; -import static de.jaschastarke.minecraft.utils.Locale.L; - -import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -79,11 +76,11 @@ public class Inventory { try { storage.load(this, Target.getTarget(gm)); } catch (IllegalArgumentException e) { - if (Core.plugin.config.getUnsafeStorage()) { + //if (Core.plugin.config.getUnsafeStorage()) { throw e; - } else { - getPlayer().sendMessage(ChatColor.DARK_RED + L("exception.storage.load")); - } + //} else { + //getPlayer().sendMessage(ChatColor.DARK_RED + L("exception.storage.load")); + //} } } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/store/Fallback.java b/src/de/jaschastarke/minecraft/limitedcreative/store/Fallback.java index 7835c75..b7a545e 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/store/Fallback.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/store/Fallback.java @@ -26,8 +26,6 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import de.jaschastarke.minecraft.limitedcreative.Core; - public class Fallback { public static void loadVersion1(PlayerInventory inv, ConfigurationSection sect) { @@ -64,14 +62,14 @@ public class Fallback { } public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) { - if (!Core.plugin.config.getUnsafeStorage()) { + //if (!Core.plugin.config.getUnsafeStorage()) { section.set(path, item); - } else { // unsafe enchants fallback + /*} else { // unsafe enchants fallback Map serialize = item.serialize(); if (serialize.containsKey("type") && serialize.get("type") instanceof Material) serialize.put("type", serialize.get("type").toString()); section.createSection(path, serialize); - }; + };*/ } public static ItemStack sectionGetItem(ConfigurationSection section, String path) { if (section.isItemStack(path)) { diff --git a/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java b/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java index f94318d..0f48b5f 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/store/InvConfStorage.java @@ -24,6 +24,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; import de.jaschastarke.minecraft.limitedcreative.Core; import de.jaschastarke.minecraft.limitedcreative.Inventory; @@ -33,9 +34,9 @@ abstract public class InvConfStorage extends PlayerInventoryStorage { public void store(Inventory pinv, ConfigurationSection sect) { PlayerInventory inv = pinv.getPlayer().getInventory(); - sect.set("version", 2); - if (Core.plugin.config.getUnsafeStorage()) - sect.set("unsafe", true); + sect.set("version", 4); + /*if (Core.plugin.config.getUnsafeStorage()) + sect.set("unsafe", true);*/ storeItems(sect.createSection("armor"), inv.getArmorContents()); storeItems(sect.createSection("inv"), inv.getContents()); } @@ -77,15 +78,10 @@ abstract public class InvConfStorage extends PlayerInventoryStorage { return items; } - protected Object serialize(ItemStack is) { + protected Object serialize(ItemStack is) {/* if (Core.plugin.config.getUnsafeStorage()) { - Map serialized = is.serialize(); - Map tagData = NBTagSerializer.serializeTags(is); - if (tagData != null) { - serialized.put("tag", tagData); - } - return serialized; - } + return getRecursiveSerialized(is); + }*/ return is; } @@ -98,7 +94,7 @@ abstract public class InvConfStorage extends PlayerInventoryStorage { int amount = sect.getInt("amount", 1); ItemStack result = new ItemStack(type, amount, damage); - if (sect.contains("enchantments")) { + if (sect.contains("enchantments")) { // conf-version 2 for (Map.Entry entry : sect.getConfigurationSection("enchantments").getValues(false).entrySet()) { Enchantment enchantment = Enchantment.getByName(entry.getKey().toString()); if ((enchantment != null) && (entry.getValue() instanceof Integer)) { @@ -106,9 +102,11 @@ abstract public class InvConfStorage extends PlayerInventoryStorage { } } } - if (sect.contains("tag")) { - Map map = sect.getConfigurationSection("tag").getValues(false); - result = NBTagSerializer.unserializeTags(result, map); + if (sect.contains("tag")) { // Backward compatibility for 1.4.5-R0.2; Was Conf-Version 2, but should be 3 ;) + ConfigurationSection tag = sect.getConfigurationSection("tag"); + ItemMeta meta = result.getItemMeta(); + meta.setDisplayName(tag.getString("name")); + result.setItemMeta(meta); } return result; } else if (is instanceof Map) { @@ -118,4 +116,15 @@ abstract public class InvConfStorage extends PlayerInventoryStorage { return null; } } + + /*protected static Map getRecursiveSerialized(ConfigurationSerializable conf) { + Map serialized = new HashMap(conf.serialize()); // de-immutable + for (Map.Entry entry : serialized.entrySet()) { + if (entry.getValue() instanceof ConfigurationSerializable) { + entry.setValue(getRecursiveSerialized((ConfigurationSerializable) entry.getValue())); // immutable + //serialized.put(entry.getKey(), getRecursiveSerialized((ConfigurationSerializable) entry.getValue())); + } + } + return serialized; + }*/ } diff --git a/src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java b/src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java deleted file mode 100644 index 51e005d..0000000 --- a/src/de/jaschastarke/minecraft/limitedcreative/store/NBTagSerializer.java +++ /dev/null @@ -1,75 +0,0 @@ -package de.jaschastarke.minecraft.limitedcreative.store; - -import java.util.HashMap; -import java.util.Map; - -import net.minecraft.server.NBTTagCompound; - -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -public class NBTagSerializer { - - public static Map serializeTags(ItemStack cis) { - Map map = null; - NBTTagCompound tag = getTag(cis); - if (tag != null && tag.getCompound("display") != null) { - NBTTagCompound display = tag.getCompound("display"); - if (display.hasKey("Name")) { - map = new HashMap(); - map.put("name", display.getString("Name")); - } - } - return map; - } - - public static ItemStack unserializeTags(ItemStack cis, Map data) { - if (data.size() > 0) { - if (!(cis instanceof CraftItemStack)) { - cis = new CraftItemStack(cis); - } - NBTTagCompound nbt = getTag(cis, true); - - if (data.containsKey("name")) { - NBTTagCompound display; - if (nbt.hasKey("display")) { - display = nbt.getCompound("display"); - } else { - display = new NBTTagCompound("display"); - nbt.setCompound("display", display); - } - display.setString("Name", (String) data.get("name")); - } - } - return cis; - } - - private static NBTTagCompound getTag(ItemStack stack, boolean force) { - NBTTagCompound nbt = getTag(stack); - if (nbt == null && force) { - nbt = new NBTTagCompound(); - getMCItemStack(stack).setTag(nbt); - } - return nbt; - } - - private static NBTTagCompound getTag(ItemStack stack) { - net.minecraft.server.ItemStack is = getMCItemStack(stack); - if (is != null) { - return is.getTag(); - } else { - return null; - } - } - - private static net.minecraft.server.ItemStack getMCItemStack(ItemStack stack) { - if (stack instanceof CraftItemStack) { - return getMCItemStack((CraftItemStack) stack); - } else { - return null; - } - } - private static net.minecraft.server.ItemStack getMCItemStack(CraftItemStack stack) { - return stack.getHandle(); - } -} From 9773ce0343c6e1407defe7a9424fbd8c19eef0b4 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 22 Dec 2012 23:28:28 +0100 Subject: [PATCH 7/8] fixed authme maven dep. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ade8e9c..0b3260d 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,7 @@ uk.org.whoami authme - 2.7.0b2 + 2.7.0 com.onarandombox.multiversecore From 6ff79cfc9e30490810bb1de8d8062c94b45e8dfc Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 12 Jan 2013 14:52:29 +0100 Subject: [PATCH 8/8] v1.4.6b: - Support AuthMe Inventory-Events: * So login and logout _should_ never again f*ckup inventories --- plugin.yml | 2 +- pom.xml | 4 +- .../integration/AbstractCommunicator.java | 11 +++- .../integration/AuthMeInventories.java | 51 +++++++++++++++++++ .../minecraft/integration/Communicator.java | 15 +++++- .../minecraft/limitedcreative/Core.java | 3 ++ .../minecraft/limitedcreative/LCPlayer.java | 36 +++++++------ src/de/jaschastarke/minecraft/utils/Util.java | 35 +++++++++++++ 8 files changed, 136 insertions(+), 21 deletions(-) create mode 100644 src/de/jaschastarke/minecraft/integration/AuthMeInventories.java diff --git a/plugin.yml b/plugin.yml index ffdaacb..60d6a68 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LimitedCreative main: de.jaschastarke.minecraft.limitedcreative.Core -version: 1.4.6a +version: 1.4.6b softdepend: [WorldGuard, WorldEdit, MultiInv] dev-url: http://dev.bukkit.org/server-mods/limited-creative/ commands: diff --git a/pom.xml b/pom.xml index 0b3260d..4aeefc4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.jaschastarke LimitedCreative LimitedCreative - 1.4.6a + 1.4.6b https://github.com/possi/LimitedCreative scm:git:git://github.com/possi/LimitedCreative.git @@ -102,7 +102,7 @@ uk.org.whoami authme - 2.7.0 + 2.7.1 com.onarandombox.multiversecore diff --git a/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java b/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java index 4f458f3..3fc454b 100644 --- a/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java +++ b/src/de/jaschastarke/minecraft/integration/AbstractCommunicator.java @@ -20,6 +20,8 @@ package de.jaschastarke.minecraft.integration; //import java.util.HashMap; //import java.util.Map; +import static de.jaschastarke.minecraft.utils.Util.compareVersion; + //import org.bukkit.event.EventHandler; //import org.bukkit.event.Listener; /*import org.bukkit.event.server.PluginDisableEvent; @@ -27,7 +29,7 @@ import org.bukkit.event.server.PluginEnableEvent;*/ import org.bukkit.plugin.java.JavaPlugin; abstract public class AbstractCommunicator /*implements Listener*/ { - private JavaPlugin plugin; + protected JavaPlugin plugin; //private Map, CommunicationBridge> bridges = new HashMap, CommunicationBridge>(); public AbstractCommunicator(JavaPlugin plugin) { @@ -37,6 +39,13 @@ abstract public class AbstractCommunicator /*implements Listener*/ { protected boolean isPluginEnabled(String plugin) { return this.plugin.getServer().getPluginManager().isPluginEnabled(plugin); } + protected boolean isPluginEnabled(String plugin, String minVersion) { + if (isPluginEnabled(plugin)) { + String ver = this.plugin.getServer().getPluginManager().getPlugin(plugin).getDescription().getVersion(); + return compareVersion(ver, minVersion) > 0; + } + return false; + } /*@SuppressWarnings("unchecked") protected T getBridge(Class cls) { if (!bridges.containsKey(cls)) { diff --git a/src/de/jaschastarke/minecraft/integration/AuthMeInventories.java b/src/de/jaschastarke/minecraft/integration/AuthMeInventories.java new file mode 100644 index 0000000..a87754a --- /dev/null +++ b/src/de/jaschastarke/minecraft/integration/AuthMeInventories.java @@ -0,0 +1,51 @@ +package de.jaschastarke.minecraft.integration; + +import org.bukkit.GameMode; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import uk.org.whoami.authme.events.RestoreInventoryEvent; +import uk.org.whoami.authme.events.StoreInventoryEvent; + +import de.jaschastarke.minecraft.limitedcreative.Core; +import de.jaschastarke.minecraft.limitedcreative.LCPlayer; +import de.jaschastarke.minecraft.limitedcreative.Players; + +public class AuthMeInventories implements Listener { + public AuthMeInventories(JavaPlugin plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void onStoreInventory(StoreInventoryEvent event) { + Core.debug("AuthMe Store Event: "+event.getPlayer().getName()); + LCPlayer player = Players.get(event.getPlayer()); + + event.getPlayer().closeInventory(); + GameMode cgm = event.getPlayer().getGameMode(); + + if (cgm == GameMode.ADVENTURE && !Core.plugin.config.getAdventureInv()) + cgm = GameMode.SURVIVAL; + + if (cgm != GameMode.CREATIVE || Core.plugin.config.getStoreCreative()) { + player.getInv().save(cgm); + } + } + @EventHandler + public void onRestoreInventory(RestoreInventoryEvent event) { + Core.debug("AuthMe Restore Event: "+event.getPlayer().getName()); + LCPlayer player = Players.get(event.getPlayer()); + + event.getPlayer().closeInventory(); + GameMode cgm = event.getPlayer().getGameMode(); + + if (cgm == GameMode.ADVENTURE && !Core.plugin.config.getAdventureInv()) + cgm = GameMode.SURVIVAL; + + if (player.getInv().isStored(cgm)) { + player.getInv().load(cgm); + event.setCancelled(true); + } + } +} diff --git a/src/de/jaschastarke/minecraft/integration/Communicator.java b/src/de/jaschastarke/minecraft/integration/Communicator.java index 283c085..2af494a 100644 --- a/src/de/jaschastarke/minecraft/integration/Communicator.java +++ b/src/de/jaschastarke/minecraft/integration/Communicator.java @@ -31,12 +31,25 @@ public class Communicator extends AbstractCommunicator { } public boolean isLoggedIn(Player player) { - if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedInComplete(player)) + if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedIn(player)) return false; if (isPluginEnabled("xAuth") && !xAuth.isLoggedInNotGuest(player)) return false; return true; } + + public boolean isLoggedInComplete(Player player) { + if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedInComplete(player)) + return false; + return true; + } + + + public void hookAuthInvs() { + if (isPluginEnabled("AuthMe", "2.7.0b2")) { + new AuthMeInventories(this.plugin); + } + } public boolean isCreative(World world) { boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE; diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Core.java b/src/de/jaschastarke/minecraft/limitedcreative/Core.java index f221a4e..f8839da 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Core.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Core.java @@ -76,6 +76,9 @@ public class Core extends JavaPlugin { warn(L("basic.conflict", "MultiInv", L("basic.feature.store"))); config.setTempStoreEnabled(false); } + if (config.getStoreEnabled()) { + com.hookAuthInvs(); + } getServer().getPluginManager().registerEvents(new MainListener(this), this); // 2nd Feature: Creative Limitations (Restrictions) diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java index 0b2bf3a..26599fa 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java @@ -62,7 +62,7 @@ public class LCPlayer { //name = player.getName(); //touch(); - if (!this.isActiveRegionGameMode(player.getGameMode())) { + if (!this.isActiveRegionGameMode(player.getGameMode()) && plugin.com.isLoggedInComplete(getPlayer())) { setInPermanentGameMode(player.getGameMode()); } } @@ -170,22 +170,24 @@ public class LCPlayer { public boolean onSetGameMode(GameMode gm) { Core.debug(getName() + " going into " + gm); - if (isActiveRegionGameMode()) { // change to the other gamemode as the area defines - if (!isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows - if (!plugin.config.getRegionOptional() && !hasPermission(Perms.REGIONS_BYPASS)) { - getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase())); - Core.debug("... denied"); - return false; + if (plugin.com.isLoggedInComplete(getPlayer())) { // if authme is changing GameMode before going to teleport, this should be remembered + if (isActiveRegionGameMode()) { // change to the other gamemode as the area defines + if (!isActiveRegionGameMode(gm)) { // only when we are not switching to the mode the region allows + if (!plugin.config.getRegionOptional() && !hasPermission(Perms.REGIONS_BYPASS)) { + getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase())); + Core.debug("... denied"); + return false; + } else { + setOptionalRegionGameMode(gm); + } } else { - setOptionalRegionGameMode(gm); + // we are changing to the mode the region defines, thats not permanent + setOptionalRegionGameMode(null); + setInPermanentGameMode(null); } } else { - // we are changing to the mode the region defines, thats not permanent - setOptionalRegionGameMode(null); - setInPermanentGameMode(null); + setInPermanentGameMode(gm); // we are not in a region, so the mode change is permanent } - } else { - setInPermanentGameMode(gm); // we are not in a region, so the mode change is permanent } /* @@ -412,9 +414,6 @@ public class LCPlayer { return true; } - /* - * Attention: "Creative" stands for "the other gamemode". So true may mean, "be survival in creative world". - */ public void setRegionGameMode(GameMode region_gamemode, PlayerAreaEvent area_event) { Core.debug(getName()+": changed region: "+region_gamemode+": " + area_event); @@ -458,6 +457,11 @@ public class LCPlayer { // 3. (because of else) we are not longer in that mode // result: advise him to not longer allowed to that region storeActiveRegionGameMode(null); + } else if (region_gamemode == CURRENT_GAMEMODE && !this.isInPermanentGameMode(CURRENT_GAMEMODE)) { + if (!isActiveRegionGameMode(region_gamemode)) { + // we have no information why we are already in this gamemode, so this may be because of an AuthMe change-and-teleport + storeActiveRegionGameMode(region_gamemode); + } } /** At the moment, in permanent game mode, it ignores all regions else if (this.isRegionGameMode()) { diff --git a/src/de/jaschastarke/minecraft/utils/Util.java b/src/de/jaschastarke/minecraft/utils/Util.java index cda6270..cf76008 100644 --- a/src/de/jaschastarke/minecraft/utils/Util.java +++ b/src/de/jaschastarke/minecraft/utils/Util.java @@ -91,4 +91,39 @@ final public class Util { public static String toString(Location loc) { return "{X: "+loc.getBlockX()+", Y: "+loc.getBlockY()+", Z: "+loc.getBlockZ()+"}"; } + + /** + * Compares 2 Version Strings + * + * Only Numbers are interpreted. Any non-numeric char separates sub-versions. + * + * @param v1 First version String + * @param v2 Version String to compare with + * @return -1 when v1 < v2; 1 when v1 > v2; 0 when equal + */ + public static int compareVersion(String v1, String v2) { + String[] ver1 = v1.split("[^0-9]+"); + String[] ver2 = v2.split("[^0-9]+"); + + for (int i = 0; i < Math.min(ver1.length, ver2.length); i++) { + int diff = new Integer(ver1[i]).compareTo(new Integer(ver2[i])); + if (diff != 0) + return diff < 0 ? -1 : 1; + } + return ver1.length == ver2.length ? 0 : ver1.length < ver2.length ? -1 : 1; + + /*String[] vals1 = v1.split("\\."); + String[] vals2 = v2.split("\\."); + int i=0; + while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { + i++; + } + + if (i < vals1.length && i < vals2.length) { + int diff = new Integer(vals1[i]).compareTo(new Integer(vals2[i])); + return diff < 0 ? -1 : diff == 0 ? 0 : 1; + } + + return vals1.length < vals2.length ? -1 : vals1.length == vals2.length ? 0 : 1;*/ + } }