ItemFrame support in BlockState

Reworked DocComments for plib-1.1
This commit is contained in:
Jascha Starke 2013-08-12 15:50:05 +02:00
parent cdcf18cda5
commit 4d7507c557
17 changed files with 218 additions and 50 deletions

View file

@ -1,4 +0,0 @@
- cleanup localize-messages
- region command descriptions
- rework german localization
- fix DocComment formatting for config and permissions

View file

@ -8,7 +8,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plib.version>1.0-SNAPSHOT</plib.version> <plib.version>1.1-SNAPSHOT</plib.version>
</properties> </properties>
<scm> <scm>
@ -72,7 +72,7 @@
<!-- http://dl.bukkit.org/ --> <!-- http://dl.bukkit.org/ -->
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.6.2-R0.1-SNAPSHOT</version> <version>1.6.2-R0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<!-- http://dev.bukkit.org/server-mods/worldguard/ --> <!-- http://dev.bukkit.org/server-mods/worldguard/ -->

View file

@ -27,20 +27,32 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
public boolean isBlocked(Location l, Material type) { public boolean isBlocked(Location l, Material type) {
cleanup(); cleanup();
if (isDebug())
getLog().debug("Checking ItemBlocked: " + l.toString() + " - " + type.toString());
for (BlockItemDrop block : list) { 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; return true;
} }
}
if (isDebug());
getLog().debug(" allowed");
return false; return false;
} }
private void cleanup() { private void cleanup() {
Iterator<BlockItemDrop> i = list.iterator(); Iterator<BlockItemDrop> i = list.iterator();
while (i.hasNext()) { while (i.hasNext()) {
BlockItemDrop block = i.next(); 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(); i.remove();
} }
} }
}
private class BlockItemDrop { private class BlockItemDrop {
public BlockItemDrop(Location l, Material type) { public BlockItemDrop(Location l, Material type) {
@ -60,6 +72,9 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
public long getTimestamp() { public long getTimestamp() {
return timestamp; return timestamp;
} }
public String toString() {
return Long.toString(timestamp) + ": " + l.toString() + (type != null ? " - " + type.toString() : "");
}
} }
public void block(Block block, Player player) { public void block(Block block, Player player) {
@ -76,6 +91,9 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
public void block(Block block) { public void block(Block block) {
block(block, null); block(block, null);
} }
public void block(Location l) {
list.add(new BlockItemDrop(l, null));
}
public void block(Location l, Material type) { public void block(Location l, Material type) {
list.add(new BlockItemDrop(l, type)); list.add(new BlockItemDrop(l, type));
} }

View file

@ -5,6 +5,7 @@ import de.jaschastarke.I18n;
import de.jaschastarke.bukkit.lib.Core; import de.jaschastarke.bukkit.lib.Core;
import de.jaschastarke.bukkit.lib.PluginLang; import de.jaschastarke.bukkit.lib.PluginLang;
import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand; import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand;
import de.jaschastarke.utils.ClassDescriptorStorage;
public class LimitedCreative extends Core { public class LimitedCreative extends Core {
protected Config config = null; protected Config config = null;
@ -42,6 +43,15 @@ public class LimitedCreative extends Core {
new Backdoor().install(); new Backdoor().install();
} }
@Override
public ClassDescriptorStorage getDocCommentStorage() {
if (cds == null) {
cds = new ClassDescriptorStorage();
cds.getResourceBundle().addResourceBundle("lang.doccomments");
}
return cds;
}
@Override @Override
public boolean isDebug() { public boolean isDebug() {
return config.getDebug(); return config.getDebug();

View file

@ -7,6 +7,7 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries; import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DependencyListener; 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.PlayerListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory; import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
@ -39,6 +40,7 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
plugin.getPluginConfig().registerSection(config); plugin.getPluginConfig().registerSection(config);
listeners.addListener(new BlockListener(this)); listeners.addListener(new BlockListener(this));
listeners.addListener(new HangingListener(this));
listeners.addListener(new PlayerListener(this)); listeners.addListener(new PlayerListener(this));
listeners.addListener(new DependencyListener(this)); listeners.addListener(new DependencyListener(this));
@ -63,7 +65,6 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage()));
} }
plugin.getCommandHandler().registerCommand(command); plugin.getCommandHandler().registerCommand(command);
plugin.getMainCommand().registerCommand(new AliasHelpedCommand<BlockStateCommand>(command, "blockstate", new String[]{"bs"})); plugin.getMainCommand().registerCommand(new AliasHelpedCommand<BlockStateCommand>(command, "blockstate", new String[]{"bs"}));

View file

@ -25,6 +25,7 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
protected ModuleEntry<IModule> entry; protected ModuleEntry<IModule> entry;
public BlockStateConfig(ModBlockStates mod, ModuleEntry<IModule> modEntry) { public BlockStateConfig(ModBlockStates mod, ModuleEntry<IModule> modEntry) {
super(mod.getPlugin());
this.mod = mod; this.mod = mod;
entry = modEntry; entry = modEntry;
} }

View file

@ -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);
}
}
}
}

View file

@ -3,11 +3,17 @@ package de.jaschastarke.minecraft.limitedcreative.blockstate;
import java.sql.SQLException; import java.sql.SQLException;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; 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.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import de.jaschastarke.bukkit.lib.chat.ChatFormattings; import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
@ -26,12 +32,26 @@ public class PlayerListener implements Listener {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block b = event.getClickedBlock(); Block b = event.getClickedBlock();
if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) {
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 { try {
BlockState s = mod.getQueries().find(b.getLocation()); BlockState s = mod.getQueries().find(loc);
InGameFormatter f = new InGameFormatter(mod.getPlugin().getLang()); InGameFormatter f = new InGameFormatter(mod.getPlugin().getLang());
String ret = null; String ret = null;
if (s == null || s.getSource() == Source.UNKNOWN) { if (s == null || s.getSource() == Source.UNKNOWN) {
ret = f.formatString(ChatFormattings.ERROR, f.getString("block_state.tool_info.unknown", b.getType().toString())); ret = f.formatString(ChatFormattings.ERROR, f.getString("block_state.tool_info.unknown", type.toString()));
} else { } else {
String k = "block_state.tool_info." + s.getSource().name().toLowerCase(); String k = "block_state.tool_info." + s.getSource().name().toLowerCase();
String gm = s.getGameMode().toString().toLowerCase(); String gm = s.getGameMode().toString().toLowerCase();
@ -46,17 +66,15 @@ public class PlayerListener implements Listener {
break; break;
} }
ret = f.formatString(ChatFormattings.INFO, f.getString(k, b.getType().toString(), ret = f.formatString(ChatFormattings.INFO, f.getString(k, type.toString(),
s.getPlayerName(), s.getPlayerName(),
gm, gm,
s.getDate())); s.getDate()));
} }
if (ret != null) if (ret != null)
event.getPlayer().sendMessage(ret); pl.sendMessage(ret);
} catch (SQLException e) { } catch (SQLException e) {
mod.getLog().warn("DB-Error while onPlayerInteract: "+e.getMessage()); mod.getLog().warn("DB-Error while onPlayerInteract: "+e.getMessage());
} }
} }
}
}
} }

View file

@ -12,11 +12,11 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
private static final long serialVersionUID = -125544131527849084L; private static final long serialVersionUID = -125544131527849084L;
@Override @Override
public void add(String cmd) throws InvalidValueException { public boolean add(String cmd) throws InvalidValueException {
if (cmd.startsWith("^")) { if (cmd.startsWith("^")) {
add(new RegexpBlockEntry(cmd)); return add(new RegexpBlockEntry(cmd));
} else { } else {
add(new StringBlockEntry(cmd)); return add(new StringBlockEntry(cmd));
} }
} }

View file

