From 7195ed133805c803fb9e96eea14f6f3ee0568495 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 1 Jul 2016 23:42:26 +0200 Subject: [PATCH] Started moving player data from the chat plugin --- .classpath | 16 ++--- bin/.gitignore | 1 + src/buttondevteam/player/TBMCPlayer.java | 61 +++++++++++++++++++ .../player/TBMCPlayerAddEvent.java | 22 +++++++ 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 bin/.gitignore create mode 100644 src/buttondevteam/player/TBMCPlayer.java create mode 100644 src/buttondevteam/player/TBMCPlayerAddEvent.java diff --git a/.classpath b/.classpath index f289777..38a4566 100644 --- a/.classpath +++ b/.classpath @@ -1,8 +1,8 @@ - - - - - - - - + + + + + + + + diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..cfe0012 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/buttondevteam/ diff --git a/src/buttondevteam/player/TBMCPlayer.java b/src/buttondevteam/player/TBMCPlayer.java new file mode 100644 index 0000000..f48b416 --- /dev/null +++ b/src/buttondevteam/player/TBMCPlayer.java @@ -0,0 +1,61 @@ +package buttondevteam.player; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +public class TBMCPlayer { + public String PlayerName; + + public UUID UUID; + + public static HashMap AllPlayers = new HashMap<>(); + + public static TBMCPlayer AddPlayerIfNeeded(UUID uuid) { + if (!AllPlayers.containsKey(uuid)) { + TBMCPlayer player = new TBMCPlayer(); + player.UUID = uuid; + Player p = Bukkit.getPlayer(uuid); + if (p != null) + player.PlayerName = p.getName(); + AllPlayers.put(uuid, player); + return player; + } + return AllPlayers.get(uuid); + } + + public static void Load(YamlConfiguration yc) { + ConfigurationSection cs = yc.getConfigurationSection("players"); + for (String key : cs.getKeys(false)) { + ConfigurationSection cs2 = cs.getConfigurationSection(key); + TBMCPlayer mp = AddPlayerIfNeeded(java.util.UUID + .fromString(cs2.getString("uuid"))); + } + } + + public static void Save(YamlConfiguration yc) { + ConfigurationSection cs = yc.createSection("players"); + for (TBMCPlayer mp : TBMCPlayer.AllPlayers.values()) { + ConfigurationSection cs2 = cs.createSection(mp.UUID.toString()); + } + } + + public static TBMCPlayer GetFromName(String name) { + Player p = Bukkit.getPlayer(name); + if (p != null) + return AllPlayers.get(p.getUniqueId()); + else + return null; + } + + public static TBMCPlayer GetFromPlayer(Player p) { + return TBMCPlayer.AllPlayers.get(p.getUniqueId()); + } +} diff --git a/src/buttondevteam/player/TBMCPlayerAddEvent.java b/src/buttondevteam/player/TBMCPlayerAddEvent.java new file mode 100644 index 0000000..9d6e49d --- /dev/null +++ b/src/buttondevteam/player/TBMCPlayerAddEvent.java @@ -0,0 +1,22 @@ +package buttondevteam.player; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class TBMCPlayerAddEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + public TBMCPlayerAddEvent(TBMCPlayer tbmcplayer) { + // TODO: Separate player configs, figure out how to make one TBMCPlayer + // object have all the other plugin properties + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +}