Added support for LogBlock and WorldGuard. #1

Merged
merged 1 commit into from Oct 2, 2011
View
@@ -31,5 +31,19 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>de.diddiz</groupId>
+ <artifactId>LogBlock</artifactId>
+ <version>1.30</version>
+ <type>jar</type>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sk89q</groupId>
+ <artifactId>worldguard</artifactId>
+ <version>5.2.2</version>
+ <type>jar</type>
+ <scope>provided</scope>
+ </dependency>
@ycros
ycros Oct 2, 2011

I added the two dependencies needed, they're set to "provided", as they're only to be used at compile time. You will need to manually install these into your maven, I haven't been able to find a repository with them.

</dependencies>
</project>
@@ -78,9 +78,13 @@ public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) {
return;
}
+ Player player = event.getPlayer();
+ Block block = event.getBlock();
@ycros
ycros Oct 2, 2011

I moved these out of the try { as I need them later on in the finally, and they are pretty simple code.

+ if (plugin.worldGuard != null && !plugin.worldGuard.canBuild(player, block))
+ return;
@ycros
ycros Oct 2, 2011

Abort if WorldGuard says the player doesn't have permission. WorldGuard will handle the error/messaging the player after this point.

+ int oldBlockType = block.getTypeId();
+ byte oldBlockData = block.getData();
try {
- Player player = event.getPlayer();
- Block block = event.getBlock();
y = block.getLocation().getBlockY();
if (block.getType() == Material.BEDROCK && block.getLocation().getBlockY() <= 5 && !player.hasPermission("bcm.breakbedrock")) {
if (!this.config.yml.getBoolean("Creative Players.Disable Bottom-of-the-World Bedrock Break", true)) {
@@ -222,6 +226,10 @@ public void onBlockBreak(BlockBreakEvent event) {
}
} catch (Exception e) {
e.printStackTrace();
+ } finally {
+ if (event.isCancelled() && plugin.logBlock != null) {
+ plugin.logBlock.getConsumer().queueBlockBreak(player.getName(), block.getLocation(), oldBlockType, oldBlockData);
+ }
@ycros
ycros Oct 2, 2011

Notify LogBlock that a block was broken, but only if we've cancelled the event. I did this in the finally because it will run even if there's a return; earlier.

}
if (this.devMode) {
this.stoptime = System.currentTimeMillis();
@@ -5,6 +5,9 @@
import java.io.InputStreamReader;
import java.net.SocketTimeoutException;
import java.net.URL;
+
+import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
+import de.diddiz.LogBlock.LogBlock;
import me.ahniolator.plugins.burningcreativesuite.commands.BCSGiveExecutor;
import me.ahniolator.plugins.burningcreativesuite.wand.BCSWandExecutor;
import me.ahniolator.plugins.burningcreativesuite.wand.BCSWandPlayerListener;
@@ -16,6 +19,8 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
@@ -38,6 +43,8 @@
public boolean isTimeFrozen = false;
public World world;
public long startTime;
+ public WorldGuardPlugin worldGuard;
+ public LogBlock logBlock;
private String dir;
private String dataDir;
private Configuration yml;
@@ -59,6 +66,17 @@ public void onEnable() {
this.blockListener = new BCSBlockListener(this, this.playerListener, this.blockListener, this.config, this.entityListener, this.dataDir, this.invManager);
this.playerListener = new BCSPlayerListener(this, this.playerListener, this.blockListener, this.config, this.entityListener, this.dataDir, this.invManager, tellUpdate);
this.entityListener = new BCSEntityListener(this, this.playerListener, this.blockListener, this.config, this.entityListener, this.dataDir, this.invManager);
+ PluginManager pluginManager = getServer().getPluginManager();
+ Plugin plugin = pluginManager.getPlugin("WorldGuard");
+ if (plugin instanceof WorldGuardPlugin) {
+ worldGuard = (WorldGuardPlugin)plugin;
+ System.out.println("[BurningCS] Hooking into WorldGuard.");
+ }
+ plugin = pluginManager.getPlugin("LogBlock");
+ if (plugin instanceof LogBlock) {
+ logBlock = (LogBlock) plugin;
+ System.out.println("[BurningCS] Hooking into LogBlock.");
+ }
@ycros
ycros Oct 2, 2011

Carefully get references to WorldGuard and LogBlock, if a user doesn't have these installed then everything will still work fine.

if (newimplemented) {
this.bcsge = new BCSGiveExecutor(this, this.config);
this.bcswe = new BCSWandExecutor(this, this.config);
@@ -7,6 +7,7 @@ main: me.ahniolator.plugins.burningcreativesuite.BurningCreativeSuite
name: Burning Creative Suite
startup: postworld
version: '1.4'
+softdepend: [WorldGuard, LogBlock]
@ycros
ycros Oct 2, 2011

Softdepend, to make sure BCS gets loaded after these two plugins if they are present.

permissions:
bcs.*:
description: Gives all permissions nodes