From c387bcbf559991cd9044bb8d1d23619c3ed733db Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Mon, 1 Dec 2014 22:18:54 +0100 Subject: [PATCH 01/12] Spigot 1.8 compatibility * 1.8 Spigot API * 6.0 WorldGuard --- pom.xml | 4 ++-- .../limitedcreative/blockstate/BlockStateCommand.java | 2 +- .../minecraft/limitedcreative/limits/PlayerListener.java | 8 ++++++-- .../minecraft/limitedcreative/regions/RegionsCommand.java | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index e361688..b195c45 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ UTF-8 1.4-SNAPSHOT - 1.7.2-R0.1-SNAPSHOT + 1.8-R0.1-SNAPSHOT @@ -84,7 +84,7 @@ com.sk89q worldguard - 5.8-SNAPSHOT + 6.0.0-SNAPSHOT diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java index 6a28282..7d5bd9a 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java @@ -223,7 +223,7 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed { return false; } - if (Bukkit.getServer().getOnlinePlayers().length > (context.isPlayer() ? 1 : 0)) { + if (Bukkit.getServer().getOnlinePlayers().size() > (context.isPlayer() ? 1 : 0)) { context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.migrate_useronline_error")); return true; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java index 5f4628f..7c17065 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java @@ -45,6 +45,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.InventoryHolder; import org.bukkit.material.DirectionalContainer; import org.bukkit.potion.PotionEffect; +import org.bukkit.projectiles.ProjectileSource; import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission; import de.jaschastarke.minecraft.lib.permissions.IDynamicPermission; @@ -224,8 +225,11 @@ public class PlayerListener implements Listener { EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) rawevent; Entity source = event.getDamager(); - if (source instanceof Projectile) - source = ((Projectile) source).getShooter(); + if (source instanceof Projectile) { + ProjectileSource shooter = ((Projectile) source).getShooter(); + if (shooter instanceof Entity) + source = (Entity) shooter; + } if (source instanceof Player) { Player player = (Player) source; diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java index b4e517f..5c99f56 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java @@ -243,7 +243,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { if (set.size() > 0) { region = set.iterator().next(); } else { - region = getWorldGuard().getGlobalRegionManager().get(w).getRegionExact(GLOBAL_REGION); + region = getWorldGuard().getGlobalRegionManager().get(w).getRegion(GLOBAL_REGION); } } else { int rpc = params.getArgumentCount() > 1 ? 1 : 0; From 648ef2070ebcd4fb037580dbf3e8271e219dfc4a Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Fri, 10 Apr 2015 23:02:32 +0200 Subject: [PATCH 02/12] Spigot 1.8.3-Update + Moved Metrics + Temporary disabled Worldedit-Integration --- pom.xml | 22 +++++++++++++++++++ .../limitedcreative/FeatureMetrics.java | 15 ++++++------- .../limitedcreative/ModBlockStates.java | 7 +++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index b195c45..8c23e65 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,11 @@ md5 http://repo.md-5.net/content/groups/public/ + + + Plugin Metrics + http://repo.mcstats.org/content/repositories/public + @@ -128,6 +133,13 @@ coreprotect 2.0.8 + + + org.mcstats.bukkit + metrics + R7 + compile + @@ -146,6 +158,9 @@ de.jaschastarke.maven.AnnotationProcessor + + **/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/* + @@ -196,6 +211,7 @@ de.jaschastarke:plib + org.mcstats.*:* @@ -207,6 +223,12 @@ + + + org.mcstats + de.jaschastarke.minecraft.limitedcreative.metrics + + diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureMetrics.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureMetrics.java index b3c3d11..66f1895 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureMetrics.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureMetrics.java @@ -3,11 +3,10 @@ package de.jaschastarke.minecraft.limitedcreative; import java.io.IOException; import org.bukkit.event.Listener; +import org.mcstats.Metrics; import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.tools.stats.IStatistics; -import de.jaschastarke.bukkit.tools.stats.MCStatsMetrics; -import de.jaschastarke.bukkit.tools.stats.MCStatsMetrics.Graph; import de.jaschastarke.bukkit.tools.stats.PiwikStatistics; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; @@ -18,7 +17,7 @@ public class FeatureMetrics extends CoreModule implements Liste super(plugin); } private IStatistics metric; - private MCStatsMetrics mcstats = null; + private Metrics mcstats = null; @Override public void onEnable() { @@ -26,12 +25,12 @@ public class FeatureMetrics extends CoreModule implements Liste metric = new PiwikStatistics(plugin); if (mcstats == null) { try { - mcstats = new MCStatsMetrics(plugin); + mcstats = new Metrics(plugin); - Graph moduleGraph = mcstats.createGraph("Module Usage"); + Metrics.Graph moduleGraph = mcstats.createGraph("Module Usage"); for (final ModuleEntry mod : plugin.getModules()) { if (mod.getModule() instanceof CoreModule) { - moduleGraph.addPlotter(new MCStatsMetrics.Plotter(((CoreModule) mod.getModule()).getName()) { + moduleGraph.addPlotter(new Metrics.Plotter(((CoreModule) mod.getModule()).getName()) { @Override public int getValue() { return mod.getState() == ModuleState.ENABLED ? 1 : 0; @@ -39,9 +38,9 @@ public class FeatureMetrics extends CoreModule implements Liste }); } } - Graph depGraph = mcstats.createGraph("Dependencies"); + Metrics.Graph depGraph = mcstats.createGraph("Dependencies"); for (final String dep : plugin.getDescription().getSoftDepend()) { - depGraph.addPlotter(new MCStatsMetrics.Plotter(dep) { + depGraph.addPlotter(new Metrics.Plotter(dep) { @Override public int getValue() { return plugin.getServer().getPluginManager().isPluginEnabled(dep) ? 1 : 0; diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index 62f86bd..370cfd5 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -17,7 +17,7 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel; import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; -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.ModuleEntry; @@ -77,11 +77,12 @@ public class ModBlockStates extends CoreModule { new BukkitRunnable() { @Override public void run() { - try { + getLog().warn("WorldEdit Integration is not Supported in this Version! Lookout for updates!"); + /*try { LCEditSessionFactory.initFactory(ModBlockStates.this); } catch (Exception e) { getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); - } + }*/ } }.runTaskLater(plugin, 1L); } From acb0717644785f591da5453077607c30dcaab669 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 11 Apr 2015 00:03:42 +0200 Subject: [PATCH 03/12] Spigot 1.8: More deprecation --- .../minecraft/limitedcreative/FeatureBlockItemSpawn.java | 2 +- .../minecraft/limitedcreative/FeatureSwitchGameMode.java | 1 + .../java/de/jaschastarke/minecraft/limitedcreative/Hooks.java | 4 ++-- .../minecraft/limitedcreative/ModInventories.java | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java index 79f2039..ed6aded 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java @@ -47,7 +47,7 @@ public class FeatureBlockItemSpawn extends CoreModule implement private void scheduleCleanUp() { if (cleanup.maxTime == 0) { // if not scheduled yet cleanup.maxTime = System.currentTimeMillis(); - plugin.getServer().getScheduler().runTaskLater(plugin, cleanup, TICK_OFFSET); + cleanup.runTaskLater(plugin, TICK_OFFSET); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java index 0309f7d..f038293 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java @@ -69,6 +69,7 @@ public class FeatureSwitchGameMode extends CoreModule { return SwitchGameModePermissions.ALL.getPermission(subPerm); } + @SuppressWarnings("deprecation") protected boolean changeGameMode(CommandContext context, String player, GameMode tgm, IAbstractPermission permission) throws MissingPermissionCommandException, CommandException { Player target = null; if (player != null && !player.isEmpty()) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java index 009e323..4e4e7e1 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java @@ -4,7 +4,6 @@ import org.bukkit.Bukkit; 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.PlayerCheckHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker; @@ -20,6 +19,7 @@ public final class Hooks { return Bukkit.getServer().getPluginManager().isPluginEnabled(pluginName); } + @SuppressWarnings("deprecation") public static void inizializeHooks(LimitedCreative plugin) { IsLoggedIn.clearHooks(); DefaultWorldGameMode.clearHooks(); @@ -27,7 +27,7 @@ public final class Hooks { InventoryIncompatible.clearHooks(); if (isAuthMePresent()) { - new AuthMeHooks(plugin); + new de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks(plugin); } if (isXAuth20Present()) { new xAuthHooks(plugin); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java index e26cd41..dc17308 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java @@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack; import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.minecraft.limitedcreative.inventories.ArmoryConfig; -import de.jaschastarke.minecraft.limitedcreative.inventories.AuthMeInventories; import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory; import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig; import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions; @@ -34,6 +33,7 @@ public class ModInventories extends CoreModule { return "Inventory"; } + @SuppressWarnings("deprecation") @Override public void initialize(ModuleEntry entry) { super.initialize(entry); @@ -42,7 +42,7 @@ public class ModInventories extends CoreModule { armor_config = config.registerSection(new ArmoryConfig(this)); if (Hooks.isAuthMePresent()) { - addModule(new AuthMeInventories(plugin, this)); + addModule(new de.jaschastarke.minecraft.limitedcreative.inventories.AuthMeInventories(plugin, this)); } String incomp = Hooks.InventoryIncompatible.test(); if (config.getEnabled() && incomp != null) { From 87cde8e182c30727c171d09364bd06975ffde8c2 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 11 Apr 2015 01:36:58 +0200 Subject: [PATCH 04/12] WorldEdit 6.0 --- pom.xml | 17 +- .../limitedcreative/ModBlockStates.java | 16 +- .../blockstate/DependencyListener.java | 28 --- .../worldedit/EditSessionExtent.java | 58 +++++ .../worldedit/EditSessionListener.java | 38 +++ .../blockstate/worldedit/LCEditSession.java | 97 -------- .../worldedit/LCEditSessionFactory.java | 216 ------------------ .../worldedit/LCEditSession_CoreProtect.java | 99 -------- .../worldedit/LCEditSession_LogBlock.java | 98 -------- 9 files changed, 114 insertions(+), 553 deletions(-) delete mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DependencyListener.java create mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java create mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionListener.java delete mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession.java delete mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSessionFactory.java delete mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_CoreProtect.java delete mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_LogBlock.java diff --git a/pom.xml b/pom.xml index 8c23e65..7c92bfc 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ UTF-8 1.4-SNAPSHOT - 1.8-R0.1-SNAPSHOT + 1.8.3-R0.1-SNAPSHOT @@ -41,9 +41,9 @@ http://repo.ja-s.de/mvn - + - bukkit-repo + spigot-repo http://repo.bukkit.org/content/groups/public @@ -91,6 +91,12 @@ worldguard 6.0.0-SNAPSHOT + + + com.sk89q + worldedit + 6.0.0-SNAPSHOT + uk.org.whoami @@ -133,7 +139,7 @@ coreprotect 2.0.8 - + org.mcstats.bukkit metrics @@ -158,9 +164,6 @@ de.jaschastarke.maven.AnnotationProcessor - - **/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/* - diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index 370cfd5..3dc9021 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -1,8 +1,11 @@ package de.jaschastarke.minecraft.limitedcreative; + import org.bukkit.event.Listener; import org.bukkit.scheduler.BukkitRunnable; +import com.sk89q.worldedit.WorldEdit; + import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand; import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks; @@ -12,12 +15,11 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig; import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel; -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.SyncronizedModel; -import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; -//import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory; +import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; +import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.EditSessionListener; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; @@ -50,7 +52,6 @@ public class ModBlockStates extends CoreModule { listeners.addListener(new BlockListener(this)); listeners.addListener(new HangingListener(this)); listeners.addListener(new PlayerListener(this)); - listeners.addListener(new DependencyListener(this)); command = new BlockStateCommand(this); } @@ -77,12 +78,11 @@ public class ModBlockStates extends CoreModule { new BukkitRunnable() { @Override public void run() { - getLog().warn("WorldEdit Integration is not Supported in this Version! Lookout for updates!"); - /*try { - LCEditSessionFactory.initFactory(ModBlockStates.this); + try { + WorldEdit.getInstance().getEventBus().register(new EditSessionListener(ModBlockStates.this)); } catch (Exception e) { getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); - }*/ + } } }.runTaskLater(plugin, 1L); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DependencyListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DependencyListener.java deleted file mode 100644 index 1da1d24..0000000 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DependencyListener.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.jaschastarke.minecraft.limitedcreative.blockstate; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.server.PluginEnableEvent; - -import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; -import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory; - -public class DependencyListener implements Listener { - private ModBlockStates mod; - - public DependencyListener(ModBlockStates mod) { - this.mod = mod; - } - - @EventHandler - public void onPluginLoaded(PluginEnableEvent event) { - if (event.getPlugin().getName().equals("LogBlock") || event.getPlugin().getName().equals("WorldEdit")) { - try { - if (mod.getPlugin().getServer().getPluginManager().isPluginEnabled("WorldEdit")) - LCEditSessionFactory.initFactory(mod); - } catch (Exception e) { - mod.getLog().warn(mod.getPlugin().getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); - } - } - } -} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java new file mode 100644 index 0000000..3120b65 --- /dev/null +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java @@ -0,0 +1,58 @@ +package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit; + +import java.util.Date; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent; + +import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; +import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState; +import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source; + +public class EditSessionExtent extends AbstractLoggingExtent { + private ModBlockStates mod; + private Player player = null; + private World world; + + public EditSessionExtent(Extent extent, ModBlockStates mod, Player player, World world) { + super(extent); + this.mod = mod; + this.player = player; + this.world = world; + } + + /** + * Called when a block is being changed. + * + * @param position the position + * @param newBlock the new block to replace the old one + */ + protected void onBlockChange(Vector pt, BaseBlock newBlock) { + if (mod.isDebug()) + mod.getLog().debug("WorldEdit-Integration: BlockChange: "+pt.toString()+" BB: " + newBlock.toString()); + Location loc = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + if (newBlock.getType() == 0) { + mod.getModel().removeState(loc.getBlock()); + } else { + BlockState s = mod.getModel().getState(loc.getBlock()); + if (s == null) { + s = new BlockState(); + s.setLocation(loc); + } + s.setGameMode(null); + s.setPlayerName(player.getName()); + s.setDate(new Date()); + s.setSource(Source.EDIT); + if (mod.isDebug()) + mod.getLog().debug("WorldEdit-Integration: Saving BlockState: " + s.toString()); + + mod.getModel().setState(s); + } + } +} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionListener.java new file mode 100644 index 0000000..c51ed3a --- /dev/null +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionListener.java @@ -0,0 +1,38 @@ +package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.sk89q.worldedit.EditSession.Stage; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.event.extent.EditSessionEvent; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.util.eventbus.Subscribe; +import com.sk89q.worldedit.world.World; + +import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; + +public class EditSessionListener { + private ModBlockStates mod; + + public EditSessionListener(ModBlockStates mod) { + this.mod = mod; + } + + @Subscribe + public void onEditSession(EditSessionEvent event) { + if (mod.getConfig().getWorldeditIntegration()) { + if (event.getStage() == Stage.BEFORE_CHANGE) { + if (mod.isDebug()) + mod.getLog().debug("WorldEdit-Integration: New EditSession: "+event.getActor().getName()+" in World "+event.getWorld().getName()); // + " (" + event.getStage() + ")"); + Actor actor = event.getActor(); + World world = event.getWorld(); + if (actor != null && actor.isPlayer() && world != null && world instanceof BukkitWorld) { + Player player = Bukkit.getPlayer(actor.getUniqueId()); + event.setExtent(new EditSessionExtent(event.getExtent(), mod, player, ((BukkitWorld) event.getWorld()).getWorld())); + } + } + } + } + +} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession.java deleted file mode 100644 index edb8f13..0000000 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession.java +++ /dev/null @@ -1,97 +0,0 @@ -package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalWorld; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.patterns.Pattern; -import com.sk89q.worldedit.regions.Region; - -import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction; - -public class LCEditSession extends EditSession { - private LCEditSessionFactory factory; - private LocalPlayer player; - - public LCEditSession(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { - super(world, maxBlocks, blockBag); - this.factory = factory; - this.player = player; - } - - public LCEditSession(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) { - super(world, maxBlocks); - this.factory = factory; - this.player = player; - } - - private DBTransaction transaction; - - @Override - public void flushQueue() { - transaction = factory.getModel().groupUpdate(); - super.flushQueue(); - if (transaction != null) { - transaction.finish(); - transaction = null; - } - } - - @Override - public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException { - boolean useTransaction = false; - if (transaction == null) { - transaction = factory.getModel().groupUpdate(); - useTransaction = true; - } - int ret; - try { - ret = super.setBlocks(region, block); - } catch (MaxChangedBlocksException e) { - transaction = null; - throw e; - } - if (transaction != null && useTransaction) { - transaction.finish(); - transaction = null; - } - return ret; - } - - @Override - public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException { - boolean useTransaction = false; - if (transaction == null) { - transaction = factory.getModel().groupUpdate(); - useTransaction = true; - } - int ret; - try { - ret = super.setBlocks(region, pattern); - } catch (MaxChangedBlocksException e) { - transaction = null; - throw e; - } - if (transaction != null && useTransaction) { - transaction.finish(); - transaction = null; - } - return ret; - } - - @Override - public boolean rawSetBlock(Vector pt, BaseBlock block) { - boolean success = super.rawSetBlock(pt, block); - if (success) { - if (transaction != null) { - factory.onTransactionBlockEdit(transaction, player, pt, block); - } else { - factory.onBlockEdit(player, pt, block); - } - } - return success; - } -} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSessionFactory.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSessionFactory.java deleted file mode 100644 index 7eeef83..0000000 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSessionFactory.java +++ /dev/null @@ -1,216 +0,0 @@ -package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit; - -import java.lang.reflect.InvocationTargetException; -import java.util.Date; - -import org.bukkit.Location; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.EditSessionFactory; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalWorld; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.bukkit.BukkitWorld; - -import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; -import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState; -import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source; -import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel; -import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction; - -public class LCEditSessionFactory extends EditSessionFactory { - private ModBlockStates mod; - private EditSessionParent parent; - - static enum EditSessionParent { - WORLDEDIT, - LOGBLOCK("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_LogBlock"), - COREPROTECT("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_CoreProtect"); - - private String cls = null; - EditSessionParent() { - } - EditSessionParent(String cls) { - this.cls = cls; - } - public EditSession createInstance(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) { - if (this.cls != null) { - try { - @SuppressWarnings("unchecked") - Class sessClass = (Class) Class.forName(cls); - return sessClass.getConstructor(LCEditSessionFactory.class, LocalWorld.class, int.class, LocalPlayer.class) - .newInstance(factory, world, maxBlocks, player); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (SecurityException e) { - e.printStackTrace(); - } - } - return new LCEditSession(factory, world, maxBlocks, player); - } - - public EditSession createInstance(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { - if (this.cls != null) { - try { - @SuppressWarnings("unchecked") - Class sessClass = (Class) Class.forName(cls); - return sessClass.getConstructor(LCEditSessionFactory.class, LocalWorld.class, int.class, LocalPlayer.class) - .newInstance(factory, world, maxBlocks, player); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (SecurityException e) { - e.printStackTrace(); - } - } - return new LCEditSession(factory, world, maxBlocks, player); - } - } - - public ModBlockStates getLimitedCreativeModule() { - return mod; - } - - public LCEditSessionFactory(ModBlockStates mod, EditSessionParent parent) { - this.mod = mod; - this.parent = parent; - } - - @Override - public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) { - return parent.createInstance(this, world, maxBlocks, player); - /*switch (parent) { - case LOGBLOCK: - return new LCEditSession_LogBlock(this, world, maxBlocks, player); - default: - return new LCEditSession(this, world, maxBlocks, player); - }*/ - } - - // Without Player, the world isn't know, so we can't opporate - /*@Override - public EditSession getEditSession(LocalWorld world, int maxBlocks) { - return new LCEditSession(this, world, maxBlocks, null); - }*/ - - @Override - public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { - return parent.createInstance(this, world, maxBlocks, blockBag, player); - /*switch (parent) { - case LOGBLOCK: - return new LCEditSession_LogBlock(this, world, maxBlocks, blockBag, player); - default: - return new LCEditSession(this, world, maxBlocks, blockBag, player); - }*/ - } - - /*@Override - public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) { - return new LCEditSession(this, world, maxBlocks, blockBag, null); - }*/ - - public static void initFactory(ModBlockStates mod) throws Exception { - EditSessionFactory currentEditSessionFactory = WorldEdit.getInstance().getEditSessionFactory(); - if (currentEditSessionFactory instanceof LCEditSessionFactory) { - if (mod.isDebug()) - mod.getLog().debug("WorlEdit-SessionFactory is already hooked"); - } else if (currentEditSessionFactory.getClass().equals(EditSessionFactory.class)) { // not overridden - if (mod.isDebug()) - mod.getLog().debug("Replacing WorldEdits SessionFactory"); - WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.WORLDEDIT)); - } else if (currentEditSessionFactory.getClass().getName().equals("de.diddiz.worldedit.LogBlockEditSessionFactory")) { - if (mod.isDebug()) - mod.getLog().debug("Replacing LogBlocks WorldEdit-SessionFactory"); - WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.LOGBLOCK)); - } else if (currentEditSessionFactory.getClass().getName().equals("net.coreprotect.worldedit.CoreProtectEditSessionFactory")) { - if (mod.isDebug()) - mod.getLog().debug("Replacing CoreProtects WorldEdit-SessionFactory"); - WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.COREPROTECT)); - } else { - throw new Exception("WorldEdit-SessionFactory is hooked by an unknown another Plugin (" + currentEditSessionFactory.getClass().getName() + ")."); - } - } - - /*public void onBlockEdit(Vector pt, BaseBlock block) { - this.onBlockEdit(null, pt, block); - }*/ - - public DBModel getModel() { - return mod.getModel(); - } - - public boolean onBlockEdit(LocalPlayer player, Vector pt, BaseBlock block) { - if (player != null) { - Location loc = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); - if (block.getType() == 0) { - mod.getModel().removeState(loc.getBlock()); - } else { - BlockState s = mod.getModel().getState(loc.getBlock()); - if (s == null) { - s = new BlockState(); - s.setLocation(loc); - } - s.setGameMode(null); - s.setPlayerName(player.getName()); - s.setDate(new Date()); - s.setSource(Source.EDIT); - if (mod.isDebug()) - mod.getLog().debug("Saving BlockState: " + s.toString()); - - mod.getModel().setState(s); - } - return true; - } else { - return false; - } - } - - public boolean onTransactionBlockEdit(DBTransaction transaction, LocalPlayer player, Vector pt, BaseBlock block) { - if (player != null) { - Location loc = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); - if (block.getType() == 0) { - transaction.removeState(loc.getBlock()); - } else { - BlockState s = mod.getModel().getState(loc.getBlock()); - if (s == null) { - s = new BlockState(); - s.setLocation(loc); - } - s.setGameMode(null); - s.setPlayerName(player.getName()); - s.setDate(new Date()); - s.setSource(Source.EDIT); - if (mod.isDebug()) - mod.getLog().debug("Saving BlockState: " + s.toString()); - - transaction.setState(s); - } - return true; - } else { - return false; - } - } - -} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_CoreProtect.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_CoreProtect.java deleted file mode 100644 index e2ec4ff..0000000 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_CoreProtect.java +++ /dev/null @@ -1,99 +0,0 @@ -package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit; - -import net.coreprotect.CoreProtect; -import net.coreprotect.worldedit.CoreProtectEditSession; - -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalWorld; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.patterns.Pattern; -import com.sk89q.worldedit.regions.Region; - -import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction; - -public class LCEditSession_CoreProtect extends CoreProtectEditSession { - private LCEditSessionFactory factory; - private LocalPlayer player; - - public LCEditSession_CoreProtect(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { - super(world, maxBlocks, blockBag, player, CoreProtect.getInstance()); - this.factory = factory; - this.player = player; - } - - public LCEditSession_CoreProtect(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) { - super(world, maxBlocks, player, CoreProtect.getInstance()); - this.factory = factory; - this.player = player; - } - - private DBTransaction transaction; - - @Override - public void flushQueue() { - transaction = factory.getModel().groupUpdate(); - super.flushQueue(); - if (transaction != null) { - transaction.finish(); - transaction = null; - } - } - - @Override - public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException { - boolean useTransaction = false; - if (transaction == null) { - transaction = factory.getModel().groupUpdate(); - useTransaction = true; - } - int ret; - try { - ret = super.setBlocks(region, block); - } catch (MaxChangedBlocksException e) { - transaction = null; - throw e; - } - if (transaction != null && useTransaction) { - transaction.finish(); - transaction = null; - } - return ret; - } - - @Override - public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException { - boolean useTransaction = false; - if (transaction == null) { - transaction = factory.getModel().groupUpdate(); - useTransaction = true; - } - int ret; - try { - ret = super.setBlocks(region, pattern); - } catch (MaxChangedBlocksException e) { - transaction = null; - throw e; - } - if (transaction != null && useTransaction) { - transaction.finish(); - transaction = null; - } - return ret; - } - - @Override - public boolean rawSetBlock(Vector pt, BaseBlock block) { - boolean success = super.rawSetBlock(pt, block); - if (success) { - if (transaction != null) { - factory.onTransactionBlockEdit(transaction, player, pt, block); - } else { - factory.onBlockEdit(player, pt, block); - } - } - return success; - } -} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_LogBlock.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_LogBlock.java deleted file mode 100644 index 00b90b4..0000000 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_LogBlock.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit; - -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalWorld; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.patterns.Pattern; -import com.sk89q.worldedit.regions.Region; - -import de.diddiz.LogBlock.LogBlock; -import de.diddiz.worldedit.LogBlockEditSession; -import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction; - -public class LCEditSession_LogBlock extends LogBlockEditSession { - private LCEditSessionFactory factory; - private LocalPlayer player; - - public LCEditSession_LogBlock(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { - super(world, maxBlocks, blockBag, player, LogBlock.getInstance()); - this.factory = factory; - this.player = player; - } - - public LCEditSession_LogBlock(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) { - super(world, maxBlocks, player, LogBlock.getInstance()); - this.factory = factory; - this.player = player; - } - - private DBTransaction transaction; - - @Override - public void flushQueue() { - transaction = factory.getModel().groupUpdate(); - super.flushQueue(); - if (transaction != null) { - transaction.finish(); - transaction = null; - } - } - - @Override - public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException { - boolean useTransaction = false; - if (transaction == null) { - transaction = factory.getModel().groupUpdate(); - useTransaction = true; - } - int ret; - try { - ret = super.setBlocks(region, block); - } catch (MaxChangedBlocksException e) { - transaction = null; - throw e; - } - if (transaction != null && useTransaction) { - transaction.finish(); - transaction = null; - } - return ret; - } - - @Override - public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException { - boolean useTransaction = false; - if (transaction == null) { - transaction = factory.getModel().groupUpdate(); - useTransaction = true; - } - int ret; - try { - ret = super.setBlocks(region, pattern); - } catch (MaxChangedBlocksException e) { - transaction = null; - throw e; - } - if (transaction != null && useTransaction) { - transaction.finish(); - transaction = null; - } - return ret; - } - - @Override - public boolean rawSetBlock(Vector pt, BaseBlock block) { - boolean success = super.rawSetBlock(pt, block); - if (success) { - if (transaction != null) { - factory.onTransactionBlockEdit(transaction, player, pt, block); - } else { - factory.onBlockEdit(player, pt, block); - } - } - return success; - } -} From 7b72e1d5cf30009ae018e17d29d1b5cb27aadc39 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 11 Apr 2015 01:47:40 +0200 Subject: [PATCH 05/12] WorldEdit 6.0 --- pom.xml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pom.xml b/pom.xml index 7c92bfc..74b7796 100644 --- a/pom.xml +++ b/pom.xml @@ -127,18 +127,6 @@ xauth 2.0.26 - - - de.diddiz - logblock - dev-SNAPSHOT - - - - net.coreprotect - coreprotect - 2.0.8 - org.mcstats.bukkit @@ -189,8 +177,6 @@ MultiInv Multiverse-Inventories Vault - LogBlock - CoreProtect http://dev.bukkit.org/server-mods/limited-creative/ From d010249107bcb5ef33033045343b3d2b36b86c85 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Sat, 11 Apr 2015 14:09:41 +0200 Subject: [PATCH 06/12] Spigot 1.8: Armor Stand Support (Somehow. Spigot Implementation is Buggy) --- .gitignore | 4 +- .../FeatureBlockItemSpawn.java | 18 +- .../limitedcreative/ModBlockStates.java | 6 +- .../blockstate/BlockStateConfig.java | 4 +- ...ener.java => HangingStandingListener.java} | 323 +++++++++++------- .../limits/EntityListener.java | 3 +- .../limitedcreative/limits/LimitConfig.java | 4 +- .../limits/PlayerListener.java | 16 +- 8 files changed, 234 insertions(+), 144 deletions(-) rename src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/{HangingListener.java => HangingStandingListener.java} (50%) diff --git a/.gitignore b/.gitignore index 6162bc0..81c0eb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,13 @@ /bin -# Eclipse stuff +# IDE stuff /.project /.classpath /.settings /.buildpath /.checkstyle +/.idea +/LimitedCreative.iml # maven /target diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java index ed6aded..33817ec 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java @@ -4,17 +4,16 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import de.jaschastarke.bukkit.lib.CoreModule; @@ -47,10 +46,10 @@ public class FeatureBlockItemSpawn extends CoreModule implement private void scheduleCleanUp() { if (cleanup.maxTime == 0) { // if not scheduled yet cleanup.maxTime = System.currentTimeMillis(); - cleanup.runTaskLater(plugin, TICK_OFFSET); + Bukkit.getScheduler().runTaskLater(plugin, cleanup, TICK_OFFSET); } } - + private class BlockItemDrop { public BlockItemDrop(Location l, Material type) { this.l = l; @@ -96,11 +95,15 @@ public class FeatureBlockItemSpawn extends CoreModule implement list.add(new BlockItemDrop(l, type)); scheduleCleanUp(); } + public void block(Location l, ItemStack item) { + if (item != null) + block(l, item.getType()); + } @EventHandler(ignoreCancelled = true) public void onItemSpawn(ItemSpawnEvent event) { - if (event.getEntity() instanceof Item) { - if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) { + if (event.getEntity() != null) { + if (this.isBlocked(event.getLocation().getBlock().getLocation(), event.getEntity().getItemStack().getType())) { event.setCancelled(true); } } @@ -113,8 +116,9 @@ public class FeatureBlockItemSpawn extends CoreModule implement return debug; } - private class CleanUp extends BukkitRunnable { + private class CleanUp implements Runnable { public long maxTime = 0; + @Override public void run() { if (plugin.isDebug()) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index 3dc9021..2560bf9 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -15,10 +15,10 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig; import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel; -import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingListener; +import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingStandingListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel; -import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; +import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.EditSessionListener; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; @@ -50,7 +50,7 @@ public class ModBlockStates extends CoreModule { this.addModule(new BlockFall(plugin)); listeners.addListener(new BlockListener(this)); - listeners.addListener(new HangingListener(this)); + listeners.addListener(new HangingStandingListener(this)); listeners.addListener(new PlayerListener(this)); command = new BlockStateCommand(this); 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 ac6f059..4ce0ea8 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java @@ -93,11 +93,11 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub * * Without threading, huge WorldEdits becomes much noticeable slower. * - * default: false + * default: true */ @IsConfigurationNode(order = 150) public boolean getUseThreading() { - return config.getBoolean("useThreading", false); + return config.getBoolean("useThreading", true); } /** diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java similarity index 50% rename from src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java rename to src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java index 0977897..fa70363 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java @@ -1,117 +1,206 @@ -package de.jaschastarke.minecraft.limitedcreative.blockstate; - -import java.util.Date; - -import org.bukkit.GameMode; -import org.bukkit.Material; -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.entity.EntityDamageByEntityEvent; -import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.hanging.HangingPlaceEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; - -import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; - -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 (mod.getConfig().getIgnoredWorlds().contains(event.getRightClicked().getWorld().getName())) - return; - if (event.getRightClicked() instanceof ItemFrame) { - if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) { - if (mod.isDebug()) - mod.getLog().debug("Modifying hanging: " + event.getRightClicked().getLocation().toString()); - - if (event.getPlayer().getGameMode() != GameMode.CREATIVE) { - if (mod.isDebug()) - mod.getLog().debug("... was placed by creative. Modify prevented"); - event.setCancelled(true); - return; - } - } else { - BlockState 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.getModel().setState(s); - } - } - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerLeftInteractEntity(EntityDamageByEntityEvent event) { - if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) - return; - if (event.getDamager() instanceof Player && event.getEntity() instanceof ItemFrame) { - if (mod.getModel().isRestricted(event.getEntity().getLocation().getBlock())) { - if (mod.isDebug()) - mod.getLog().debug("Modifying hanging: " + event.getEntity().getLocation().toString()); - - if (((Player) event.getDamager()).getGameMode() != GameMode.CREATIVE) { - if (mod.isDebug()) - mod.getLog().debug("... was placed by creative. Modify prevented"); - event.setCancelled(true); - return; - } - } else { - BlockState s = new BlockState(); - s.setLocation(event.getEntity().getLocation().getBlock().getLocation()); - s.setPlayer((Player) event.getDamager()); - s.setDate(new Date()); - - if (mod.isDebug()) - mod.getLog().debug("Saving BlockState: " + s.toString()); - - mod.getModel().setState(s); - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onHangingBreak(HangingBreakEvent event) { - if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) - return; - if (event.getEntity() instanceof ItemFrame) { - if (mod.isDebug()) - mod.getLog().debug("Breaking hanging: " + event.getEntity().getLocation().toString()); - - if (mod.getModel().isRestricted(event.getEntity().getLocation().getBlock())) { - if (mod.isDebug()) - mod.getLog().debug("... was placed by creative. Drop prevented"); - - 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.getModel().removeState(event.getEntity().getLocation().getBlock()); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onHangingPlace(HangingPlaceEvent event) { - if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) - return; - if (event.getEntity() instanceof ItemFrame) { - BlockState 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()); - - mod.getModel().setState(s); - } - } -} +package de.jaschastarke.minecraft.limitedcreative.blockstate; + +import java.util.Date; + +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.ArmorStand; +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.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; + +public class HangingStandingListener implements Listener { + private ModBlockStates mod; + public HangingStandingListener(ModBlockStates mod) { + this.mod = mod; + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getRightClicked().getWorld().getName())) + return; + if (event.getRightClicked() instanceof ItemFrame) { + if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) { + if (mod.isDebug()) + mod.getLog().debug("Modifying hanging: " + event.getRightClicked().getLocation().toString()); + + if (event.getPlayer().getGameMode() != GameMode.CREATIVE) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Modify prevented"); + event.setCancelled(true); + } + } else { + BlockState 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.getModel().setState(s); + } + } else if (event.getRightClicked() instanceof ArmorStand) { + if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) { + if (mod.isDebug()) + mod.getLog().debug("Modifying standing: " + event.getRightClicked().getLocation().toString()); + + if (event.getPlayer().getGameMode() != GameMode.CREATIVE) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Modify prevented"); + event.setCancelled(true); + } + } else { + BlockState 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.getModel().setState(s); + } + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { + onPlayerInteractEntity(event); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onArmorStandManipulateEvent(PlayerArmorStandManipulateEvent event) { + onPlayerInteractEntity(event); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerLeftInteractEntity(EntityDamageByEntityEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; + if (event.getDamager() instanceof Player && event.getEntity() instanceof ItemFrame) { + if (mod.getModel().isRestricted(event.getEntity().getLocation().getBlock())) { + if (mod.isDebug()) + mod.getLog().debug("Modifying hanging: " + event.getEntity().getLocation().toString()); + + if (((Player) event.getDamager()).getGameMode() != GameMode.CREATIVE) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Modify prevented"); + event.setCancelled(true); + } + } else { + BlockState s = new BlockState(); + s.setLocation(event.getEntity().getLocation().getBlock().getLocation()); + s.setPlayer((Player) event.getDamager()); + s.setDate(new Date()); + + if (mod.isDebug()) + mod.getLog().debug("Saving BlockState: " + s.toString()); + + mod.getModel().setState(s); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onHangingBreak(HangingBreakEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; + if (event.getEntity() instanceof ItemFrame) { + if (mod.isDebug()) + mod.getLog().debug("Breaking hanging: " + event.getEntity().getLocation().toString()); + + if (mod.getModel().isRestricted(event.getEntity().getLocation().getBlock())) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Drop prevented"); + + 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.getModel().removeState(event.getEntity().getLocation().getBlock()); + } + } + + protected void checkArmoryDestroy(ArmorStand entity, boolean deRemove) { + if (mod.isDebug()) + mod.getLog().debug("Breaking standing: " + entity.getLocation().toString()); + + if (mod.getModel().isRestricted(entity.getLocation().getBlock())) { + if (mod.isDebug()) + mod.getLog().debug("... was placed by creative. Drop prevented"); + + + mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), Material.ARMOR_STAND); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), Material.ARMOR_STAND); + + mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getHelmet()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getChestplate()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getBoots()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getItemInHand()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getLeggings()); + + mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getHelmet()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getChestplate()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getBoots()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getItemInHand()); + mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getLeggings()); + /*entity.setBoots(null); + entity.setChestplate(null); + entity.setHelmet(null); + entity.setItemInHand(null); + entity.setLeggings(null);*/ + } + + if (deRemove) + mod.getModel().removeState(entity.getLocation().getBlock()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onStandingBreak(EntityDeathEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; + if (event.getEntity() instanceof ArmorStand) { + checkArmoryDestroy((ArmorStand) event.getEntity(), true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onStandingBreaking(EntityDamageByEntityEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; + if (event.getEntity() instanceof ArmorStand) { + // TODO: Bug in Spigot, we can not check for destroying yet. so the block state stays in DB :( + //if (event.getEntity().isDead() || ((ArmorStand) event.getEntity()).getHealth() <= event.getFinalDamage()) { + checkArmoryDestroy((ArmorStand) event.getEntity(), false); + //} + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onHangingPlace(HangingPlaceEvent event) { + if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) + return; + if (event.getEntity() instanceof ItemFrame) { + BlockState 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()); + + mod.getModel().setState(s); + } + } +} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/EntityListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/EntityListener.java index f043b66..008ebe4 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/EntityListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/EntityListener.java @@ -19,7 +19,6 @@ package de.jaschastarke.minecraft.limitedcreative.limits; import org.bukkit.GameMode; import org.bukkit.entity.Creature; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -53,7 +52,7 @@ public class EntityListener implements Listener { @EventHandler public void onEntityDeath(EntityDeathEvent event) { - if (event.getEntity() instanceof LivingEntity && event.getDroppedExp() > 0) { + if (event.getEntity() != null && event.getDroppedExp() > 0) { if (mod.getNoDropMobs().isXPPrevented(event.getEntity())) { event.setDroppedExp(0); event.getDrops().clear(); 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 be75db9..99b5a9d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java @@ -125,7 +125,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup } - public static enum BlockPickup implements IToGeneric { + public enum BlockPickup implements IToGeneric { PREVENT, REMOVE; @@ -289,7 +289,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup public Object getValue(final IConfigurationNode node) { Object val = super.getValue(node); if (node.getName().equals("pickup") && val == null) { - return new Boolean(false); + return false; } else { return val; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java index 7c17065..499b29d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java @@ -35,13 +35,7 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerEvent; -import org.bukkit.event.player.PlayerExpChangeEvent; -import org.bukkit.event.player.PlayerGameModeChangeEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.*; import org.bukkit.inventory.InventoryHolder; import org.bukkit.material.DirectionalContainer; import org.bukkit.potion.PotionEffect; @@ -185,13 +179,11 @@ public class PlayerListener implements Listener { if (!checkPermission(event, NoLimitPermissions.CHEST)) { event.setCancelled(true); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.chest")); - return; } } else if (mod.getConfig().getBlockInteraction().isListed(block)) { if (!checkPermission(event, NoLimitPermissions.INTERACT(block))) { event.setCancelled(true); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.interact")); - return; } } } @@ -213,11 +205,15 @@ public class PlayerListener implements Listener { if (!checkPermission(event, NoLimitPermissions.BASE_INTERACT)) { event.setCancelled(true); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.entity")); - return; } } } } + + @EventHandler + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { + onPlayerInteractEntity(event); + } @EventHandler(ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageEvent rawevent) { From 256f1656228b8e2160b3d4ed306364be6a0296e3 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Mon, 11 May 2015 20:15:11 +0200 Subject: [PATCH 07/12] Spectator, chestOpen ^ Inventory * Support for Spectator-Mode (always gets creative Inventory) * Prevent Attack across Region borders * chestOpen now allows Inventory again, to make /inv addons possible * Placing into creative regions should now be handled again (survival regions may bugged? but no one uses them at all, or?) --- .../limitedcreative/ModInventories.java | 4 +++ .../inventories/Inventory.java | 3 +- .../limits/BlackListEntity.java | 29 ++++++++++++++-- .../limits/PlayerListener.java | 10 +++--- .../regions/BlockListener.java | 2 +- .../regions/PlayerListener.java | 34 +++++++++++++++++-- 6 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java index dc17308..ae3869f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java @@ -90,8 +90,12 @@ public class ModInventories extends CoreModule { GameMode cgm = player.getGameMode(); if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure()) gm = GameMode.SURVIVAL; + else if (gm == GameMode.SPECTATOR) + gm = GameMode.CREATIVE; if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure()) cgm = GameMode.SURVIVAL; + else if (cgm == GameMode.SPECTATOR) + cgm = GameMode.CREATIVE; if (gm != cgm) { if (gm != GameMode.CREATIVE || config.getStoreCreative()) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java index 7a7dc75..615fe1c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/Inventory.java @@ -31,7 +31,8 @@ public class Inventory { public enum Target { SURVIVAL, CREATIVE, - ADVENTURE; + ADVENTURE, + SPECTATOR; public static Target getTarget(GameMode gm) { return Target.valueOf(gm.name()); 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 d12a5fe..a25cedd 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import de.jaschastarke.bukkit.lib.configuration.command.ITabComplete; +import de.jaschastarke.bukkit.lib.configuration.command.ListConfigValue; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -11,9 +13,32 @@ import de.jaschastarke.bukkit.lib.configuration.ConfigurableList; import de.jaschastarke.bukkit.lib.configuration.IToGeneric; import de.jaschastarke.configuration.InvalidValueException; -public class BlackListEntity extends ArrayList implements ConfigurableList, IToGeneric { +public class BlackListEntity extends ArrayList implements ConfigurableList, IToGeneric, ITabComplete { private static final long serialVersionUID = 6150727863411513873L; + @Override + public List tabComplete(String[] args, String[] chain) { + if (args.length > 0 && chain.length > 0) { + List hints = new ArrayList(); + String action = chain[chain.length - 1]; + if (action.equalsIgnoreCase(ListConfigValue.ADD)) { + for (EntityType m : EntityType.values()) { + if (m.name().toLowerCase().startsWith(args[0].toLowerCase())) { + hints.add(m.name()); + } + } + } else if (action.equalsIgnoreCase(ListConfigValue.REMOVE)) { + for (Blacklisted bl : this) { + if (bl.toString().toLowerCase().startsWith(args[0].toLowerCase())) { + hints.add(bl.toString()); + } + } + } + return hints; + } + return null; + } + public static class Blacklisted { private String stringRep; private EntityType type; @@ -36,7 +61,7 @@ public class BlackListEntity extends ArrayList impl } if (type == null) - throw new InvalidValueException("Entity '" + stringRep + "' not found"); + throw new InvalidValueException("Entity '" + rep + "' not found"); stringRep = rep; } public Blacklisted(EntityType et) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java index 499b29d..4c3dc80 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java @@ -79,10 +79,12 @@ public class PlayerListener implements Listener { public void onInventoryOpen(InventoryOpenEvent event) { if (event.getPlayer() instanceof Player) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { - if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory()))) - return; - event.setCancelled(true); - ((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory")); + if (!mod.getConfig().getBlockChestInteraction()) { + if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory()))) + return; + event.setCancelled(true); + ((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory")); + } } } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java index 743e1ea..b99a173 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/BlockListener.java @@ -82,7 +82,7 @@ public class BlockListener extends Listener { } } else if (diffrent_region) { // do not build inside of "survial-region in creative world" when outside - if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { + if (/*getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && */getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { event.getPlayer().sendMessage(L("blocked.inside_place")); event.setCancelled(true); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java index a415f7c..5152f4a 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/PlayerListener.java @@ -10,7 +10,9 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.InventoryHolder; @@ -48,7 +50,7 @@ public class PlayerListener extends Listener { } } else if (diffrent_region) { // do not break inside of "survial-region in creative world" when outside - if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { // TODO: Rework + if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { event.getPlayer().sendMessage(L("blocked.inside_interact")); event.setCancelled(true); } @@ -69,12 +71,40 @@ public class PlayerListener extends Listener { } } else if (diffrent_region) { // do not break inside of "survial-region in creative world" when outside - if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { + if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { event.getPlayer().sendMessage(L("blocked.inside_interact_entity")); event.setCancelled(true); } } } + + @EventHandler(ignoreCancelled = true) + public void onPlayerDamange(EntityDamageByEntityEvent event) { + if (event.getDamager() instanceof Player) { + PlayerMeta pmeta = new PlayerMeta((Player) event.getDamager()); + Location loc = event.getEntity().getLocation(); + boolean diffrent_region = getRM().isDiffrentRegion((Player) event.getDamager(), loc); + + if (pmeta.isActiveRegionGameMode() && diffrent_region) { + // do not break outside of "gamemod-change-region" when in the region + if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != pmeta.getActiveRegionGameMode()) { + event.getDamager().sendMessage(L("blocked.outside_interact_entity")); + event.setCancelled(true); + } + } else if (diffrent_region) { + // do not break inside of "survial-region in creative world" when outside + if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != ((Player) event.getDamager()).getGameMode()) { + event.getDamager().sendMessage(L("blocked.inside_interact_entity")); + event.setCancelled(true); + } + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { + onPlayerInteractEntity(event); + } private boolean isRegionOptional(Player player) { return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL); From 1efdf717b5d8d4b69851c6bbeb60f04014445fd8 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Wed, 2 Mar 2016 19:57:25 +0100 Subject: [PATCH 08/12] Incomplete Spectator-Support --- .../minecraft/limitedcreative/FeatureSwitchGameMode.java | 8 ++++++++ .../limitedcreative/SwitchGameModePermissions.java | 5 +++++ src/main/resources/lang/messages.properties | 1 + src/main/resources/lang/messages_de.properties | 1 + 4 files changed, 15 insertions(+) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java index f038293..61eef00 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureSwitchGameMode.java @@ -138,6 +138,14 @@ public class FeatureSwitchGameMode extends CoreModule { public boolean adventure(CommandContext context, String player) throws MissingPermissionCommandException, CommandException { return changeGameMode(context, player, GameMode.ADVENTURE, SwitchGameModePermissions.ADVENTURE); } + @IsCommand("spectator") + @Alias("sp") + @Description(value = "command.switch.spectator", translate = true) + @NeedsPermission(value={"spectator", "backonly"}, optional = true) + @Usages("[player]") + public boolean spectator(CommandContext context, String player) throws MissingPermissionCommandException, CommandException { + return changeGameMode(context, player, GameMode.SPECTATOR, SwitchGameModePermissions.SPECTATOR); + } @Override public List getTabCompleter(MethodCommand cmd) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/SwitchGameModePermissions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/SwitchGameModePermissions.java index 015e15a..3739611 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/SwitchGameModePermissions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/SwitchGameModePermissions.java @@ -46,6 +46,11 @@ public class SwitchGameModePermissions extends ParentPermissionContainerNode { */ @IsChildPermission public final static BasicPermission ADVENTURE = new BasicPermission(ALL, "adventure", PermissionDefault.FALSE); + /** + * Allows switching of own game mode to spectator, but not to creative/survival/adventure + */ + @IsChildPermission + public final static BasicPermission SPECTATOR = new BasicPermission(ALL, "spectator", PermissionDefault.FALSE); /** * Allows switching of other users game mode diff --git a/src/main/resources/lang/messages.properties b/src/main/resources/lang/messages.properties index fd88c9c..556128d 100644 --- a/src/main/resources/lang/messages.properties +++ b/src/main/resources/lang/messages.properties @@ -11,6 +11,7 @@ command.regions: LimitedCreative-Region-Command: configure creative regions command.switch.survival: Changes the game mode of a player to survival command.switch.creative: Changes the game mode of a player to creative command.switch.adventure: Changes the game mode of a player to adventure +command.switch.spectator: Changes the game mode of a player to spectator command.config.reload: Reloads configuration and re-initializes all active modules. command.config.reload.success: The plugin was successfully reloaded. command.gamemode.changed: {0}''s game mode has been changed diff --git a/src/main/resources/lang/messages_de.properties b/src/main/resources/lang/messages_de.properties index d0b2f30..1e1ae2f 100644 --- a/src/main/resources/lang/messages_de.properties +++ b/src/main/resources/lang/messages_de.properties @@ -11,6 +11,7 @@ command.regions: LimitedCreative-Region-Kommando: Kreativ-Regionen konfigurieren command.switch.survival: Ändert den Spielmodus des Spielers zu Überleben command.switch.creative: Ändert den Spielmodus des Spielers zu Kreativ command.switch.adventure: Ändert den Spielmodus des Spielers zu Abenteuer +command.switch.spectator: Ändert den Spielmodus des Spielers zu Beobachter command.config.reload: Lädt die Konfiguration neu und initialisiert alle Module neu command.config.reload.success: Das Plugin wurde erfolgreich neu geladen command.gamemode.changed: {0}''s GameMode wurde geändert From 8cfc3b7f01566c7e8b0dee471e9309b1465a9587 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Wed, 2 Mar 2016 22:47:46 +0100 Subject: [PATCH 09/12] Spigot 1.9 Update --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 74b7796..527601e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ UTF-8 1.4-SNAPSHOT - 1.8.3-R0.1-SNAPSHOT + 1.9-SNAPSHOT @@ -127,11 +127,11 @@ xauth 2.0.26 - + org.mcstats.bukkit metrics - R7 + R8-SNAPSHOT compile @@ -260,8 +260,8 @@ org.apache.maven.wagon wagon-ssh - 1.0 + 2.1 - + From b2e154be450d9aec27b4afde91f9763f77b052bb Mon Sep 17 00:00:00 2001 From: pickernickel Date: Wed, 18 May 2016 03:31:28 -0500 Subject: [PATCH 10/12] Slime block compatibility. --- pom.xml | 2 +- .../blockstate/BlockListener.java | 30 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 527601e..fb79de4 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ UTF-8 1.4-SNAPSHOT - 1.9-SNAPSHOT + 1.9.4-R0.1-SNAPSHOT diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java index 49a2723..2062bd1 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockListener.java @@ -1,6 +1,5 @@ package de.jaschastarke.minecraft.limitedcreative.blockstate; -import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; @@ -144,19 +143,15 @@ public class BlockListener implements Listener { return; event.getBlock().setMetadata("LCBS_pistonIsAlreadyExtended", blockAlreadExtended); - Block source = event.getBlock().getRelative(event.getDirection()); /*if (mod.isDebug()) mod.getLog().debug("PistonExtend "+source.getType()+" "+source.getLocation()+" "+event.getDirection());*/ - List movedBlocks = new ArrayList(); - while (source != null && source.getType() != Material.AIR) { - movedBlocks.add(0, source); // put on top, so iterating the - source = source.getRelative(event.getDirection()); - } + List movedBlocks = event.getBlocks(); if (movedBlocks.size() > 0) { DBTransaction update = mod.getModel().groupUpdate(); - for (Block sblock : movedBlocks) { + for(int count = movedBlocks.size()-1; count >= 0; count--){ + Block sblock = movedBlocks.get(count); Block dest = sblock.getRelative(event.getDirection()); if (mod.isDebug()) mod.getLog().debug("PistionExtend moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation()); @@ -173,12 +168,19 @@ public class BlockListener implements Listener { return; event.getBlock().removeMetadata("LCBS_pistonIsAlreadyExtended", mod.getPlugin()); - Block dest = event.getBlock().getRelative(event.getDirection()); - Block source = dest.getRelative(event.getDirection()); - if (event.isSticky() && source.getType() != Material.AIR) { - if (mod.isDebug()) - mod.getLog().debug("PistionRetract moves "+source.getType()+"-Block from "+source.getLocation()+" to "+dest.getLocation()); - mod.getModel().moveState(source, source.getRelative(event.getDirection().getOppositeFace())); + List movedBlocks = event.getBlocks(); + if(movedBlocks.size() > 0) + { + DBTransaction update = mod.getModel().groupUpdate(); + for(int count = movedBlocks.size()-1; count >= 0; count--){ + Block sblock = movedBlocks.get(count); + Block dest = sblock.getRelative(event.getDirection()); + if (mod.isDebug()) + mod.getLog().debug("PistionRetract moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation()); + + update.moveState(sblock, dest); + } + update.finish(); } } } From 05d37326e0a06bf57415aa30e118434e7573304b Mon Sep 17 00:00:00 2001 From: pickernickel Date: Wed, 18 May 2016 23:54:48 -0500 Subject: [PATCH 11/12] Circumvented some deprecated API usage. --- .../limitedcreative/FeatureBlockItemSpawn.java | 4 ++-- .../blockstate/BlockStateCommand.java | 6 ++---- .../blockstate/HangingStandingListener.java | 1 - .../limitedcreative/blockstate/PlayerListener.java | 4 ++-- .../limitedcreative/inventories/store/Fallback.java | 12 ++++++------ .../minecraft/limitedcreative/limits/BlackList.java | 2 +- .../limitedcreative/limits/BlackListEntity.java | 2 +- .../limitedcreative/limits/NoLimitPermissions.java | 6 +++--- .../limitedcreative/limits/PlayerListener.java | 4 ++-- .../limitedcreative/regions/RegionsCommand.java | 10 +++++----- .../regions/worldguard/ApplicableRegions.java | 9 +++++---- .../regions/worldguard/CustomRegionManager.java | 6 +----- .../worldguard/events/PlayerUpdateAreaEvent.java | 7 +++---- 13 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java index 33817ec..e0b29ed 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java @@ -74,11 +74,11 @@ public class FeatureBlockItemSpawn extends CoreModule implement } public void block(Block block, Player player) { - if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { + if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)) { block(block.getLocation(), block.getType()); } else { // doesn't include silktouch - for (ItemStack i : block.getDrops(player.getItemInHand())) { + for (ItemStack i : block.getDrops(player.getInventory().getItemInMainHand())) { block(block.getLocation(), i.getType()); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java index 7d5bd9a..5aac8df 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java @@ -7,8 +7,6 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.scheduler.BukkitRunnable; - import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.selections.Selection; @@ -105,7 +103,7 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed { if (mod.getConfig().getLogSurvival()) { context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.nothing_to_cleanup")); } else { - mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new BukkitRunnable() { + mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() { @Override public void run() { int countDeleted = mod.getModel().cleanUp(DBModel.Cleanup.SURVIVAL); @@ -168,7 +166,7 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed { final Location min = selection.getMinimumPoint(); final Location max = selection.getMaximumPoint(); - mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new BukkitRunnable() { + mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() { @Override public void run() { if (mod.isDebug()) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java index fa70363..9c7c161 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/HangingStandingListener.java @@ -11,7 +11,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.hanging.HangingBreakEvent; 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 b00bca5..62d37a1 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java @@ -29,7 +29,7 @@ public class PlayerListener implements Listener { public void onInteract(PlayerInteractEvent event) { 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)) { + if (b != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { if (mod.getConfig().getIgnoredWorlds().contains(event.getClickedBlock().getWorld().getName())) { event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", event.getClickedBlock().getWorld().getName())); } else { @@ -41,7 +41,7 @@ public class PlayerListener implements Listener { @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)) { + if (e != null && e instanceof ItemFrame && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { if (mod.getConfig().getIgnoredWorlds().contains(e.getWorld().getName())) { event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", e.getWorld().getName())); } else { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java index cc08897..c0a44aa 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/Fallback.java @@ -47,7 +47,7 @@ public class Fallback { @Override public void store(ConfigurationSection section) { for (int i = 0; i < inv.getSize(); i++) { - if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) + if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR)) sectionSetItem(section, String.valueOf(i), inv.getItem(i)); } } @@ -97,7 +97,7 @@ public class Fallback { public static Map storeInventory(PlayerInventory inv) { Map map = new HashMap(); for (int i = 0; i < inv.getSize(); i++) { - if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) { + if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR)) { map.put(i, inv.getItem(i)); } } @@ -133,13 +133,13 @@ public class Fallback { @Override public void store(ConfigurationSection section) { - if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0) + if (inv.getHelmet() != null && !inv.getHelmet().getType().equals(Material.AIR)) Items.sectionSetItem(section, "helmet", inv.getHelmet()); - if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0) + if (inv.getChestplate() != null && !inv.getChestplate().getType().equals(Material.AIR)) Items.sectionSetItem(section, "chestplate", inv.getChestplate()); - if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0) + if (inv.getLeggings() != null && !inv.getLeggings().getType().equals(Material.AIR)) Items.sectionSetItem(section, "leggins", inv.getLeggings()); - if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0) + if (inv.getBoots() != null && !inv.getBoots().getType().equals(Material.AIR)) Items.sectionSetItem(section, "boots", inv.getBoots()); } 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 d7ebfd8..0b7dd04 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackList.java @@ -55,7 +55,7 @@ public class BlackList extends ArrayList implements Confi } public boolean matches(Block block) { if (hasData) { - return md.equals(new MaterialData(block.getType(), block.getData())); + return md.equals(block.getState().getData()); } else { return block.getType().equals(md.getItemType()); } 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 a25cedd..0eb4b41 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/BlackListEntity.java @@ -52,7 +52,7 @@ public class BlackListEntity extends ArrayList impl type = null; } if (type == null) - type = EntityType.fromName(rep); + type = EntityType.valueOf(rep); try { if (type == null) type = EntityType.valueOf(rep); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java index 383e370..14e1b32 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/NoLimitPermissions.java @@ -118,16 +118,16 @@ public class NoLimitPermissions extends SimplePermissionContainerNode { return new InventoryPermission(CHEST, invtype); } public static IDynamicPermission INTERACT(Block block) { - return new MaterialPermission(BASE_INTERACT, new MaterialData(block.getType(), block.getData())); + return new MaterialPermission(BASE_INTERACT, block.getState().getData()); } public static IDynamicPermission USE(Block block) { - return new MaterialPermission(BASE_USE, new MaterialData(block.getType(), block.getData())); + return new MaterialPermission(BASE_USE, block.getState().getData()); } public static IDynamicPermission USE(MaterialData m) { return new MaterialPermission(BASE_USE, m); } public static IDynamicPermission BREAK(Block block) { - return new MaterialPermission(BASE_BREAK, new MaterialData(block.getType(), block.getData())); + return new MaterialPermission(BASE_BREAK, block.getState().getData()); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java index 4c3dc80..4155538 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java @@ -195,8 +195,8 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) { - if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getItemInHand())) { - if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getItemInHand().getData()))) { + if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getInventory().getItemInMainHand())) { + if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getInventory().getItemInMainHand().getData()))) { event.setCancelled(true); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.use")); return; diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java index 5c99f56..7d385e9 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionsCommand.java @@ -138,7 +138,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { if (idx > -1 && context.getArgument(idx) != null) w = Bukkit.getWorld(context.getArgument(idx)); if (w != null) { - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); + RegionManager mgr = getWorldGuard().getRegionManager(w); if (mgr != null) { List hints = new ArrayList(); for (String rId : mgr.getRegions().keySet()) { @@ -174,7 +174,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { if (w == null) throw new CommandException(L("command.worldguard.world_not_found")); - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); + RegionManager mgr = getWorldGuard().getRegionManager(w); ProtectedRegion region = mgr.getRegion(params.getArgument(0)); if (region == null && params.getArgument(0).equalsIgnoreCase("__global__")) { region = new GlobalProtectedRegion(params.getArgument(0)); @@ -238,16 +238,16 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed { ProtectedRegion region = null; if (params.getArgumentCount() == 0 && context.isPlayer()) { - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(context.getPlayer().getWorld()); + RegionManager mgr = getWorldGuard().getRegionManager(context.getPlayer().getWorld()); ApplicableRegionSet set = mgr.getApplicableRegions(context.getPlayer().getLocation()); if (set.size() > 0) { region = set.iterator().next(); } else { - region = getWorldGuard().getGlobalRegionManager().get(w).getRegion(GLOBAL_REGION); + region = getWorldGuard().getRegionManager(w).getRegion(GLOBAL_REGION); } } else { int rpc = params.getArgumentCount() > 1 ? 1 : 0; - RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); + RegionManager mgr = getWorldGuard().getRegionManager(w); region = mgr.getRegion(params.getArgument(rpc)); if (region == null && params.getArgument(rpc).equalsIgnoreCase(GLOBAL_REGION)) { region = new GlobalProtectedRegion(params.getArgument(rpc)); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java index 1dba934..986ca81 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/ApplicableRegions.java @@ -22,6 +22,7 @@ import org.bukkit.entity.Player; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.regions.ProtectedRegion; public class ApplicableRegions { @@ -36,28 +37,28 @@ public class ApplicableRegions { public boolean allows(StateFlag flag) { extendRegionFlags(); - boolean r = regions.allows(flag); + boolean r = regions.queryState(null, flag).equals(State.ALLOW); contractRegionFlags(); return r; } public boolean allows(StateFlag flag, Player player) { extendRegionFlags(); - boolean r = regions.allows(flag, mgr.getWorldGuard().wrapPlayer(player)); + boolean r = regions.queryState(mgr.getWorldGuard().wrapPlayer(player), flag).equals(State.ALLOW); contractRegionFlags(); return r; } public , V> V getFlag(T flag) { extendRegionFlags(); - V r = regions.getFlag(flag); + V r = regions.queryValue(null, flag); contractRegionFlags(); return r; } public , V> V getFlag(T flag, Player player) { extendRegionFlags(); - V r = regions.getFlag(flag, mgr.getWorldGuard().wrapPlayer(player)); + V r = regions.queryValue(mgr.getWorldGuard().wrapPlayer(player), flag); contractRegionFlags(); return r; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java index 227481e..ba15f6f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java @@ -34,7 +34,6 @@ import org.bukkit.entity.Player; import com.sk89q.worldguard.bukkit.BukkitUtil; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.GlobalRegionManager; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; @@ -160,10 +159,7 @@ public class CustomRegionManager { private WorldGuardPlugin getWorldGuard() { return ((WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME)); } - - public GlobalRegionManager getWGGlobalManager() { - return getWorldGuard().getGlobalRegionManager(); - } + public RegionManager getWGManager(World world) { return getWorldGuard().getRegionManager(world); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java index fcf0274..49e8c4f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/events/PlayerUpdateAreaEvent.java @@ -17,7 +17,6 @@ */ package de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -25,11 +24,11 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.ApplicableRe import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager; public class PlayerUpdateAreaEvent extends PlayerAreaEvent { - private String player; + private Player player; private String hash; protected CustomRegionManager mgr; - public PlayerUpdateAreaEvent(CustomRegionManager mgr, String player, String hash) { + public PlayerUpdateAreaEvent(CustomRegionManager mgr, Player player, String hash) { this.mgr = mgr; this.player = player; this.hash = hash; @@ -46,7 +45,7 @@ public class PlayerUpdateAreaEvent extends PlayerAreaEvent { @Override public Player getPlayer() { - return Bukkit.getServer().getPlayerExact(player); + return player; } private static final HandlerList handlers = new HandlerList(); From 8c1240cc24fd9e1c65e1351b550f524714714fb9 Mon Sep 17 00:00:00 2001 From: pickernickel Date: Sun, 22 May 2016 02:48:08 -0500 Subject: [PATCH 12/12] Use UUID instead of player name. --- .../blockstate/BlockState.java | 23 ++++++++++++------- .../limitedcreative/blockstate/DBQueries.java | 4 ++-- .../worldedit/EditSessionExtent.java | 2 +- .../inventories/store/InvYamlStorage.java | 4 ++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java index a44fc58..b3242da 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java @@ -1,6 +1,7 @@ package de.jaschastarke.minecraft.limitedcreative.blockstate; import java.util.Date; +import java.util.UUID; import javax.persistence.Column; //import javax.persistence.EmbeddedId; @@ -37,7 +38,7 @@ public class BlockState { private GameMode gameMode; @Column(name = "player") - private String playerName; + private UUID uuid; @NotNull @Column(name = "cdate") @@ -51,7 +52,7 @@ public class BlockState { public BlockState(BlockState copy) { this.location = copy.location; this.gameMode = copy.gameMode; - this.playerName = copy.playerName; + this.uuid = copy.uuid; this.date = copy.date; this.source = copy.source; } @@ -72,24 +73,29 @@ public class BlockState { this.gameMode = gm; } - public String getPlayerName() { - return playerName; + public UUID getPlayerUUID() { + return uuid; } + public String getPlayerName() { + return Bukkit.getOfflinePlayer(uuid).getName(); + } + + //TODO Rename public void setPlayerName(String s) { - playerName = s; + uuid = UUID.fromString(s); } public OfflinePlayer getPlayer() { - OfflinePlayer p = Bukkit.getPlayerExact(playerName); + OfflinePlayer p = Bukkit.getPlayer(uuid); if (p == null) - p = Bukkit.getOfflinePlayer(playerName); + p = Bukkit.getOfflinePlayer(uuid); return p; } public void setPlayer(OfflinePlayer player) { setSource(Source.PLAYER); - this.playerName = player.getName(); + this.uuid = player.getUniqueId(); if (player instanceof Player) { setGameMode(((Player) player).getGameMode()); } @@ -119,6 +125,7 @@ public class BlockState { @Override public String toString() { + String playerName = Bukkit.getOfflinePlayer(uuid).getName(); //return blockLocation.toString() + " by " + return location.toString() + " by " + (source == Source.PLAYER ? playerName : (source.toString() + (playerName != null ? "(" + playerName + ")" : ""))) + diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java index 2c6f416..ba5d85b 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java @@ -138,7 +138,7 @@ public class DBQueries { update.setString(1, s.getGameMode().name()); else update.setInt(1, s.getGameMode().getValue()); - update.setString(2, s.getPlayerName()); + update.setString(2, s.getPlayerUUID().toString()); update.setTimestamp(3, new java.sql.Timestamp(s.getDate().getTime())); if (db.getType() == Type.MySQL) update.setString(4, s.getSource().name()); @@ -207,7 +207,7 @@ public class DBQueries { insert.setString(5, s.getGameMode().name()); else insert.setInt(5, s.getGameMode().getValue()); - insert.setString(6, s.getPlayerName()); + insert.setString(6, s.getPlayerUUID().toString()); insert.setTimestamp(7, new java.sql.Timestamp(s.getDate().getTime())); if (db.getType() == Type.MySQL) insert.setString(8, s.getSource().name()); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java index 3120b65..8ba5e1d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java @@ -46,7 +46,7 @@ public class EditSessionExtent extends AbstractLoggingExtent { s.setLocation(loc); } s.setGameMode(null); - s.setPlayerName(player.getName()); + s.setPlayerName(player.getUniqueId().toString()); s.setDate(new Date()); s.setSource(Source.EDIT); if (mod.isDebug()) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java index 326960b..7aa8d33 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java @@ -71,9 +71,9 @@ public class InvYamlStorage extends InvConfStorage { protected File getFile(Inventory pinv, Target target) { if (target != default_target) { - return new File(dir, pinv.getPlayer().getName() + "_" + target.toString().toLowerCase() + SUFFIX); + return new File(dir, pinv.getPlayer().getUniqueId() + "_" + target.toString().toLowerCase() + SUFFIX); } else { - return new File(dir, pinv.getPlayer().getName() + SUFFIX); + return new File(dir, pinv.getPlayer().getUniqueId() + SUFFIX); } } }