Exception stuff and player data stuff

This commit is contained in:
Norbi Peti 2020-10-25 01:18:20 +02:00
parent c6ba0ec607
commit c52a6873fe
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
16 changed files with 115 additions and 163 deletions

View file

@ -204,7 +204,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version> <version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- <dependency> <!-- <dependency>

View file

@ -1,50 +1,32 @@
package buttondevteam.chat; package buttondevteam.chat;
import buttondevteam.chat.components.flair.FlairStates; import buttondevteam.chat.components.flair.FlairStates;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.ListConfigData;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.player.EnumPlayerData;
import buttondevteam.lib.player.PlayerClass; import buttondevteam.lib.player.PlayerClass;
import buttondevteam.lib.player.PlayerData;
import buttondevteam.lib.player.TBMCPlayerBase; import buttondevteam.lib.player.TBMCPlayerBase;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@PlayerClass(pluginname = "Button1Chat") @PlayerClass(pluginname = "Button1Chat")
public class ChatPlayer extends TBMCPlayerBase { public class ChatPlayer extends TBMCPlayerBase {
public PlayerData<String> UserName() { public final ConfigData<String> UserName = getConfig().getData("UserName", "");
return data(null);
}
public List<String> UserNames() { public final ListConfigData<String> UserNames = getConfig().getListData("UserNames");
return data(new ArrayList<String>()).get();
}
public PlayerData<Integer> FlairTime() { public final ConfigData<Integer> FlairTime = getConfig().getData("FlairTime", FlairTimeNone);
return data(FlairTimeNone);
}
public EnumPlayerData<FlairStates> FlairState() { public final ConfigData<FlairStates> FlairState = getConfig().getData("FlairState", FlairStates.NoComment,
return dataEnum(FlairStates.class, FlairStates.NoComment); fs -> FlairStates.valueOf((String) fs), FlairStates::toString);
}
public PlayerData<Integer> FCount() { public final ConfigData<Integer> FCount = getConfig().getData("FCount", 0);
return data(0);
}
public PlayerData<Integer> FDeaths() { public final ConfigData<Integer> FDeaths = getConfig().getData("FDeaths", 0);
return data(0);
}
public PlayerData<Boolean> FlairCheater() { public final ConfigData<Boolean> FlairCheater = getConfig().getData("FlairCheater", false);
return data(false);
}
public PlayerData<ArrayList<Integer>> NameColorLocations() { // No byte[], no TIntArrayList public final ListConfigData<Integer> NameColorLocations = getConfig().getListData("NameColorLocations"); // No byte[], no TIntArrayList
return data(null);
}
public boolean Working; public boolean Working;
// public int Tables = 10; // public int Tables = 10;
@ -64,7 +46,7 @@ public class ChatPlayer extends TBMCPlayerBase {
* @return The flair * @return The flair
*/ */
public String GetFormattedFlair(boolean noformats) { public String GetFormattedFlair(boolean noformats) {
int time = FlairTime().get(); int time = FlairTime.get();
if (time == FlairTimeCantPress) if (time == FlairTimeCantPress)
return noformats ? "(can't press)" : "§r(--s)§r"; return noformats ? "(can't press)" : "§r(--s)§r";
if (time == FlairTimeNonPresser) if (time == FlairTimeNonPresser)
@ -84,13 +66,13 @@ public class ChatPlayer extends TBMCPlayerBase {
} }
public void SetFlair(int time) { public void SetFlair(int time) {
FlairTime().set(time); FlairTime.set(time);
FlairUpdate(); FlairUpdate();
} }
public void SetFlair(int time, boolean cheater) { public void SetFlair(int time, boolean cheater) {
FlairTime().set(time); FlairTime.set(time);
FlairCheater().set(cheater); FlairCheater.set(cheater);
FlairUpdate(); FlairUpdate();
} }
@ -104,9 +86,9 @@ public class ChatPlayer extends TBMCPlayerBase {
} }
public short GetFlairColor() { public short GetFlairColor() {
if (FlairCheater().get()) if (FlairCheater.get())
return 0x5; return 0x5;
final int flairTime = FlairTime().get(); final int flairTime = FlairTime.get();
if (flairTime == FlairTimeNonPresser) if (flairTime == FlairTimeNonPresser)
return 0x7; return 0x7;
else if (flairTime == FlairTimeCantPress) else if (flairTime == FlairTimeCantPress)
@ -127,6 +109,6 @@ public class ChatPlayer extends TBMCPlayerBase {
} }
public double getF() { public double getF() {
return (double) FCount().get() / (double) FDeaths().get(); return (double) FCount.get() / (double) FDeaths.get();
} }
} }

View file

@ -25,7 +25,6 @@ import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Essentials;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
@ -60,8 +59,8 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
TBMCChatAPI.RegisterChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global TBMCChatAPI.RegisterChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
if (!setupEconomy() || !setupPermissions()) if (!setupPermissions())
TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up economy or permissions!")); TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up permissions!"), this);
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
Component.registerComponent(this, new TownColorComponent()); Component.registerComponent(this, new TownColorComponent());
@ -88,7 +87,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
} }
public static Permission permission = null; public static Permission permission = null;
public static Economy economy = null;
private boolean setupPermissions() { private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager() RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()
@ -99,14 +97,4 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
return (permission != null); return (permission != null);
} }
private boolean setupEconomy() {
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager()
.getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return (economy != null);
}
} }

