Changed isInWorldChat to correct isInDungeonChat

Started with the new playeroffline system
This commit is contained in:
Grafe 2013-01-21 01:34:44 +01:00
parent adbfe1e218
commit f0b564a452
4 changed files with 104 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
@ -23,7 +24,7 @@ import com.dre.dungeonsxl.game.GameCheckpoint;
import com.dre.dungeonsxl.game.GameWorld;
public class DPlayer {
public P p=P.p;
public static P p=P.p;
public static CopyOnWriteArrayList<DPlayer> players=new CopyOnWriteArrayList<DPlayer>();
@ -44,7 +45,7 @@ public class DPlayer {
public GameMode oldGamemode;
public boolean isEditing;
public boolean isInWorldChat=false;
public boolean isInDungeonChat=false;
public boolean isReady=false;
public boolean isFinished=false;
@ -388,6 +389,36 @@ public class DPlayer {
}
//Static
public static void saveSession(Configuration cFile){
int id = 0;
for(DPlayer dplayer : players){
cFile.set("DPlayer."+id+".name", dplayer.player.getName());
if(dplayer.checkpoint!=null){
cFile.set("DPlayer."+id+".lastcheckpoint", dplayer.checkpoint.location);
}
cFile.set("DPlayer."+id+".class", dplayer.dclass.name);
cFile.set("DPlayer."+id+".isEditing", dplayer.isEditing);
cFile.set("DPlayer."+id+".isFinished", dplayer.isFinished);
cFile.set("DPlayer."+id+".isinTestMode", dplayer.isinTestMode);
cFile.set("DPlayer."+id+".isInDungeonChat", dplayer.isInDungeonChat);
cFile.set("DPlayer."+id+".isReady", dplayer.isReady);
cFile.set("DPlayer."+id+".offlineTime", dplayer.offlineTime);
cFile.set("DPlayer."+id+".oldArmor", dplayer.oldArmor);
cFile.set("DPlayer."+id+".oldExp", dplayer.oldExp);
cFile.set("DPlayer."+id+".oldFireTicks", dplayer.oldFireTicks);
cFile.set("DPlayer."+id+".oldFoodLevel", dplayer.oldFoodLevel);
cFile.set("DPlayer."+id+".oldGamemode", dplayer.oldGamemode);
cFile.set("DPlayer."+id+".oldHealth", dplayer.oldHealth);
cFile.set("DPlayer."+id+".oldInventory", dplayer.oldInventory);
cFile.set("DPlayer."+id+".oldLocation", dplayer.oldLocation);
cFile.set("DPlayer."+id+".oldLvl", dplayer.oldLvl);
cFile.set("DPlayer."+id+".respawnInventory", dplayer.respawnInventory);
cFile.set("DPlayer."+id+".treasureInv", dplayer.treasureInv);
cFile.set("DPlayer."+id+".wolfRespawnTime", dplayer.wolfRespawnTime);
id++;
}
}
public static void remove(DPlayer player){
players.remove(player);
}

View File

@ -12,12 +12,17 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import net.milkbowl.vault.permission.Permission;
import net.minecraft.server.v1_4_6.EntityPlayer;
import net.minecraft.server.v1_4_6.MinecraftServer;
import net.minecraft.server.v1_4_6.PlayerInteractManager;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
import org.bukkit.craftbukkit.v1_4_6.CraftWorld;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
@ -448,6 +453,67 @@ public class P extends JavaPlugin{
return NumberUtils.toInt(string, 0);
}
public Player getOfflinePlayer(String player) {
Player pplayer = null;
try {
//See if the player has data files
// Find the player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
// Find player name
for (File playerfile : playerfolder.listFiles()) {
String filename = playerfile.getName();
String playername = filename.substring(0, filename.length() - 4);
if(playername.trim().equalsIgnoreCase(player)) {
//This player plays on the server!
MinecraftServer server = ((CraftServer)Bukkit.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager(server.getWorldServer(0)));
Player target = (entity == null) ? null : (Player) entity.getBukkitEntity();
if(target != null) {
target.loadData();
return target;
}
}
}
}
catch(Exception e) {
return null;
}
return pplayer;
}
public boolean setOfflinePlayerPosition(String player, Location location){
try {
//See if the player has data files
// Find the player folder
File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
// Find player name
for (File playerfile : playerfolder.listFiles()) {
String filename = playerfile.getName();
String playername = filename.substring(0, filename.length() - 4);
if(playername.trim().equalsIgnoreCase(player)) {
//This player plays on the server!
MinecraftServer server = ((CraftServer)Bukkit.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager(server.getWorldServer(0)));
entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
entity.world = ((CraftWorld) location.getWorld()).getHandle();
Player target = (entity == null) ? null : (Player) entity.getBukkitEntity();
target.saveData();
return true;
}
}
}
catch(Exception e) {
return false;
}
return false;
}
// -------------------------------------------- //
// LOGGING
// -------------------------------------------- //

View File

@ -17,11 +17,11 @@ public class CMDChat extends DCommand{
public void onExecute(String[] args, Player player) {
DPlayer dplayer=DPlayer.get(player);
if(dplayer!=null){
if(dplayer.isInWorldChat) {
dplayer.isInWorldChat=false;
if(dplayer.isInDungeonChat) {
dplayer.isInDungeonChat=false;
p.msg(player,p.language.get("Cmd_Chat_NormalChat"));
}else{
dplayer.isInWorldChat=true;
dplayer.isInDungeonChat=true;
p.msg(player,p.language.get("Cmd_Chat_DungeonChat"));
}
}else{

View File

@ -280,7 +280,7 @@ public class PlayerListener implements Listener{
Player player=event.getPlayer();
DPlayer dplayer=DPlayer.get(player);
if(dplayer!=null){
if(dplayer.isInWorldChat){
if(dplayer.isInDungeonChat){
dplayer.msg(player.getDisplayName()+": "+event.getMessage());
event.setCancelled(true);
}