Skip to content

Commit

Permalink
Complete recode of 'on player changes sign'
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jul 4, 2013
1 parent 7f7e1af commit d10cf7c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
Expand Up @@ -9,6 +9,7 @@
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.Utilities;
import net.citizensnpcs.api.CitizensAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand Down Expand Up @@ -229,19 +230,29 @@ public void blockRedstone(BlockRedstoneEvent event) {
}

@EventHandler
public void signChange(SignChangeEvent event) {
public void signChange(final SignChangeEvent event) {

Map<String, Object> context = new HashMap<String, Object>();
final Map<String, Object> context = new HashMap<String, Object>();

context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("sign_contents", new dList(Arrays.asList(((Sign) event.getBlock().getState()).getLines())));
final Player player = event.getPlayer();
final Block block = event.getBlock();
final String[] original = ((Sign) block.getState()).getLines();

String determination = doEvents
(Arrays.asList("player changes sign"),
null, event.getPlayer(), context);

if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {
public void run() {
((Sign) block.getState()).update();

context.put("old", new dList(Arrays.asList(original)));

context.put("location", new dLocation(block.getLocation()));
context.put("lines", new dList(Arrays.asList(((Sign) block.getState()).getLines())));

String determination = doEvents
(Arrays.asList("player changes sign"),
null, player, context);
if (determination.toUpperCase().startsWith("CANCELLED")) Utilities.setSignLines(((Sign) block.getState()), original);
}
}, 1);
}


Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/aufdemrand/denizen/utilities/Utilities.java
Expand Up @@ -11,6 +11,8 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -313,5 +315,20 @@ public static List<File> listDScriptFiles(File dir, boolean recursive) {
public static Random getRandom() {
return random;
}

public static void setSignLines(final BlockState sign, String[] lines) {
int n = 0;

for (String line : lines) {

((Sign) sign).setLine(n, line);
n++;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {
public void run() {
((Sign) sign).update();
}
}, 1);
}

}

0 comments on commit d10cf7c

Please sign in to comment.