View file

@ -1,7 +1,6 @@
package buttondevteam.chat.commands.ucmds; package buttondevteam.chat.commands.ucmds;
import buttondevteam.chat.PluginMain; import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
@ -19,16 +18,12 @@ public class InfoCommand extends UCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(CommandSender sender, OfflinePlayer player) { public boolean def(CommandSender sender, OfflinePlayer player) {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
try (TBMCPlayer p = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class)) { TBMCPlayer p = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class);
if (p == null) { if (p == null) {
sender.sendMessage("§cThe specified player cannot be found"); sender.sendMessage("§cThe specified player cannot be found");
return; return;
}
sender.sendMessage(p.getInfo(InfoTarget.MCCommand));
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while getting player information!", e);
sender.sendMessage("§cError while getting player information!");
} }
sender.sendMessage(p.getInfo(InfoTarget.MCCommand));
}); });
return true; return true;
} }

View file

@ -8,12 +8,12 @@ import buttondevteam.core.ComponentManager;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ComponentMetadata; import buttondevteam.lib.architecture.ComponentMetadata;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import lombok.val; import lombok.val;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; 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.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
@ -34,9 +34,9 @@ public class ChatOnlyComponent extends Component<PluginMain> implements Listener
} }
@EventHandler @EventHandler
public void playerJoin(TBMCPlayerJoinEvent event) { public void playerJoin(PlayerJoinEvent event) {
val p = event.getPlayer(); val p = event.getPlayer();
val cp = event.GetPlayer().asPluginPlayer(ChatPlayer.class); val cp = TBMCPlayer.getPlayer(p.getUniqueId(), ChatPlayer.class);
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
cp.ChatOnly = false; cp.ChatOnly = false;
p.setGameMode(GameMode.SURVIVAL); p.setGameMode(GameMode.SURVIVAL);
@ -44,7 +44,7 @@ public class ChatOnlyComponent extends Component<PluginMain> implements Listener
} }
public static void tellrawCreate(ChatPlayer mp, TellrawPart json) { public static void tellrawCreate(ChatPlayer mp, TellrawPart json) {
if(!ComponentManager.isEnabled(ChatOnlyComponent.class)) if (!ComponentManager.isEnabled(ChatOnlyComponent.class))
return; return;
if (mp != null && mp.ChatOnly) { if (mp != null && mp.ChatOnly) {
json.addExtra(new TellrawPart("[C]") json.addExtra(new TellrawPart("[C]")

View file

@ -24,21 +24,21 @@ public class AcceptCommand extends UCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(Player player, @Command2.OptionalArg String username) { public boolean def(Player player, @Command2.OptionalArg String username) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
if (username == null && p.UserNames().size() > 1) { if (username == null && p.UserNames.get().size() > 1) {
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>"); player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("§6Usernames:"); sb.append("§6Usernames:");
for (String name : p.UserNames()) for (String name : p.UserNames.get())
sb.append(" ").append(name); sb.append(" ").append(name);
player.sendMessage(sb.toString()); player.sendMessage(sb.toString());
return true; return true;
} }
if (p.FlairState().get().equals(FlairStates.NoComment) || p.UserNames().size() == 0) { if (p.FlairState.get().equals(FlairStates.NoComment) || p.UserNames.get().size() == 0) {
player.sendMessage("§cError: You need to write your username to the reddit thread§r"); player.sendMessage("§cError: You need to write your username to the reddit thread§r");
player.sendMessage(component.flairThreadURL().get()); player.sendMessage(component.flairThreadURL().get());
return true; return true;
} }
if (username != null && !p.UserNames().contains(username)) { if (username != null && !p.UserNames.get().contains(username)) {
player.sendMessage("§cError: Unknown name: " + username + "§r"); player.sendMessage("§cError: Unknown name: " + username + "§r");
return true; return true;
} }
@ -47,14 +47,14 @@ public class AcceptCommand extends UCommandBase {
return true; return true;
} }
if ((username != null ? username : p.UserNames().get(0)).equals(p.UserName().get())) { if ((username != null ? username : p.UserNames.get().get(0)).equals(p.UserName.get())) {
player.sendMessage("§cYou already have this user's flair.§r"); player.sendMessage("§cYou already have this user's flair.§r");
return true; return true;
} }
if (username != null) if (username != null)
p.UserName().set(username); p.UserName.set(username);
else else
p.UserName().set(p.UserNames().get(0)); p.UserName.set(p.UserNames.get().get(0));
player.sendMessage("§bObtaining flair..."); player.sendMessage("§bObtaining flair...");
p.Working = true; p.Working = true;
@ -65,22 +65,19 @@ public class AcceptCommand extends UCommandBase {
try { try {
component.DownloadFlair(mp); component.DownloadFlair(mp);
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException( TBMCCoreAPI.SendException("An error occured while downloading flair for " + player.getCustomName() + "!", e, component);
"An error occured while downloading flair for " + player.getCustomName() + "!", e); 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; mp.Working = false;
return; return;
} }
if (mp.FlairState().get().equals(FlairStates.Commented)) { if (mp.FlairState.get().equals(FlairStates.Commented)) {
player.sendMessage( 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.");
"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; mp.Working = false;
return; return;
} }
String flair = mp.GetFormattedFlair(); String flair = mp.GetFormattedFlair();
mp.FlairState().set(FlairStates.Accepted); mp.FlairState.set(FlairStates.Accepted);
FlairComponent.ConfirmUserMessage(mp); FlairComponent.ConfirmUserMessage(mp);
player.sendMessage("§bYour flair has been set:§r " + flair); player.sendMessage("§bYour flair has been set:§r " + flair);
mp.Working = false; mp.Working = false;

View file

@ -78,20 +78,19 @@ public class FlairComponent extends Component<PluginMain> {
ign = ign.trim(); ign = ign.trim();
if (PlayersWithFlairs.contains(ign)) if (PlayersWithFlairs.contains(ign))
continue; continue;
try (ChatPlayer mp = TBMCPlayerBase.getFromName(ign, ChatPlayer.class)) { // Loads player file ChatPlayer mp = TBMCPlayerBase.getFromName(ign, ChatPlayer.class); // Loads player file
if (mp == null) if (mp == null)
continue; continue;
/* /*
* if (!JoinedBefore(mp, 2015, 6, 5)) continue; * if (!JoinedBefore(mp, 2015, 6, 5)) continue;
*/ */
if (!mp.UserNames().contains(author)) if (!mp.UserNames.get().contains(author))
mp.UserNames().add(author); mp.UserNames.get().add(author);
if (mp.FlairState().get().equals(FlairStates.NoComment)) { if (mp.FlairState.get().equals(FlairStates.NoComment)) {
mp.FlairState().set(FlairStates.Commented); mp.FlairState.set(FlairStates.Commented);
ConfirmUserMessage(mp); ConfirmUserMessage(mp);
}
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
} }
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
} }
} catch (Exception e) { } catch (Exception e) {
errorcount++; errorcount++;
@ -99,7 +98,7 @@ public class FlairComponent extends Component<PluginMain> {
errorcount = 0; errorcount = 0;
if (!e.getMessage().contains("Server returned HTTP response code") if (!e.getMessage().contains("Server returned HTTP response code")
&& !(e instanceof UnknownHostException)) && !(e instanceof UnknownHostException))
TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e); TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e, this);
} }
} }
try { try {
@ -108,11 +107,12 @@ public class FlairComponent extends Component<PluginMain> {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
} }
void DownloadFlair(ChatPlayer mp) throws IOException { void DownloadFlair(ChatPlayer mp) throws IOException {
String[] flairdata = TBMCCoreAPI String[] flairdata = TBMCCoreAPI
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get()) .DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName.get())
.replace("\"", "").split(":"); .replace("\"", "").split(":");
String flair; String flair;
if (flairdata.length > 1) if (flairdata.length > 1)
@ -124,12 +124,12 @@ public class FlairComponent extends Component<PluginMain> {
flairclass = flairdata[2]; flairclass = flairdata[2];
else else
flairclass = "unknown"; flairclass = "unknown";
SetFlair(mp, flair, flairclass, mp.UserName().get()); SetFlair(mp, flair, flairclass, mp.UserName.get());
} }
private static void SetFlair(ChatPlayer p, String text, String flairclass, String username) { private void SetFlair(ChatPlayer p, String text, String flairclass, String username) {
p.UserName().set(username); p.UserName.set(username);
p.FlairState().set(FlairStates.Recognised); p.FlairState.set(FlairStates.Recognised);
switch (flairclass) { switch (flairclass) {
case "cheater": case "cheater":
p.SetFlair(Short.parseShort(text), true); p.SetFlair(Short.parseShort(text), true);
@ -145,9 +145,9 @@ public class FlairComponent extends Component<PluginMain> {
p.SetFlair(ChatPlayer.FlairTimeCantPress); p.SetFlair(ChatPlayer.FlairTimeCantPress);
} }
} catch (Exception e) { } catch (Exception e) {
p.FlairState().set(FlairStates.Commented); // Flair unknown p.FlairState.set(FlairStates.Commented); // Flair unknown
p.SetFlair(ChatPlayer.FlairTimeNone); p.SetFlair(ChatPlayer.FlairTimeNone);
TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName() + "!", e); TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName() + "!", e, this);
} }
return; return;
default: default:
@ -181,8 +181,8 @@ public class FlairComponent extends Component<PluginMain> {
public static void ConfirmUserMessage(ChatPlayer mp) { public static void ConfirmUserMessage(ChatPlayer mp) {
Player p = Bukkit.getPlayer(mp.getUUID()); Player p = Bukkit.getPlayer(mp.getUUID());
if (mp.FlairState().get().equals(FlairStates.Commented) && p != null) if (mp.FlairState.get().equals(FlairStates.Commented) && p != null)
if (mp.UserNames().size() > 1) if (mp.UserNames.get().size() > 1)
p.sendMessage( p.sendMessage(
"§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r"); "§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r");
else else

View file

@ -15,18 +15,18 @@ public final class IgnoreCommand extends UCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(Player player) { public boolean def(Player player) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
if (p.FlairState().get().equals(FlairStates.Accepted)) { if (p.FlairState.get().equals(FlairStates.Accepted)) {
player.sendMessage("§cYou can only ignore the \"write your name in the thread\" message."); player.sendMessage("§cYou can only ignore the \"write your name in the thread\" message.");
return true; return true;
} }
if (p.FlairState().get().equals(FlairStates.Commented)) { if (p.FlairState.get().equals(FlairStates.Commented)) {
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you."); player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
return true; return true;
} }
if (!p.FlairState().get().equals(FlairStates.Ignored)) { if (!p.FlairState.get().equals(FlairStates.Ignored)) {
p.FlairState().set(FlairStates.Ignored); p.FlairState.set(FlairStates.Ignored);
p.SetFlair(ChatPlayer.FlairTimeNone); p.SetFlair(ChatPlayer.FlairTimeNone);
p.UserName().set(""); p.UserName.set("");
player.sendMessage("§bYou have ignored the message.§r"); player.sendMessage("§bYou have ignored the message.§r");
} else } else
player.sendMessage("§cYou already ignored the message.§r"); player.sendMessage("§cYou already ignored the message.§r");

View file

@ -35,22 +35,22 @@ public class SetFlairCommand extends AdminCommandBase {
ft = Short.parseShort(flairtime); ft = Short.parseShort(flairtime);
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage( sender.sendMessage(
"§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage."); "§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage.");
return true; return true;
} }
} }
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class); ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
mp.SetFlair(ft, cheater); mp.SetFlair(ft, cheater);
mp.FlairState().set(FlairStates.Accepted); mp.FlairState.set(FlairStates.Accepted);
if (username == null) if (username == null)
mp.UserName().set(""); mp.UserName.set("");
else { else {
mp.UserName().set(username); mp.UserName.set(username);
if (!mp.UserNames().contains(username)) if (!mp.UserNames.get().contains(username))
mp.UserNames().add(username); mp.UserNames.get().add(username);
} }
sender.sendMessage( sender.sendMessage(
"§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r"); "§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
return true; return true;
} }

