From 545688fbd83b3e9b6c518deac52e96660856aaaa Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sat, 25 May 2013 15:09:49 +0200 Subject: [PATCH] Improve SIGNBlock: Material and Data --- src/com/dre/dungeonsxl/signs/SIGNBlock.java | 37 ++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/com/dre/dungeonsxl/signs/SIGNBlock.java b/src/com/dre/dungeonsxl/signs/SIGNBlock.java index 33e81b80..bd8ee7da 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNBlock.java +++ b/src/com/dre/dungeonsxl/signs/SIGNBlock.java @@ -1,6 +1,7 @@ package com.dre.dungeonsxl.signs; import org.bukkit.block.Sign; +import org.bukkit.Material; import com.dre.dungeonsxl.game.GameWorld; public class SIGNBlock extends DSign { @@ -14,6 +15,8 @@ public class SIGNBlock extends DSign { private boolean active; private int offBlockId = 0; private int onBlockId = 0; + private byte offBlockData = 0x0; + private byte onBlockData = 0x0; public SIGNBlock(Sign sign, GameWorld gworld) { super(sign, gworld); @@ -29,16 +32,40 @@ public class SIGNBlock extends DSign { @Override public void onInit() { String lines[] = sign.getLines(); - offBlockId = p.parseInt(lines[1]); - onBlockId = p.parseInt(lines[2]); - sign.getBlock().setTypeId(offBlockId); + if (!lines[1].equals("")) { + String line1[] = lines[1].split(","); + Material offBlock = Material.matchMaterial(line1[0]); + if (offBlock != null) { + offBlockId = offBlock.getId(); + } else { + offBlockId = p.parseInt(line1[0]); + } + if (line1.length > 1) { + offBlockData = (byte) p.parseInt(line1[1]); + } + } + + if (!lines[2].equals("")) { + String line2[] = lines[2].split(","); + Material onBlock = Material.matchMaterial(line2[0]); + if (onBlock != null) { + onBlockId = onBlock.getId(); + } else { + onBlockId = p.parseInt(line2[0]); + } + if (line2.length > 1) { + onBlockData = (byte) p.parseInt(line2[1]); + } + } + + sign.getBlock().setTypeIdAndData(offBlockId, offBlockData, true); initialized = true; } @Override public void onTrigger() { if (initialized && !active) { - sign.getBlock().setTypeId(onBlockId); + sign.getBlock().setTypeIdAndData(onBlockId, onBlockData, true); active = true; } } @@ -46,7 +73,7 @@ public class SIGNBlock extends DSign { @Override public void onDisable() { if (initialized && active) { - sign.getBlock().setTypeId(offBlockId); + sign.getBlock().setTypeIdAndData(offBlockId, offBlockData, true); active = false; } }