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:
parent
d8cc4f2412
commit
f322468d40
15 changed files with 116 additions and 33 deletions
6
pom.xml
6
pom.xml
|
@ -8,7 +8,7 @@
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<plib.version>1.2</plib.version>
|
||||
<plib.version>1.3-SNAPSHOT</plib.version>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
@ -78,13 +78,13 @@
|
|||
<!-- http://dev.bukkit.org/server-mods/worldguard/ -->
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>5.7.3</version>
|
||||
<version>5.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- http://dev.bukkit.org/server-mods/authme-reloaded/ -->
|
||||
<groupId>uk.org.whoami</groupId>
|
||||
<artifactId>authme</artifactId>
|
||||
<version>2.9.3</version>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- http://dev.bukkit.org/server-mods/multiverse-core/ -->
|
||||
|
|
|
@ -6,7 +6,6 @@ import de.jaschastarke.hooking.BooleanHooker;
|
|||
import de.jaschastarke.hooking.GetHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks;
|
||||
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.WorldTypeHooker;
|
||||
import de.jaschastarke.minecraft.limitedcreative.hooks.xAuthHooks;
|
||||
|
@ -35,9 +34,9 @@ public final class Hooks {
|
|||
}
|
||||
if (isPluginEnabled("Multiverse-Core")) {
|
||||
new MultiVerseHooks(plugin);
|
||||
} else if (isPluginEnabled("MultiWorld")) {
|
||||
}/* else if (isPluginEnabled("MultiWorld")) { // MultiWord suckz, the Creative-World-Setting doesn't affect anything
|
||||
new MultiWorldHooks(plugin);
|
||||
}
|
||||
}*/
|
||||
|
||||
InventoryIncompatible.register(new GetHooker.Check<String>() {
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.jaschastarke.minecraft.limitedcreative;
|
|||
|
||||
import de.jaschastarke.bukkit.lib.CoreModule;
|
||||
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.BlockStateCommand;
|
||||
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
|
||||
|
@ -41,6 +42,10 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
|
|||
config = new BlockStateConfig(this, entry);
|
||||
plugin.getPluginConfig().registerSection(config);
|
||||
|
||||
if (plugin.getModule(AttachedBlocksDestroy.class) == null) {
|
||||
plugin.addModule(new AttachedBlocksDestroy(plugin));
|
||||
}
|
||||
|
||||
listeners.addListener(new BlockListener(this));
|
||||
listeners.addListener(new HangingListener(this));
|
||||
listeners.addListener(new PlayerListener(this));
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.WeakHashMap;
|
|||
import org.bukkit.entity.Entity;
|
||||
|
||||
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.EntityListener;
|
||||
import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig;
|
||||
|
@ -36,10 +37,13 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
|
|||
listeners.addListener(new BlockListener(this));
|
||||
config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry));
|
||||
|
||||
/*blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
|
||||
blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
|
||||
if (blockDrops == null)
|
||||
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
|
||||
*/
|
||||
|
||||
if (plugin.getModule(AttachedBlocksDestroy.class) == null) {
|
||||
plugin.addModule(new AttachedBlocksDestroy(plugin));
|
||||
}
|
||||
|
||||
if (!config.getEnabled()) {
|
||||
entry.initialState = ModuleState.DISABLED;
|
||||
|
@ -47,6 +51,10 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
|
|||
}
|
||||
}
|
||||
|
||||
public FeatureBlockItemSpawn getBlockSpawn() {
|
||||
return blockDrops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import de.jaschastarke.bukkit.lib.events.AttachedBlockDestroyedEvent;
|
||||
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
|
@ -50,6 +51,27 @@ public class BlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
public void onBlocksBreakByExplosion(EntityExplodeEvent event) {
|
||||
try {
|
||||
|
|
|
@ -12,7 +12,7 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
|
|||
private static final long serialVersionUID = -125544131527849084L;
|
||||
|
||||
@Override
|
||||
public boolean add(String cmd) throws InvalidValueException {
|
||||
public boolean addSetting(String cmd) throws InvalidValueException {
|
||||
if (cmd.startsWith("^")) {
|
||||
return add(new RegexpBlockEntry(cmd));
|
||||
} else {
|
||||
|
@ -21,7 +21,7 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(String e) {
|
||||
public boolean removeSetting(String e) {
|
||||
for (Iterator<ICmdBlockEntry> iterator = this.iterator(); iterator.hasNext();) {
|
||||
ICmdBlockEntry entry = iterator.next();
|
||||
if (entry.toString().equalsIgnoreCase(e)) {
|
||||
|
@ -41,4 +41,9 @@ public class CmdBlockList extends ArrayList<ICmdBlockEntry> implements Configura
|
|||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSettings() {
|
||||
clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub
|
|||
if (config.contains("commands") && config.isList("commands")) {
|
||||
for (Object e : config.getList("commands")) {
|
||||
try {
|
||||
blockList.add(e.toString());
|
||||
blockList.addSetting(e.toString());
|
||||
} catch (InvalidValueException e1) {
|
||||
mod.getLog().warn(e1.getMessage());
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
} else {
|
||||
try {
|
||||
if (el != null)
|
||||
add(el.toString());
|
||||
addSetting(el.toString());
|
||||
} catch (InvalidValueException e) {
|
||||
System.err.println(e.getCause().getMessage());
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
}
|
||||
|
||||
@Override // ConfigurableList, not List<E>
|
||||
public boolean add(String e) throws InvalidValueException {
|
||||
public boolean addSetting(String e) throws InvalidValueException {
|
||||
if (!contains(e)) {
|
||||
return add(new Blacklisted(e));
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
}
|
||||
|
||||
@Override // ConfigurableList, not List<E>
|
||||
public boolean remove(String e) {
|
||||
public boolean removeSetting(String e) {
|
||||
Iterator<Blacklisted> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().toString().equalsIgnoreCase(e)) {
|
||||
|
@ -139,4 +139,9 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
|
|||
public List<String> toGeneric() {
|
||||
return toStringList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSettings() {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
} else {
|
||||
try {
|
||||
if (el != null)
|
||||
add(el.toString());
|
||||
addSetting(el.toString());
|
||||
} catch (InvalidValueException e) {
|
||||
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>
|
||||
public boolean add(String e) throws InvalidValueException {
|
||||
public boolean addSetting(String e) throws InvalidValueException {
|
||||
if (!contains(e)) {
|
||||
return add(new Blacklisted(e));
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
}
|
||||
|
||||
@Override // ConfigurableList, not List<E>
|
||||
public boolean remove(String e) {
|
||||
public boolean removeSetting(String e) {
|
||||
Iterator<Blacklisted> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().toString().equalsIgnoreCase(e)) {
|
||||
|
@ -131,4 +131,9 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
|
|||
public List<String> toGeneric() {
|
||||
return toStringList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSettings() {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
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.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) {
|
||||
return mod.getPlugin().getPermManager().hasPermission(player, perm);
|
||||
}
|
||||
private boolean checkPermission(Player player, IAbstractPermission perm) {
|
||||
return mod.getPlugin().getPermManager().hasPermission(player, perm);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,11 +73,14 @@ public class RegionListener extends Listener {
|
|||
if (mod.isDebug())
|
||||
mod.getLog().debug(player.getName()+": changed region: "+regionGameMode+": " + areaEvent);
|
||||
|
||||
PlayerMoveEvent moveEvent = null;
|
||||
GameMode defaultGameMode;
|
||||
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 defaultGameMode = Hooks.DefaultWorldGameMode.get(moveEvent != null ? moveEvent.getTo().getWorld() : player.getWorld());
|
||||
|
||||
if (regionGameMode != null && currentGameMode != regionGameMode && !pmeta.isActiveRegionGameMode(regionGameMode)) {
|
||||
if (mod.isDebug())
|
||||
|
@ -93,9 +96,11 @@ public class RegionListener extends Listener {
|
|||
pmeta.storeActiveRegionGameMode(regionGameMode); // have to be set, before setGameMode
|
||||
|
||||
if (!isOptional) {
|
||||
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) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug(player.getName()+": leaving creative area");
|
||||
|
@ -106,8 +111,10 @@ public class RegionListener extends Listener {
|
|||
// result: change him back to default mode
|
||||
if (checkSwitchFlight(areaEvent)) {
|
||||
pmeta.storeActiveRegionGameMode(null);
|
||||
if (Hooks.IsLoggedIn.test(player)) { // don't change gamemode on login
|
||||
player.setGameMode(defaultGameMode);
|
||||
}
|
||||
}
|
||||
} else if (regionGameMode == null && pmeta.isActiveRegionGameMode()) {
|
||||
if (mod.isDebug())
|
||||
mod.getLog().debug(player.getName()+": leaving creative area (while already in default gamemode)");
|
||||
|
|
|
@ -37,6 +37,7 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.Region;
|
|||
*/
|
||||
@ArchiveDocComments
|
||||
public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
|
||||
private final static String GLOBAL_REGION = "__global__";
|
||||
private ModRegions mod;
|
||||
private HelpCommand help;
|
||||
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"
|
||||
+ L("command.worldguard.available_flags") + FlagList.getStringListAvailableFlags(context.getSender());
|
||||
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();
|
||||
try {
|
||||
if (value != null) {
|
||||
if (value != null && value.trim().length() > 0) {
|
||||
reg.setFlag(flag, flag.parseInput(getWorldGuard(), context.getSender(), value));
|
||||
} else {
|
||||
reg.setFlag(flag, null);
|
||||
|
@ -172,12 +180,14 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
|
|||
ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation());
|
||||
if (set.size() > 0) {
|
||||
region = set.iterator().next();
|
||||
} else {
|
||||
region = getWorldGuard().getGlobalRegionManager().get(w).getRegionExact(GLOBAL_REGION);
|
||||
}
|
||||
} else {
|
||||
int rpc = params.getArgumentCount() > 1 ? 1 : 0;
|
||||
RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w);
|
||||
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));
|
||||
mgr.addRegion(region);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,11 @@ public class CustomRegionManager {
|
|||
|
||||
ConfigurationSection fs = rs.contains("flags") ? rs.getConfigurationSection("flags") : rs.createSection("flags");
|
||||
|
||||
if (value == null) {
|
||||
fs.set(flag.getName(), null);
|
||||
} else {
|
||||
fs.set(flag.getName(), flag.marshal((V) value));
|
||||
}
|
||||
|
||||
try {
|
||||
c.save(file);
|
||||
|
|
|
@ -49,14 +49,11 @@ public class Region {
|
|||
}
|
||||
|
||||
public void setFlag(Flag<?> flag, Object value) {
|
||||
if (value == null) {
|
||||
removeFlag(flag);
|
||||
} else {
|
||||
if (flags != null)
|
||||
if (flags != null && value != null)
|
||||
flags.add(new FlagValue(flag, value));
|
||||
mgr.storeFlag(this, flag, value);
|
||||
}
|
||||
}
|
||||
public ProtectedRegion getProtectedRegion() {
|
||||
return region;
|
||||
}
|
||||
|
|
|
@ -69,4 +69,7 @@ public class PlayerNewLocationAreaEvent extends PlayerAreaEvent {
|
|||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
public Location getNewLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue