Removed reload command and fixed errors

This commit is contained in:
Norbi Peti 2016-10-29 19:47:13 +02:00
parent c810053558
commit fe51c015db
12 changed files with 102 additions and 173 deletions

View file

@ -14,7 +14,6 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -68,9 +67,7 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerLoad(TBMCPlayerLoadEvent e) {
YamlConfiguration yc = e.GetPlayerConfig();
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
short tcp = (short) yc.getInt("flairtime");
cp.FlairUpdate();
}
@ -187,7 +184,7 @@ public class PlayerListener implements Listener {
if (event.getMessage().length() < 2)
return;
int index = event.getMessage().indexOf(" ");
ChatPlayer mp = ChatPlayer.OnlinePlayers.get(event.getPlayer().getUniqueId());
ChatPlayer mp = TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class);
String cmd = "";
if (index == -1) {
cmd = event.getMessage().substring(1);
@ -366,10 +363,10 @@ public class PlayerListener implements Listener {
Ftimer.cancel();
ActiveF = true;
FCount = 0;
FPlayer = ChatPlayer.OnlinePlayers.get(e.getEntity().getUniqueId());
FPlayer.FDeaths++;
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId()).asPluginPlayer(ChatPlayer.class);
FPlayer.setFDeaths(FPlayer.getFDeaths() + 1);
for (Player p : PluginMain.GetPlayers()) {
ChatPlayer mp = ChatPlayer.OnlinePlayers.get(p.getUniqueId());
ChatPlayer mp = TBMCPlayer.getPlayerAs(p.getUniqueId(), ChatPlayer.class);
mp.PressedF = false;
p.sendMessage("§bPress F to pay respects.§r");
}
@ -430,14 +427,14 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
ChatPlayer mp = ChatPlayer.GetFromPlayer(e.getPlayer());
ChatPlayer mp = TBMCPlayer.getPlayerAs(e.getPlayer(), ChatPlayer.class);
if (mp.ChatOnly)
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerTeleport(PlayerTeleportEvent e) {
if (ChatPlayer.GetFromPlayer(e.getPlayer()).ChatOnly) {
if (TBMCPlayer.getPlayerAs(e.getPlayer(), ChatPlayer.class).ChatOnly) {
e.setCancelled(true);
e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode.");
}

View file

@ -18,6 +18,7 @@ import org.htmlcleaner.TagNode;
import buttondevteam.chat.commands.CommandCaller;
import buttondevteam.chat.commands.YeehawCommand;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.chat.TBMCChatAPI;
import com.google.gson.JsonArray;
@ -70,7 +71,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
Console = this.getServer().getConsoleSender();
LoadFiles(false);
LoadFiles();
SB = PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
if (SB.getObjective("town") == null)
@ -138,19 +139,20 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
ign = ign.trim();
if (PlayersWithFlairs.contains(ign))
continue;
ChatPlayer mp = ChatPlayer.getFromName(ign); // Loads player file
if (mp == null)
continue;
/*
* if (!JoinedBefore(mp, 2015, 6, 5)) continue;
*/
if (!mp.UserNames.contains(author))
mp.UserNames.add(author);
if (mp.FlairState.equals(FlairStates.NoComment)) {
mp.FlairState = FlairStates.Commented;
ConfirmUserMessage(mp);
} else
PlayersWithFlairs.add(ign);
try (ChatPlayer mp = TBMCPlayer.getFromName(ign).asPluginPlayer(ChatPlayer.class)) { // Loads player file
if (mp == null)
continue;
/*
* if (!JoinedBefore(mp, 2015, 6, 5)) continue;
*/
if (!mp.getUserNames().contains(author))
mp.getUserNames().add(author);
if (mp.getFlairState().equals(FlairStates.NoComment)) {
mp.setFlairState(FlairStates.Commented);
ConfirmUserMessage(mp);
} else
PlayersWithFlairs.add(ign);
}
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
@ -169,8 +171,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
}
public void DownloadFlair(ChatPlayer mp) throws MalformedURLException, IOException {
String[] flairdata = TBMCCoreAPI.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName)
.replace("\"", "").split(":");
String[] flairdata = TBMCCoreAPI
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.getUserName()).replace("\"", "")
.split(":");
String flair;
if (flairdata.length > 1)
flair = flairdata[1];
@ -181,14 +184,14 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
flairclass = flairdata[2];
else
flairclass = "unknown";
SetFlair(mp, flair, flairclass, mp.UserName);
SetFlair(mp, flair, flairclass, mp.getUserName());
}
public static Exception LastException;
private void SetFlair(ChatPlayer p, String text, String flairclass, String username) {
p.UserName = username;
p.FlairState = FlairStates.Recognised;
p.setUserName(username);
p.setFlairState(FlairStates.Recognised);
switch (flairclass) {
case "cheater":
p.SetFlair(Short.parseShort(text), true);
@ -205,20 +208,20 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
p.SetFlair(ChatPlayer.FlairTimeCantPress);
}
} catch (Exception e) {
p.FlairState = FlairStates.Commented; // Flair unknown
p.setFlairState(FlairStates.Commented); // Flair unknown
p.SetFlair(ChatPlayer.FlairTimeNone);
e.printStackTrace();
}
} else {
try {
if (CheckForJoinDate(p)) {
p.FlairState = FlairStates.Commented; // Flair unknown
p.setFlairState(FlairStates.Commented); // Flair unknown
p.SetFlair(ChatPlayer.FlairTimeNone);
} else {
p.SetFlair(ChatPlayer.FlairTimeCantPress);
}
} catch (Exception e) {
p.FlairState = FlairStates.Commented; // Flair unknown
p.setFlairState(FlairStates.Commented); // Flair unknown
p.SetFlair(ChatPlayer.FlairTimeNone);
e.printStackTrace();
}
@ -235,7 +238,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
}
public static boolean JoinedBefore(ChatPlayer mp, int year, int month, int day) throws Exception {
URL url = new URL("https://www.reddit.com/u/" + mp.UserName);
URL url = new URL("https://www.reddit.com/u/" + mp.getUserName());
URLConnection con = url.openConnection();
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
InputStream in = con.getInputStream();
@ -253,9 +256,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
}
public static void ConfirmUserMessage(ChatPlayer mp) {
Player p = Bukkit.getPlayer(mp.UUID);
if (mp.FlairState.equals(FlairStates.Commented) && p != null)
if (mp.UserNames.size() > 1)
Player p = Bukkit.getPlayer(mp.getUuid());
if (mp.getFlairState().equals(FlairStates.Commented) && p != null)
if (mp.getUserNames().size() > 1)
p.sendMessage(
"§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r");
else
@ -269,12 +272,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
public static int AnnounceTime = 15 * 60 * 1000;
public static void LoadFiles(boolean reload) {
if (reload) {
PluginMain.Instance.getLogger().info("Cleanup for reloading...");
ChatPlayer.OnlinePlayers.clear();
AnnounceMessages.clear();
}
public static void LoadFiles() {
PluginMain.Instance.getLogger().info("Loading files...");
try {
File file = new File("TBMC/chatsettings.yml");

View file

@ -5,25 +5,24 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.chat.TBMCCommandBase;
public final class ChatonlyCommand extends TBMCCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[]{
"§6---- Chat-only mode ----",
"This mode makes you invincible but unable to move, teleport or interact with the world in any way",
"It was designed for chat clients",
"Once enabled, the only way of disabling it is by relogging to the server"
return new String[] { "§6---- Chat-only mode ----", //
"This mode makes you invincible but unable to move, teleport or interact with the world in any way", //
"It was designed for chat clients", //
"Once enabled, the only way of disabling it is by relogging to the server" //
};
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player=(Player)sender;
ChatPlayer p = ChatPlayer.OnlinePlayers.get(player
.getUniqueId());
Player player = (Player) sender;
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
p.ChatOnly = true;
player.setGameMode(GameMode.SPECTATOR);
player.sendMessage("§bChat-only mode enabled. You are now invincible.");

View file

@ -4,6 +4,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.chat.TBMCCommandBase;
public final class OOCCommand extends TBMCCommandBase {
@ -21,12 +22,13 @@ public final class OOCCommand extends TBMCCommandBase {
if (args.length == 0) {
return false;
} else {
ChatPlayer.GetFromPlayer(player).RPMode = false;
final ChatPlayer cp = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
cp.RPMode = false;
String message = "";
for (String arg : args)
message += arg + " ";
player.chat(message.substring(0, message.length() - 1));
ChatPlayer.GetFromPlayer(player).RPMode = true;
cp.RPMode = true;
}
return true;
}

View file

@ -9,35 +9,36 @@ import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.FlairStates;
import buttondevteam.chat.PlayerJoinTimerTask;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCPlayer;
public class AcceptCommand extends UCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Accept flair ----",
"Accepts a flair from Reddit",
"Use /u accept <username> if you commented from multiple accounts" };
return new String[] { "§6---- Accept flair ----", //
"Accepts a flair from Reddit", //
"Use /u accept <username> if you commented from multiple accounts" //
};
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
final Player player = (Player) sender;
ChatPlayer p = ChatPlayer.GetFromPlayer(player);
if (args.length < 1 && p.UserNames.size() > 1) {
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
if (args.length < 1 && p.getUserNames().size() > 1) {
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
StringBuilder sb = new StringBuilder();
sb.append("§6Usernames:");
for (String username : p.UserNames)
for (String username : p.getUserNames())
sb.append(" ").append(username);
player.sendMessage(sb.toString());
return true;
}
if (p.FlairState.equals(FlairStates.NoComment)
|| p.UserNames.size() == 0) {
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/TheButtonMinecraft§r");
if (p.getFlairState().equals(FlairStates.NoComment) || p.getUserNames().size() == 0) {
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/ChromaGamers§r");
return true;
}
if (args.length > 0 && !p.UserNames.contains(args[0])) {
if (args.length > 0 && !p.getUserNames().contains(args[0])) {
player.sendMessage("§cError: Unknown name: " + args[0] + "§r");
return true;
}
@ -46,14 +47,14 @@ public class AcceptCommand extends UCommandBase {
return true;
}
if ((args.length > 0 ? args[0] : p.UserNames.get(0)).equals(p.UserName)) {
if ((args.length > 0 ? args[0] : p.getUserNames().get(0)).equals(p.getUserName())) {
player.sendMessage("§cYou already have this user's flair.§r");
return true;
}
if (args.length > 0)
p.UserName = args[0];
p.setUserName(args[0]);
else
p.UserName = p.UserNames.get(0);
p.setUserName(p.getUserNames().get(0));
player.sendMessage("§bObtaining flair...");
p.Working = true;
@ -65,18 +66,20 @@ public class AcceptCommand extends UCommandBase {
PluginMain.Instance.DownloadFlair(mp);
} catch (Exception e) {
e.printStackTrace();
player.sendMessage("Sorry, but an error occured while trying to get your flair. Please contact a mod.");
player.sendMessage(
"Sorry, but an error occured while trying to get your flair. Please contact a mod.");
mp.Working = false;
return;
}
if (mp.FlairState.equals(FlairStates.Commented)) {
player.sendMessage("Sorry, but your flair isn't recorded. Please ask an admin to set it for you. Also, prepare a comment on /r/thebutton, if possible.");
if (mp.getFlairState().equals(FlairStates.Commented)) {
player.sendMessage(
"Sorry, but your flair isn't recorded. Please ask an admin to set it for you. Also, prepare a comment on /r/thebutton, if possible.");
mp.Working = false;
return;
}
String flair = mp.GetFormattedFlair();
mp.FlairState = FlairStates.Accepted;
mp.setFlairState(FlairStates.Accepted);
PluginMain.ConfirmUserMessage(mp);
player.sendMessage("§bYour flair has been set:§r " + flair);
mp.Working = false;

View file

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
import buttondevteam.chat.formatting.ChatFormatter;
import buttondevteam.lib.TBMCPlayer;
public class CCommand extends UCommandBase {
@ -18,7 +19,7 @@ public class CCommand extends UCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
ChatPlayer p = ChatPlayer.GetFromPlayer(player);
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
if (args.length < 1) {
if (PluginMain.permission.has(player, "tbmc.rainbow")) {
p.RainbowPresserColorMode = !p.RainbowPresserColorMode;

View file

@ -5,13 +5,13 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.FlairStates;
import buttondevteam.lib.TBMCPlayer;
public final class IgnoreCommand extends UCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] {
"§6---- Ignore flair ----",
return new String[] { "§6---- Ignore flair ----",
"Stop the \"write your name in the thread\" message from showing up",
"Use /u ignore <username> if you commented from multiple accounts" };
}
@ -19,19 +19,19 @@ public final class IgnoreCommand extends UCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
final Player player = (Player) sender;
ChatPlayer p = ChatPlayer.GetFromPlayer(player);
if (p.FlairState.equals(FlairStates.Accepted)) {
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
if (p.getFlairState().equals(FlairStates.Accepted)) {
player.sendMessage("§cYou can only ignore the \"write your name in the thread\" message.");
return true;
}
if (p.FlairState.equals(FlairStates.Commented)) {
if (p.getFlairState().equals(FlairStates.Commented)) {
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
return true;
}
if (!p.FlairState.equals(FlairStates.Ignored)) {
p.FlairState = FlairStates.Ignored;
if (!p.getFlairState().equals(FlairStates.Ignored)) {
p.setFlairState(FlairStates.Ignored);
p.SetFlair(ChatPlayer.FlairTimeNone);
p.UserName = "";
p.setUserName("");
player.sendMessage("§bYou have ignored the message.§r");
} else
player.sendMessage("§cYou already ignored the message.§r");

View file

@ -3,13 +3,13 @@ package buttondevteam.chat.commands.ucmds;
import org.bukkit.command.CommandSender;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.TBMCPlayer;
public class NameCommand extends UCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] {
"§6---- Get username ----",
return new String[] { "§6---- Get username ----",
"This command allows you to see the Reddit username of a player if they have one associated",
"Usage: /u name <playername>" };
}
@ -19,13 +19,12 @@ public class NameCommand extends UCommandBase {
if (args.length == 0) {
return false;
}
ChatPlayer mp = ChatPlayer.getFromName(args[0]);
ChatPlayer mp = TBMCPlayer.getFromName(args[0]).asPluginPlayer(ChatPlayer.class);
if (mp == null) {
sender.sendMessage("§cUnknown user: "
+ args[0]);
sender.sendMessage("§cUnknown user: " + args[0]);
return true;
}
sender.sendMessage("§bUsername of " + args[0] + ": " + mp.UserName);
sender.sendMessage("§bUsername of " + args[0] + ": " + mp.getUserName());
return true;
}

View file

@ -1,47 +0,0 @@
package buttondevteam.chat.commands.ucmds.admin;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
public class ConfirmCommand extends AdminCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6--- Confirm reload ----", "Use this after using /u admin reload and /u admin save" };
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (ReloadCommand.Reloader == sender) {
try {
if (sender != PluginMain.Console)
PluginMain.Console.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
sender.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
PluginMain.LoadFiles(true);
// TODO: Add players online
for (Player p : PluginMain.GetPlayers())
ChatPlayer.GetFromPlayer(p); // TODO: Reload other TBMC plugin data?
if (sender != PluginMain.Console)
PluginMain.Console.sendMessage("§6-- Reloading done!§r");
sender.sendMessage("§6-- Reloading done!§r");
ReloadCommand.Reloader = null;
} catch (Exception e) {
PluginMain.Instance.getLogger().warning("Error!\n" + e);
if (sender != PluginMain.Console)
sender.sendMessage("§cAn error occured. See console for details.§r");
PluginMain.LastException = e;
}
} else
sender.sendMessage("§cYou need to do /u admin reload first.§r");
return true;
}
@Override
public String GetAdminCommandPath() {
return "confirm";
}
}

View file

@ -3,6 +3,7 @@ package buttondevteam.chat.commands.ucmds.admin;
import org.bukkit.command.CommandSender;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.TBMCPlayer;
public class PlayerInfoCommand extends AdminCommandBase {
@ -18,18 +19,24 @@ public class PlayerInfoCommand extends AdminCommandBase {
if (args.length == 0) {
return false;
}
ChatPlayer p = ChatPlayer.getFromName(args[0]);
ChatPlayer p = TBMCPlayer.getFromName(args[0]).asPluginPlayer(ChatPlayer.class);
if (p == null) {
sender.sendMessage("§cPlayer not found: " + args[0] + "§r");
return true;
}
StringBuilder sb = new StringBuilder();
sb.append("§6Usernames:");
for (String username : p.UserNames)
for (String username : p.getUserNames())
sb.append(" ").append(username);
sender.sendMessage(new String[] { "Player name: " + p.PlayerName, "User flair: " + p.GetFormattedFlair(),
"Username: " + p.UserName, "Flair state: " + p.FlairState, sb.toString(), "FCount: " + p.FCount,
"FDeaths: " + p.FDeaths });
sender.sendMessage(new String[] { //
"Player name: " + p.getPlayerName(), //
"User flair: " + p.GetFormattedFlair(), //
"Username: " + p.getUserName(), //
"Flair state: " + p.getFlairState(), //
sb.toString(), //
"FCount: " + p.getFCount(), //
"FDeaths: " + p.getFDeaths() //
});
return true;
}

View file

@ -1,31 +0,0 @@
package buttondevteam.chat.commands.ucmds.admin;
import org.bukkit.command.CommandSender;
public final class ReloadCommand extends AdminCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Reload plugin ----", "This command allows you to reload the plugin's config",
"This isn't the same as reloading the server, and should not cause any issues with other plugins",
"Save the config by using /u admin save before you reload it",
"Because of this, you'll need to confirm the reload with /u admin confirm" };
}
public static CommandSender Reloader;
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Reloader = sender;
sender.sendMessage(
"§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when ready.§r");
sender.sendMessage("§bNote that this command may not set players up correctly as of now.");
return true;
}
@Override
public String GetAdminCommandPath() {
return "reload";
}
}

View file

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.FlairStates;
import buttondevteam.lib.TBMCPlayer;
public class SetFlairCommand extends AdminCommandBase {
@ -52,18 +53,18 @@ public class SetFlairCommand extends AdminCommandBase {
sender.sendMessage("§cUnknown value for cheater parameter. Run without args to see usage.");
return true;
}
ChatPlayer mp = ChatPlayer.GetFromPlayer(p);
ChatPlayer mp = TBMCPlayer.getPlayerAs(p, ChatPlayer.class);
mp.SetFlair(flairtime, cheater);
mp.FlairState = FlairStates.Accepted;
mp.setFlairState(FlairStates.Accepted);
if (args.length < 4)
mp.UserName = "";
mp.setUserName("");
else {
mp.UserName = args[3];
if (!mp.UserNames.contains(args[3]))
mp.UserNames.add(args[3]);
mp.setUserName(args[3]);
if (!mp.getUserNames().contains(args[3]))
mp.getUserNames().add(args[3]);
}
sender.sendMessage(
"§bThe flair has been set. Player: " + mp.PlayerName + " Flair: " + mp.GetFormattedFlair() + "§r");
"§bThe flair has been set. Player: " + mp.getPlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
return true;
}