diff --git a/src/com/dre/dungeonsxl/DMobType.java b/src/com/dre/dungeonsxl/DMobType.java index 7b6ac35f..9284bb5a 100644 --- a/src/com/dre/dungeonsxl/DMobType.java +++ b/src/com/dre/dungeonsxl/DMobType.java @@ -92,8 +92,14 @@ public class DMobType { } } + /* Set Health */ + if(maxHealth > 0){ + entity.setMaxHealth(maxHealth); + entity.setHealth(maxHealth); + } + /* Spawn Mob */ - new DMob(entity, maxHealth, gWorld, this); + new DMob(entity, gWorld, this); } } diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index 7c1218ac..ae56d9b9 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -32,14 +32,12 @@ import org.bukkit.plugin.java.JavaPlugin; import com.dre.dungeonsxl.commands.DCommandRoot; import com.dre.dungeonsxl.game.GameCheckpoint; import com.dre.dungeonsxl.game.GameWorld; -import com.dre.dungeonsxl.game.MobSpawner; import com.dre.dungeonsxl.listener.BlockListener; import com.dre.dungeonsxl.listener.CommandListener; 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.DSignRoot; public class P extends JavaPlugin{ public static P p; @@ -81,9 +79,6 @@ public class P extends JavaPlugin{ //Init Commands new DCommandRoot(); - - //Init Signtypes - DSignRoot.init();; //InitFolders this.initFolders(); @@ -145,7 +140,6 @@ public class P extends JavaPlugin{ LeaveSign.lsigns.clear(); DCommandRoot.root.commands.clear(); GameCheckpoint.gcheckpoints.clear(); - MobSpawner.mobspawners.clear(); //Delete Worlds GameWorld.deleteAll(); @@ -195,7 +189,6 @@ public class P extends JavaPlugin{ p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() { public void run() { - MobSpawner.updateAll(); GameWorld.update(); GameCheckpoint.update(); DPlayer.update(true); diff --git a/src/com/dre/dungeonsxl/game/DMob.java b/src/com/dre/dungeonsxl/game/DMob.java index bd245e8a..bb559852 100644 --- a/src/com/dre/dungeonsxl/game/DMob.java +++ b/src/com/dre/dungeonsxl/game/DMob.java @@ -14,7 +14,7 @@ public class DMob { public LivingEntity entity; public DMobType type; - public DMob(LivingEntity entity, int live, GameWorld gworld, DMobType type){ + public DMob(LivingEntity entity, GameWorld gworld, DMobType type){ gworld.dmobs.add(this); this.entity = entity; @@ -26,12 +26,6 @@ public class DMob { this.entity.getEquipment().setLeggingsDropChance(0); this.entity.getEquipment().setBootsDropChance(0); this.entity.getEquipment().setItemInHandDropChance(0); - - /* Max Health */ - if(live>0){ - this.entity.setMaxHealth(live); - this.entity.setHealth(live); - } } //Statics diff --git a/src/com/dre/dungeonsxl/game/GameWorld.java b/src/com/dre/dungeonsxl/game/GameWorld.java index f6767bd0..c87dcae1 100644 --- a/src/com/dre/dungeonsxl/game/GameWorld.java +++ b/src/com/dre/dungeonsxl/game/GameWorld.java @@ -26,7 +26,6 @@ import com.dre.dungeonsxl.DConfig; import com.dre.dungeonsxl.DPlayer; import com.dre.dungeonsxl.P; import com.dre.dungeonsxl.signs.DSign; -import com.dre.dungeonsxl.signs.DSignRoot; public class GameWorld { private static P p=P.p; @@ -76,13 +75,7 @@ public class GameWorld { public void checkSign(Block block){ if((block.getState() instanceof Sign)){ Sign sign = (Sign) block.getState(); - String[] lines=sign.getLines(); - - for(DSign signType : DSignRoot.get()){ - if(lines[0].equalsIgnoreCase("["+signType.name+"]")){ - signType.onDungeonInit(sign, this); - } - } + DSign.create(sign, this); } } diff --git a/src/com/dre/dungeonsxl/game/MobSpawner.java b/src/com/dre/dungeonsxl/game/MobSpawner.java deleted file mode 100644 index a9c4d0c0..00000000 --- a/src/com/dre/dungeonsxl/game/MobSpawner.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.dre.dungeonsxl.game; - -import java.util.concurrent.CopyOnWriteArrayList; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.inventory.ItemStack; - -import com.dre.dungeonsxl.DMobType; - -public class MobSpawner { - public static CopyOnWriteArrayList mobspawners=new CopyOnWriteArrayList(); - - //Variables - private String mob; - private Block block; - private int maxinterval; - private int interval=0; - private int amount; - private int radius; - private int live; - - public MobSpawner(Block block, String mob, int interval, int amount, int radius, int live){ - mobspawners.add(this); - - this.block=block; - this.mob=mob; - this.maxinterval=interval; - this.amount=amount; - this.radius=radius; - this.live=live; - } - - public void update(){ - World world=this.block.getWorld(); - GameWorld gworld = GameWorld.get(world); - if(gworld != null){ - for(Player player:world.getPlayers()){ - if(player.getWorld()==world){ - if(player.getLocation().distance(this.block.getLocation())1){ - amount--; - }else{ - mobspawners.remove(this); - } - } - this.interval=this.maxinterval; - } - this.interval--; - return; - } - } - } - } - } - - //Static - public static void updateAll(){ - for(MobSpawner spawner:mobspawners){ - spawner.update(); - } - } - -} diff --git a/src/com/dre/dungeonsxl/signs/DSign.java b/src/com/dre/dungeonsxl/signs/DSign.java index 8e57d659..12ff910c 100644 --- a/src/com/dre/dungeonsxl/signs/DSign.java +++ b/src/com/dre/dungeonsxl/signs/DSign.java @@ -6,13 +6,62 @@ import com.dre.dungeonsxl.P; import com.dre.dungeonsxl.game.GameWorld; public abstract class DSign { - public static P p = P.p; + protected static P p = P.p; - public String name; - public String permissions; - public boolean onInit; + public static String name = ""; + public static String buildPermissions = ""; + public static boolean onDungeonInit = false; + + protected Sign sign; + protected GameWorld gworld; + + public DSign(Sign sign, GameWorld gworld){ + this.sign = sign; + this.gworld = gworld; + } public abstract boolean check(Sign sign); - public abstract void onDungeonInit(Sign sign, GameWorld gworld); - public abstract void onTrigger(Sign sign, GameWorld gworld); + + public void onInit(){ + + } + + public void onTrigger(){ + + } + + public static DSign create(Sign sign, GameWorld gworld){ + String[] lines = sign.getLines(); + DSign dSign = null; + + if(lines[0].equalsIgnoreCase("["+SIGNCheckpoint.name+"]")) { + dSign = new SIGNCheckpoint(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNChest.name+"]")) { + dSign = new SIGNChest(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNChunkUpdater.name+"]")) { + dSign = new SIGNChunkUpdater(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNClasses.name+"]")) { + dSign = new SIGNClasses(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNEnd.name+"]")) { + dSign = new SIGNEnd(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNLeave.name+"]")) { + dSign = new SIGNLeave(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNLobby.name+"]")) { + dSign = new SIGNLobby(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNMob.name+"]")) { + dSign = new SIGNMob(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNMsg.name+"]")) { + dSign = new SIGNMsg(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNPlace.name+"]")) { + dSign = new SIGNPlace(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNReady.name+"]")) { + dSign = new SIGNReady(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNSoundMsg.name+"]")) { + dSign = new SIGNSoundMsg(sign, gworld); + } else if (lines[0].equalsIgnoreCase("["+SIGNStart.name+"]")) { + dSign = new SIGNStart(sign, gworld); + } + + return dSign; + } } diff --git a/src/com/dre/dungeonsxl/signs/DSignRoot.java b/src/com/dre/dungeonsxl/signs/DSignRoot.java deleted file mode 100644 index 61db4497..00000000 --- a/src/com/dre/dungeonsxl/signs/DSignRoot.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.dre.dungeonsxl.signs; - -import java.util.concurrent.CopyOnWriteArrayList; - -public class DSignRoot { - 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 index 1a8024c1..3f5f4d52 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java +++ b/src/com/dre/dungeonsxl/signs/SIGNCheckpoint.java @@ -6,7 +6,16 @@ import com.dre.dungeonsxl.game.GameCheckpoint; 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; + + public SIGNCheckpoint(Sign sign, GameWorld gworld) { + super(sign, gworld); + // TODO Auto-generated constructor stub + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -15,13 +24,13 @@ public class SIGNCheckpoint extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { String lines[] = sign.getLines(); int radius = 0; - if(lines[2] != null ){ - if(lines[2].length() > 0){ - radius = p.parseInt(lines[2]); + if(lines[1] != null ){ + if(lines[1].length() > 0){ + radius = p.parseInt(lines[1]); } } @@ -30,7 +39,7 @@ public class SIGNCheckpoint extends DSign{ } @Override - public void onTrigger(Sign sign, GameWorld gworld) { + public void onTrigger() { // TODO Auto-generated method stub } diff --git a/src/com/dre/dungeonsxl/signs/SIGNChest.java b/src/com/dre/dungeonsxl/signs/SIGNChest.java index 02e4ba1d..7c414020 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNChest.java +++ b/src/com/dre/dungeonsxl/signs/SIGNChest.java @@ -6,7 +6,15 @@ import com.dre.dungeonsxl.game.GameChest; 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 SIGNChest(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -15,7 +23,7 @@ public class SIGNChest extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { if(sign.getTypeId()==63){ for(int x=-1;x<=1;x++){ if(sign.getBlock().getRelative(x, 0, 0).getTypeId()==54){ @@ -34,10 +42,4 @@ public class SIGNChest extends DSign{ 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 index 30d55685..13a1177b 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java +++ b/src/com/dre/dungeonsxl/signs/SIGNChunkUpdater.java @@ -5,7 +5,16 @@ import org.bukkit.block.Sign; 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 SIGNChunkUpdater(Sign sign, GameWorld gworld) { + super(sign, gworld); + // TODO Auto-generated constructor stub + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -14,11 +23,11 @@ public class SIGNChunkUpdater extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { String lines[] = sign.getLines(); Chunk chunk = gworld.world.getChunkAt(sign.getBlock()); - if(!lines[2].equals("")){ - Integer radius = p.parseInt(lines[2]); + if(!lines[1].equals("")){ + Integer radius = p.parseInt(lines[1]); for(int x = -radius; x1){ + amount--; + }else{ + p.getServer().getScheduler().cancelTask(this.id); + } + } + + sign.interval = sign.maxinterval; + } + sign.interval--; + } } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNMsg.java b/src/com/dre/dungeonsxl/signs/SIGNMsg.java index a37a0e28..47709f72 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNMsg.java +++ b/src/com/dre/dungeonsxl/signs/SIGNMsg.java @@ -6,7 +6,15 @@ import com.dre.dungeonsxl.game.GameMessage; 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 SIGNMsg(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -15,20 +23,20 @@ public class SIGNMsg extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { String lines[] = sign.getLines(); - if(lines[2]!=""&&lines[3]!=""){ - String msg = gworld.config.getMsg(p.parseInt(lines[2]),true); + if(lines[1]!=""&&lines[2]!=""){ + String msg = gworld.config.getMsg(p.parseInt(lines[1]),true); if(msg!=null){ - gworld.messages.add(new GameMessage(sign.getBlock().getLocation(), msg,p.parseInt(lines[3]), false)); + gworld.messages.add(new GameMessage(sign.getBlock().getLocation(), msg,p.parseInt(lines[2]), false)); sign.setTypeId(0); } } } @Override - public void onTrigger(Sign sign, GameWorld gworld) { + public void onTrigger() { // TODO Auto-generated method stub } diff --git a/src/com/dre/dungeonsxl/signs/SIGNPlace.java b/src/com/dre/dungeonsxl/signs/SIGNPlace.java index 72fb7a10..7f2a38ee 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNPlace.java +++ b/src/com/dre/dungeonsxl/signs/SIGNPlace.java @@ -6,7 +6,15 @@ import com.dre.dungeonsxl.game.GamePlaceableBlock; 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 SIGNPlace(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -15,15 +23,9 @@ public class SIGNPlace extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { String lines[] = sign.getLines(); - gworld.placeableBlocks.add(new GamePlaceableBlock(sign.getBlock(), lines[2], lines[3]) ); + gworld.placeableBlocks.add(new GamePlaceableBlock(sign.getBlock(), lines[1], lines[2]) ); sign.setTypeId(0); } - - @Override - public void onTrigger(Sign sign, GameWorld gworld) { - // TODO Auto-generated method stub - - } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNReady.java b/src/com/dre/dungeonsxl/signs/SIGNReady.java index ffc6e0df..1e826b3b 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNReady.java +++ b/src/com/dre/dungeonsxl/signs/SIGNReady.java @@ -5,7 +5,15 @@ import org.bukkit.block.Sign; 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 SIGNReady(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -14,7 +22,7 @@ public class SIGNReady extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { gworld.blocksReady.add(sign.getBlock()); sign.setLine(0, ChatColor.BLUE+"############"); sign.setLine(1, ChatColor.DARK_GREEN+"Ready"); @@ -22,9 +30,4 @@ public class SIGNReady extends DSign{ sign.setLine(3, ChatColor.BLUE+"############"); sign.update(); } - - @Override - public void onTrigger(Sign sign, GameWorld gworld) { - - } } diff --git a/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java b/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java index 6b98880b..a85efcf0 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java +++ b/src/com/dre/dungeonsxl/signs/SIGNSoundMsg.java @@ -6,7 +6,15 @@ import com.dre.dungeonsxl.game.GameMessage; 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 SIGNSoundMsg(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -15,20 +23,20 @@ public class SIGNSoundMsg extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { String lines[] = sign.getLines(); - if(lines[2]!=""&&lines[3]!=""){ - String msg = gworld.config.getMsg(p.parseInt(lines[2]),true); + if(lines[1]!=""&&lines[2]!=""){ + String msg = gworld.config.getMsg(p.parseInt(lines[1]),true); if(msg!=null){ - gworld.messages.add(new GameMessage(sign.getBlock().getLocation(), msg,p.parseInt(lines[3]), true)); + gworld.messages.add(new GameMessage(sign.getBlock().getLocation(), msg,p.parseInt(lines[2]), true)); sign.setTypeId(0); } } } @Override - public void onTrigger(Sign sign, GameWorld gworld) { + public void onTrigger() { // TODO Auto-generated method stub } diff --git a/src/com/dre/dungeonsxl/signs/SIGNStart.java b/src/com/dre/dungeonsxl/signs/SIGNStart.java index 2ca363ca..a8f179c2 100644 --- a/src/com/dre/dungeonsxl/signs/SIGNStart.java +++ b/src/com/dre/dungeonsxl/signs/SIGNStart.java @@ -4,7 +4,15 @@ import org.bukkit.block.Sign; 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 SIGNStart(Sign sign, GameWorld gworld) { + super(sign, gworld); + } + @Override public boolean check(Sign sign) { // TODO Auto-generated method stub @@ -13,14 +21,8 @@ public class SIGNStart extends DSign{ } @Override - public void onDungeonInit(Sign sign, GameWorld gworld) { + public void onInit() { gworld.locStart = sign.getLocation(); sign.setTypeId(0); } - - @Override - public void onTrigger(Sign sign, GameWorld gworld) { - // TODO Auto-generated method stub - - } }