Merge pull request #33 from Sn0wStorm/master

Extended Sign system for multiple Triggers
This commit is contained in:
Grafe 2013-04-10 08:07:45 -07:00
commit 01760d3d30
10 changed files with 145 additions and 43 deletions

View File

@ -468,6 +468,7 @@ public class DPlayer {
for(DSign sign : gworld.dSigns){ for(DSign sign : gworld.dSigns){
if(sign != null){ if(sign != null){
if(sign.isDistanceTrigger()){ if(sign.isDistanceTrigger()){
if((sign.isRedstoneTrigger() == false && sign.isSignTrigger() == false) || sign.isPowered()){
if(dplayer.player.getLocation().distance(sign.getSign().getLocation()) < sign.getDtDistance()){ if(dplayer.player.getLocation().distance(sign.getSign().getLocation()) < sign.getDtDistance()){
sign.onTrigger(); sign.onTrigger();
} }
@ -478,4 +479,5 @@ public class DPlayer {
} }
} }
} }
}
} }

View File

@ -26,7 +26,7 @@ public class CMDHelp extends DCommand{
} }
int page=1; int page=1;
int pages=(int)(DCommandRoot.root.commands.size()/6); int pages=(int)Math.ceil(DCommandRoot.root.commands.size()/6.0);
if(args.length>1){ if(args.length>1){
try{ try{
@ -40,12 +40,12 @@ public class CMDHelp extends DCommand{
p.msg(sender, ChatColor.GREEN+"============[ "+ChatColor.GOLD+"Help DungeonsXL - "+page+"/"+pages+ChatColor.GREEN+" ]============",false); p.msg(sender, ChatColor.GREEN+"============[ "+ChatColor.GOLD+"Help DungeonsXL - "+page+"/"+pages+ChatColor.GREEN+" ]============",false);
int i=0; int i=-1;
int ipage=1; int ipage=1;
for(DCommand command:DCommandRoot.root.commands){ for(DCommand command:DCommandRoot.root.commands){
if((command.isConsoleCommand && isConsole) || (command.isPlayerCommand && isPlayer)){ if((command.isConsoleCommand && isConsole) || (command.isPlayerCommand && isPlayer)){
i++; i++;
if(i>6){ if(i>5){
i=0; i=0;
ipage++; ipage++;
} }

View File

@ -90,6 +90,17 @@ public class GameWorld {
} }
} }
} }
for(DSign dSign : this.dSigns){
if(dSign != null){
if(dSign.isRedstoneTrigger()){
if(dSign.getRtBlock().isBlockPowered()){
dSign.onUpdate(0,true);
}else{
dSign.onUpdate(0,false);
}
}
}
}
} }
public void msg(String msg) { public void msg(String msg) {

View File

@ -204,7 +204,9 @@ public class BlockListener implements Listener {
if(sign!=null){ if(sign!=null){
if(sign.isRedstoneTrigger()){ if(sign.isRedstoneTrigger()){
if(sign.getRtBlock().isBlockPowered()){ if(sign.getRtBlock().isBlockPowered()){
sign.onTrigger(); sign.onUpdate(0,true);
}else{
sign.onUpdate(0,false);
} }
} }
} }

View File

@ -26,6 +26,8 @@ public abstract class DSign {
private boolean isSignTrigger = false; private boolean isSignTrigger = false;
private int stId; private int stId;
private boolean[] isPowered = new boolean[2];
public abstract boolean check(); public abstract boolean check();
public abstract String getPermissions(); public abstract String getPermissions();
@ -37,7 +39,9 @@ public abstract class DSign {
this.gworld = gworld; this.gworld = gworld;
//Check Trigger //Check Trigger
String[] splitted = sign.getLine(3).split(" "); String[] typeSplit = sign.getLine(3).split(",");
for(String typeSplitPart:typeSplit){
String[] splitted = typeSplitPart.split(" ");
if(splitted.length > 0){ if(splitted.length > 0){
if(splitted[0].equalsIgnoreCase("R")){ if(splitted[0].equalsIgnoreCase("R")){
if(sign.getBlock().getType() == Material.WALL_SIGN){ if(sign.getBlock().getType() == Material.WALL_SIGN){
@ -77,6 +81,7 @@ public abstract class DSign {
} }
} }
} }
}
public void onInit(){ public void onInit(){
@ -86,6 +91,10 @@ public abstract class DSign {
} }
public void onUpdate(int type,boolean powered){
}
public static DSign create(Sign sign, GameWorld gworld){ public static DSign create(Sign sign, GameWorld gworld){
String[] lines = sign.getLines(); String[] lines = sign.getLines();
DSign dSign = null; DSign dSign = null;
@ -131,6 +140,18 @@ public abstract class DSign {
//Getter anb Setter //Getter anb Setter
public void setPowered(int type,boolean powered) {
isPowered[type] = powered;
}
public boolean isPowered() { //0=Redstone 1=Sign
if( (isPowered[0]||!isRedstoneTrigger()) && (isPowered[1]||!isSignTrigger()) ){
return true;
} else {
return false;
}
}
public boolean isRedstoneTrigger() { public boolean isRedstoneTrigger() {
return isRedstoneTrigger; return isRedstoneTrigger;
} }

View File

@ -33,6 +33,18 @@ public class SIGNCheckpoint extends DSign{
initialized = true; initialized = true;
} }
@Override
public void onUpdate(int type,boolean powered) {
if(initialized){
setPowered(type,powered);
if(!isDistanceTrigger()){
if(isPowered()){
onTrigger();
}
}
}
}
@Override @Override
public void onTrigger() { public void onTrigger() {
if(initialized){ if(initialized){

View File

@ -57,6 +57,18 @@ public class SIGNMob extends DSign{
initialized = true; initialized = true;
} }
@Override
public void onUpdate(int type,boolean powered) {
if(initialized){
setPowered(type,powered);
if(!isDistanceTrigger()){
if(isPowered()){
onTrigger();
}
}
}
}
@Override @Override
public void onTrigger() { public void onTrigger() {
if(initialized){ if(initialized){

View File

@ -40,6 +40,18 @@ public class SIGNMsg extends DSign{
initialized = true; initialized = true;
} }
@Override
public void onUpdate(int type,boolean powered) {
if(initialized){
setPowered(type,powered);
if(!isDistanceTrigger()){
if(isPowered()){
onTrigger();
}
}
}
}
@Override @Override
public void onTrigger() { public void onTrigger() {
if(initialized){ if(initialized){

View File

@ -45,6 +45,18 @@ public class SIGNSoundMsg extends DSign{
initialized = true; initialized = true;
} }
@Override
public void onUpdate(int type,boolean powered) {
if(initialized){
setPowered(type,powered);
if(!isDistanceTrigger()){
if(isPowered()){
onTrigger();
}
}
}
}
@Override @Override
public void onTrigger() { public void onTrigger() {
if(initialized){ if(initialized){

View File

@ -30,6 +30,24 @@ public class SIGNTrigger extends DSign{
initialized = true; initialized = true;
} }
@Override
public void onUpdate(int type,boolean powered) {
if(initialized){
setPowered(type,powered);
if(!isDistanceTrigger()){
for(DSign dsign : this.gworld.dSigns){
if(dsign != null){
if(dsign.isSignTrigger()){
if(triggerId == dsign.getStId()){
dsign.onUpdate(1,isPowered());
}
}
}
}
}
}
}
@Override @Override
public void onTrigger() { public void onTrigger() {
if(initialized){ if(initialized){
@ -37,7 +55,7 @@ public class SIGNTrigger extends DSign{
if(dsign != null){ if(dsign != null){
if(dsign.isSignTrigger()){ if(dsign.isSignTrigger()){
if(triggerId == dsign.getStId()){ if(triggerId == dsign.getStId()){
dsign.onTrigger(); dsign.onUpdate(1,true);
} }
} }
} }