From 6968f314a990ae7949ae41299c2732de640e26bb Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 10 Apr 2013 16:48:29 +0200 Subject: [PATCH] Extended Sign system for multiple Triggers --- src/com/dre/dungeonsxl/DPlayer.java | 6 +- src/com/dre/dungeonsxl/commands/CMDHelp.java | 6 +- src/com/dre/dungeonsxl/game/GameWorld.java | 11 +++ .../dungeonsxl/listener/BlockListener.java | 4 +- src/com/dre/dungeonsxl/signs/DSign.java | 91 ++++++++++++------- .../dre/dungeonsxl/signs/SIGNCheckpoint.java | 12 +++ src/com/dre/dungeonsxl/signs/SIGNMob.java | 12 +++ src/com/dre/dungeonsxl/signs/SIGNMsg.java | 12 +++ .../dre/dungeonsxl/signs/SIGNSoundMsg.java | 12 +++ src/com/dre/dungeonsxl/signs/SIGNTrigger.java | 22 ++++- 10 files changed, 145 insertions(+), 43 deletions(-) diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index a86a4d6e..59b6902c 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -468,8 +468,10 @@ public class DPlayer { for(DSign sign : gworld.dSigns){ if(sign != null){ if(sign.isDistanceTrigger()){ - if(dplayer.player.getLocation().distance(sign.getSign().getLocation()) < sign.getDtDistance()){ - sign.onTrigger(); + if((sign.isRedstoneTrigger() == false && sign.isSignTrigger() == false) || sign.isPowered()){ + if(dplayer.player.getLocation().distance(sign.getSign().getLocation()) < sign.getDtDistance()){ + sign.onTrigger(); + } } } } diff --git a/src/com/dre/dungeonsxl/commands/CMDHelp.java b/src/com/dre/dungeonsxl/commands/CMDHelp.java index a87589fa..41fc07ab 100644 --- a/src/com/dre/dungeonsxl/commands/CMDHelp.java +++ b/src/com/dre/dungeonsxl/commands/CMDHelp.java @@ -26,7 +26,7 @@ public class CMDHelp extends DCommand{ } 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){ try{ @@ -40,12 +40,12 @@ public class CMDHelp extends DCommand{ p.msg(sender, ChatColor.GREEN+"============[ "+ChatColor.GOLD+"Help DungeonsXL - "+page+"/"+pages+ChatColor.GREEN+" ]============",false); - int i=0; + int i=-1; int ipage=1; for(DCommand command:DCommandRoot.root.commands){ if((command.isConsoleCommand && isConsole) || (command.isPlayerCommand && isPlayer)){ i++; - if(i>6){ + if(i>5){ i=0; ipage++; } diff --git a/src/com/dre/dungeonsxl/game/GameWorld.java b/src/com/dre/dungeonsxl/game/GameWorld.java index 47e5c89c..e6f25fa7 100644 --- a/src/com/dre/dungeonsxl/game/GameWorld.java +++ b/src/com/dre/dungeonsxl/game/GameWorld.java @@ -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) { diff --git a/src/com/dre/dungeonsxl/listener/BlockListener.java b/src/com/dre/dungeonsxl/listener/BlockListener.java index 86bffa6c..1eadb9a7 100644 --- a/src/com/dre/dungeonsxl/listener/BlockListener.java +++ b/src/com/dre/dungeonsxl/listener/BlockListener.java @@ -204,7 +204,9 @@ public class BlockListener implements Listener { if(sign!=null){ if(sign.isRedstoneTrigger()){ if(sign.getRtBlock().isBlockPowered()){ - sign.onTrigger(); + sign.onUpdate(0,true); + }else{ + sign.onUpdate(0,false); } } } diff --git a/src/com/dre/dungeonsxl/signs/DSign.java b/src/com/dre/dungeonsxl/signs/DSign.java index c964b07d..87516296 100644 --- a/src/com/dre/dungeonsxl/signs/DSign.java +++ b/src/com/dre/dungeonsxl/signs/DSign.java @@ -25,6 +25,8 @@ public abstract class DSign { //Sign Trigger private boolean isSignTrigger = false; private int stId; + + private boolean[] isPowered = new boolean[2]; public abstract boolean check(); @@ -37,42 +39,45 @@ public abstract class DSign { this.gworld = gworld; //Check Trigger - String[] splitted = sign.getLine(3).split(" "); - if(splitted.length > 0){ - if(splitted[0].equalsIgnoreCase("R")){ - if(sign.getBlock().getType() == Material.WALL_SIGN){ - switch(sign.getData().getData()){ - case 5: - rtBlock = sign.getBlock().getRelative(BlockFace.WEST); - break; - case 4: - rtBlock = sign.getBlock().getRelative(BlockFace.EAST); - break; - case 3: - rtBlock = sign.getBlock().getRelative(BlockFace.NORTH); - break; - case 2: - rtBlock = sign.getBlock().getRelative(BlockFace.SOUTH); - break; + String[] typeSplit = sign.getLine(3).split(","); + for(String typeSplitPart:typeSplit){ + String[] splitted = typeSplitPart.split(" "); + if(splitted.length > 0){ + if(splitted[0].equalsIgnoreCase("R")){ + if(sign.getBlock().getType() == Material.WALL_SIGN){ + switch(sign.getData().getData()){ + case 5: + rtBlock = sign.getBlock().getRelative(BlockFace.WEST); + break; + case 4: + rtBlock = sign.getBlock().getRelative(BlockFace.EAST); + break; + case 3: + rtBlock = sign.getBlock().getRelative(BlockFace.NORTH); + break; + case 2: + rtBlock = sign.getBlock().getRelative(BlockFace.SOUTH); + break; + } + } else { + rtBlock = sign.getBlock().getRelative(BlockFace.DOWN); + } + + if(rtBlock != null){ + this.isRedstoneTrigger = true; + } + } else if(splitted[0].equalsIgnoreCase("D")){ + this.isDistanceTrigger = true; + + if(splitted.length > 1){ + dtDistance = p.parseInt(splitted[1]); + } + } else if(splitted[0].equalsIgnoreCase("T")){ + this.isSignTrigger = true; + + if(splitted.length > 1){ + stId = p.parseInt(splitted[1]); } - } else { - rtBlock = sign.getBlock().getRelative(BlockFace.DOWN); - } - - if(rtBlock != null){ - this.isRedstoneTrigger = true; - } - } else if(splitted[0].equalsIgnoreCase("D")){ - this.isDistanceTrigger = true; - - if(splitted.length > 1){ - dtDistance = p.parseInt(splitted[1]); - } - } else if(splitted[0].equalsIgnoreCase("T")){ - this.isSignTrigger = true; - - if(splitted.length > 1){ - stId = p.parseInt(splitted[1]); } } } @@ -84,6 +89,10 @@ public abstract class DSign { public void onTrigger(){ + } + + public void onUpdate(int type,boolean powered){ + } public static DSign create(Sign sign, GameWorld gworld){ @@ -131,6 +140,18 @@ public abstract class DSign { //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() { return isRedstoneTrigger; } diff --git a/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java b/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java index b0a5833d..95a7724c 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java +++ b/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java @@ -33,6 +33,18 @@ public class SIGNCheckpoint extends DSign{ initialized = true; } + @Override + public void onUpdate(int type,boolean powered) { + if(initialized){ + setPowered(type,powered); + if(!isDistanceTrigger()){ + if(isPowered()){ + onTrigger(); + } + } + } + } + @Override public void onTrigger() { if(initialized){ diff --git a/src/com/dre/dungeonsxl/signs/SIGNMob.java b/src/com/dre/dungeonsxl/signs/SIGNMob.java index 1abe0d04..70a2b6ba 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNMob.java +++ b/src/com/dre/dungeonsxl/signs/SIGNMob.java @@ -57,6 +57,18 @@ public class SIGNMob extends DSign{ initialized = true; } + @Override + public void onUpdate(int type,boolean powered) { + if(initialized){ + setPowered(type,powered); + if(!isDistanceTrigger()){ + if(isPowered()){ + onTrigger(); + } + } + } + } + @Override public void onTrigger() { if(initialized){ diff --git a/src/com/dre/dungeonsxl/signs/SIGNMsg.java b/src/com/dre/dungeonsxl/signs/SIGNMsg.java index 1c42f7ae..19fc545a 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNMsg.java +++ b/src/com/dre/dungeonsxl/signs/SIGNMsg.java @@ -40,6 +40,18 @@ public class SIGNMsg extends DSign{ initialized = true; } + @Override + public void onUpdate(int type,boolean powered) { + if(initialized){ + setPowered(type,powered); + if(!isDistanceTrigger()){ + if(isPowered()){ + onTrigger(); + } + } + } + } + @Override public void onTrigger() { if(initialized){ diff --git a/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java b/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java index 648dd3d4..11216c99 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java +++ b/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java @@ -45,6 +45,18 @@ public class SIGNSoundMsg extends DSign{ initialized = true; } + @Override + public void onUpdate(int type,boolean powered) { + if(initialized){ + setPowered(type,powered); + if(!isDistanceTrigger()){ + if(isPowered()){ + onTrigger(); + } + } + } + } + @Override public void onTrigger() { if(initialized){ diff --git a/src/com/dre/dungeonsxl/signs/SIGNTrigger.java b/src/com/dre/dungeonsxl/signs/SIGNTrigger.java index 73397f50..cbdcb131 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNTrigger.java +++ b/src/com/dre/dungeonsxl/signs/SIGNTrigger.java @@ -29,7 +29,25 @@ public class SIGNTrigger extends DSign{ 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 public void onTrigger() { if(initialized){ @@ -37,7 +55,7 @@ public class SIGNTrigger extends DSign{ if(dsign != null){ if(dsign.isSignTrigger()){ if(triggerId == dsign.getStId()){ - dsign.onTrigger(); + dsign.onUpdate(1,true); } } }