From f3283de8dd9397ee98f5e7147e5c1030463f578e Mon Sep 17 00:00:00 2001 From: NuclearW Date: Mon, 30 Jan 2012 10:09:45 -0500 Subject: [PATCH] Terrible horrible workaround for R2 behavior --- .../nossr50/listeners/mcBlockListener.java | 13 +++-- src/main/java/com/gmail/nossr50/m.java | 3 ++ src/main/java/com/gmail/nossr50/mcMMO.java | 11 ++++- .../runnables/ChangeDataValueTimer.java | 47 +++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index e74606cf7..95f47ec0d 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -73,12 +73,17 @@ public class mcBlockListener implements Listener } //Check if the blocks placed should be monitored so they do not give out XP in the future - if(m.shouldBeWatched(block)) + if(m.shouldBeWatched(event.getItemInHand().getTypeId())) // Modified for terrible hack for R2 issue { - if(block.getTypeId() != 17 && block.getTypeId() != 39 && block.getTypeId() != 40 && block.getTypeId() != 91 && block.getTypeId() != 86) - block.setData((byte) 5); //Change the byte - else if(block.getTypeId() == 17 || block.getTypeId() == 39 || block.getTypeId() == 40 || block.getTypeId() == 91 || block.getTypeId() == 86) + if(block.getTypeId() != 17 && block.getTypeId() != 39 && block.getTypeId() != 40 && block.getTypeId() != 91 && block.getTypeId() != 86) { + //block.setData((byte) 5); //Change the byte + //The following is a method to get around a breakage in 1.1-R2, + //it should be removed as soon as functionality to change a block + //in this event returns. + plugin.changeQueue.push(block); + } else if(block.getTypeId() == 17 || block.getTypeId() == 39 || block.getTypeId() == 40 || block.getTypeId() == 91 || block.getTypeId() == 86) { plugin.misc.blockWatchList.add(block); + } } if(block.getTypeId() == 42 && LoadProperties.anvilmessages) diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index c3694d338..7eb16b326 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -89,6 +89,9 @@ public class m public static boolean shouldBeWatched(Block block) { int id = block.getTypeId(); + return shouldBeWatched(id); + } + public static boolean shouldBeWatched(int id) { return id == 103 || id == 82 || id == 16 || id == 73 || id == 49 || id == 81 || id == 83 || id == 86 || id == 91 || id == 1 || id == 17 || id == 42 || id == 87 || id == 89 || id == 2 || id == 3 || id == 12 || id == 13 || id == 21 || id == 15 || id == 14 || id == 56 || id == 38 || id == 37 || id == 39 || id == 40 || id == 24; } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 58f56c16c..4de14a2d6 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -24,7 +24,7 @@ import com.gmail.nossr50.commands.mc.*; import com.gmail.nossr50.commands.party.*; import com.gmail.nossr50.commands.general.*; import com.gmail.nossr50.config.*; -import com.gmail.nossr50.runnables.mcTimer; +import com.gmail.nossr50.runnables.*; import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.listeners.mcBlockListener; import com.gmail.nossr50.listeners.mcEntityListener; @@ -35,6 +35,7 @@ import com.gmail.nossr50.skills.*; import com.nijikokun.bukkit.Permissions.Permissions; import org.bukkit.Bukkit; + import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -44,6 +45,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashMap; import java.util.logging.Level; @@ -52,6 +54,7 @@ import java.util.logging.Logger; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.PluginManager; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.player.FileManager; @@ -84,6 +87,7 @@ public class mcMMO extends JavaPlugin private Permissions permissions; private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION + private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(this); //R2 block place workaround //private Timer mcMMO_SpellTimer = new Timer(true); //Alias - Command @@ -96,6 +100,9 @@ public class mcMMO extends JavaPlugin LoadProperties config = new LoadProperties(); //Jar stuff public static File mcmmo; + + //Queue for block data change for R2 workaround + public ArrayDeque changeQueue = new ArrayDeque(); public void onEnable() { @@ -157,6 +164,8 @@ public class mcMMO extends JavaPlugin System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20); + //R2 block place workaround + Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10); registerCommands(); diff --git a/src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java b/src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java new file mode 100644 index 000000000..c2cbab52e --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java @@ -0,0 +1,47 @@ +/* + This file is part of mcMMO. + + mcMMO is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + mcMMO is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mcMMO. If not, see . +*/ +package com.gmail.nossr50.runnables; + +import org.bukkit.block.Block; + +import com.gmail.nossr50.mcMMO; + +/* + * This file was created for a breakage introduced in 1.1-R2 + * It should be removed afterwards if the breakage is removed. + */ +public class ChangeDataValueTimer implements Runnable { + private mcMMO plugin; + + public ChangeDataValueTimer(mcMMO instance) { + this.plugin = instance; + } + + public void run() { + int size = plugin.changeQueue.size(); + if(size == 0) return; + if(size > 25) { + size = (int) Math.floor(size / 10); + } + + for(int i = 0; i < size; i++) { + Block change = plugin.changeQueue.poll(); + if(change == null) continue; + change.setData((byte) 5); + } + } +}