Moved GameCheckpoint to SIGNCheckpoint

Signed-off-by: Grafe <flingelfrank@hotmail.com>
This commit is contained in:
Grafe 2013-03-26 13:50:35 +01:00
parent 26a9772f34
commit 19a1060324
5 changed files with 14 additions and 77 deletions

View File

@ -19,7 +19,6 @@ import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.Spout; import org.getspout.spoutapi.Spout;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.dre.dungeonsxl.game.GameCheckpoint;
import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.game.GameWorld;
public class DPlayer { public class DPlayer {
@ -41,7 +40,7 @@ public class DPlayer {
public boolean isFinished=false; public boolean isFinished=false;
public DClass dclass; public DClass dclass;
public GameCheckpoint checkpoint; public Location checkpoint;
public Wolf wolf; public Wolf wolf;
public int wolfRespawnTime=30; public int wolfRespawnTime=30;
public long offlineTime; public long offlineTime;
@ -130,7 +129,6 @@ public class DPlayer {
try { try {
file.createNewFile(); file.createNewFile();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -142,7 +140,6 @@ public class DPlayer {
try { try {
playerConfig.save(file); playerConfig.save(file);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -212,7 +209,7 @@ public class DPlayer {
if(this.checkpoint==null){ if(this.checkpoint==null){
this.player.teleport(dgroup.getGworld().locStart); this.player.teleport(dgroup.getGworld().locStart);
}else{ }else{
this.player.teleport(this.checkpoint.location); this.player.teleport(this.checkpoint);
} }
if(this.wolf!=null){ if(this.wolf!=null){
this.wolf.teleport(this.player); this.wolf.teleport(this.player);
@ -360,7 +357,7 @@ public class DPlayer {
} }
} }
public void setCheckpoint(GameCheckpoint checkpoint){ public void setCheckpoint(Location checkpoint){
this.checkpoint=checkpoint; this.checkpoint=checkpoint;
} }
@ -429,9 +426,9 @@ public class DPlayer {
dplayer.wolf.teleport(dgroup.getGworld().locStart); dplayer.wolf.teleport(dgroup.getGworld().locStart);
} }
}else{ }else{
dplayer.player.teleport(dplayer.checkpoint.location); dplayer.player.teleport(dplayer.checkpoint);
if(dplayer.wolf!=null){ if(dplayer.wolf!=null){
dplayer.wolf.teleport(dplayer.checkpoint.location); dplayer.wolf.teleport(dplayer.checkpoint);
} }
} }

View File

@ -30,7 +30,6 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; 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.GameWorld; import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.listener.BlockListener; import com.dre.dungeonsxl.listener.BlockListener;
import com.dre.dungeonsxl.listener.CommandListener; import com.dre.dungeonsxl.listener.CommandListener;
@ -139,7 +138,6 @@ public class P extends JavaPlugin{
DPortal.portals.clear(); DPortal.portals.clear();
LeaveSign.lsigns.clear(); LeaveSign.lsigns.clear();
DCommandRoot.root.commands.clear(); DCommandRoot.root.commands.clear();
GameCheckpoint.gcheckpoints.clear();
//Delete Worlds //Delete Worlds
GameWorld.deleteAll(); GameWorld.deleteAll();
@ -190,7 +188,6 @@ public class P extends JavaPlugin{
p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() { p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() {
public void run() { public void run() {
GameWorld.update(); GameWorld.update();
GameCheckpoint.update();
DPlayer.update(true); DPlayer.update(true);
} }
}, 0L, 20L); }, 0L, 20L);

View File

@ -1,49 +0,0 @@
package com.dre.dungeonsxl.game;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Location;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
public class GameCheckpoint {
public static CopyOnWriteArrayList<GameCheckpoint> gcheckpoints=new CopyOnWriteArrayList<GameCheckpoint>();
//Variables
public GameWorld gworld;
public Location location;
public int radius;
public CopyOnWriteArrayList<DPlayer> dplayerHasUsed=new CopyOnWriteArrayList<DPlayer>();
public GameCheckpoint(GameWorld gworld, Location location, int radius){
gcheckpoints.add(this);
this.location=location;
this.radius=radius;
if(this.radius==0){
this.radius=5;
}
this.gworld=gworld;
}
//Statics
public static void update(){
for(GameCheckpoint gpoint:gcheckpoints){
for(DPlayer dplayer:DPlayer.get(gpoint.gworld.world)){
if(!gpoint.dplayerHasUsed.contains(dplayer)){
if(dplayer.player.getLocation().distance(gpoint.location)<=gpoint.radius){
dplayer.setCheckpoint(gpoint);
P.p.msg(dplayer.player, P.p.language.get("Player_CheckpointReached"));//ChatColor.GOLD+"Checkpoint erreicht!");
gpoint.dplayerHasUsed.add(dplayer);
}
}
}
}
}
}

View File

@ -236,13 +236,13 @@ public class PlayerListener implements Listener{
dplayer.wolf.teleport(dgroup.getGworld().locStart); dplayer.wolf.teleport(dgroup.getGworld().locStart);
} }
}else{ }else{
event.setRespawnLocation(dplayer.checkpoint.location); event.setRespawnLocation(dplayer.checkpoint);
//Da einige Plugins einen anderen Respawn setzen wird ein Scheduler gestartet der den Player nach einer Sekunde teleportiert. //Da einige Plugins einen anderen Respawn setzen wird ein Scheduler gestartet der den Player nach einer Sekunde teleportiert.
p.getServer().getScheduler().scheduleSyncDelayedTask(p, new RespawnRunnable(player,dplayer.checkpoint.location), 10); p.getServer().getScheduler().scheduleSyncDelayedTask(p, new RespawnRunnable(player,dplayer.checkpoint), 10);
if(dplayer.wolf!=null){ if(dplayer.wolf!=null){
dplayer.wolf.teleport(dplayer.checkpoint.location); dplayer.wolf.teleport(dplayer.checkpoint);
} }
} }
} }

View File

@ -2,7 +2,8 @@ package com.dre.dungeonsxl.signs;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameCheckpoint; import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld; import com.dre.dungeonsxl.game.GameWorld;
public class SIGNCheckpoint extends DSign{ public class SIGNCheckpoint extends DSign{
@ -13,7 +14,6 @@ public class SIGNCheckpoint extends DSign{
public SIGNCheckpoint(Sign sign, GameWorld gworld) { public SIGNCheckpoint(Sign sign, GameWorld gworld) {
super(sign, gworld); super(sign, gworld);
// TODO Auto-generated constructor stub
} }
@Override @Override
@ -25,22 +25,14 @@ public class SIGNCheckpoint extends DSign{
@Override @Override
public void onInit() { public void onInit() {
String lines[] = sign.getLines();
int radius = 0;
if(lines[1] != null ){
if(lines[1].length() > 0){
radius = p.parseInt(lines[1]);
}
}
new GameCheckpoint(gworld, sign.getLocation(), radius);
sign.setTypeId(0); sign.setTypeId(0);
} }
@Override @Override
public void onTrigger() { public void onTrigger() {
// TODO Auto-generated method stub for(DPlayer dplayer:DPlayer.get(this.gworld.world)){
dplayer.setCheckpoint(this.sign.getLocation());
P.p.msg(dplayer.player, P.p.language.get("Player_CheckpointReached"));
}
} }
} }