View file

@ -199,7 +199,7 @@ public class ChatProcessing {
if (!VanillaUtils.tellRaw(p, jsonstr)) if (!VanillaUtils.tellRaw(p, jsonstr))
ChatUtils.sendChatMessage(channel, sender, message, p); ChatUtils.sendChatMessage(channel, sender, message, p);
} catch (Exception ex) { } catch (Exception ex) {
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex); TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex, PluginMain.Instance);
sender.sendMessage("§cAn error occured while sending the message."); sender.sendMessage("§cAn error occured while sending the message.");
return true; return true;
} }

View file

@ -23,7 +23,7 @@ import java.util.stream.Collectors;
}) })
public class FTopCommand extends ICommand2MC { public class FTopCommand extends ICommand2MC {
private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR); private final File playerdir = new File("TBMC/players/");
private ChatPlayer[] cached; private ChatPlayer[] cached;
private long lastcache = 0; private long lastcache = 0;

View file

@ -116,8 +116,8 @@ public class FunComponent extends Component<PluginMain> implements Listener {
Runnable tt = () -> { Runnable tt = () -> {
if (ActiveF) { if (ActiveF) {
ActiveF = false; ActiveF = false;
if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1) if (FPlayer != null && FPlayer.FCount.get() < Integer.MAX_VALUE - 1)
FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size()); FPlayer.FCount.set(FPlayer.FCount.get() + Fs.size());
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL,
"§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people") "§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
+ " paid their respects.§r", fTarget); + " paid their respects.§r", fTarget);
@ -131,7 +131,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
ActiveF = true; ActiveF = true;
Fs.clear(); Fs.clear();
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class); FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class);
FPlayer.FDeaths().set(FPlayer.FDeaths().get() + 1); FPlayer.FDeaths.set(FPlayer.FDeaths.get() + 1);
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL,
"§bPress F to pay respects.§r", fTarget); "§bPress F to pay respects.§r", fTarget);
Ftask = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20); Ftask = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20);
@ -170,7 +170,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
} }
val user = ChromaGamerBase.getFromSender(event.getSender()); val user = ChromaGamerBase.getFromSender(event.getSender());
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false)); target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
val chan = user.channel().get(); val chan = user.channel.get();
TBMCChatAPI.SendSystemMessage(chan, chan.getRTR(event.getSender()), ChromaUtils.getDisplayName(event.getSender()) + " un" + s TBMCChatAPI.SendSystemMessage(chan, chan.getRTR(event.getSender()), ChromaUtils.getDisplayName(event.getSender()) + " un" + s
+ "'d " + target.getDisplayName(), unlolTarget); + "'d " + target.getDisplayName(), unlolTarget);
} }

