Various fixes
This commit is contained in:
parent
cc45238034
commit
0b9aab4c9c
5 changed files with 60 additions and 25 deletions
4
plugin.yml
Normal file
4
plugin.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name: ButtonPluginBucket
|
||||||
|
main: buttondevteam.MainPlugin
|
||||||
|
version: 1.0
|
||||||
|
author: TBMCPlugins
|
|
@ -1,5 +1,8 @@
|
||||||
package buttondevteam.core.player;
|
package buttondevteam.core.player;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class CoreSubPlugin {
|
public class CoreSubPlugin {
|
||||||
|
@ -10,6 +13,7 @@ public class CoreSubPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
System.out.println("Players subplugin registered!");
|
Bukkit.getPluginManager().registerEvents(new PlayerListener(), plugin);
|
||||||
|
plugin.getLogger().log(Level.INFO, "Core subplugin registered!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
package buttondevteam.core.player;
|
package buttondevteam.core.player;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void OnPlayerJoin(PlayerJoinEvent event) {
|
public void OnPlayerJoin(PlayerJoinEvent event) {
|
||||||
try {
|
if (TBMCPlayer.LoadPlayer(event.getPlayer()) == null)
|
||||||
TBMCPlayer.LoadPlayer(event.getPlayer().getUniqueId());
|
event.getPlayer().sendMessage("§c[TBMC] Failed to load player data! Please contact a mod.");
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void OnPlayerLeave(PlayerQuitEvent event) {
|
||||||
|
TBMCPlayer.SavePlayer(TBMCPlayer.GetPlayer(event.getPlayer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,11 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.Towny;
|
||||||
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import com.palmergames.bukkit.towny.object.ResidentModes;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* The class for holding data common to all TBMC plugins
|
* The class for holding data common to all TBMC plugins
|
||||||
|
@ -22,6 +27,8 @@ import org.bukkit.entity.Player;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TBMCPlayer {
|
public class TBMCPlayer {
|
||||||
|
private static final String TBMC_PLAYERS_DIR = "TBMC/players";
|
||||||
|
|
||||||
public String PlayerName;
|
public String PlayerName;
|
||||||
|
|
||||||
public UUID UUID;
|
public UUID UUID;
|
||||||
|
@ -51,20 +58,31 @@ public class TBMCPlayer {
|
||||||
return TBMCPlayer.OnlinePlayers.get(p.getUniqueId());
|
return TBMCPlayer.OnlinePlayers.get(p.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
static TBMCPlayer LoadPlayer(UUID uuid) throws Exception {
|
static TBMCPlayer LoadPlayer(Player p) {
|
||||||
if (OnlinePlayers.containsKey(uuid))
|
if (OnlinePlayers.containsKey(p.getUniqueId()))
|
||||||
return OnlinePlayers.get(uuid);
|
return OnlinePlayers.get(p.getUniqueId());
|
||||||
File file = new File("TBMC/players");
|
File file = new File(TBMC_PLAYERS_DIR);
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
file = new File("TBMC/players", uuid.toString() + ".yml");
|
file = new File(TBMC_PLAYERS_DIR, p.getUniqueId().toString() + ".yml");
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
return AddPlayer(uuid);
|
return AddPlayer(p);
|
||||||
else {
|
else {
|
||||||
final YamlConfiguration yc = new YamlConfiguration();
|
final YamlConfiguration yc = new YamlConfiguration();
|
||||||
|
try {
|
||||||
yc.load(file);
|
yc.load(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
new Exception("Failed to load player data for " + p.getUniqueId(), e).printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
TBMCPlayer player = new TBMCPlayer();
|
TBMCPlayer player = new TBMCPlayer();
|
||||||
player.UUID = uuid;
|
player.UUID = p.getUniqueId();
|
||||||
player.PlayerName = yc.getString("playername");
|
player.PlayerName = yc.getString("playername");
|
||||||
|
if (!p.getName().equals(player.PlayerName)) {
|
||||||
|
System.out.println("Renaming " + player.PlayerName + " to " + p.getName());
|
||||||
|
TownyUniverse tu = Towny.getPlugin(Towny.class).getTownyUniverse();
|
||||||
|
tu.getResidentMap().get(player.PlayerName).setName(p.getName());
|
||||||
|
System.out.println("Renaming done.");
|
||||||
|
}
|
||||||
|
|
||||||
// Load in other plugins
|
// Load in other plugins
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerLoadEvent(yc, player));
|
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerLoadEvent(yc, player));
|
||||||
|
@ -72,15 +90,11 @@ public class TBMCPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static TBMCPlayer AddPlayer(UUID uuid) {
|
static TBMCPlayer AddPlayer(Player p) {
|
||||||
if (OnlinePlayers.containsKey(uuid))
|
|
||||||
return OnlinePlayers.get(uuid);
|
|
||||||
TBMCPlayer player = new TBMCPlayer();
|
TBMCPlayer player = new TBMCPlayer();
|
||||||
player.UUID = uuid;
|
player.UUID = p.getUniqueId();
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
|
||||||
if (p != null)
|
|
||||||
player.PlayerName = p.getName();
|
player.PlayerName = p.getName();
|
||||||
OnlinePlayers.put(uuid, player);
|
OnlinePlayers.put(p.getUniqueId(), player);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerAddEvent(player));
|
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerAddEvent(player));
|
||||||
SavePlayer(player);
|
SavePlayer(player);
|
||||||
return player;
|
return player;
|
||||||
|
@ -91,7 +105,7 @@ public class TBMCPlayer {
|
||||||
yc.set("playername", player.PlayerName);
|
yc.set("playername", player.PlayerName);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerSaveEvent(yc, player));
|
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerSaveEvent(yc, player));
|
||||||
try {
|
try {
|
||||||
yc.save("tbmcplayers/" + player.UUID + ".yml");
|
yc.save(TBMC_PLAYERS_DIR + "/" + player.UUID + ".yml");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
new Exception("Failed to save player data for " + player.PlayerName, e).printStackTrace();
|
new Exception("Failed to save player data for " + player.PlayerName, e).printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,22 @@ package buttondevteam.core.player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* This event gets called when a new player joins. After this event, the
|
||||||
|
* {@link TBMCPlayerSaveEvent} will be called.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Norbi
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class TBMCPlayerAddEvent extends Event {
|
public class TBMCPlayerAddEvent extends Event {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private TBMCPlayer player;
|
private TBMCPlayer player;
|
||||||
|
|
||||||
public TBMCPlayerAddEvent(TBMCPlayer player) {
|
public TBMCPlayerAddEvent(TBMCPlayer player) {
|
||||||
//TODO: Convert player configs
|
// TODO: Convert player configs
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue