Usage of AttachedBlock CustomEvents to prevent drop of torches and co

Disabled MultiWorld-GameMode-Hook (as MW-GameMode dosn't work at all)
plib 1.3 compatibilty to prevent NPE
Region-Command and Flag-Storage fixes
Creative-World-Suicide fix
This commit is contained in:
Jascha Starke 2013-09-21 22:12:40 +02:00
parent d8cc4f2412
commit f322468d40
15 changed files with 116 additions and 33 deletions

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.2</plib.version> <plib.version>1.3-SNAPSHOT</plib.version>
</properties> </properties>
<scm> <scm>
@ -78,13 +78,13 @@
<!-- http://dev.bukkit.org/server-mods/worldguard/ --> <!-- http://dev.bukkit.org/server-mods/worldguard/ -->
<groupId>com.sk89q</groupId> <groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId> <artifactId>worldguard</artifactId>
<version>5.7.3</version> <version>5.8</version>
</dependency> </dependency>
<dependency> <dependency>
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ --> <!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
<groupId>uk.org.whoami</groupId> <groupId>uk.org.whoami</groupId>
<artifactId>authme</artifactId> <artifactId>authme</artifactId>
<version>2.9.3</version> <version>2.9.4</version>
</dependency> </dependency>
<dependency> <dependency>
<!-- http://dev.bukkit.org/server-mods/multiverse-core/ --> <!-- http://dev.bukkit.org/server-mods/multiverse-core/ -->

View file

@ -6,7 +6,6 @@ import de.jaschastarke.hooking.BooleanHooker;
import de.jaschastarke.hooking.GetHooker; import de.jaschastarke.hooking.GetHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks; import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks; import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiWorldHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.xAuthHooks; import de.jaschastarke.minecraft.limitedcreative.hooks.xAuthHooks;
@ -35,9 +34,9 @@ public final class Hooks {
} }
if (isPluginEnabled("Multiverse-Core")) { if (isPluginEnabled("Multiverse-Core")) {
new MultiVerseHooks(plugin); new MultiVerseHooks(plugin);
} else if (isPluginEnabled("MultiWorld")) { }/* else if (isPluginEnabled("MultiWorld")) { // MultiWord suckz, the Creative-World-Setting doesn't affect anything
new MultiWorldHooks(plugin); new MultiWorldHooks(plugin);
} }*/
InventoryIncompatible.register(new GetHooker.Check<String>() { InventoryIncompatible.register(new GetHooker.Check<String>() {
@Override @Override

View file

@ -2,6 +2,7 @@ package de.jaschastarke.minecraft.limitedcreative;
import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand; import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
import de.jaschastarke.bukkit.lib.modules.AttachedBlocksDestroy;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
@ -41,6 +42,10 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
config = new BlockStateConfig(this, entry); config = new BlockStateConfig(this, entry);
plugin.getPluginConfig().registerSection(config); plugin.getPluginConfig().registerSection(config);
if (plugin.getModule(AttachedBlocksDestroy.class) == null) {
plugin.addModule(new AttachedBlocksDestroy(plugin));
}
listeners.addListener(new BlockListener(this)); listeners.addListener(new BlockListener(this));
listeners.addListener(new HangingListener(this)); listeners.addListener(new HangingListener(this));
listeners.addListener(new PlayerListener(this)); listeners.addListener(new PlayerListener(this));

View file

@ -5,6 +5,7 @@ import java.util.WeakHashMap;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.modules.AttachedBlocksDestroy;
import de.jaschastarke.minecraft.limitedcreative.limits.BlockListener; import de.jaschastarke.minecraft.limitedcreative.limits.BlockListener;
import de.jaschastarke.minecraft.limitedcreative.limits.EntityListener; import de.jaschastarke.minecraft.limitedcreative.limits.EntityListener;
import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig; import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig;
@ -36,17 +37,24 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
listeners.addListener(new BlockListener(this)); listeners.addListener(new BlockListener(this));
config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry)); config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry));
/*blockDrops = plugin.getModule(FeatureBlockItemSpawn.class); blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
if (blockDrops == null) if (blockDrops == null)
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule(); blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
*/
if (plugin.getModule(AttachedBlocksDestroy.class) == null) {
plugin.addModule(new AttachedBlocksDestroy(plugin));
}
if (!config.getEnabled()) { if (!config.getEnabled()) {
entry.initialState = ModuleState.DISABLED; entry.initialState = ModuleState.DISABLED;
return; return;
} }
} }
public FeatureBlockItemSpawn getBlockSpawn() {
return blockDrops;
}
@Override @Override
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();