View file

@ -11,7 +11,6 @@ import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -70,9 +69,10 @@ public class NColorCommand extends UCommandBase {
player.sendMessage("§cAll colors need to be represented in your name. (Use as Test|name|123 instead of |Testname123|)"); player.sendMessage("§cAll colors need to be represented in your name. (Use as Test|name|123 instead of |Testname123|)");
return true; return true;
} }
cp.NameColorLocations().set(new ArrayList<>(list)); // No byte[], no TIntArrayList var clist = cp.NameColorLocations.get(); // No byte[], no TIntArrayList
clist.clear();
clist.addAll(list);
TownColorComponent.updatePlayerColors(player, cp); TownColorComponent.updatePlayerColors(player, cp);
cp.save();
player.sendMessage("§bName colors set: " + player.getDisplayName()); player.sendMessage("§bName colors set: " + player.getDisplayName());
return true; return true;
} }

View file

@ -10,7 +10,7 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ComponentMetadata; import buttondevteam.lib.architecture.ComponentMetadata;
import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.player.TBMCPlayerJoinEvent; import buttondevteam.lib.player.TBMCPlayer;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
@ -22,7 +22,9 @@ import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.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.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.dynmap.towny.DTBridge; import org.dynmap.towny.DTBridge;
@ -130,7 +132,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
nc = Color.White; nc = Color.White;
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc); setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc);
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Error while setting town color for town " + entry.getKey() + "!", e); TBMCCoreAPI.SendException("Error while setting town color for town " + entry.getKey() + "!", e, this);
} }
} }
}); });
@ -149,7 +151,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
DTBridge.setTownColor(dtp, town, c2i.apply(nationcolor == null ? colors[0] : nationcolor), DTBridge.setTownColor(dtp, town, c2i.apply(nationcolor == null ? colors[0] : nationcolor),
c2i.apply(colors.length > 1 && nationcolor != null ? colors[1] : colors[0])); c2i.apply(colors.length > 1 && nationcolor != null ? colors[1] : colors[0]));
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e); TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e, component);
} }
} }
@ -186,7 +188,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
else else
len = name.length() / clrs.length;*/ len = name.length() / clrs.length;*/
boolean usenc = component.useNationColors().get(); boolean usenc = component.useNationColors().get();
val nclar = cp.NameColorLocations().get(); val nclar = cp.NameColorLocations.get();
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray(); int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + (usenc ? 1 : 0))) //+1: Nation color if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + (usenc ? 1 : 0))) //+1: Nation color
ncl = null; // Reset if name length changed ncl = null; // Reset if name length changed
@ -224,8 +226,8 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
cp.FlairUpdate(); //Update in list cp.FlairUpdate(); //Update in list
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(TBMCPlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
updatePlayerColors(event.getPlayer(), event.GetPlayer().asPluginPlayer(ChatPlayer.class)); updatePlayerColors(event.getPlayer(), TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class));
} }
} }

