From 808b50fb614b0e0507ba7f64692ac8feb8ef27c6 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Tue, 29 Oct 2013 13:09:17 +0100 Subject: [PATCH] CoreProtect WE-Integration support --- pom.xml | 10 +++++- .../limitedcreative/ModBlockStates.java | 17 ++++++--- .../worldedit/LCEditSessionFactory.java | 7 +++- .../worldedit/LCEditSession_CoreProtect.java | 35 +++++++++++++++++++ src/main/resources/lang/messages.properties | 2 +- .../resources/lang/messages_de.properties | 2 +- 6 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_CoreProtect.java diff --git a/pom.xml b/pom.xml index c8a8a4f..a9920da 100644 --- a/pom.xml +++ b/pom.xml @@ -9,6 +9,7 @@ UTF-8 1.4-SNAPSHOT + 1.6.4-R1.0 @@ -77,7 +78,7 @@ org.bukkit bukkit - 1.6.2-R0.1 + ${bukkit.version} @@ -121,6 +122,12 @@ logblock dev-SNAPSHOT + + + net.coreprotect + coreprotect + 2.0.8 + @@ -165,6 +172,7 @@ Multiverse-Inventories Vault LogBlock + CoreProtect http://dev.bukkit.org/server-mods/limited-creative/ diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index 0360a42..94d25c1 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -1,6 +1,7 @@ package de.jaschastarke.minecraft.limitedcreative; import org.bukkit.event.Listener; +import org.bukkit.scheduler.BukkitRunnable; import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand; @@ -72,11 +73,17 @@ public class ModBlockStates extends CoreModule { return; } super.onEnable(); - try { - if (plugin.getServer().getPluginManager().isPluginEnabled("WorldEdit")) - LCEditSessionFactory.initFactory(this); - } catch (Exception e) { - getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); + if (plugin.getServer().getPluginManager().isPluginEnabled("WorldEdit")) { + new BukkitRunnable() { + @Override + public void run() { + try { + LCEditSessionFactory.initFactory(ModBlockStates.this); + } catch (Exception e) { + getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); + } + } + }.runTaskLater(plugin, 1L); } plugin.getCommandHandler().registerCommand(command); 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 index 04bd949..6c5f69c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSessionFactory.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSessionFactory.java @@ -25,7 +25,8 @@ public class LCEditSessionFactory extends EditSessionFactory { static enum EditSessionParent { WORLDEDIT, - LOGBLOCK("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_LogBlock"); + LOGBLOCK("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_LogBlock"), + COREPROTECT("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_CoreProtect"); private String cls = null; EditSessionParent() { @@ -141,6 +142,10 @@ public class LCEditSessionFactory extends EditSessionFactory { 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() + ")."); } 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 new file mode 100644 index 0000000..ff8f945 --- /dev/null +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_CoreProtect.java @@ -0,0 +1,35 @@ +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.Vector; +import com.sk89q.worldedit.bags.BlockBag; +import com.sk89q.worldedit.blocks.BaseBlock; + +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; + } + + @Override + public boolean rawSetBlock(Vector pt, BaseBlock block) { + boolean success = super.rawSetBlock(pt, block); + if (success) + factory.onBlockEdit(player, pt, block); + return success; + } +} diff --git a/src/main/resources/lang/messages.properties b/src/main/resources/lang/messages.properties index 697e98d..fd88c9c 100644 --- a/src/main/resources/lang/messages.properties +++ b/src/main/resources/lang/messages.properties @@ -69,7 +69,7 @@ blocked.break: You are not allowed to break this type of block blocked.region.piston: Moving {0} block out of creative area was blocked at {1} blocked.region.piston_in: Moving {0} block into creative area was blocked at {1} -block_state.warning.worldedit_sessionfactory_failed: Failed to hook into WorldEdit. WorldEdit-actions can''t be traced. Error: +block_state.warning.worldedit_sessionfactory_failed: Failed to hook into WorldEdit. WorldEdit-actions can''t be traced. Error: {0} block_state.tool_info.seed: This {0}-Block is generated by the god who created this world block_state.tool_info.player: This {0}-Block was created by ''{1}'' in {2}-mode on {3} block_state.tool_info.edit: This {0}-Block was modified with WorldEdit by ''{1}'' on {3} diff --git a/src/main/resources/lang/messages_de.properties b/src/main/resources/lang/messages_de.properties index a9e5c6c..d0b2f30 100644 --- a/src/main/resources/lang/messages_de.properties +++ b/src/main/resources/lang/messages_de.properties @@ -69,7 +69,7 @@ blocked.break: Du darfst diesen Block nicht zerst blocked.region.piston: Verschieben eines {0} Blocks aus einem GameMode-Bereich wurde bei {1} verhindet blocked.region.piston_in: Verschieben eines {0} Blocks in einen GameMode-Bereich wurde bei {1} verhindet -block_state.warning.worldedit_sessionfactory_failed: Fehler beim Einhängen in WorldEdit. WorldEdit-Aktionen können nicht nachvollzogen werden. Fehler: +block_state.warning.worldedit_sessionfactory_failed: Fehler beim Einhängen in WorldEdit. WorldEdit-Aktionen können nicht nachvollzogen werden. Fehler: {0} block_state.tool_info.seed: Dieser {0}-Block wurde von dem Gott generiert der diese Welt erschuf block_state.tool_info.player: Dieser {0}-Block wurde am {3} von ''{1}'' im {2}-Modus gebaut block_state.tool_info.edit: Der {0}-Block wurde am {3} von ''{1}'' mit WorldEdit gesetzt