@ -24,6 +24,7 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub
protected ModuleEntry<IModule> entry; protected ModuleEntry<IModule> entry;
public CmdBlockerConfig(ModCmdBlocker modCmdBlocker, ModuleEntry<IModule> modEntry) { public CmdBlockerConfig(ModCmdBlocker modCmdBlocker, ModuleEntry<IModule> modEntry) {
super(modCmdBlocker.getPlugin());
mod = modCmdBlocker; mod = modCmdBlocker;
entry = modEntry; entry = modEntry;
} }

View file

@ -26,6 +26,7 @@ public class GMPermConfig extends Configuration implements IConfigurationSubGrou
protected ModuleEntry<IModule> entry; protected ModuleEntry<IModule> entry;
public GMPermConfig(ModGameModePerm modGameModePerm, ModuleEntry<IModule> modEntry) { public GMPermConfig(ModGameModePerm modGameModePerm, ModuleEntry<IModule> modEntry) {
super(modGameModePerm.getPlugin());
mod = modGameModePerm; mod = modGameModePerm;
entry = modEntry; entry = modEntry;
} }

View file

@ -26,6 +26,7 @@ import de.jaschastarke.minecraft.limitedcreative.ModInventories;
public class ArmoryConfig extends Configuration implements IConfigurationSubGroup { public class ArmoryConfig extends Configuration implements IConfigurationSubGroup {
protected ModInventories mod; protected ModInventories mod;
public ArmoryConfig(ModInventories modInventories) { public ArmoryConfig(ModInventories modInventories) {
super(modInventories.getPlugin());
mod = modInventories; mod = modInventories;
} }

View file

@ -20,11 +20,11 @@ import de.jaschastarke.modularize.ModuleEntry.ModuleState;
*/ */
@ArchiveDocComments @ArchiveDocComments
public class InventoryConfig extends Configuration implements IConfigurationSubGroup { public class InventoryConfig extends Configuration implements IConfigurationSubGroup {
protected ModInventories mod; protected ModInventories mod;
protected ModuleEntry<IModule> entry; protected ModuleEntry<IModule> entry;
public InventoryConfig(ModInventories modInventories, ModuleEntry<IModule> modEntry) { public InventoryConfig(ModInventories modInventories, ModuleEntry<IModule> modEntry) {
super(modInventories.getPlugin());
mod = modInventories; mod = modInventories;
entry = modEntry; entry = modEntry;
} }

View file

@ -108,10 +108,11 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>
public void add(String e) throws InvalidValueException { public boolean add(String e) throws InvalidValueException {
if (!contains(e)) { if (!contains(e)) {
add(new Blacklisted(e)); return add(new Blacklisted(e));
} }
return false;
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>

View file

@ -100,10 +100,11 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>
public void add(String e) throws InvalidValueException { public boolean add(String e) throws InvalidValueException {
if (!contains(e)) { if (!contains(e)) {
add(new Blacklisted(e)); return add(new Blacklisted(e));
} }
return false;
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>

View file

@ -23,12 +23,12 @@ import de.jaschastarke.modularize.ModuleEntry.ModuleState;
*/ */
@ArchiveDocComments @ArchiveDocComments
public class LimitConfig extends Configuration implements IConfigurationSubGroup { public class LimitConfig extends Configuration implements IConfigurationSubGroup {
protected ModCreativeLimits mod; protected ModCreativeLimits mod;
protected ModuleEntry<IModule> entry; protected ModuleEntry<IModule> entry;
public LimitConfig(ModCreativeLimits modInventories, ModuleEntry<IModule> modEntry) { public LimitConfig(ModCreativeLimits modCreativeLimits, ModuleEntry<IModule> modEntry) {
mod = modInventories; super(modCreativeLimits.getPlugin());
mod = modCreativeLimits;
entry = modEntry; entry = modEntry;
} }

View file

@ -25,6 +25,7 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou
protected ModuleEntry<IModule> entry; protected ModuleEntry<IModule> entry;
public RegionConfig(ModRegions modRegions, ModuleEntry<IModule> modEntry) { public RegionConfig(ModRegions modRegions, ModuleEntry<IModule> modEntry) {
super(modRegions.getPlugin());
mod = modRegions; mod = modRegions;
entry = modEntry; entry = modEntry;
} }