From f0b564a4525f515917c5701bbfbc7e1b26f0e424 Mon Sep 17 00:00:00 2001 From: Grafe Date: Mon, 21 Jan 2013 01:34:44 +0100 Subject: [PATCH] Changed isInWorldChat to correct isInDungeonChat Started with the new playeroffline system --- src/com/dre/dungeonsxl/DPlayer.java | 35 +++++++++- src/com/dre/dungeonsxl/P.java | 68 ++++++++++++++++++- src/com/dre/dungeonsxl/commands/CMDChat.java | 6 +- .../dungeonsxl/listener/PlayerListener.java | 2 +- 4 files changed, 104 insertions(+), 7 deletions(-) diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index b83d43e6..ee5c18d5 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -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 players=new CopyOnWriteArrayList(); @@ -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); } diff --git a/src/com/dre/dungeonsxl/P.java b/src/com/dre/dungeonsxl/P.java index e7684947..9a2e1346 100644 --- a/src/com/dre/dungeonsxl/P.java +++ b/src/com/dre/dungeonsxl/P.java @@ -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 // -------------------------------------------- // diff --git a/src/com/dre/dungeonsxl/commands/CMDChat.java b/src/com/dre/dungeonsxl/commands/CMDChat.java index 6a045a28..9040fa81 100644 --- a/src/com/dre/dungeonsxl/commands/CMDChat.java +++ b/src/com/dre/dungeonsxl/commands/CMDChat.java @@ -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{ diff --git a/src/com/dre/dungeonsxl/listener/PlayerListener.java b/src/com/dre/dungeonsxl/listener/PlayerListener.java index b91c9e3b..47a2773d 100644 --- a/src/com/dre/dungeonsxl/listener/PlayerListener.java +++ b/src/com/dre/dungeonsxl/listener/PlayerListener.java @@ -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); }