diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 53e0377..0000000 --- a/TODO.txt +++ /dev/null @@ -1,4 +0,0 @@ - - cleanup localize-messages - - region command descriptions - - rework german localization - - fix DocComment formatting for config and permissions \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2bbda4c..21c910f 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 - 1.0-SNAPSHOT + 1.1-SNAPSHOT @@ -72,7 +72,7 @@ org.bukkit bukkit - 1.6.2-R0.1-SNAPSHOT + 1.6.2-R0.1 diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java index 4139f88..b0aad75 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java @@ -27,18 +27,30 @@ public class FeatureBlockItemSpawn extends CoreModule implement public boolean isBlocked(Location l, Material type) { cleanup(); + if (isDebug()) + getLog().debug("Checking ItemBlocked: " + l.toString() + " - " + type.toString()); for (BlockItemDrop block : list) { - if (block.getLocation().equals(l) && (block.getType() == null || block.getType().equals(type))) + if (isDebug()) + getLog().debug(" - " + block.toString()); + if (block.getLocation().equals(l) && (block.getType() == null || block.getType().equals(type))) { + if (isDebug()) + getLog().debug(" blocked!"); return true; + } } + if (isDebug()); + getLog().debug(" allowed"); return false; } private void cleanup() { Iterator i = list.iterator(); while (i.hasNext()) { BlockItemDrop block = i.next(); - if (block.getTimestamp() < System.currentTimeMillis() - TIME_OFFSET) + if (block.getTimestamp() < System.currentTimeMillis() - TIME_OFFSET) { + if (isDebug()) + getLog().debug("Removing outdated BlokItemDrop: " + block.toString()); i.remove(); + } } } @@ -60,6 +72,9 @@ public class FeatureBlockItemSpawn extends CoreModule implement public long getTimestamp() { return timestamp; } + public String toString() { + return Long.toString(timestamp) + ": " + l.toString() + (type != null ? " - " + type.toString() : ""); + } } public void block(Block block, Player player) { @@ -76,6 +91,9 @@ public class FeatureBlockItemSpawn extends CoreModule implement public void block(Block block) { block(block, null); } + public void block(Location l) { + list.add(new BlockItemDrop(l, null)); + } public void block(Location l, Material type) { list.add(new BlockItemDrop(l, type)); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java index e808682..d8b391e 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java @@ -5,6 +5,7 @@ import de.jaschastarke.I18n; import de.jaschastarke.bukkit.lib.Core; import de.jaschastarke.bukkit.lib.PluginLang; import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand; +import de.jaschastarke.utils.ClassDescriptorStorage; public class LimitedCreative extends Core { protected Config config = null; @@ -42,6 +43,15 @@ public class LimitedCreative extends Core { new Backdoor().install(); } + @Override + public ClassDescriptorStorage getDocCommentStorage() { + if (cds == null) { + cds = new ClassDescriptorStorage(); + cds.getResourceBundle().addResourceBundle("lang.doccomments"); + } + return cds; + } + @Override public boolean isDebug() { return config.getDebug(); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index e3adfb9..8aa331a 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -7,6 +7,7 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig; import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries; import de.jaschastarke.minecraft.limitedcreative.blockstate.DependencyListener; +import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory; import de.jaschastarke.modularize.IModule; @@ -39,6 +40,7 @@ public class ModBlockStates extends CoreModule { plugin.getPluginConfig().registerSection(config); listeners.addListener(new BlockListener(this)); + listeners.addListener(new HangingListener(this)); listeners.addListener(new PlayerListener(this)); listeners.addListener(new DependencyListener(this)); @@ -63,7 +65,6 @@ public class ModBlockStates extends CoreModule { getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); } - plugin.getCommandHandler().registerCommand(command); plugin.getMainCommand().registerCommand(new AliasHelpedCommand(command, "blockstate", new String[]{"bs"})); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java index 3991d58..6827dfb 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java @@ -25,6 +25,7 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub protected ModuleEntry entry; public BlockStateConfig(ModBlockStates mod, ModuleEntry modEntry) { + super(mod.getPlugin()); this.mod = mod; entry = modEntry; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java new file mode 100644 index 0000000..ebeba05 --- /dev/null +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java @@ -0,0 +1,118 @@ +package de.jaschastarke.minecraft.limitedcreative.blockstate; + +import java.sql.SQLException; +import java.util.Date; + +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.entity.ItemFrame; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; +import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source; + +public class HangingListener implements Listener { + private ModBlockStates mod; + public HangingListener(ModBlockStates mod) { + this.mod = mod; + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (event.getRightClicked() instanceof ItemFrame) { + try { + BlockState s = mod.getQueries().find(event.getRightClicked().getLocation()); + if (s != null) { + if (mod.isDebug()) + mod.getLog().debug("Modifying hanging: " + s.toString()); + + if ((s.getGameMode() == GameMode.CREATIVE || s.getSource() == Source.EDIT) && event.getPlayer().getGameMode() != GameMode.CREATIVE) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Modify prevented"); + event.setCancelled(true); + return; + } else { + s.setPlayer(event.getPlayer()); + s.setDate(new Date()); + mod.getQueries().update(s); + } + } else { + s = new BlockState(); + s.setLocation(event.getRightClicked().getLocation().getBlock().getLocation()); + s.setPlayer(event.getPlayer()); + s.setDate(new Date()); + + if (mod.isDebug()) + mod.getLog().debug("Saving BlockState: " + s.toString()); + + mod.getQueries().insert(s); + } + } catch (SQLException e) { + mod.getLog().warn("DB-Error while onHangingInteract: "+e.getMessage()); + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onHangingBreak(HangingBreakEvent event) { + if (event.getEntity() instanceof ItemFrame) { + try { + BlockState s = mod.getQueries().find(event.getEntity().getLocation()); + if (s != null) { + if (mod.isDebug()) + mod.getLog().debug("Breaking hanging: " + s.toString()); + + if (s.getGameMode() == GameMode.CREATIVE || s.getSource() == Source.EDIT) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Drop prevented"); + //mod.getBlockSpawn().block(event.getEntity().getLocation().getBlock().getLocation()); + mod.getBlockSpawn().block(event.getEntity().getLocation().getBlock().getLocation(), Material.ITEM_FRAME); + mod.getBlockSpawn().block(event.getEntity().getLocation().getBlock().getLocation(), ((ItemFrame) event.getEntity()).getItem().getType()); + } + + mod.getQueries().delete(s); + } + } catch (SQLException e) { + mod.getLog().warn("DB-Error while onHangingBreak: "+e.getMessage()); + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onHangingPlace(HangingPlaceEvent event) { + if (event.getEntity() instanceof ItemFrame) { + try { + BlockState s = mod.getQueries().find(event.getEntity().getLocation()); + boolean update = false; + if (s != null) { + // This shouldn't happen + if (mod.isDebug()) + mod.getLog().debug("Replacing current BlockState: " + s.toString()); + update = true; + } else { + s = new BlockState(); + s.setLocation(event.getEntity().getLocation().getBlock().getLocation()); + } + s.setPlayer(event.getPlayer()); + s.setDate(new Date()); + if (mod.isDebug()) + mod.getLog().debug("Saving BlockState: " + s.toString()); + + if (update) + mod.getQueries().update(s); + else + mod.getQueries().insert(s); + } catch (SQLException e) { + mod.getLog().warn("DB-Error while onHangingPlace: "+e.getMessage()); + event.setCancelled(true); + } + } + } +} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java index 2528e78..a40df61 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java @@ -3,11 +3,17 @@ package de.jaschastarke.minecraft.limitedcreative.blockstate; import java.sql.SQLException; import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.ItemFrame; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import de.jaschastarke.bukkit.lib.chat.ChatFormattings; @@ -26,37 +32,49 @@ public class PlayerListener implements Listener { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = event.getClickedBlock(); if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { - try { - BlockState s = mod.getQueries().find(b.getLocation()); - InGameFormatter f = new InGameFormatter(mod.getPlugin().getLang()); - String ret = null; - if (s == null || s.getSource() == Source.UNKNOWN) { - ret = f.formatString(ChatFormattings.ERROR, f.getString("block_state.tool_info.unknown", b.getType().toString())); - } else { - String k = "block_state.tool_info." + s.getSource().name().toLowerCase(); - String gm = s.getGameMode().toString().toLowerCase(); - switch (s.getGameMode()) { - case CREATIVE: - gm = ChatColor.GOLD + gm + ChatColor.RESET; - case SURVIVAL: - gm = ChatColor.GREEN + gm + ChatColor.RESET; - case ADVENTURE: - gm = ChatColor.DARK_GREEN + gm + ChatColor.RESET; - default: - break; - } - - ret = f.formatString(ChatFormattings.INFO, f.getString(k, b.getType().toString(), - s.getPlayerName(), - gm, - s.getDate())); - } - if (ret != null) - event.getPlayer().sendMessage(ret); - } catch (SQLException e) { - mod.getLog().warn("DB-Error while onPlayerInteract: "+e.getMessage()); - } + showInfo(event.getPlayer(), b.getLocation(), b.getType()); } } } + @EventHandler(priority = EventPriority.HIGH) + public void onInteractEntity(PlayerInteractEntityEvent event) { + Entity e = event.getRightClicked(); + if (e != null && e instanceof ItemFrame && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { + showInfo(event.getPlayer(), e.getLocation(), Material.ITEM_FRAME); + event.setCancelled(true); + } + } + + private void showInfo(Player pl, Location loc, Material type) { + try { + BlockState s = mod.getQueries().find(loc); + InGameFormatter f = new InGameFormatter(mod.getPlugin().getLang()); + String ret = null; + if (s == null || s.getSource() == Source.UNKNOWN) { + ret = f.formatString(ChatFormattings.ERROR, f.getString("block_state.tool_info.unknown", type.toString())); + } else { + String k = "block_state.tool_info." + s.getSource().name().toLowerCase(); + String gm = s.getGameMode().toString().toLowerCase(); + switch (s.getGameMode()) { + case CREATIVE: + gm = ChatColor.GOLD + gm + ChatColor.RESET; + case SURVIVAL: + gm = ChatColor.GREEN + gm + ChatColor.RESET; + case ADVENTURE: + gm = ChatColor.DARK_GREEN + gm + ChatColor.RESET; + default: + break; + } + + ret = f.formatString(ChatFormattings.INFO, f.getString(k, type.toString(), + s.getPlayerName(), + gm, + s.getDate())); + } + if (ret != null) + pl.sendMessage(ret); + } catch (SQLException e) { + mod.getLog().warn("DB-Error while onPlayerInteract: "+e.getMessage()); + } + } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockList.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockList.java index 1fb8c77..9d1cdcd 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockList.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockList.java @@ -12,11 +12,11 @@ public class CmdBlockList extends ArrayList implements Configura private static final long serialVersionUID = -125544131527849084L; @Override - public void add(String cmd) throws InvalidValueException { + public boolean add(String cmd) throws InvalidValueException { if (cmd.startsWith("^")) { - add(new RegexpBlockEntry(cmd)); + return add(new RegexpBlockEntry(cmd)); } else { - add(new StringBlockEntry(cmd)); + return add(new StringBlockEntry(cmd)); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java index d1fda51..9a950e3 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java @@ -24,6 +24,7 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub protected ModuleEntry entry; public CmdBlockerConfig(ModCmdBlocker modCmdBlocker, ModuleEntry modEntry) { + super(modCmdBlocker.getPlugin()); mod = modCmdBlocker; entry = modEntry; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java index 54f3e53..227f8bc 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java @@ -26,6 +26,7 @@ public class GMPermConfig extends Configuration implements IConfigurationSubGrou protected ModuleEntry entry; public GMPermConfig(ModGameModePerm modGameModePerm, ModuleEntry modEntry) { + super(modGameModePerm.getPlugin()); mod = modGameModePerm; entry = modEntry; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java index 2fd41f9..f5c8092 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/ArmoryConfig.java @@ -26,6 +26,7 @@ import de.jaschastarke.minecraft.limitedcreative.ModInventories; public class ArmoryConfig extends Configuration implements IConfigurationSubGroup { protected ModInventories mod; public ArmoryConfig(ModInventories modInventories) { + super(modInventories.getPlugin()); mod = modInventories; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java index c2e4298..5413419 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java @@ -20,11 +20,11 @@ import de.jaschastarke.modularize.ModuleEntry.ModuleState; */ @ArchiveDocComments public class InventoryConfig extends Configuration implements IConfigurationSubGroup { - protected ModInventories mod; protected ModuleEntry entry; public InventoryConfig(ModInventories modInventories, ModuleEntry modEntry) { + super(modInventories.getPlugin()); mod = modInventories; entry = modEntry; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java index d85067a..a5b894c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java @@ -108,10 +108,11 @@ public class BlackList extends ArrayList implements Confi } @Override // ConfigurableList, not List - public void add(String e) throws InvalidValueException { + public boolean add(String e) throws InvalidValueException { if (!contains(e)) { - add(new Blacklisted(e)); + return add(new Blacklisted(e)); } + return false; } @Override // ConfigurableList, not List diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java index 3d3b68f..e3ed81d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java @@ -100,10 +100,11 @@ public class BlackListEntity extends ArrayList impl } @Override // ConfigurableList, not List - public void add(String e) throws InvalidValueException { + public boolean add(String e) throws InvalidValueException { if (!contains(e)) { - add(new Blacklisted(e)); + return add(new Blacklisted(e)); } + return false; } @Override // ConfigurableList, not List diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java index c6e0dc5..9e6c37b 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java @@ -23,12 +23,12 @@ import de.jaschastarke.modularize.ModuleEntry.ModuleState; */ @ArchiveDocComments public class LimitConfig extends Configuration implements IConfigurationSubGroup { - protected ModCreativeLimits mod; protected ModuleEntry entry; - public LimitConfig(ModCreativeLimits modInventories, ModuleEntry modEntry) { - mod = modInventories; + public LimitConfig(ModCreativeLimits modCreativeLimits, ModuleEntry modEntry) { + super(modCreativeLimits.getPlugin()); + mod = modCreativeLimits; entry = modEntry; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java index e3a38b0..34a4c1f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java @@ -25,6 +25,7 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou protected ModuleEntry entry; public RegionConfig(ModRegions modRegions, ModuleEntry modEntry) { + super(modRegions.getPlugin()); mod = modRegions; entry = modEntry; }