Player data moving is in progress...
This commit is contained in:
parent
7195ed1338
commit
e9fc7457e3
7 changed files with 152 additions and 7 deletions
|
@ -6,11 +6,13 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import buttondevteam.alisolarflare.aliarrow.AliArrowSubPlugin;
|
import buttondevteam.alisolarflare.aliarrow.AliArrowSubPlugin;
|
||||||
|
import buttondevteam.player.PlayerSubPlugin;
|
||||||
|
|
||||||
public class MainPlugin extends JavaPlugin {
|
public class MainPlugin extends JavaPlugin {
|
||||||
private PluginDescriptionFile pdfFile;
|
private PluginDescriptionFile pdfFile;
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
private AliArrowSubPlugin aliArrowSubPlugin;
|
private AliArrowSubPlugin aliArrowSubPlugin;
|
||||||
|
private PlayerSubPlugin playerSubPlugin;
|
||||||
|
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
//Logs "Plugin Enabled", registers commands
|
//Logs "Plugin Enabled", registers commands
|
||||||
|
@ -27,6 +29,8 @@ public class MainPlugin extends JavaPlugin {
|
||||||
private void registerSubPlugins() {
|
private void registerSubPlugins() {
|
||||||
aliArrowSubPlugin = new AliArrowSubPlugin(this);
|
aliArrowSubPlugin = new AliArrowSubPlugin(this);
|
||||||
aliArrowSubPlugin.register();
|
aliArrowSubPlugin.register();
|
||||||
|
playerSubPlugin = new PlayerSubPlugin(this);
|
||||||
|
playerSubPlugin.register();
|
||||||
}
|
}
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
17
src/buttondevteam/player/PlayerListener.java
Normal file
17
src/buttondevteam/player/PlayerListener.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package buttondevteam.player;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void OnPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
try {
|
||||||
|
TBMCPlayer.LoadPlayer(event.getPlayer().getUniqueId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
src/buttondevteam/player/PlayerSubPlugin.java
Normal file
15
src/buttondevteam/player/PlayerSubPlugin.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package buttondevteam.player;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class PlayerSubPlugin {
|
||||||
|
public static Plugin plugin;
|
||||||
|
|
||||||
|
public PlayerSubPlugin(Plugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register() {
|
||||||
|
System.out.println("Players subplugin registered!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
package buttondevteam.player;
|
package buttondevteam.player;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,15 +11,19 @@ import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class TBMCPlayer {
|
public class TBMCPlayer {
|
||||||
public String PlayerName;
|
public String PlayerName;
|
||||||
|
|
||||||
public UUID UUID;
|
public UUID UUID;
|
||||||
|
|
||||||
public static HashMap<UUID, TBMCPlayer> AllPlayers = new HashMap<>();
|
public static HashMap<UUID, TBMCPlayer> OnlinePlayers = new HashMap<>();
|
||||||
|
|
||||||
|
public HashMap<String, String> Settings = new HashMap<>();
|
||||||
|
|
||||||
public static TBMCPlayer AddPlayerIfNeeded(UUID uuid) {
|
public static TBMCPlayer AddPlayerIfNeeded(UUID uuid) {
|
||||||
if (!AllPlayers.containsKey(uuid)) {
|
if (!AllPlayers.containsKey(uuid)) {
|
||||||
|
@ -31,23 +38,28 @@ public class TBMCPlayer {
|
||||||
return AllPlayers.get(uuid);
|
return AllPlayers.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Load(YamlConfiguration yc) {
|
public static void Load(YamlConfiguration yc) { //OLD
|
||||||
ConfigurationSection cs = yc.getConfigurationSection("players");
|
ConfigurationSection cs = yc.getConfigurationSection("players");
|
||||||
for (String key : cs.getKeys(false)) {
|
for (String key : cs.getKeys(false)) {
|
||||||
ConfigurationSection cs2 = cs.getConfigurationSection(key);
|
ConfigurationSection cs2 = cs.getConfigurationSection(key);
|
||||||
TBMCPlayer mp = AddPlayerIfNeeded(java.util.UUID
|
TBMCPlayer mp = AddPlayerIfNeeded(java.util.UUID.fromString(cs2.getString("uuid")));
|
||||||
.fromString(cs2.getString("uuid")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Save(YamlConfiguration yc) {
|
public static void Save(YamlConfiguration yc) { //OLD
|
||||||
ConfigurationSection cs = yc.createSection("players");
|
ConfigurationSection cs = yc.createSection("players");
|
||||||
for (TBMCPlayer mp : TBMCPlayer.AllPlayers.values()) {
|
for (TBMCPlayer mp : TBMCPlayer.AllPlayers.values()) {
|
||||||
ConfigurationSection cs2 = cs.createSection(mp.UUID.toString());
|
ConfigurationSection cs2 = cs.createSection(mp.UUID.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
* The player's name
|
||||||
|
* @return The {@link TBMCPlayer} object for the player
|
||||||
|
*/
|
||||||
public static TBMCPlayer GetFromName(String name) {
|
public static TBMCPlayer GetFromName(String name) {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
Player p = Bukkit.getPlayer(name);
|
Player p = Bukkit.getPlayer(name);
|
||||||
if (p != null)
|
if (p != null)
|
||||||
return AllPlayers.get(p.getUniqueId());
|
return AllPlayers.get(p.getUniqueId());
|
||||||
|
@ -55,7 +67,39 @@ public class TBMCPlayer {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TBMCPlayer GetFromPlayer(Player p) {
|
/**
|
||||||
|
* @param p
|
||||||
|
* The Player object
|
||||||
|
* @return The {@link TBMCPlayer} object for the player
|
||||||
|
*/
|
||||||
|
public static TBMCPlayer GetPlayer(Player p) {
|
||||||
return TBMCPlayer.AllPlayers.get(p.getUniqueId());
|
return TBMCPlayer.AllPlayers.get(p.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TBMCPlayer LoadPlayer(UUID uuid) throws Exception {
|
||||||
|
if (OnlinePlayers.containsKey(uuid))
|
||||||
|
return OnlinePlayers.get(uuid);
|
||||||
|
File file = new File("TBMC/players");
|
||||||
|
file.mkdirs();
|
||||||
|
file = new File("TBMC/players", uuid.toString() + ".yml");
|
||||||
|
if (!file.exists())
|
||||||
|
return AddPlayer(uuid);
|
||||||
|
else {
|
||||||
|
final YamlConfiguration yc = new YamlConfiguration();
|
||||||
|
yc.load(file);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static TBMCPlayer AddPlayer(UUID uuid) {
|
||||||
|
if (OnlinePlayers.containsKey(uuid))
|
||||||
|
return OnlinePlayers.get(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,17 @@ import org.bukkit.event.HandlerList;
|
||||||
public class TBMCPlayerAddEvent extends Event {
|
public class TBMCPlayerAddEvent extends Event {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
public TBMCPlayerAddEvent(TBMCPlayer tbmcplayer) {
|
private TBMCPlayer player;
|
||||||
|
|
||||||
|
public TBMCPlayerAddEvent(TBMCPlayer player) {
|
||||||
// TODO: Separate player configs, figure out how to make one TBMCPlayer
|
// TODO: Separate player configs, figure out how to make one TBMCPlayer
|
||||||
// object have all the other plugin properties
|
// object have all the other plugin properties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TBMCPlayer GetPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
|
31
src/buttondevteam/player/TBMCPlayerBase.java
Normal file
31
src/buttondevteam/player/TBMCPlayerBase.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package buttondevteam.player;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Base class for other plugins' player data.
|
||||||
|
* </p>
|
||||||
|
* <ol>
|
||||||
|
* <li>Add extra data fields</li>
|
||||||
|
* <li>Add the extra data to the load/save methods</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @author Norbi
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class TBMCPlayerBase {
|
||||||
|
public abstract void OnPlayerAdd(TBMCPlayerAddEvent event);
|
||||||
|
|
||||||
|
public abstract void OnPlayerLoad();
|
||||||
|
|
||||||
|
public abstract void OnPlayerSave();
|
||||||
|
|
||||||
|
public abstract <T extends TBMCPlayerBase> T GetPlayerAs(TBMCPlayer player);
|
||||||
|
|
||||||
|
public <T extends TBMCPlayerBase> T GetPlayerAs(Player player) {
|
||||||
|
return GetPlayerAs(TBMCPlayer.GetPlayer(player));
|
||||||
|
}
|
||||||
|
}
|
28
src/buttondevteam/player/TBMCPlayerLoadEvent.java
Normal file
28
src/buttondevteam/player/TBMCPlayerLoadEvent.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package buttondevteam.player;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class TBMCPlayerLoadEvent extends Event {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private YamlConfiguration config;
|
||||||
|
|
||||||
|
public TBMCPlayerLoadEvent(YamlConfiguration yc) {
|
||||||
|
this.config = yc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YamlConfiguration GetPlayerConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue