From 838fa9fe0346db5c791bed1dabc2112d8e6515c0 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 23 Jun 2016 01:09:49 +0200 Subject: [PATCH] Prev commit fixed #34, #21 is still WIP --- .../AnnouncerThread.java | 50 +-- .../Channel.java | 38 +- .../ChatProcessing.java | 4 +- .../Commands.java | 17 +- .../CreativeGlobalMechanic.java | 154 ++++---- .../FlairStates.java | 10 +- .../JarUtils.java | 180 +++++----- .../MaybeOfflinePlayer.java | 330 +++++++++--------- .../PlayerJoinTimerTask.java | 24 +- .../PlayerListener.java | 2 +- .../PluginMain.java | 4 +- 11 files changed, 399 insertions(+), 414 deletions(-) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/AnnouncerThread.java (90%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/Channel.java (90%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/ChatProcessing.java (96%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/Commands.java (92%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/CreativeGlobalMechanic.java (93%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/FlairStates.java (62%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/JarUtils.java (94%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/MaybeOfflinePlayer.java (95%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/PlayerJoinTimerTask.java (74%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/PlayerListener.java (97%) rename src/io/github/norbipeti/{thebuttonmc => thebuttonmcchat}/PluginMain.java (96%) diff --git a/src/io/github/norbipeti/thebuttonmc/AnnouncerThread.java b/src/io/github/norbipeti/thebuttonmcchat/AnnouncerThread.java similarity index 90% rename from src/io/github/norbipeti/thebuttonmc/AnnouncerThread.java rename to src/io/github/norbipeti/thebuttonmcchat/AnnouncerThread.java index 8301935..89df016 100644 --- a/src/io/github/norbipeti/thebuttonmc/AnnouncerThread.java +++ b/src/io/github/norbipeti/thebuttonmcchat/AnnouncerThread.java @@ -1,25 +1,25 @@ -package io.github.norbipeti.thebuttonmc; - -import org.bukkit.entity.Player; - -public class AnnouncerThread { - private static int AnnounceMessageIndex = 0; - - public static void Run() { - while (!PluginMain.Instance.stop) { - try { - Thread.sleep(PluginMain.AnnounceTime); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) { - for (Player player : PluginMain.GetPlayers()) - player.sendMessage(PluginMain.AnnounceMessages - .get(AnnounceMessageIndex)); - AnnounceMessageIndex++; - if (AnnounceMessageIndex == PluginMain.AnnounceMessages.size()) - AnnounceMessageIndex = 0; - } - } - } -} +package io.github.norbipeti.thebuttonmcchat; + +import org.bukkit.entity.Player; + +public class AnnouncerThread { + private static int AnnounceMessageIndex = 0; + + public static void Run() { + while (!PluginMain.Instance.stop) { + try { + Thread.sleep(PluginMain.AnnounceTime); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) { + for (Player player : PluginMain.GetPlayers()) + player.sendMessage(PluginMain.AnnounceMessages + .get(AnnounceMessageIndex)); + AnnounceMessageIndex++; + if (AnnounceMessageIndex == PluginMain.AnnounceMessages.size()) + AnnounceMessageIndex = 0; + } + } + } +} diff --git a/src/io/github/norbipeti/thebuttonmc/Channel.java b/src/io/github/norbipeti/thebuttonmcchat/Channel.java similarity index 90% rename from src/io/github/norbipeti/thebuttonmc/Channel.java rename to src/io/github/norbipeti/thebuttonmcchat/Channel.java index 11aab55..ad6dcb1 100644 --- a/src/io/github/norbipeti/thebuttonmc/Channel.java +++ b/src/io/github/norbipeti/thebuttonmcchat/Channel.java @@ -1,19 +1,19 @@ -package io.github.norbipeti.thebuttonmc; - -public class Channel { - public final String DisplayName; - public final String Color; - public final String Command; - - public Channel(String displayname, String color, String command) { - DisplayName = displayname; - Color = color; - Command = command; - } - - public static Channel GlobalChat = new Channel("§fg§f", "white", "g"); - public static Channel TownChat = new Channel("§3TC§f", "dark_aqua", "tc"); - public static Channel NationChat = new Channel("§6NC§f", "gold", "nc"); - public static Channel AdminChat = new Channel("§cADMIN§f", "red", "a"); - public static Channel ModChat = new Channel("§9MOD§f", "blue", "mod"); -} +package io.github.norbipeti.thebuttonmcchat; + +public class Channel { + public final String DisplayName; + public final String Color; + public final String Command; + + public Channel(String displayname, String color, String command) { + DisplayName = displayname; + Color = color; + Command = command; + } + + public static Channel GlobalChat = new Channel("§fg§f", "white", "g"); + public static Channel TownChat = new Channel("§3TC§f", "dark_aqua", "tc"); + public static Channel NationChat = new Channel("§6NC§f", "gold", "nc"); + public static Channel AdminChat = new Channel("§cADMIN§f", "red", "a"); + public static Channel ModChat = new Channel("§9MOD§f", "blue", "mod"); +} diff --git a/src/io/github/norbipeti/thebuttonmc/ChatProcessing.java b/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java similarity index 96% rename from src/io/github/norbipeti/thebuttonmc/ChatProcessing.java rename to src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java index 5a6e47a..af85b5b 100644 --- a/src/io/github/norbipeti/thebuttonmc/ChatProcessing.java +++ b/src/io/github/norbipeti/thebuttonmcchat/ChatProcessing.java @@ -1,6 +1,6 @@ -package io.github.norbipeti.thebuttonmc; +package io.github.norbipeti.thebuttonmcchat; -import io.github.norbipeti.thebuttonmc.commands.UnlolCommand; +import io.github.norbipeti.thebuttonmcchat.commands.UnlolCommand; import java.net.MalformedURLException; import java.net.URL; diff --git a/src/io/github/norbipeti/thebuttonmc/Commands.java b/src/io/github/norbipeti/thebuttonmcchat/Commands.java similarity index 92% rename from src/io/github/norbipeti/thebuttonmc/Commands.java rename to src/io/github/norbipeti/thebuttonmcchat/Commands.java index 3c6d857..702bd7d 100644 --- a/src/io/github/norbipeti/thebuttonmc/Commands.java +++ b/src/io/github/norbipeti/thebuttonmcchat/Commands.java @@ -1,4 +1,4 @@ -package io.github.norbipeti.thebuttonmc; +package io.github.norbipeti.thebuttonmcchat; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; @@ -214,21 +214,6 @@ public class Commands implements CommandExecutor { if (player == null || player.isOp() || player.getName().equals("NorbiPeti")) { switch (args[1].toLowerCase()) { - case "add": - if (args.length < 3) { - SendMessage(player, "§cUsage: /u announce add "); - return; - } - StringBuilder sb = new StringBuilder(); - for (int i = 2; i < args.length; i++) { - sb.append(args[i]); - if (i != args.length - 1) - sb.append(" "); - } - String finalmessage = sb.toString().replace('&', '§'); - PluginMain.AnnounceMessages.add(finalmessage); - SendMessage(player, "§bAnnouncement added.§r"); - break; case "remove": if (args.length < 3) { SendMessage(player, "§cUsage: /u announce remove "); diff --git a/src/io/github/norbipeti/thebuttonmc/CreativeGlobalMechanic.java b/src/io/github/norbipeti/thebuttonmcchat/CreativeGlobalMechanic.java similarity index 93% rename from src/io/github/norbipeti/thebuttonmc/CreativeGlobalMechanic.java rename to src/io/github/norbipeti/thebuttonmcchat/CreativeGlobalMechanic.java index 79158e4..b7789d3 100644 --- a/src/io/github/norbipeti/thebuttonmc/CreativeGlobalMechanic.java +++ b/src/io/github/norbipeti/thebuttonmcchat/CreativeGlobalMechanic.java @@ -1,77 +1,77 @@ -package io.github.norbipeti.thebuttonmc; - -import java.util.EnumSet; -import java.util.List; - -import org.bukkit.event.EventHandler; - -import au.com.mineauz.minigames.MinigamePlayer; -import au.com.mineauz.minigames.events.StartMinigameEvent; -import au.com.mineauz.minigames.gametypes.MinigameType; -import au.com.mineauz.minigames.mechanics.GameMechanicBase; -import au.com.mineauz.minigames.minigame.Minigame; -import au.com.mineauz.minigames.minigame.modules.MinigameModule; - -public class CreativeGlobalMechanic extends GameMechanicBase { - - @Override - public boolean checkCanStart(Minigame arg0, MinigamePlayer arg1) { - return true; - } - - @Override - public MinigameModule displaySettings(Minigame arg0) { - return null; - } - - @Override - public void endMinigame(Minigame arg0, List arg1, - List arg2) { - - } - - @Override - public String getMechanic() { - return "creativeglobal"; - } - - @Override - public void joinMinigame(Minigame mg, MinigamePlayer mp) { - mp.setCanFly(true); - mp.setAllowTeleport(true); - } - - @Override - public void quitMinigame(Minigame mg, MinigamePlayer mp, boolean forced) { - mg.getBlockRecorder().clearRestoreData(); - - } - - @Override - public void startMinigame(Minigame mg, MinigamePlayer mp) { - mp.setAllowTeleport(true); - } - - @Override - public void stopMinigame(Minigame arg0, MinigamePlayer arg1) { - - } - - @Override - public EnumSet validTypes() { - return EnumSet.of(MinigameType.MULTIPLAYER); - } - - @EventHandler - private void minigameStart(StartMinigameEvent event) { - if (event.getMinigame().getMechanicName().equals(getMechanic())) { - final List players = event.getPlayers(); - // final Minigame minigame = event.getMinigame(); - for (MinigamePlayer player : players) { - player.setCanFly(true); - player.setAllowTeleport(true); - } - } - } - -} +package io.github.norbipeti.thebuttonmcchat; + +import java.util.EnumSet; +import java.util.List; + +import org.bukkit.event.EventHandler; + +import au.com.mineauz.minigames.MinigamePlayer; +import au.com.mineauz.minigames.events.StartMinigameEvent; +import au.com.mineauz.minigames.gametypes.MinigameType; +import au.com.mineauz.minigames.mechanics.GameMechanicBase; +import au.com.mineauz.minigames.minigame.Minigame; +import au.com.mineauz.minigames.minigame.modules.MinigameModule; + +public class CreativeGlobalMechanic extends GameMechanicBase { + + @Override + public boolean checkCanStart(Minigame arg0, MinigamePlayer arg1) { + return true; + } + + @Override + public MinigameModule displaySettings(Minigame arg0) { + return null; + } + + @Override + public void endMinigame(Minigame arg0, List arg1, + List arg2) { + + } + + @Override + public String getMechanic() { + return "creativeglobal"; + } + + @Override + public void joinMinigame(Minigame mg, MinigamePlayer mp) { + mp.setCanFly(true); + mp.setAllowTeleport(true); + } + + @Override + public void quitMinigame(Minigame mg, MinigamePlayer mp, boolean forced) { + mg.getBlockRecorder().clearRestoreData(); + + } + + @Override + public void startMinigame(Minigame mg, MinigamePlayer mp) { + mp.setAllowTeleport(true); + } + + @Override + public void stopMinigame(Minigame arg0, MinigamePlayer arg1) { + + } + + @Override + public EnumSet validTypes() { + return EnumSet.of(MinigameType.MULTIPLAYER); + } + + @EventHandler + private void minigameStart(StartMinigameEvent event) { + if (event.getMinigame().getMechanicName().equals(getMechanic())) { + final List players = event.getPlayers(); + // final Minigame minigame = event.getMinigame(); + for (MinigamePlayer player : players) { + player.setCanFly(true); + player.setAllowTeleport(true); + } + } + } + +} diff --git a/src/io/github/norbipeti/thebuttonmc/FlairStates.java b/src/io/github/norbipeti/thebuttonmcchat/FlairStates.java similarity index 62% rename from src/io/github/norbipeti/thebuttonmc/FlairStates.java rename to src/io/github/norbipeti/thebuttonmcchat/FlairStates.java index 70aabeb..98e6614 100644 --- a/src/io/github/norbipeti/thebuttonmc/FlairStates.java +++ b/src/io/github/norbipeti/thebuttonmcchat/FlairStates.java @@ -1,5 +1,5 @@ -package io.github.norbipeti.thebuttonmc; - -public enum FlairStates { - Accepted, Ignored, Recognised, Commented, NoComment -} +package io.github.norbipeti.thebuttonmcchat; + +public enum FlairStates { + Accepted, Ignored, Recognised, Commented, NoComment +} diff --git a/src/io/github/norbipeti/thebuttonmc/JarUtils.java b/src/io/github/norbipeti/thebuttonmcchat/JarUtils.java similarity index 94% rename from src/io/github/norbipeti/thebuttonmc/JarUtils.java rename to src/io/github/norbipeti/thebuttonmcchat/JarUtils.java index 342bbe9..a6234c7 100644 --- a/src/io/github/norbipeti/thebuttonmc/JarUtils.java +++ b/src/io/github/norbipeti/thebuttonmcchat/JarUtils.java @@ -1,90 +1,90 @@ -package io.github.norbipeti.thebuttonmc; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLDecoder; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -public class JarUtils { - - public static boolean extractFromJar(final String fileName, - final String dest) throws IOException { - if (getRunningJar() == null) { - return false; - } - final File file = new File(dest); - if (file.isDirectory()) { - file.mkdir(); - return false; - } - if (!file.exists()) { - file.getParentFile().mkdirs(); - } - - final JarFile jar = getRunningJar(); - final Enumeration e = jar.entries(); - while (e.hasMoreElements()) { - final JarEntry je = e.nextElement(); - if (!je.getName().contains(fileName)) { - continue; - } - final InputStream in = new BufferedInputStream( - jar.getInputStream(je)); - final OutputStream out = new BufferedOutputStream( - new FileOutputStream(file)); - copyInputStream(in, out); - jar.close(); - return true; - } - jar.close(); - return false; - } - - private final static void copyInputStream(final InputStream in, - final OutputStream out) throws IOException { - try { - final byte[] buff = new byte[4096]; - int n; - while ((n = in.read(buff)) > 0) { - out.write(buff, 0, n); - } - } finally { - out.flush(); - out.close(); - in.close(); - } - } - - public static URL getJarUrl(final File file) throws IOException { - return new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/"); - } - - public static JarFile getRunningJar() throws IOException { - if (!RUNNING_FROM_JAR) { - return null; // null if not running from jar - } - String path = new File(JarUtils.class.getProtectionDomain() - .getCodeSource().getLocation().getPath()).getAbsolutePath(); - path = URLDecoder.decode(path, "UTF-8"); - return new JarFile(path); - } - - private static boolean RUNNING_FROM_JAR = false; - - static { - final URL resource = JarUtils.class.getClassLoader().getResource( - "plugin.yml"); - if (resource != null) { - RUNNING_FROM_JAR = true; - } - } - -} +package io.github.norbipeti.thebuttonmcchat; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLDecoder; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public class JarUtils { + + public static boolean extractFromJar(final String fileName, + final String dest) throws IOException { + if (getRunningJar() == null) { + return false; + } + final File file = new File(dest); + if (file.isDirectory()) { + file.mkdir(); + return false; + } + if (!file.exists()) { + file.getParentFile().mkdirs(); + } + + final JarFile jar = getRunningJar(); + final Enumeration e = jar.entries(); + while (e.hasMoreElements()) { + final JarEntry je = e.nextElement(); + if (!je.getName().contains(fileName)) { + continue; + } + final InputStream in = new BufferedInputStream( + jar.getInputStream(je)); + final OutputStream out = new BufferedOutputStream( + new FileOutputStream(file)); + copyInputStream(in, out); + jar.close(); + return true; + } + jar.close(); + return false; + } + + private final static void copyInputStream(final InputStream in, + final OutputStream out) throws IOException { + try { + final byte[] buff = new byte[4096]; + int n; + while ((n = in.read(buff)) > 0) { + out.write(buff, 0, n); + } + } finally { + out.flush(); + out.close(); + in.close(); + } + } + + public static URL getJarUrl(final File file) throws IOException { + return new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/"); + } + + public static JarFile getRunningJar() throws IOException { + if (!RUNNING_FROM_JAR) { + return null; // null if not running from jar + } + String path = new File(JarUtils.class.getProtectionDomain() + .getCodeSource().getLocation().getPath()).getAbsolutePath(); + path = URLDecoder.decode(path, "UTF-8"); + return new JarFile(path); + } + + private static boolean RUNNING_FROM_JAR = false; + + static { + final URL resource = JarUtils.class.getClassLoader().getResource( + "plugin.yml"); + if (resource != null) { + RUNNING_FROM_JAR = true; + } + } + +} diff --git a/src/io/github/norbipeti/thebuttonmc/MaybeOfflinePlayer.java b/src/io/github/norbipeti/thebuttonmcchat/MaybeOfflinePlayer.java similarity index 95% rename from src/io/github/norbipeti/thebuttonmc/MaybeOfflinePlayer.java rename to src/io/github/norbipeti/thebuttonmcchat/MaybeOfflinePlayer.java index 187376f..b4ab8cf 100644 --- a/src/io/github/norbipeti/thebuttonmc/MaybeOfflinePlayer.java +++ b/src/io/github/norbipeti/thebuttonmcchat/MaybeOfflinePlayer.java @@ -1,165 +1,165 @@ -package io.github.norbipeti.thebuttonmc; - -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 MaybeOfflinePlayer { - public String PlayerName; - public String UserName; - public List UserNames; - private short FlairTime; - public FlairStates FlairState; - public boolean RPMode = true; - public boolean PressedF; - public Location SavedLocation; - public boolean Working; - // public int Tables = 10; - public Channel CurrentChannel = Channel.GlobalChat; - public int FCount; - public boolean SendingLink = false; - public int FDeaths; - public boolean RainbowPresserColorMode = false; - public String OtherColorMode = ""; - public boolean ChatOnly = false; - public boolean FlairCheater = false; - public int LoginWarningCount = 0; - public static final short FlairTimeNonPresser = -1; - public static final short FlairTimeCantPress = -2; - public static final short FlairTimeNone = -3; - - public UUID UUID; - - public static HashMap AllPlayers = new HashMap<>(); - - public static MaybeOfflinePlayer AddPlayerIfNeeded(UUID uuid) { - if (!AllPlayers.containsKey(uuid)) { - MaybeOfflinePlayer player = new MaybeOfflinePlayer(); - player.UUID = uuid; - player.FlairTime = FlairTimeNone; - player.FlairState = FlairStates.NoComment; - player.UserNames = new ArrayList<>(); - 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); - MaybeOfflinePlayer mp = AddPlayerIfNeeded(java.util.UUID - .fromString(cs2.getString("uuid"))); - mp.UserName = cs2.getString("username"); - String tmp = cs2.getString("flairtime"); - if (tmp.equals("--")) - mp.FlairTime = FlairTimeNonPresser; - else if (tmp.equals("??")) - mp.FlairTime = FlairTimeCantPress; - else if (tmp.length() > 0) - mp.FlairTime = Short.parseShort(tmp); - String flairstate = cs2.getString("flairstate"); - if (flairstate != null) - mp.FlairState = FlairStates.valueOf(flairstate); - else - mp.FlairState = FlairStates.NoComment; - mp.PlayerName = cs2.getString("playername"); - mp.UserNames = cs2.getStringList("usernames"); - mp.FCount = cs2.getInt("fcount"); - mp.FDeaths = cs2.getInt("fdeaths"); - mp.FlairCheater = cs2.getBoolean("flaircheater"); - } - } - - public static void Save(YamlConfiguration yc) { - ConfigurationSection cs = yc.createSection("players"); - for (MaybeOfflinePlayer mp : MaybeOfflinePlayer.AllPlayers.values()) { - ConfigurationSection cs2 = cs.createSection(mp.UUID.toString()); - cs2.set("playername", mp.PlayerName); - cs2.set("username", mp.UserName); - cs2.set("flairtime", mp.FlairTime); - cs2.set("flairstate", mp.FlairState.toString()); - cs2.set("uuid", mp.UUID.toString()); - cs2.set("usernames", mp.UserNames); - cs2.set("fcount", mp.FCount); - cs2.set("fdeaths", mp.FDeaths); - cs2.set("flaircheater", mp.FlairCheater); - } - } - - public static MaybeOfflinePlayer GetFromName(String name) { - Player p = Bukkit.getPlayer(name); - if (p != null) - return AllPlayers.get(p.getUniqueId()); - else - return null; - } - - public String GetFormattedFlair() { - if (FlairTime == FlairTimeCantPress) - return String.format("§r(--s)§r"); - if (FlairTime == FlairTimeNonPresser) - return String.format("§7(--s)§r"); - if (FlairTime == FlairTimeNone) - return ""; - return String.format("§%x(%ss)§r", GetFlairColor(), FlairTime); - } - - public void SetFlair(short time) { - FlairTime = time; - FlairUpdate(); - } - - public void SetFlair(short time, boolean cheater) { - FlairTime = time; - FlairCheater = cheater; - FlairUpdate(); - } - - public void FlairUpdate() { - - // Flairs from Command Block The Button - Teams - // PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add() - Player p = Bukkit.getPlayer(UUID); - p.setPlayerListName(String.format("%s%s", p.getName(), - GetFormattedFlair())); - } - - public short GetFlairColor() { - if (FlairCheater) - return 0x5; - if (FlairTime == -1) - return 0x7; - else if (FlairTime == -2) - return 0xf; - else if (FlairTime <= 60 && FlairTime >= 52) - return 0x5; - else if (FlairTime <= 51 && FlairTime >= 42) - return 0x9; - else if (FlairTime <= 41 && FlairTime >= 32) - return 0xa; - else if (FlairTime <= 31 && FlairTime >= 22) - return 0xe; - else if (FlairTime <= 21 && FlairTime >= 11) - return 0x6; - else if (FlairTime <= 11 && FlairTime >= 0) - return 0xc; - return 0xf; - } - - public short GetFlairTime() { - return FlairTime; - } - - public static MaybeOfflinePlayer GetFromPlayer(Player p) { - return MaybeOfflinePlayer.AllPlayers.get(p.getUniqueId()); - } -} +package io.github.norbipeti.thebuttonmcchat; + +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 MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public List UserNames; + private short FlairTime; + public FlairStates FlairState; + public boolean RPMode = true; + public boolean PressedF; + public Location SavedLocation; + public boolean Working; + // public int Tables = 10; + public Channel CurrentChannel = Channel.GlobalChat; + public int FCount; + public boolean SendingLink = false; + public int FDeaths; + public boolean RainbowPresserColorMode = false; + public String OtherColorMode = ""; + public boolean ChatOnly = false; + public boolean FlairCheater = false; + public int LoginWarningCount = 0; + public static final short FlairTimeNonPresser = -1; + public static final short FlairTimeCantPress = -2; + public static final short FlairTimeNone = -3; + + public UUID UUID; + + public static HashMap AllPlayers = new HashMap<>(); + + public static MaybeOfflinePlayer AddPlayerIfNeeded(UUID uuid) { + if (!AllPlayers.containsKey(uuid)) { + MaybeOfflinePlayer player = new MaybeOfflinePlayer(); + player.UUID = uuid; + player.FlairTime = FlairTimeNone; + player.FlairState = FlairStates.NoComment; + player.UserNames = new ArrayList<>(); + 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); + MaybeOfflinePlayer mp = AddPlayerIfNeeded(java.util.UUID + .fromString(cs2.getString("uuid"))); + mp.UserName = cs2.getString("username"); + String tmp = cs2.getString("flairtime"); + if (tmp.equals("--")) + mp.FlairTime = FlairTimeNonPresser; + else if (tmp.equals("??")) + mp.FlairTime = FlairTimeCantPress; + else if (tmp.length() > 0) + mp.FlairTime = Short.parseShort(tmp); + String flairstate = cs2.getString("flairstate"); + if (flairstate != null) + mp.FlairState = FlairStates.valueOf(flairstate); + else + mp.FlairState = FlairStates.NoComment; + mp.PlayerName = cs2.getString("playername"); + mp.UserNames = cs2.getStringList("usernames"); + mp.FCount = cs2.getInt("fcount"); + mp.FDeaths = cs2.getInt("fdeaths"); + mp.FlairCheater = cs2.getBoolean("flaircheater"); + } + } + + public static void Save(YamlConfiguration yc) { + ConfigurationSection cs = yc.createSection("players"); + for (MaybeOfflinePlayer mp : MaybeOfflinePlayer.AllPlayers.values()) { + ConfigurationSection cs2 = cs.createSection(mp.UUID.toString()); + cs2.set("playername", mp.PlayerName); + cs2.set("username", mp.UserName); + cs2.set("flairtime", mp.FlairTime); + cs2.set("flairstate", mp.FlairState.toString()); + cs2.set("uuid", mp.UUID.toString()); + cs2.set("usernames", mp.UserNames); + cs2.set("fcount", mp.FCount); + cs2.set("fdeaths", mp.FDeaths); + cs2.set("flaircheater", mp.FlairCheater); + } + } + + public static MaybeOfflinePlayer GetFromName(String name) { + Player p = Bukkit.getPlayer(name); + if (p != null) + return AllPlayers.get(p.getUniqueId()); + else + return null; + } + + public String GetFormattedFlair() { + if (FlairTime == FlairTimeCantPress) + return String.format("§r(--s)§r"); + if (FlairTime == FlairTimeNonPresser) + return String.format("§7(--s)§r"); + if (FlairTime == FlairTimeNone) + return ""; + return String.format("§%x(%ss)§r", GetFlairColor(), FlairTime); + } + + public void SetFlair(short time) { + FlairTime = time; + FlairUpdate(); + } + + public void SetFlair(short time, boolean cheater) { + FlairTime = time; + FlairCheater = cheater; + FlairUpdate(); + } + + public void FlairUpdate() { + + // Flairs from Command Block The Button - Teams + // PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add() + Player p = Bukkit.getPlayer(UUID); + p.setPlayerListName(String.format("%s%s", p.getName(), + GetFormattedFlair())); + } + + public short GetFlairColor() { + if (FlairCheater) + return 0x5; + if (FlairTime == -1) + return 0x7; + else if (FlairTime == -2) + return 0xf; + else if (FlairTime <= 60 && FlairTime >= 52) + return 0x5; + else if (FlairTime <= 51 && FlairTime >= 42) + return 0x9; + else if (FlairTime <= 41 && FlairTime >= 32) + return 0xa; + else if (FlairTime <= 31 && FlairTime >= 22) + return 0xe; + else if (FlairTime <= 21 && FlairTime >= 11) + return 0x6; + else if (FlairTime <= 11 && FlairTime >= 0) + return 0xc; + return 0xf; + } + + public short GetFlairTime() { + return FlairTime; + } + + public static MaybeOfflinePlayer GetFromPlayer(Player p) { + return MaybeOfflinePlayer.AllPlayers.get(p.getUniqueId()); + } +} diff --git a/src/io/github/norbipeti/thebuttonmc/PlayerJoinTimerTask.java b/src/io/github/norbipeti/thebuttonmcchat/PlayerJoinTimerTask.java similarity index 74% rename from src/io/github/norbipeti/thebuttonmc/PlayerJoinTimerTask.java rename to src/io/github/norbipeti/thebuttonmcchat/PlayerJoinTimerTask.java index 6bfe602..89f621a 100644 --- a/src/io/github/norbipeti/thebuttonmc/PlayerJoinTimerTask.java +++ b/src/io/github/norbipeti/thebuttonmcchat/PlayerJoinTimerTask.java @@ -1,12 +1,12 @@ -package io.github.norbipeti.thebuttonmc; - -import java.util.TimerTask; - -public abstract class PlayerJoinTimerTask extends TimerTask { - - @Override - public abstract void run(); - - public MaybeOfflinePlayer mp; - -} +package io.github.norbipeti.thebuttonmcchat; + +import java.util.TimerTask; + +public abstract class PlayerJoinTimerTask extends TimerTask { + + @Override + public abstract void run(); + + public MaybeOfflinePlayer mp; + +} diff --git a/src/io/github/norbipeti/thebuttonmc/PlayerListener.java b/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java similarity index 97% rename from src/io/github/norbipeti/thebuttonmc/PlayerListener.java rename to src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java index f5f0a8d..f48984c 100644 --- a/src/io/github/norbipeti/thebuttonmc/PlayerListener.java +++ b/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java @@ -1,4 +1,4 @@ -package io.github.norbipeti.thebuttonmc; +package io.github.norbipeti.thebuttonmcchat; import java.io.File; import java.io.IOException; diff --git a/src/io/github/norbipeti/thebuttonmc/PluginMain.java b/src/io/github/norbipeti/thebuttonmcchat/PluginMain.java similarity index 96% rename from src/io/github/norbipeti/thebuttonmc/PluginMain.java rename to src/io/github/norbipeti/thebuttonmcchat/PluginMain.java index 6b5e7ba..945966a 100644 --- a/src/io/github/norbipeti/thebuttonmc/PluginMain.java +++ b/src/io/github/norbipeti/thebuttonmcchat/PluginMain.java @@ -1,4 +1,4 @@ -package io.github.norbipeti.thebuttonmc; +package io.github.norbipeti.thebuttonmcchat; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.economy.Economy; @@ -25,7 +25,7 @@ import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownyUniverse; -import io.github.norbipeti.thebuttonmc.commands.TBMCCommandBase; +import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; import java.io.*; import java.lang.String;