Changed GameMessages update method

This commit is contained in:
Grafe 2013-01-18 03:08:55 +01:00
parent cdf8331dbe
commit 1e3482fe3c
5 changed files with 32 additions and 38 deletions

View File

@ -123,8 +123,8 @@ public class DConfig {
} }
/* Secure Objects */ /* Secure Objects */
if(configFile.contains("secureobjects")){ if(configFile.contains("secureObjects")){
List<Integer> secureobjectlist = configFile.getIntegerList("secureobjects"); List<Integer> secureobjectlist = configFile.getIntegerList("secureObjects");
for(int i:secureobjectlist){ for(int i:secureobjectlist){
this.secureObjects.add(Material.getMaterial(i)); this.secureObjects.add(Material.getMaterial(i));
} }
@ -172,13 +172,13 @@ public class DConfig {
} }
//Secure Objects //Secure Objects
CopyOnWriteArrayList<Integer> secureobjectsids=new CopyOnWriteArrayList<Integer>(); CopyOnWriteArrayList<Integer> secureObjectsids=new CopyOnWriteArrayList<Integer>();
for(Material mat:this.secureObjects){ for(Material mat:this.secureObjects){
secureobjectsids.add(mat.getId()); secureObjectsids.add(mat.getId());
} }
configFile.set("secureobjects", secureobjectsids); configFile.set("secureObjects", secureObjectsids);
//Invited Players //Invited Players
configFile.set("invitedplayers", this.invitedPlayers); configFile.set("invitedplayers", this.invitedPlayers);

View File

@ -189,7 +189,7 @@ public class DPlayer {
if(groupplayer!=null){ if(groupplayer!=null){
for(ItemStack istack:this.player.getInventory()){ for(ItemStack istack:this.player.getInventory()){
if(istack!=null){ if(istack!=null){
if(gworld.secureobjects.contains(istack.getType())){ if(gworld.secureObjects.contains(istack.getType())){
groupplayer.getInventory().addItem(istack); groupplayer.getInventory().addItem(istack);
} }
} }

View File

@ -27,7 +27,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.dre.dungeonsxl.commands.DCommandRoot; import com.dre.dungeonsxl.commands.DCommandRoot;
import com.dre.dungeonsxl.game.GameCheckpoint; import com.dre.dungeonsxl.game.GameCheckpoint;
import com.dre.dungeonsxl.game.GameMessage;
import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.game.MobSpawner; import com.dre.dungeonsxl.game.MobSpawner;
import com.dre.dungeonsxl.listener.BlockListener; import com.dre.dungeonsxl.listener.BlockListener;
@ -141,7 +140,6 @@ public class P extends JavaPlugin{
LeaveSign.lsigns.clear(); LeaveSign.lsigns.clear();
DCommandRoot.root.commands.clear(); DCommandRoot.root.commands.clear();
GameCheckpoint.gcheckpoints.clear(); GameCheckpoint.gcheckpoints.clear();
GameMessage.gmessages.clear();
MobSpawner.mobspawners.clear(); MobSpawner.mobspawners.clear();
//Delete Worlds //Delete Worlds
@ -192,7 +190,6 @@ public class P extends JavaPlugin{
public void run() { public void run() {
MobSpawner.updateAll(); MobSpawner.updateAll();
GameWorld.update(); GameWorld.update();
GameMessage.updateAll();
GameCheckpoint.update(); GameCheckpoint.update();
DPlayer.update(true); DPlayer.update(true);

View File

@ -2,7 +2,7 @@ package com.dre.dungeonsxl.game;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.block.Block; import org.bukkit.Location;
import org.getspout.spoutapi.Spout; import org.getspout.spoutapi.Spout;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
@ -11,44 +11,37 @@ import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P; import com.dre.dungeonsxl.P;
public class GameMessage { public class GameMessage {
public static CopyOnWriteArrayList<GameMessage> gmessages=new CopyOnWriteArrayList<GameMessage>();
//Variables //Variables
public CopyOnWriteArrayList<DPlayer> playerDone=new CopyOnWriteArrayList<DPlayer>(); public CopyOnWriteArrayList<DPlayer> playerDone=new CopyOnWriteArrayList<DPlayer>();
public Block block; public Location location;
public String msg; public String msg;
public GameWorld gworld;
public int radius; public int radius;
public boolean isSpoutSoundMsg; public boolean isSpoutSoundMsg;
public GameMessage(Block block, int msgid,GameWorld gworld,int radius,boolean isSpoutSoundMsg){ public GameMessage(Location location, String msg,int radius,boolean isSpoutSoundMsg){
this.block=block; this.location=location;
this.msg=gworld.config.getMsg(msgid); this.msg = msg;
this.gworld=gworld;
this.radius=radius; this.radius=radius;
this.isSpoutSoundMsg=isSpoutSoundMsg; this.isSpoutSoundMsg=isSpoutSoundMsg;
if(this.msg!=null){
gmessages.add(this);
}
} }
//Static //Static
public static void updateAll(){ public static void update(GameWorld gworld){
for(GameMessage gmessage:gmessages){ for(GameMessage gmessage:gworld.messages){
for(DPlayer dplayer:DPlayer.get(gmessage.gworld.world)){ for(DPlayer dplayer:DPlayer.get(gworld.world)){
if(!gmessage.playerDone.contains(dplayer)){ if(!gmessage.playerDone.contains(dplayer)){
if(dplayer.player.getLocation().distance(gmessage.block.getLocation())<gmessage.radius+1){ if(dplayer.player.getLocation().distance(gmessage.location)<gmessage.radius+1){
gmessage.playerDone.add(dplayer); gmessage.playerDone.add(dplayer);
if(gmessage.isSpoutSoundMsg){ if(gmessage.isSpoutSoundMsg){
if(P.p.isSpoutEnabled){ if(P.p.isSpoutEnabled){
SpoutPlayer sPlayer = Spout.getServer().getPlayer(dplayer.player.getName()); SpoutPlayer sPlayer = Spout.getServer().getPlayer(dplayer.player.getName());
if(sPlayer.isSpoutCraftEnabled()){ if(sPlayer.isSpoutCraftEnabled()){
SpoutManager.getSoundManager().playCustomMusic(P.p, sPlayer, gmessage.msg, false, gmessage.block.getLocation()); SpoutManager.getSoundManager().playCustomMusic(P.p, sPlayer, gmessage.msg, false, gmessage.location);
} }
} }
} else { } else {

View File

@ -46,8 +46,9 @@ public class GameWorld {
public CopyOnWriteArrayList<Block> blocksLeave=new CopyOnWriteArrayList<Block>(); public CopyOnWriteArrayList<Block> blocksLeave=new CopyOnWriteArrayList<Block>();
public boolean isPlaying=false; public boolean isPlaying=false;
public int id; public int id;
public CopyOnWriteArrayList<Material> secureobjects = new CopyOnWriteArrayList<Material>(); public CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
public CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<Chunk>(); public CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<Chunk>();
public CopyOnWriteArrayList<GameMessage> messages = new CopyOnWriteArrayList<GameMessage>();
public CopyOnWriteArrayList<Sign> signClass=new CopyOnWriteArrayList<Sign>(); public CopyOnWriteArrayList<Sign> signClass=new CopyOnWriteArrayList<Sign>();
public CopyOnWriteArrayList<DMob> dmobs = new CopyOnWriteArrayList<DMob>(); public CopyOnWriteArrayList<DMob> dmobs = new CopyOnWriteArrayList<DMob>();
@ -187,16 +188,22 @@ public class GameWorld {
} }
if(lines[1].equalsIgnoreCase("msg")){ if(lines[1].equalsIgnoreCase("msg")){
if(lines[2]!=""&&lines[3]!=""){ if(lines[2]!=""&&lines[3]!=""){
new GameMessage(block,p.parseInt(lines[2]),this,p.parseInt(lines[3]),false); 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); block.setTypeId(0);
} }
} }
}
if(lines[1].equalsIgnoreCase("soundmsg")){ if(lines[1].equalsIgnoreCase("soundmsg")){
if(lines[2]!=""&&lines[3]!=""){ if(lines[2]!=""&&lines[3]!=""){
new GameMessage(block,p.parseInt(lines[2]),this,p.parseInt(lines[3]),true); 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); block.setTypeId(0);
} }
} }
}
if(lines[1].equalsIgnoreCase("checkpoint")){ if(lines[1].equalsIgnoreCase("checkpoint")){
int radius=0; int radius=0;
@ -246,10 +253,8 @@ public class GameWorld {
this.checkSign(block); this.checkSign(block);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -308,7 +313,6 @@ public class GameWorld {
try { try {
file.createNewFile(); file.createNewFile();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -352,7 +356,7 @@ public class GameWorld {
gworld.config = new DConfig(new File(p.getDataFolder()+"/dungeons/"+gworld.dungeonname, "config.yml")); gworld.config = new DConfig(new File(p.getDataFolder()+"/dungeons/"+gworld.dungeonname, "config.yml"));
//Secure Objects //Secure Objects
gworld.secureobjects=gworld.config.secureObjects; gworld.secureObjects=gworld.config.secureObjects;
//World //World
p.copyDirectory(file,new File("DXL_Game_"+gworld.id)); p.copyDirectory(file,new File("DXL_Game_"+gworld.id));
@ -375,10 +379,8 @@ public class GameWorld {
os.close(); os.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -390,6 +392,8 @@ public class GameWorld {
public static void update(){ public static void update(){
for(GameWorld gworld:gworlds){ for(GameWorld gworld:gworlds){
//Update Messages
GameMessage.update(gworld);
//Update Spiders //Update Spiders
for(LivingEntity mob:gworld.world.getLivingEntities()){ for(LivingEntity mob:gworld.world.getLivingEntities()){