diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index 02af68ac..7df1aefa 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -39,6 +39,7 @@ import com.dre.dungeonsxl.listener.EntityListener; import com.dre.dungeonsxl.listener.HangingListener; import com.dre.dungeonsxl.listener.PlayerListener; import com.dre.dungeonsxl.listener.WorldListener; +import com.dre.dungeonsxl.signs.DSignTypeRoot; public class P extends JavaPlugin{ public static P p; @@ -80,6 +81,9 @@ public class P extends JavaPlugin{ //Init Commands new DCommandRoot(); + + //Init Signtypes + DSignTypeRoot.init();; //InitFolders this.initFolders(); diff --git a/src/com/dre/dungeonsxl/commands/DCommandRoot.java b/src/com/dre/dungeonsxl/commands/DCommandRoot.java index 88bb3345..5518922f 100644 --- a/src/com/dre/dungeonsxl/commands/DCommandRoot.java +++ b/src/com/dre/dungeonsxl/commands/DCommandRoot.java @@ -46,6 +46,4 @@ public class DCommandRoot { this.commands.add(cmdHelp); this.commands.add(cmdReload); } - - } diff --git a/src/com/dre/dungeonsxl/game/DSign.java b/src/com/dre/dungeonsxl/game/DSign.java deleted file mode 100644 index 9b834c4e..00000000 --- a/src/com/dre/dungeonsxl/game/DSign.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dre.dungeonsxl.game; - -public class DSign { - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - -} diff --git a/src/com/dre/dungeonsxl/game/DSignType.java b/src/com/dre/dungeonsxl/game/DSignType.java deleted file mode 100644 index f58571e3..00000000 --- a/src/com/dre/dungeonsxl/game/DSignType.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dre.dungeonsxl.game; - -public class DSignType { - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - -} diff --git a/src/com/dre/dungeonsxl/game/GameWorld.java b/src/com/dre/dungeonsxl/game/GameWorld.java index 703753fe..bfa53f26 100644 --- a/src/com/dre/dungeonsxl/game/GameWorld.java +++ b/src/com/dre/dungeonsxl/game/GameWorld.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.ChatColor; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -23,11 +22,11 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Spider; -import com.dre.dungeonsxl.DClass; import com.dre.dungeonsxl.DConfig; -import com.dre.dungeonsxl.DGSign; import com.dre.dungeonsxl.DPlayer; import com.dre.dungeonsxl.P; +import com.dre.dungeonsxl.signs.DSignType; +import com.dre.dungeonsxl.signs.DSignTypeRoot; public class GameWorld { private static P p=P.p; @@ -79,160 +78,9 @@ public class GameWorld { Sign sign = (Sign) block.getState(); String[] lines=sign.getLines(); - if(!isPlaying){ - if (lines[1].equalsIgnoreCase("lobby")) { - this.locLobby=block.getLocation(); - block.setTypeId(0); - } else if (lines[1].equalsIgnoreCase("ready")) { - this.blocksReady.add(block); - sign.setLine(0, ChatColor.BLUE+"############"); - sign.setLine(1, ChatColor.DARK_GREEN+"Ready"); - sign.setLine(2, ""); - sign.setLine(3, ChatColor.BLUE+"############"); - sign.update(); - } else if (lines[1].equalsIgnoreCase("leave")){ - this.blocksLeave.add(block); - sign.setLine(0, ChatColor.BLUE+"############"); - sign.setLine(1, ChatColor.DARK_GREEN+"Leave"); - sign.setLine(2, ""); - sign.setLine(3, ChatColor.BLUE+"############"); - sign.update(); - } else if (lines[1].equalsIgnoreCase("start")){ - this.locStart=block.getLocation(); - block.setTypeId(0); - } else if (lines[1].equalsIgnoreCase("end")){ - this.blocksEnd.add(block); - sign.setLine(0, ChatColor.DARK_BLUE+"############"); - sign.setLine(1, ChatColor.DARK_GREEN+"End"); - sign.setLine(2, ""); - sign.setLine(3, ChatColor.DARK_BLUE+"############"); - sign.update(); - } else if (lines[1].equalsIgnoreCase("classes")){ - if(!config.isLobbyDisabled()){ - int[] direction=DGSign.getDirection(block.getData()); - int directionX=direction[0]; - int directionZ=direction[1]; - - int xx=0,zz=0; - for(DClass dclass:this.config.getClasses()){ - - //Check existing signs - boolean isContinued=true; - for(Sign isusedsign:this.signClass){ - if(dclass.name.equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))){ - isContinued=false; - } - } - - if(isContinued){ - Block classBlock=block.getRelative(xx,0,zz); - - if(classBlock.getData()==sign.getData().getData()&&classBlock.getTypeId()==68&&(classBlock.getState() instanceof Sign)){ - Sign classSign = (Sign) classBlock.getState(); - - classSign.setLine(0, ChatColor.DARK_BLUE+"############"); - classSign.setLine(1, ChatColor.DARK_GREEN+dclass.name); - classSign.setLine(2, ""); - classSign.setLine(3, ChatColor.DARK_BLUE+"############"); - classSign.update(); - this.signClass.add(classSign); - }else{ - break; - } - xx=xx+directionX; - zz=zz+directionZ; - } - } - } - else{ - block.setTypeId(0); - } - - } else if (lines[1].equalsIgnoreCase("chunkupdater")){ - Chunk chunk = this.world.getChunkAt(block); - if(!lines[2].equals("")){ - Integer radius = p.parseInt(lines[2]); - for(int x = -radius; x0){ - radius=p.parseInt(lines[2]); - } - } - - new GameCheckpoint(this,block.getLocation(),radius); - block.setTypeId(0); - } - if(lines[1].equalsIgnoreCase("chest")){ - if(sign.getTypeId()==63){ - for(int x=-1;x<=1;x++){ - if(sign.getBlock().getRelative(x, 0, 0).getTypeId()==54){ - new GameChest(sign.getBlock().getRelative(x, 0, 0),this); - } - } - for(int z=-1;z<=1;z++){ - if(sign.getBlock().getRelative(0, 0, z).getTypeId()==54){ - if(sign.getBlock().getRelative(0, 0, z)!=null){ - new GameChest(sign.getBlock().getRelative(0, 0, z),this); - } - } - } - } - block.setTypeId(0); + for(DSignType signType : DSignTypeRoot.get()){ + if(lines[0].equalsIgnoreCase("["+signType.name+"]")){ + signType.onDungeonInit(sign, this); } } } diff --git a/src/com/dre/dungeonsxl/signs/DSignType.java b/src/com/dre/dungeonsxl/signs/DSignType.java new file mode 100644 index 00000000..3a2f3421 --- /dev/null +++ b/src/com/dre/dungeonsxl/signs/DSignType.java @@ -0,0 +1,18 @@ +package com.dre.dungeonsxl.signs; + +import org.bukkit.block.Sign; + +import com.dre.dungeonsxl.P; +import com.dre.dungeonsxl.game.GameWorld; + +public abstract class DSignType { + public static P p = P.p; + + public String name; + public String permissions; + public boolean onInit; + + public abstract boolean check(Sign sign); + public abstract void onDungeonInit(Sign sign, GameWorld gworld); + public abstract void onTrigger(Sign sign, GameWorld gworld); +} diff --git a/src/com/dre/dungeonsxl/signs/DSignTypeRoot.java b/src/com/dre/dungeonsxl/signs/DSignTypeRoot.java new file mode 100644 index 00000000..bca91d8b --- /dev/null +++ b/src/com/dre/dungeonsxl/signs/DSignTypeRoot.java @@ -0,0 +1,43 @@ +package com.dre.dungeonsxl.signs; + +import java.util.concurrent.CopyOnWriteArrayList; + +public class DSignTypeRoot { + private static CopyOnWriteArrayList signTypes = new CopyOnWriteArrayList(); + + //SignTypes + private static SIGNCheckpoint signCheckpoint = new SIGNCheckpoint(); + private static SIGNChest signChest = new SIGNChest(); + private static SIGNChunkUpdater signChunkUpdater = new SIGNChunkUpdater(); + private static SIGNClasses signClasses = new SIGNClasses(); + private static SIGNEnd signEnd = new SIGNEnd(); + private static SIGNLeave signLeave = new SIGNLeave(); + private static SIGNLobby signLobby = new SIGNLobby(); + private static SIGNMob signMob = new SIGNMob(); + private static SIGNMsg signMsg = new SIGNMsg(); + private static SIGNPlace signPlace = new SIGNPlace(); + private static SIGNReady signReady = new SIGNReady(); + private static SIGNSoundMsg signSoundMsg = new SIGNSoundMsg(); + private static SIGNStart signStart = new SIGNStart(); + + //Methods + public static void init(){ + signTypes.add(signCheckpoint); + signTypes.add(signChest); + signTypes.add(signChunkUpdater); + signTypes.add(signClasses); + signTypes.add(signEnd); + signTypes.add(signLeave); + signTypes.add(signLobby); + signTypes.add(signMob); + signTypes.add(signMsg); + signTypes.add(signPlace); + signTypes.add(signReady); + signTypes.add(signSoundMsg); + signTypes.add(signStart); + } + + public static CopyOnWriteArrayList get(){ + return signTypes; + } +} diff --git a/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java b/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java new file mode 100644 index 00000000..e978e7f6 --- /dev/null +++ b/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java @@ -0,0 +1,37 @@ +package com.dre.dungeonsxl.signs; + +import org.bukkit.block.Sign; + +import com.dre.dungeonsxl.game.GameCheckpoint; +import com.dre.dungeonsxl.game.GameWorld; + +public class SIGNCheckpoint extends DSignType{ + + @Override + public boolean check(Sign sign) { + // TODO Auto-generated method stub + + return false; + } + + @Override + public void onDungeonInit(Sign sign, GameWorld gworld) { + String lines[] = sign.getLines(); + int radius = 0; + + if(lines[2] != null ){ + if(lines[2].length() > 0){ + radius = p.parseInt(lines[2]); + } + } + + new GameCheckpoint(gworld, sign.getLocation(), radius); + sign.setTypeId(0); + } + + @Override + public void onTrigger(Sign sign, GameWorld gworld) { + // TODO Auto-generated method stub + + } +} diff --git a/src/com/dre/dungeonsxl/signs/SIGNChest.java b/src/com/dre/dungeonsxl/signs/SIGNChest.java new file mode 100644 index 00000000..9a7735af --- /dev/null +++ b/src/com/dre/dungeonsxl/signs/SIGNChest.java @@ -0,0 +1,43 @@ +package com.dre.dungeonsxl.signs; + +import org.bukkit.block.Sign; + +import com.dre.dungeonsxl.game.GameChest; +import com.dre.dungeonsxl.game.GameWorld; + +public class SIGNChest extends DSignType{ + + @Override + public boolean check(Sign sign) { + // TODO Auto-generated method stub + + return false; + } + + @Override + public void onDungeonInit(Sign sign, GameWorld gworld) { + if(sign.getTypeId()==63){ + for(int x=-1;x<=1;x++){ + if(sign.getBlock().getRelative(x, 0, 0).getTypeId()==54){ + new GameChest(sign.getBlock().getRelative(x, 0, 0), gworld); + } + } + + for(int z=-1;z<=1;z++){ + if(sign.getBlock().getRelative(0, 0, z).getTypeId()==54){ + if(sign.getBlock().getRelative(0, 0, z)!=null){ + new GameChest(sign.getBlock().getRelative(0, 0, z), gworld); + } + } + } + } + + sign.setTypeId(0); + } + + @Override + public void onTrigger(Sign sign, GameWorld gworld) { + // TODO Auto-generated method stub + + } +} diff --git a/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java b/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java new file mode 100644 index 00000000..39572100 --- /dev/null +++ b/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java @@ -0,0 +1,41 @@ +package com.dre.dungeonsxl.signs; + +import org.bukkit.Chunk; +import org.bukkit.block.Sign; +import com.dre.dungeonsxl.game.GameWorld; + +public class SIGNChunkUpdater extends DSignType{ + + @Override + public boolean check(Sign sign) { + // TODO Auto-generated method stub + + return false; + } + + @Override + public void onDungeonInit(Sign sign, GameWorld gworld) { + String lines[] = sign.getLines(); + Chunk chunk = gworld.world.getChunkAt(sign.getBlock()); + if(!lines[2].equals("")){ + Integer radius = p.parseInt(lines[2]); + for(int x = -radius; x