View file

@ -7,31 +7,26 @@ import buttondevteam.chat.commands.ucmds.HistoryCommand;
import buttondevteam.chat.components.flair.FlairComponent; import buttondevteam.chat.components.flair.FlairComponent;
import buttondevteam.chat.components.flair.FlairStates; import buttondevteam.chat.components.flair.FlairStates;
import buttondevteam.core.ComponentManager; import buttondevteam.core.ComponentManager;
import buttondevteam.lib.player.TBMCPlayerJoinEvent; import buttondevteam.lib.player.TBMCPlayerBase;
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.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.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Timer; import java.util.Timer;
public class PlayerJoinLeaveListener implements Listener { public class PlayerJoinLeaveListener implements Listener {
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLoad(TBMCPlayerLoadEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
cp.FlairUpdate();
}
@EventHandler
public void onPlayerTBMCJoin(TBMCPlayerJoinEvent e) {
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
Player p = e.getPlayer(); Player p = e.getPlayer();
ChatPlayer cp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
cp.FlairUpdate();
if (ComponentManager.isEnabled(FlairComponent.class)) { if (ComponentManager.isEnabled(FlairComponent.class)) {
if (!cp.FlairState().get().equals(FlairStates.NoComment)) { if (!cp.FlairState.get().equals(FlairStates.NoComment)) {
FlairComponent.ConfirmUserMessage(cp); FlairComponent.ConfirmUserMessage(cp);
Timer timer = new Timer(); Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@ -61,10 +56,6 @@ public class PlayerJoinLeaveListener implements Listener {
HistoryCommand.showHistory(e.getPlayer(), null); HistoryCommand.showHistory(e.getPlayer(), null);
} }
@EventHandler
public void onPlayerSave(TBMCPlayerSaveEvent e) {
}
@EventHandler @EventHandler
public void onPlayerLeave(PlayerQuitEvent event) { public void onPlayerLeave(PlayerQuitEvent event) {
PlayerListener.nicknames.inverse().remove(event.getPlayer().getUniqueId()); PlayerListener.nicknames.inverse().remove(event.getPlayer().getUniqueId());

View file

@ -53,21 +53,18 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onGetInfo(TBMCPlayerGetInfoEvent e) { public void onGetInfo(TBMCPlayerGetInfoEvent e) {
try (ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class)) { ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class);
if (cp == null) if (cp == null)
return; return;
e.addInfo("Minecraft name: " + cp.PlayerName().get()); e.addInfo("Minecraft name: " + cp.PlayerName().get());
if (cp.UserName().get() != null && cp.UserName().get().length() > 0) if (cp.UserName.get() != null && cp.UserName.get().length() > 0)
e.addInfo("Reddit name: " + cp.UserName().get()); e.addInfo("Reddit name: " + cp.UserName.get());
if (ComponentManager.isEnabled(FlairComponent.class)) { if (ComponentManager.isEnabled(FlairComponent.class)) {
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand); final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0) if (flair.length() > 0)
e.addInfo("/r/TheButton flair: " + flair); e.addInfo("/r/TheButton flair: " + flair);
}
e.addInfo(String.format("Respect: %.2f", cp.getF()));
} catch (Exception ex) {
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
} }
e.addInfo(String.format("Respect: %.2f", cp.getF()));
} }
private long lastError = 0; private long lastError = 0;
@ -88,7 +85,7 @@ public class PlayerListener implements Listener {
p.sendMessage("[" + e.getChannel().DisplayName().get() + "] §cSome features in the message below might be unavailable due to an error."); p.sendMessage("[" + e.getChannel().DisplayName().get() + "] §cSome features in the message below might be unavailable due to an error.");
} }
ChatUtils.sendChatMessage(e); ChatUtils.sendChatMessage(e);
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex); TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex, PluginMain.Instance);
} }
} }