From 1e3482fe3ceb796ed06073af110b252b93bfdae9 Mon Sep 17 00:00:00 2001 From: Grafe Date: Fri, 18 Jan 2013 03:08:55 +0100 Subject: [PATCH] Changed GameMessages update method --- src/com/dre/dungeonsxl/DConfig.java | 10 ++++---- src/com/dre/dungeonsxl/DPlayer.java | 2 +- src/com/dre/dungeonsxl/P.java | 5 +--- src/com/dre/dungeonsxl/game/GameMessage.java | 27 ++++++++------------ src/com/dre/dungeonsxl/game/GameWorld.java | 26 +++++++++++-------- 5 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/com/dre/dungeonsxl/DConfig.java b/src/com/dre/dungeonsxl/DConfig.java index 022fd953..69658c44 100644 --- a/src/com/dre/dungeonsxl/DConfig.java +++ b/src/com/dre/dungeonsxl/DConfig.java @@ -123,8 +123,8 @@ public class DConfig { } /* Secure Objects */ - if(configFile.contains("secureobjects")){ - List secureobjectlist = configFile.getIntegerList("secureobjects"); + if(configFile.contains("secureObjects")){ + List secureobjectlist = configFile.getIntegerList("secureObjects"); for(int i:secureobjectlist){ this.secureObjects.add(Material.getMaterial(i)); } @@ -172,13 +172,13 @@ public class DConfig { } //Secure Objects - CopyOnWriteArrayList secureobjectsids=new CopyOnWriteArrayList(); + CopyOnWriteArrayList secureObjectsids=new CopyOnWriteArrayList(); for(Material mat:this.secureObjects){ - secureobjectsids.add(mat.getId()); + secureObjectsids.add(mat.getId()); } - configFile.set("secureobjects", secureobjectsids); + configFile.set("secureObjects", secureObjectsids); //Invited Players configFile.set("invitedplayers", this.invitedPlayers); diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index f62dc9ae..54bf04d2 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -189,7 +189,7 @@ public class DPlayer { if(groupplayer!=null){ for(ItemStack istack:this.player.getInventory()){ if(istack!=null){ - if(gworld.secureobjects.contains(istack.getType())){ + if(gworld.secureObjects.contains(istack.getType())){ groupplayer.getInventory().addItem(istack); } } diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index 45a37aca..e7684947 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -27,7 +27,6 @@ import org.bukkit.plugin.java.JavaPlugin; import com.dre.dungeonsxl.commands.DCommandRoot; import com.dre.dungeonsxl.game.GameCheckpoint; -import com.dre.dungeonsxl.game.GameMessage; import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.game.MobSpawner; import com.dre.dungeonsxl.listener.BlockListener; @@ -141,7 +140,6 @@ public class P extends JavaPlugin{ LeaveSign.lsigns.clear(); DCommandRoot.root.commands.clear(); GameCheckpoint.gcheckpoints.clear(); - GameMessage.gmessages.clear(); MobSpawner.mobspawners.clear(); //Delete Worlds @@ -192,10 +190,9 @@ public class P extends JavaPlugin{ public void run() { MobSpawner.updateAll(); GameWorld.update(); - GameMessage.updateAll(); GameCheckpoint.update(); DPlayer.update(true); - + //Tutorial Mode if(p.mainConfig.tutorialActivated){ for(Player player:p.getServer().getOnlinePlayers()){ diff --git a/src/com/dre/dungeonsxl/game/GameMessage.java b/src/com/dre/dungeonsxl/game/GameMessage.java index 76aecf49..1983e5bc 100644 --- a/src/com/dre/dungeonsxl/game/GameMessage.java +++ b/src/com/dre/dungeonsxl/game/GameMessage.java @@ -2,7 +2,7 @@ package com.dre.dungeonsxl.game; import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.block.Block; +import org.bukkit.Location; import org.getspout.spoutapi.Spout; import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.player.SpoutPlayer; @@ -11,44 +11,37 @@ import com.dre.dungeonsxl.DPlayer; import com.dre.dungeonsxl.P; public class GameMessage { - public static CopyOnWriteArrayList gmessages=new CopyOnWriteArrayList(); //Variables public CopyOnWriteArrayList playerDone=new CopyOnWriteArrayList(); - public Block block; + public Location location; public String msg; - public GameWorld gworld; public int radius; public boolean isSpoutSoundMsg; - public GameMessage(Block block, int msgid,GameWorld gworld,int radius,boolean isSpoutSoundMsg){ - this.block=block; - this.msg=gworld.config.getMsg(msgid); - this.gworld=gworld; + public GameMessage(Location location, String msg,int radius,boolean isSpoutSoundMsg){ + this.location=location; + this.msg = msg; this.radius=radius; this.isSpoutSoundMsg=isSpoutSoundMsg; - - if(this.msg!=null){ - gmessages.add(this); - } } //Static - public static void updateAll(){ - for(GameMessage gmessage:gmessages){ - for(DPlayer dplayer:DPlayer.get(gmessage.gworld.world)){ + public static void update(GameWorld gworld){ + for(GameMessage gmessage:gworld.messages){ + for(DPlayer dplayer:DPlayer.get(gworld.world)){ if(!gmessage.playerDone.contains(dplayer)){ - if(dplayer.player.getLocation().distance(gmessage.block.getLocation()) blocksLeave=new CopyOnWriteArrayList(); public boolean isPlaying=false; public int id; - public CopyOnWriteArrayList secureobjects = new CopyOnWriteArrayList(); + public CopyOnWriteArrayList secureObjects = new CopyOnWriteArrayList(); public CopyOnWriteArrayList loadedChunks = new CopyOnWriteArrayList(); + public CopyOnWriteArrayList messages = new CopyOnWriteArrayList(); public CopyOnWriteArrayList signClass=new CopyOnWriteArrayList(); public CopyOnWriteArrayList dmobs = new CopyOnWriteArrayList(); @@ -187,14 +188,20 @@ public class GameWorld { } if(lines[1].equalsIgnoreCase("msg")){ if(lines[2]!=""&&lines[3]!=""){ - new GameMessage(block,p.parseInt(lines[2]),this,p.parseInt(lines[3]),false); - block.setTypeId(0); + String msg = config.getMsg(p.parseInt(lines[2])); + if(msg!=null){ + messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),false)); + block.setTypeId(0); + } } } if(lines[1].equalsIgnoreCase("soundmsg")){ if(lines[2]!=""&&lines[3]!=""){ - new GameMessage(block,p.parseInt(lines[2]),this,p.parseInt(lines[3]),true); - block.setTypeId(0); + String msg = config.getMsg(p.parseInt(lines[2])); + if(msg!=null){ + messages.add(new GameMessage(block.getLocation(),msg,p.parseInt(lines[3]),true)); + block.setTypeId(0); + } } } if(lines[1].equalsIgnoreCase("checkpoint")){ @@ -246,10 +253,8 @@ public class GameWorld { this.checkSign(block); } } catch (FileNotFoundException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -308,7 +313,6 @@ public class GameWorld { try { file.createNewFile(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -352,7 +356,7 @@ public class GameWorld { gworld.config = new DConfig(new File(p.getDataFolder()+"/dungeons/"+gworld.dungeonname, "config.yml")); //Secure Objects - gworld.secureobjects=gworld.config.secureObjects; + gworld.secureObjects=gworld.config.secureObjects; //World p.copyDirectory(file,new File("DXL_Game_"+gworld.id)); @@ -375,10 +379,8 @@ public class GameWorld { os.close(); } catch (FileNotFoundException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } @@ -390,6 +392,8 @@ public class GameWorld { public static void update(){ for(GameWorld gworld:gworlds){ + //Update Messages + GameMessage.update(gworld); //Update Spiders for(LivingEntity mob:gworld.world.getLivingEntities()){