From 90a625cae0acc8a2ce57d0856a8e731a81f02729 Mon Sep 17 00:00:00 2001 From: Grafe Date: Wed, 27 Mar 2013 01:02:05 +0100 Subject: [PATCH] Finished new Sign system and added Triggers Signed-off-by: Grafe --- plugin.yml | 2 +- src/com/dre/dungeonsxl/DPlayer.java | 103 ++++++++-------- src/com/dre/dungeonsxl/EditWorld.java | 6 +- src/com/dre/dungeonsxl/LanguageReader.java | 2 + src/com/dre/dungeonsxl/game/GameWorld.java | 31 ++--- .../dungeonsxl/listener/BlockListener.java | 106 +++++++++++------ .../dungeonsxl/listener/EntityListener.java | 24 ++-- src/com/dre/dungeonsxl/signs/DSign.java | 111 ++++++++++++++++-- .../dre/dungeonsxl/signs/SIGNCheckpoint.java | 35 ++++-- src/com/dre/dungeonsxl/signs/SIGNChest.java | 20 +++- .../dungeonsxl/signs/SIGNChunkUpdater.java | 20 +++- src/com/dre/dungeonsxl/signs/SIGNClasses.java | 29 +++-- src/com/dre/dungeonsxl/signs/SIGNEnd.java | 18 ++- src/com/dre/dungeonsxl/signs/SIGNLeave.java | 18 ++- src/com/dre/dungeonsxl/signs/SIGNLobby.java | 20 +++- src/com/dre/dungeonsxl/signs/SIGNMob.java | 36 ++++-- src/com/dre/dungeonsxl/signs/SIGNMsg.java | 31 +++-- src/com/dre/dungeonsxl/signs/SIGNPlace.java | 20 +++- src/com/dre/dungeonsxl/signs/SIGNReady.java | 18 ++- .../dre/dungeonsxl/signs/SIGNSoundMsg.java | 37 ++++-- src/com/dre/dungeonsxl/signs/SIGNStart.java | 20 +++- src/com/dre/dungeonsxl/signs/SIGNTrigger.java | 55 +++++++++ 22 files changed, 552 insertions(+), 210 deletions(-) create mode 100644 src/com/dre/dungeonsxl/signs/SIGNTrigger.java diff --git a/plugin.yml b/plugin.yml index dda5efff..b96ab50b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: DungeonsXL -version: 0.7.6 +version: 0.8 main: com.dre.dungeonsxl.P authors: [Frank Baumann] softdepend: [Vault] diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index ec0aa306..7e18b063 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -20,6 +20,7 @@ import org.getspout.spoutapi.Spout; import org.getspout.spoutapi.player.SpoutPlayer; import com.dre.dungeonsxl.game.GameWorld; +import com.dre.dungeonsxl.signs.DSign; public class DPlayer { public static P p=P.p; @@ -403,67 +404,75 @@ public class DPlayer { public static void update(boolean updateSecond){ for(DPlayer dplayer:players){ if(!updateSecond){ - //Check in World if(!dplayer.player.getWorld().equals(dplayer.world)){ if(dplayer.isEditing){ EditWorld eworld=EditWorld.get(dplayer.world); - if(eworld!=null){ - if(eworld.lobby==null){ + if(eworld != null){ + if(eworld.lobby == null){ dplayer.player.teleport(eworld.world.getSpawnLocation()); }else{ dplayer.player.teleport(eworld.lobby); } } - }else{ - GameWorld gworld=GameWorld.get(dplayer.world); - if(gworld!=null){ - if(gworld!=null){ - - DGroup dgroup=DGroup.get(dplayer.player); - if(dplayer.checkpoint==null){ - dplayer.player.teleport(dgroup.getGworld().locStart); - if(dplayer.wolf!=null){ - dplayer.wolf.teleport(dgroup.getGworld().locStart); - } - }else{ - dplayer.player.teleport(dplayer.checkpoint); - if(dplayer.wolf!=null){ - dplayer.wolf.teleport(dplayer.checkpoint); - } + } else { + GameWorld gworld = GameWorld.get(dplayer.world); + if(gworld != null){ + DGroup dgroup=DGroup.get(dplayer.player); + if(dplayer.checkpoint == null){ + dplayer.player.teleport(dgroup.getGworld().locStart); + if(dplayer.wolf != null){ + dplayer.wolf.teleport(dgroup.getGworld().locStart); } - - - //Respawn Items - for(ItemStack istack:dplayer.respawnInventory){ - if(istack!=null){ - dplayer.player.getInventory().addItem(istack); - } + }else{ + dplayer.player.teleport(dplayer.checkpoint); + if(dplayer.wolf != null){ + dplayer.wolf.teleport(dplayer.checkpoint); } - dplayer.respawnInventory.clear(); + } + + //Respawn Items + for(ItemStack istack : dplayer.respawnInventory){ + if(istack != null){ + dplayer.player.getInventory().addItem(istack); + } + } + dplayer.respawnInventory.clear(); + } + } + } + } else { + GameWorld gworld = GameWorld.get(dplayer.world); + + if(gworld != null){ + //Update Wolf + if(dplayer.wolf!=null){ + if(dplayer.wolf.isDead()){ + if(dplayer.wolfRespawnTime<=0){ + dplayer.wolf=(Wolf) dplayer.world.spawnEntity(dplayer.player.getLocation(), EntityType.WOLF); + dplayer.wolf.setTamed(true); + dplayer.wolf.setOwner(dplayer.player); + dplayer.wolfRespawnTime=30; + } + dplayer.wolfRespawnTime--; + } + } + + //Kick offline players + if(dplayer.offlineTime > 0){ + if(dplayer.offlineTime < System.currentTimeMillis()){ + dplayer.leave(); + } + } + + //Check Distance Trigger Signs + for(DSign sign : gworld.dSigns){ + if(sign.isDistanceTrigger()){ + if(dplayer.player.getLocation().distance(sign.getSign().getLocation()) < sign.getDtDistance()){ + sign.onTrigger(); } } } } - }else{ - //Update Wolf - if(dplayer.wolf!=null){ - if(dplayer.wolf.isDead()){ - if(dplayer.wolfRespawnTime<=0){ - dplayer.wolf=(Wolf) dplayer.world.spawnEntity(dplayer.player.getLocation(), EntityType.WOLF); - dplayer.wolf.setTamed(true); - dplayer.wolf.setOwner(dplayer.player); - dplayer.wolfRespawnTime=30; - } - dplayer.wolfRespawnTime--; - } - } - - //Kick offline players - if(dplayer.offlineTime > 0){ - if(dplayer.offlineTime < System.currentTimeMillis()){ - dplayer.leave(); - } - } } } } diff --git a/src/com/dre/dungeonsxl/EditWorld.java b/src/com/dre/dungeonsxl/EditWorld.java index c51745b3..ed3f8d32 100644 --- a/src/com/dre/dungeonsxl/EditWorld.java +++ b/src/com/dre/dungeonsxl/EditWorld.java @@ -75,10 +75,8 @@ public class EditWorld { out.close(); } catch (FileNotFoundException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -88,7 +86,7 @@ public class EditWorld { Sign sign = (Sign) block.getState(); String[] lines=sign.getLines(); - if(lines[1].equalsIgnoreCase("lobby")){ + if(lines[0].equalsIgnoreCase("[lobby]")){ this.lobby=block.getLocation(); } } @@ -173,10 +171,8 @@ public class EditWorld { os.close(); } catch (FileNotFoundException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } diff --git a/src/com/dre/dungeonsxl/LanguageReader.java b/src/com/dre/dungeonsxl/LanguageReader.java index 8bd801ff..baefee5e 100644 --- a/src/com/dre/dungeonsxl/LanguageReader.java +++ b/src/com/dre/dungeonsxl/LanguageReader.java @@ -61,6 +61,7 @@ public class LanguageReader { defaults.put("Player_PortalDeleted","&6Portal gelöscht!"); defaults.put("Player_PortalProgress","&6Erster Block gewählt, nun der zweite!"); defaults.put("Player_PortalCreated","&6Portal erstellt!"); + defaults.put("Player_SignCreated","&6Schild erstellt!"); /* Cmds */ defaults.put("Cmd_Chat_DungeonChat","&6Du bist nun im Dungeon-Chat"); @@ -101,6 +102,7 @@ public class LanguageReader { defaults.put("Error_SpoutCraftOnly","&4Du brauchst SpoutCraft um diesen Dungeon spielen zu können!"); defaults.put("Error_NoPortal","&4Du musst ein Portal anschauen!"); defaults.put("Error_NoPlayerCommand","&6/dxl &v1&4 kann man nicht als Spieler ausführen!"); + defaults.put("Error_SignWrongFormat","&4 Das Schild ist nicht im richtigen Format!"); /* Help */ defaults.put("Help_Cmd_Chat","/dxl chat - Ändert den Chat-Modus"); diff --git a/src/com/dre/dungeonsxl/game/GameWorld.java b/src/com/dre/dungeonsxl/game/GameWorld.java index 50bb1888..98077ea4 100644 --- a/src/com/dre/dungeonsxl/game/GameWorld.java +++ b/src/com/dre/dungeonsxl/game/GameWorld.java @@ -50,7 +50,9 @@ public class GameWorld { public CopyOnWriteArrayList signClass=new CopyOnWriteArrayList(); public CopyOnWriteArrayList dmobs = new CopyOnWriteArrayList(); public CopyOnWriteArrayList gchests = new CopyOnWriteArrayList(); + public CopyOnWriteArrayList dSigns = new CopyOnWriteArrayList(); public DConfig config; + public GameWorld(){ gworlds.add(this); @@ -74,28 +76,17 @@ public class GameWorld { public void checkSign(Block block){ if((block.getState() instanceof Sign)){ Sign sign = (Sign) block.getState(); - DSign.create(sign, this); + dSigns.add(DSign.create(sign, this)); } } public void startGame() { this.isPlaying=true; - ObjectInputStream os; - try { - os = new ObjectInputStream(new FileInputStream(new File("DXL_Game_"+this.id+"/DXLData.data"))); - int length=os.readInt(); - for(int i=0; i0 && maxPlayersPerGroup>0){ - if(DGSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup)!=null){ + if (data.length == 2) { + int maxGroups = P.p.parseInt(data[0]); + int maxPlayersPerGroup = P.p.parseInt(data[1]); + if (maxGroups > 0 && maxPlayersPerGroup > 0) { + if (DGSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup) != null) { event.setCancelled(true); } } } - } - if(lines[1].equalsIgnoreCase("Leave")){ - if(block.getState() instanceof Sign){ + } else if(lines[1].equalsIgnoreCase("Leave")) { + if (block.getState() instanceof Sign) { Sign sign = (Sign) block.getState(); new LeaveSign(sign); } @@ -138,20 +138,31 @@ public class BlockListener implements Listener { } } } - } - - //Editworld Signs - - else{ - if(lines[0].equalsIgnoreCase("[DXL]")){ - eworld.checkSign(event.getBlock()); - eworld.sign.add(event.getBlock()); - }else{ - eworld.sign.remove(event.getBlock()); + } else { //Editworld Signs + Sign sign = (Sign) block.getState(); + if(sign != null){ + sign.setLine(0, lines[0]); + sign.setLine(1, lines[1]); + sign.setLine(2, lines[2]); + sign.setLine(3, lines[3]); + + DSign dsign = DSign.create(sign, null); + + if (dsign != null) { + if (player.isOp() || P.p.permission.has(player, dsign.getPermissions())) { + if (dsign.check()) { + eworld.checkSign(block); + eworld.sign.add(block); + P.p.msg(player, P.p.language.get("Player_SignCreated")); + } else { + P.p.msg(player, P.p.language.get("Error_SignWrongFormat")); + } + } else { + P.p.msg(player, P.p.language.get("Error_NoPermissions")); + } + } } } - - } @EventHandler(priority = EventPriority.NORMAL) @@ -174,4 +185,33 @@ public class BlockListener implements Listener { } + @EventHandler(priority = EventPriority.NORMAL) + public void onBlockRedstoneEvent(BlockRedstoneEvent event){ + new RedstoneEventTask(event).runTaskLater(P.p, 1); + } + + public class RedstoneEventTask extends BukkitRunnable { + private final BlockRedstoneEvent event; + + public RedstoneEventTask(BlockRedstoneEvent event) { + this.event = event; + } + + public void run() { + for(GameWorld gworld : GameWorld.gworlds){ + if(event.getBlock().getWorld() == gworld.world){ + for(DSign sign : gworld.dSigns){ + if(sign.isRedstoneTrigger()){ + if(sign.getRtBlock().isBlockPowered()){ + sign.onTrigger(); + } + } + } + } + } + } + + } + + } diff --git a/src/com/dre/dungeonsxl/listener/EntityListener.java b/src/com/dre/dungeonsxl/listener/EntityListener.java index a4eb7fba..b4510c66 100644 --- a/src/com/dre/dungeonsxl/listener/EntityListener.java +++ b/src/com/dre/dungeonsxl/listener/EntityListener.java @@ -35,24 +35,16 @@ public class EntityListener implements Listener{ public void onCreatureSpawn(CreatureSpawnEvent event){ World world=event.getLocation().getWorld(); - EditWorld eworld=EditWorld.get(world); + EditWorld eworld = EditWorld.get(world); + GameWorld gworld = GameWorld.get(world); - if(eworld!=null){ + if(eworld != null || gworld!=null){ if( - event.getSpawnReason()==SpawnReason.CHUNK_GEN|| - event.getSpawnReason()==SpawnReason.BREEDING|| - event.getSpawnReason()==SpawnReason.NATURAL){ - event.setCancelled(true); - } - } - - GameWorld gworld=GameWorld.get(world); - - if(gworld!=null){ - if( - event.getSpawnReason()==SpawnReason.CHUNK_GEN|| - event.getSpawnReason()==SpawnReason.BREEDING|| - event.getSpawnReason()==SpawnReason.NATURAL){ + event.getSpawnReason() == SpawnReason.CHUNK_GEN || + event.getSpawnReason() == SpawnReason.BREEDING || + event.getSpawnReason() == SpawnReason.NATURAL || + event.getSpawnReason() == SpawnReason.DEFAULT) + { event.setCancelled(true); } } diff --git a/src/com/dre/dungeonsxl/signs/DSign.java b/src/com/dre/dungeonsxl/signs/DSign.java index 12ff910c..c964b07d 100644 --- a/src/com/dre/dungeonsxl/signs/DSign.java +++ b/src/com/dre/dungeonsxl/signs/DSign.java @@ -1,5 +1,8 @@ package com.dre.dungeonsxl.signs; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import com.dre.dungeonsxl.P; @@ -8,20 +11,73 @@ import com.dre.dungeonsxl.game.GameWorld; public abstract class DSign { protected static P p = P.p; - public static String name = ""; - public static String buildPermissions = ""; - public static boolean onDungeonInit = false; - protected Sign sign; protected GameWorld gworld; + //Distance Trigger + private boolean isDistanceTrigger = false; + private int dtDistance = 5; + + //Redstone Trigger + private boolean isRedstoneTrigger = false; + private Block rtBlock; + + //Sign Trigger + private boolean isSignTrigger = false; + private int stId; + + public abstract boolean check(); + + public abstract String getPermissions(); + + public abstract boolean isOnDungeonInit(); + public DSign(Sign sign, GameWorld gworld){ this.sign = sign; 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; + } + } 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]); + } + } + } } - - public abstract boolean check(Sign sign); - + public void onInit(){ } @@ -60,8 +116,47 @@ public abstract class DSign { dSign = new SIGNSoundMsg(sign, gworld); } else if (lines[0].equalsIgnoreCase("["+SIGNStart.name+"]")) { dSign = new SIGNStart(sign, gworld); - } + } else if (lines[0].equalsIgnoreCase("["+SIGNTrigger.name+"]")) { + dSign = new SIGNTrigger(sign, gworld); + } + + if (dSign != null && gworld != null) { + if (dSign.isOnDungeonInit()) { + dSign.onInit(); + } + } return dSign; } + + + //Getter anb Setter + public boolean isRedstoneTrigger() { + return isRedstoneTrigger; + } + + public boolean isDistanceTrigger() { + return isDistanceTrigger; + } + + public Block getRtBlock() { + return rtBlock; + } + + public int getDtDistance() { + return dtDistance; + } + + public boolean isSignTrigger() { + return isSignTrigger; + } + + public int getStId() { + return stId; + } + + public Sign getSign() { + return sign; + } + } diff --git a/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java b/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java index 29d85baf..b0a5833d 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java +++ b/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java @@ -9,30 +9,49 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNCheckpoint extends DSign{ public static String name = "Checkpoint"; - public static String buildPermissions = "dxl.sign.checkpoint"; - public static boolean onDungeonInit = false; + private String buildPermissions = "dxl.sign.checkpoint"; + private boolean onDungeonInit = false; + + //Variables + private boolean initialized; public SIGNCheckpoint(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override public void onInit() { - sign.setTypeId(0); + sign.getBlock().setTypeId(0); + + initialized = true; } @Override public void onTrigger() { - for(DPlayer dplayer:DPlayer.get(this.gworld.world)){ - dplayer.setCheckpoint(this.sign.getLocation()); - P.p.msg(dplayer.player, P.p.language.get("Player_CheckpointReached")); + if(initialized){ + for(DPlayer dplayer:DPlayer.get(this.gworld.world)){ + dplayer.setCheckpoint(this.sign.getLocation()); + P.p.msg(dplayer.player, P.p.language.get("Player_CheckpointReached")); + } + + this.gworld.dSigns.remove(this); } } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNChest.java b/src/com/dre/dungeonsxl/signs/SIGNChest.java index 7c414020..ffc72b24 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNChest.java +++ b/src/com/dre/dungeonsxl/signs/SIGNChest.java @@ -8,18 +8,18 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNChest extends DSign{ public static String name = "Chest"; - public static String buildPermissions = "dxl.sign.chest"; - public static boolean onDungeonInit = false; + public String buildPermissions = "dxl.sign.chest"; + public boolean onDungeonInit = false; public SIGNChest(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -40,6 +40,16 @@ public class SIGNChest extends DSign{ } } - sign.setTypeId(0); + sign.getBlock().setTypeId(0); + } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java b/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java index 156a0df5..e2e5d47a 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java +++ b/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java @@ -7,18 +7,18 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNChunkUpdater extends DSign{ public static String name = "ChunkUpdater"; - public static String buildPermissions = "dxl.sign.chunkupdater"; - public static boolean onDungeonInit = true; + public String buildPermissions = "dxl.sign.chunkupdater"; + public boolean onDungeonInit = true; public SIGNChunkUpdater(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -38,6 +38,16 @@ public class SIGNChunkUpdater extends DSign{ chunk.load(); gworld.loadedChunks.add(chunk); } - sign.setTypeId(0); + sign.getBlock().setTypeId(0); + } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNClasses.java b/src/com/dre/dungeonsxl/signs/SIGNClasses.java index 3635af82..6facc00d 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNClasses.java +++ b/src/com/dre/dungeonsxl/signs/SIGNClasses.java @@ -11,30 +11,31 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNClasses extends DSign{ public static String name = "Classes"; - public static String buildPermissions = "dxl.sign.classes"; - public static boolean onDungeonInit = true; + public String buildPermissions = "dxl.sign.classes"; + public boolean onDungeonInit = true; public SIGNClasses(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override public void onInit() { if(!gworld.config.isLobbyDisabled()){ + int[] direction=DGSign.getDirection(sign.getBlock().getData()); int directionX=direction[0]; int directionZ=direction[1]; int xx=0,zz=0; for(DClass dclass:gworld.config.getClasses()){ - + //Check existing signs boolean isContinued=true; for(Sign isusedsign:gworld.signClass){ @@ -42,11 +43,11 @@ public class SIGNClasses extends DSign{ isContinued=false; } } - + if(isContinued){ Block classBlock=sign.getBlock().getRelative(xx,0,zz); - if(classBlock.getData()==sign.getData().getData()&&classBlock.getTypeId()==68&&(classBlock.getState() instanceof Sign)){ + if(classBlock.getData() == sign.getData().getData() && classBlock.getTypeId() == 68 && (classBlock.getState() instanceof Sign)){ Sign classSign = (Sign) classBlock.getState(); classSign.setLine(0, ChatColor.DARK_BLUE+"############"); @@ -54,16 +55,28 @@ public class SIGNClasses extends DSign{ classSign.setLine(2, ""); classSign.setLine(3, ChatColor.DARK_BLUE+"############"); classSign.update(); + gworld.signClass.add(classSign); }else{ break; } + xx=xx+directionX; zz=zz+directionZ; } } } else { - sign.setTypeId(0); + sign.getBlock().setTypeId(0); } } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNEnd.java b/src/com/dre/dungeonsxl/signs/SIGNEnd.java index 33f00a42..72eb04a4 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNEnd.java +++ b/src/com/dre/dungeonsxl/signs/SIGNEnd.java @@ -7,18 +7,18 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNEnd extends DSign{ public static String name = "End"; - public static String buildPermissions = "dxl.sign.end"; - public static boolean onDungeonInit = false; + public String buildPermissions = "dxl.sign.end"; + public boolean onDungeonInit = false; public SIGNEnd(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -30,4 +30,14 @@ public class SIGNEnd extends DSign{ sign.setLine(3, ChatColor.DARK_BLUE+"############"); sign.update(); } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNLeave.java b/src/com/dre/dungeonsxl/signs/SIGNLeave.java index a8ab85d9..322a9fe6 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNLeave.java +++ b/src/com/dre/dungeonsxl/signs/SIGNLeave.java @@ -7,18 +7,18 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNLeave extends DSign{ public static String name = "Leave"; - public static String buildPermissions = "dxl.sign.leave"; - public static boolean onDungeonInit = true; + public String buildPermissions = "dxl.sign.leave"; + public boolean onDungeonInit = true; public SIGNLeave(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -30,4 +30,14 @@ public class SIGNLeave extends DSign{ sign.setLine(3, ChatColor.BLUE+"############"); sign.update(); } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNLobby.java b/src/com/dre/dungeonsxl/signs/SIGNLobby.java index a40902c6..e6ada09a 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNLobby.java +++ b/src/com/dre/dungeonsxl/signs/SIGNLobby.java @@ -6,23 +6,33 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNLobby extends DSign{ public static String name = "Lobby"; - public static String buildPermissions = "dxl.sign.lobby"; - public static boolean onDungeonInit = true; + public String buildPermissions = "dxl.sign.lobby"; + public boolean onDungeonInit = true; public SIGNLobby(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override public void onInit() { gworld.locLobby = sign.getLocation(); - sign.setTypeId(0); + sign.getBlock().setTypeId(0); + } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNMob.java b/src/com/dre/dungeonsxl/signs/SIGNMob.java index 9d5b264f..1abe0d04 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNMob.java +++ b/src/com/dre/dungeonsxl/signs/SIGNMob.java @@ -16,8 +16,8 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNMob extends DSign{ public static String name = "Mob"; - public static String buildPermissions = "dxl.sign.mob"; - public static boolean onDungeonInit = false; + public String buildPermissions = "dxl.sign.mob"; + public boolean onDungeonInit = false; //Variables @@ -25,16 +25,17 @@ public class SIGNMob extends DSign{ private int maxinterval = 1; private int interval = 0; private int amount = 1; + private boolean initialized; public SIGNMob(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -51,15 +52,21 @@ public class SIGNMob extends DSign{ } } } - sign.setTypeId(0); + sign.getBlock().setTypeId(0); + + initialized = true; } @Override public void onTrigger() { - MobSpawnScheduler scheduler = new MobSpawnScheduler(this); - - int id = p.getServer().getScheduler().scheduleSyncRepeatingTask(p, scheduler, 0L, 20L); - scheduler.id = id; + if(initialized){ + MobSpawnScheduler scheduler = new MobSpawnScheduler(this); + + int id = p.getServer().getScheduler().scheduleSyncRepeatingTask(p, scheduler, 0L, 20L); + scheduler.id = id; + + initialized = false; + } } public class MobSpawnScheduler implements Runnable{ @@ -105,6 +112,7 @@ public class SIGNMob extends DSign{ amount--; }else{ p.getServer().getScheduler().cancelTask(this.id); + sign.gworld.dSigns.remove(this); } } @@ -113,4 +121,14 @@ public class SIGNMob extends DSign{ sign.interval--; } } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNMsg.java b/src/com/dre/dungeonsxl/signs/SIGNMsg.java index bf01d227..1c42f7ae 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNMsg.java +++ b/src/com/dre/dungeonsxl/signs/SIGNMsg.java @@ -7,21 +7,22 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNMsg extends DSign{ public static String name = "Msg"; - public static String buildPermissions = "dxl.sign.msg"; - public static boolean onDungeonInit = false; + public String buildPermissions = "dxl.sign.msg"; + public boolean onDungeonInit = false; //Variables private String msg; + private boolean initialized; public SIGNMsg(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -32,15 +33,31 @@ public class SIGNMsg extends DSign{ String msg = gworld.config.getMsg(p.parseInt(lines[1]),true); if(msg!=null){ this.msg = msg; - sign.setTypeId(0); + sign.getBlock().setTypeId(0); } } + + initialized = true; } @Override public void onTrigger() { - for(Player player : gworld.world.getPlayers()){ - p.msg(player, msg); + if(initialized){ + for(Player player : gworld.world.getPlayers()){ + p.msg(player, msg); + } + + this.gworld.dSigns.remove(this); } } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNPlace.java b/src/com/dre/dungeonsxl/signs/SIGNPlace.java index 7f2a38ee..8643fedf 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNPlace.java +++ b/src/com/dre/dungeonsxl/signs/SIGNPlace.java @@ -8,24 +8,34 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNPlace extends DSign{ public static String name = "Place"; - public static String buildPermissions = "dxl.sign.place"; - public static boolean onDungeonInit = false; + public String buildPermissions = "dxl.sign.place"; + public boolean onDungeonInit = false; public SIGNPlace(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override public void onInit() { String lines[] = sign.getLines(); gworld.placeableBlocks.add(new GamePlaceableBlock(sign.getBlock(), lines[1], lines[2]) ); - sign.setTypeId(0); + sign.getBlock().setTypeId(0); + } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNReady.java b/src/com/dre/dungeonsxl/signs/SIGNReady.java index 1e826b3b..b803a650 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNReady.java +++ b/src/com/dre/dungeonsxl/signs/SIGNReady.java @@ -7,18 +7,18 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNReady extends DSign{ public static String name = "Ready"; - public static String buildPermissions = "dxl.sign.ready"; - public static boolean onDungeonInit = true; + public String buildPermissions = "dxl.sign.ready"; + public boolean onDungeonInit = true; public SIGNReady(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -30,4 +30,14 @@ public class SIGNReady extends DSign{ sign.setLine(3, ChatColor.BLUE+"############"); sign.update(); } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java b/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java index 2efeb170..648dd3d4 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java +++ b/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java @@ -12,10 +12,11 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNSoundMsg extends DSign{ public static String name = "SoundMsg"; - public static String buildPermissions = "dxl.sign.soundmsg"; - public static boolean onDungeonInit = false; + public String buildPermissions = "dxl.sign.soundmsg"; + public boolean onDungeonInit = false; //Variables + private boolean initialized; private String msg; public SIGNSoundMsg(Sign sign, GameWorld gworld) { @@ -23,10 +24,10 @@ public class SIGNSoundMsg extends DSign{ } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override @@ -37,20 +38,36 @@ public class SIGNSoundMsg extends DSign{ String msg = gworld.config.getMsg(p.parseInt(lines[1]),true); if(msg!=null){ this.msg = msg; - sign.setTypeId(0); + sign.getBlock().setTypeId(0); } } + + initialized = true; } @Override public void onTrigger() { - if(P.p.isSpoutEnabled){ - for(Player player : gworld.world.getPlayers()){ - SpoutPlayer sPlayer = Spout.getServer().getPlayer(player.getName()); - if(sPlayer.isSpoutCraftEnabled()){ - SpoutManager.getSoundManager().playCustomMusic(P.p, sPlayer, this.msg, false, this.sign.getLocation()); + if(initialized){ + if(P.p.isSpoutEnabled){ + for(Player player : gworld.world.getPlayers()){ + SpoutPlayer sPlayer = Spout.getServer().getPlayer(player.getName()); + if(sPlayer.isSpoutCraftEnabled()){ + SpoutManager.getSoundManager().playCustomMusic(P.p, sPlayer, this.msg, false, this.sign.getLocation()); + } } } + + this.gworld.dSigns.remove(this); } } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNStart.java b/src/com/dre/dungeonsxl/signs/SIGNStart.java index a8f179c2..d44d6bfa 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNStart.java +++ b/src/com/dre/dungeonsxl/signs/SIGNStart.java @@ -6,23 +6,33 @@ import com.dre.dungeonsxl.game.GameWorld; public class SIGNStart extends DSign{ public static String name = "Start"; - public static String buildPermissions = "dxl.sign.start"; - public static boolean onDungeonInit = true; + public String buildPermissions = "dxl.sign.start"; + public boolean onDungeonInit = true; public SIGNStart(Sign sign, GameWorld gworld) { super(sign, gworld); } @Override - public boolean check(Sign sign) { + public boolean check() { // TODO Auto-generated method stub - return false; + return true; } @Override public void onInit() { gworld.locStart = sign.getLocation(); - sign.setTypeId(0); + sign.getBlock().setTypeId(0); + } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNTrigger.java b/src/com/dre/dungeonsxl/signs/SIGNTrigger.java new file mode 100644 index 00000000..a7378607 --- /dev/null +++ b/src/com/dre/dungeonsxl/signs/SIGNTrigger.java @@ -0,0 +1,55 @@ +package com.dre.dungeonsxl.signs; + +import org.bukkit.block.Sign; + +import com.dre.dungeonsxl.game.GameWorld; + +public class SIGNTrigger extends DSign{ + public static String name = "Trigger"; + public String buildPermissions = "dxl.sign.trigger"; + public boolean onDungeonInit = false; + + //Variables + private int triggerId; + private boolean initialized; + + public SIGNTrigger(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + + @Override + public boolean check() { + return true; + } + + @Override + public void onInit() { + triggerId = p.parseInt(sign.getLine(1)); + sign.getBlock().setTypeId(0); + + initialized = true; + } + + @Override + public void onTrigger() { + if(initialized){ + for(DSign dsign : this.gworld.dSigns){ + if(dsign.isSignTrigger()){ + if(triggerId == dsign.getStId()){ + dsign.onTrigger(); + } + } + } + } + } + + @Override + public String getPermissions() { + return buildPermissions; + } + + @Override + public boolean isOnDungeonInit() { + return onDungeonInit; + } +}