Improve SIGNBlock: Material and Data

This commit is contained in:
Sn0wStorm 2013-05-25 15:09:49 +02:00
parent 7d9c0b032b
commit 545688fbd8

View File

@ -1,6 +1,7 @@
package com.dre.dungeonsxl.signs; package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.Material;
import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.game.GameWorld;
public class SIGNBlock extends DSign { public class SIGNBlock extends DSign {
@ -14,6 +15,8 @@ public class SIGNBlock extends DSign {
private boolean active; private boolean active;
private int offBlockId = 0; private int offBlockId = 0;
private int onBlockId = 0; private int onBlockId = 0;
private byte offBlockData = 0x0;
private byte onBlockData = 0x0;
public SIGNBlock(Sign sign, GameWorld gworld) { public SIGNBlock(Sign sign, GameWorld gworld) {
super(sign, gworld); super(sign, gworld);
@ -29,16 +32,40 @@ public class SIGNBlock extends DSign {
@Override @Override
public void onInit() { public void onInit() {
String lines[] = sign.getLines(); String lines[] = sign.getLines();
offBlockId = p.parseInt(lines[1]); if (!lines[1].equals("")) {
onBlockId = p.parseInt(lines[2]); String line1[] = lines[1].split(",");
sign.getBlock().setTypeId(offBlockId); 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; initialized = true;
} }
@Override @Override
public void onTrigger() { public void onTrigger() {
if (initialized && !active) { if (initialized && !active) {
sign.getBlock().setTypeId(onBlockId); sign.getBlock().setTypeIdAndData(onBlockId, onBlockData, true);
active = true; active = true;
} }
} }
@ -46,7 +73,7 @@ public class SIGNBlock extends DSign {
@Override @Override
public void onDisable() { public void onDisable() {
if (initialized && active) { if (initialized && active) {
sign.getBlock().setTypeId(offBlockId); sign.getBlock().setTypeIdAndData(offBlockId, offBlockData, true);
active = false; active = false;
} }
} }