View file

@ -19,6 +19,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import de.jaschastarke.bukkit.lib.events.AttachedBlockDestroyedEvent;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
public class BlockListener implements Listener { public class BlockListener implements Listener {
@ -49,6 +50,27 @@ public class BlockListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler
public void onAttachedBlockBreak(AttachedBlockDestroyedEvent event) {
try {
BlockState s = mod.getModel().getState(event.getBlock());
if (s != null) {
if (mod.isDebug())
mod.getLog().debug("Breaking attached block: " + s.toString());
if (s.isRestricted()) {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Drop prevented");
mod.getBlockSpawn().block(event.getBlock());
}
mod.getModel().removeState(s);
}
} catch (SQLException e) {
mod.getLog().warn("DB-Error while onBlockBreak: "+e.getMessage());
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlocksBreakByExplosion(EntityExplodeEvent event) { public void onBlocksBreakByExplosion(EntityExplodeEvent event) {

View file

@ -12,7 +12,7 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
private static final long serialVersionUID = -125544131527849084L; private static final long serialVersionUID = -125544131527849084L;
@Override @Override
public boolean add(String cmd) throws InvalidValueException { public boolean addSetting(String cmd) throws InvalidValueException {
if (cmd.startsWith("^")) { if (cmd.startsWith("^")) {
return add(new RegexpBlockEntry(cmd)); return add(new RegexpBlockEntry(cmd));
} else { } else {
@ -21,7 +21,7 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
} }
@Override @Override
public boolean remove(String e) { public boolean removeSetting(String e) {
for (Iterator<ICmdBlockEntry> iterator = this.iterator(); iterator.hasNext();) { for (Iterator<ICmdBlockEntry> iterator = this.iterator(); iterator.hasNext();) {
ICmdBlockEntry entry = iterator.next(); ICmdBlockEntry entry = iterator.next();
if (entry.toString().equalsIgnoreCase(e)) { if (entry.toString().equalsIgnoreCase(e)) {
@ -41,4 +41,9 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
return list; return list;
} }
@Override
public void clearSettings() {
clear();
}
} }

View file

@ -97,7 +97,7 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub
if (config.contains("commands") && config.isList("commands")) { if (config.contains("commands") && config.isList("commands")) {
for (Object e : config.getList("commands")) { for (Object e : config.getList("commands")) {
try { try {
blockList.add(e.toString()); blockList.addSetting(e.toString());
} catch (InvalidValueException e1) { } catch (InvalidValueException e1) {
mod.getLog().warn(e1.getMessage()); mod.getLog().warn(e1.getMessage());
} }

View file

@ -75,7 +75,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
} else { } else {
try { try {
if (el != null) if (el != null)
add(el.toString()); addSetting(el.toString());
} catch (InvalidValueException e) { } catch (InvalidValueException e) {
System.err.println(e.getCause().getMessage()); System.err.println(e.getCause().getMessage());
} }
@ -108,7 +108,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>
public boolean add(String e) throws InvalidValueException { public boolean addSetting(String e) throws InvalidValueException {
if (!contains(e)) { if (!contains(e)) {
return add(new Blacklisted(e)); return add(new Blacklisted(e));
} }
@ -116,7 +116,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>
public boolean remove(String e) { public boolean removeSetting(String e) {
Iterator<Blacklisted> it = iterator(); Iterator<Blacklisted> it = iterator();
while (it.hasNext()) { while (it.hasNext()) {
if (it.next().toString().equalsIgnoreCase(e)) { if (it.next().toString().equalsIgnoreCase(e)) {
@ -139,4 +139,9 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
public List<String> toGeneric() { public List<String> toGeneric() {
return toStringList(); return toStringList();
} }
@Override
public void clearSettings() {
clear();
}
} }

View file

@ -67,7 +67,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
} else { } else {
try { try {
if (el != null) if (el != null)
add(el.toString()); addSetting(el.toString());
} catch (InvalidValueException e) { } catch (InvalidValueException e) {
System.err.println((e.getCause() != null ? e.getCause() : e).getMessage()); System.err.println((e.getCause() != null ? e.getCause() : e).getMessage());
} }
@ -100,7 +100,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>
public boolean add(String e) throws InvalidValueException { public boolean addSetting(String e) throws InvalidValueException {
if (!contains(e)) { if (!contains(e)) {
return add(new Blacklisted(e)); return add(new Blacklisted(e));
} }
@ -108,7 +108,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
} }
@Override // ConfigurableList, not List<E> @Override // ConfigurableList, not List<E>
public boolean remove(String e) { public boolean removeSetting(String e) {
Iterator<Blacklisted> it = iterator(); Iterator<Blacklisted> it = iterator();
while (it.hasNext()) { while (it.hasNext()) {
if (it.next().toString().equalsIgnoreCase(e)) { if (it.next().toString().equalsIgnoreCase(e)) {
@ -131,4 +131,9 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
public List<String> toGeneric() { public List<String> toGeneric() {
return toStringList(); return toStringList();
} }
@Override
public void clearSettings() {
clear();
}
} }

View file

@ -24,6 +24,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import de.jaschastarke.bukkit.lib.events.AttachedBlockDestroyedByPlayerEvent;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.lib.permissions.IDynamicPermission; import de.jaschastarke.minecraft.lib.permissions.IDynamicPermission;
import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits; import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits;
@ -55,8 +57,19 @@ public class BlockListener implements Listener {
} }
} }
} }
@EventHandler
public void onAttachedBlockBreak(AttachedBlockDestroyedByPlayerEvent event) {
if (event.getPlayer() != null && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!checkPermission(event.getPlayer(), NoLimitPermissions.DROP)) {
mod.getBlockSpawn().block(event.getBlock());
}
}
}
private boolean checkPermission(Player player, IDynamicPermission perm) { private boolean checkPermission(Player player, IDynamicPermission perm) {
return mod.getPlugin().getPermManager().hasPermission(player, perm); return mod.getPlugin().getPermManager().hasPermission(player, perm);
} }
private boolean checkPermission(Player player, IAbstractPermission perm) {
return mod.getPlugin().getPermManager().hasPermission(player, perm);
}
} }

View file

@ -73,11 +73,14 @@ public class RegionListener extends Listener {
if (mod.isDebug()) if (mod.isDebug())
mod.getLog().debug(player.getName()+": changed region: "+regionGameMode+": " + areaEvent); mod.getLog().debug(player.getName()+": changed region: "+regionGameMode+": " + areaEvent);
PlayerMoveEvent moveEvent = null; GameMode defaultGameMode;
if (areaEvent instanceof PlayerChangedAreaEvent) if (areaEvent instanceof PlayerChangedAreaEvent)
moveEvent = ((PlayerChangedAreaEvent) areaEvent).getMoveEvent(); defaultGameMode = Hooks.DefaultWorldGameMode.get(((PlayerChangedAreaEvent) areaEvent).getMoveEvent().getTo().getWorld());
else if (areaEvent instanceof PlayerNewLocationAreaEvent)
defaultGameMode = Hooks.DefaultWorldGameMode.get(((PlayerNewLocationAreaEvent) areaEvent).getNewLocation().getWorld());
else
defaultGameMode = Hooks.DefaultWorldGameMode.get(player.getWorld());
GameMode currentGameMode = player.getGameMode(); GameMode currentGameMode = player.getGameMode();
GameMode defaultGameMode = Hooks.DefaultWorldGameMode.get(moveEvent != null ? moveEvent.getTo().getWorld() : player.getWorld());
if (regionGameMode != null && currentGameMode != regionGameMode && !pmeta.isActiveRegionGameMode(regionGameMode)) { if (regionGameMode != null && currentGameMode != regionGameMode && !pmeta.isActiveRegionGameMode(regionGameMode)) {
if (mod.isDebug()) if (mod.isDebug())
@ -93,7 +96,9 @@ public class RegionListener extends Listener {
pmeta.storeActiveRegionGameMode(regionGameMode); // have to be set, before setGameMode pmeta.storeActiveRegionGameMode(regionGameMode); // have to be set, before setGameMode
if (!isOptional) { if (!isOptional) {
player.setGameMode(regionGameMode); if (Hooks.IsLoggedIn.test(player)) { // don't change gamemode on login
player.setGameMode(regionGameMode);
}
} }
} }
} else if (regionGameMode == null && player.getGameMode() != defaultGameMode && !pmeta.isInPermanentGameMode(currentGameMode) && pmeta.getActiveRegionGameMode() != null) { } else if (regionGameMode == null && player.getGameMode() != defaultGameMode && !pmeta.isInPermanentGameMode(currentGameMode) && pmeta.getActiveRegionGameMode() != null) {
@ -106,7 +111,9 @@ public class RegionListener extends Listener {
// result: change him back to default mode // result: change him back to default mode
if (checkSwitchFlight(areaEvent)) { if (checkSwitchFlight(areaEvent)) {
pmeta.storeActiveRegionGameMode(null); pmeta.storeActiveRegionGameMode(null);
player.setGameMode(defaultGameMode); if (Hooks.IsLoggedIn.test(player)) { // don't change gamemode on login
player.setGameMode(defaultGameMode);
}
} }
} else if (regionGameMode == null && pmeta.isActiveRegionGameMode()) { } else if (regionGameMode == null && pmeta.isActiveRegionGameMode()) {
if (mod.isDebug()) if (mod.isDebug())

View file

@ -37,6 +37,7 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.Region;
*/ */
@ArchiveDocComments @ArchiveDocComments
public class RegionsCommand extends BukkitCommand implements IHelpDescribed { public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
private final static String GLOBAL_REGION = "__global__";
private ModRegions mod; private ModRegions mod;
private HelpCommand help; private HelpCommand help;
private WorldGuardPlugin wg; private WorldGuardPlugin wg;
@ -127,11 +128,18 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
String msg = L("command.worldguard.unknown_flag") + params.getArgument(1) + "\n" String msg = L("command.worldguard.unknown_flag") + params.getArgument(1) + "\n"
+ L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender()); + L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender());
throw new CommandException(msg); throw new CommandException(msg);
} else if (params.getFlags().contains("g")) {
flag = flag.getRegionGroupFlag();
if (flag == null) {
String msg = L("command.worldguard.unknown_flag") + params.getArgument(1) + "-group\n"
+ L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender());
throw new CommandException(msg);
}
} }
String value = params.getValue(); String value = params.getValue();
try { try {
if (value != null) { if (value != null && value.trim().length() > 0) {
reg.setFlag(flag, flag.parseInput(getWorldGuard(), context.getSender(), value)); reg.setFlag(flag, flag.parseInput(getWorldGuard(), context.getSender(), value));
} else { } else {
reg.setFlag(flag, null); reg.setFlag(flag, null);
@ -172,12 +180,14 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation()); ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation());
if (set.size() > 0) { if (set.size() > 0) {
region = set.iterator().next(); region = set.iterator().next();
} else {
region = getWorldGuard().getGlobalRegionManager().get(w).getRegionExact(GLOBAL_REGION);
} }
} else { } else {
int rpc = params.getArgumentCount() > 1 ? 1 : 0; int rpc = params.getArgumentCount() > 1 ? 1 : 0;
RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w);
region = mgr.getRegion(params.getArgument(rpc)); region = mgr.getRegion(params.getArgument(rpc));
if (region == null && params.getArgument(rpc).equalsIgnoreCase("__global__")) { if (region == null && params.getArgument(rpc).equalsIgnoreCase(GLOBAL_REGION)) {
region = new GlobalProtectedRegion(params.getArgument(rpc)); region = new GlobalProtectedRegion(params.getArgument(rpc));
mgr.addRegion(region); mgr.addRegion(region);
} }

View file

@ -108,7 +108,11 @@ public class CustomRegionManager {
ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags"); ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags");
fs.set(flag.getName(), flag.marshal((V) value)); if (value == null) {
fs.set(flag.getName(), null);
} else {
fs.set(flag.getName(), flag.marshal((V) value));
}
try { try {
c.save(file); c.save(file);

View file

@ -49,13 +49,10 @@ public class Region {
} }
public void setFlag(Flag<?> flag, Object value) { public void setFlag(Flag<?> flag, Object value) {
if (value == null) { removeFlag(flag);
removeFlag(flag); if (flags != null && value != null)
} else { flags.add(new FlagValue(flag, value));
if (flags != null) mgr.storeFlag(this, flag, value);
flags.add(new FlagValue(flag, value));
mgr.storeFlag(this, flag, value);
}
} }
public ProtectedRegion getProtectedRegion() { public ProtectedRegion getProtectedRegion() {
return region; return region;

View file

@ -69,4 +69,7 @@ public class PlayerNewLocationAreaEvent extends PlayerAreaEvent {
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
public Location getNewLocation() {
return location;
}
} }