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>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>

View file

@ -1,50 +1,32 @@
package buttondevteam.chat;
import buttondevteam.chat.components.flair.FlairStates;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.ListConfigData;
import buttondevteam.lib.chat.Color;
import buttondevteam.lib.player.EnumPlayerData;
import buttondevteam.lib.player.PlayerClass;
import buttondevteam.lib.player.PlayerData;
import buttondevteam.lib.player.TBMCPlayerBase;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@PlayerClass(pluginname = "Button1Chat")
public class ChatPlayer extends TBMCPlayerBase {
public PlayerData<String> UserName() {
return data(null);
}
public final ConfigData<String> UserName = getConfig().getData("UserName", "");
public List<String> UserNames() {
return data(new ArrayList<String>()).get();
}
public final ListConfigData<String> UserNames = getConfig().getListData("UserNames");
public PlayerData<Integer> FlairTime() {
return data(FlairTimeNone);
}
public final ConfigData<Integer> FlairTime = getConfig().getData("FlairTime", FlairTimeNone);
public EnumPlayerData<FlairStates> FlairState() {
return dataEnum(FlairStates.class, FlairStates.NoComment);
}
public final ConfigData<FlairStates> FlairState = getConfig().getData("FlairState", FlairStates.NoComment,
fs -> FlairStates.valueOf((String) fs), FlairStates::toString);
public PlayerData<Integer> FCount() {
return data(0);
}
public final ConfigData<Integer> FCount = getConfig().getData("FCount", 0);
public PlayerData<Integer> FDeaths() {
return data(0);
}
public final ConfigData<Integer> FDeaths = getConfig().getData("FDeaths", 0);
public PlayerData<Boolean> FlairCheater() {
return data(false);
}
public final ConfigData<Boolean> FlairCheater = getConfig().getData("FlairCheater", false);
public PlayerData<ArrayList<Integer>> NameColorLocations() { // No byte[], no TIntArrayList
return data(null);
}
public final ListConfigData<Integer> NameColorLocations = getConfig().getListData("NameColorLocations"); // No byte[], no TIntArrayList
public boolean Working;
// public int Tables = 10;
@ -64,7 +46,7 @@ public class ChatPlayer extends TBMCPlayerBase {
* @return The flair
*/
public String GetFormattedFlair(boolean noformats) {
int time = FlairTime().get();
int time = FlairTime.get();
if (time == FlairTimeCantPress)
return noformats ? "(can't press)" : "§r(--s)§r";
if (time == FlairTimeNonPresser)
@ -84,13 +66,13 @@ public class ChatPlayer extends TBMCPlayerBase {
}
public void SetFlair(int time) {
FlairTime().set(time);
FlairTime.set(time);
FlairUpdate();
}
public void SetFlair(int time, boolean cheater) {
FlairTime().set(time);
FlairCheater().set(cheater);
FlairTime.set(time);
FlairCheater.set(cheater);
FlairUpdate();
}
@ -104,9 +86,9 @@ public class ChatPlayer extends TBMCPlayerBase {
}
public short GetFlairColor() {
if (FlairCheater().get())
if (FlairCheater.get())
return 0x5;
final int flairTime = FlairTime().get();
final int flairTime = FlairTime.get();
if (flairTime == FlairTimeNonPresser)
return 0x7;
else if (flairTime == FlairTimeCantPress)
@ -127,6 +109,6 @@ public class ChatPlayer extends TBMCPlayerBase {
}
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.TBMCChatAPI;
import com.earth2me.essentials.Essentials;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
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
if (!setupEconomy() || !setupPermissions())
TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up economy or permissions!"));
if (!setupPermissions())
TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up permissions!"), this);
if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
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 Economy economy = null;
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()
@ -99,14 +97,4 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
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;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
@ -19,16 +18,12 @@ public class InfoCommand extends UCommandBase {
@Command2.Subcommand
public boolean def(CommandSender sender, OfflinePlayer player) {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
try (TBMCPlayer p = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class)) {
if (p == null) {
sender.sendMessage("§cThe specified player cannot be found");
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!");
TBMCPlayer p = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class);
if (p == null) {
sender.sendMessage("§cThe specified player cannot be found");
return;
}
sender.sendMessage(p.getInfo(InfoTarget.MCCommand));
});
return true;
}

View file

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

View file

@ -24,21 +24,21 @@ public class AcceptCommand extends UCommandBase {
@Command2.Subcommand
public boolean def(Player player, @Command2.OptionalArg String username) {
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>");
StringBuilder sb = new StringBuilder();
sb.append("§6Usernames:");
for (String name : p.UserNames())
for (String name : p.UserNames.get())
sb.append(" ").append(name);
player.sendMessage(sb.toString());
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(component.flairThreadURL().get());
return true;
}
if (username != null && !p.UserNames().contains(username)) {
if (username != null && !p.UserNames.get().contains(username)) {
player.sendMessage("§cError: Unknown name: " + username + "§r");
return true;
}
@ -47,14 +47,14 @@ public class AcceptCommand extends UCommandBase {
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");
return true;
}
if (username != null)
p.UserName().set(username);
p.UserName.set(username);
else
p.UserName().set(p.UserNames().get(0));
p.UserName.set(p.UserNames.get().get(0));
player.sendMessage("§bObtaining flair...");
p.Working = true;
@ -65,22 +65,19 @@ public class AcceptCommand extends UCommandBase {
try {
component.DownloadFlair(mp);
} catch (Exception e) {
TBMCCoreAPI.SendException(
"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.");
TBMCCoreAPI.SendException("An error occured while downloading flair for " + player.getCustomName() + "!", e, component);
player.sendMessage("Sorry, but an error occured while trying to get your flair. Please contact a mod.");
mp.Working = false;
return;
}
if (mp.FlairState().get().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.FlairState.get().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().set(FlairStates.Accepted);
mp.FlairState.set(FlairStates.Accepted);
FlairComponent.ConfirmUserMessage(mp);
player.sendMessage("§bYour flair has been set:§r " + flair);
mp.Working = false;

View file

@ -78,20 +78,19 @@ public class FlairComponent extends Component<PluginMain> {
ign = ign.trim();
if (PlayersWithFlairs.contains(ign))
continue;
try (ChatPlayer mp = TBMCPlayerBase.getFromName(ign, ChatPlayer.class)) { // 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().get().equals(FlairStates.NoComment)) {
mp.FlairState().set(FlairStates.Commented);
ConfirmUserMessage(mp);
}
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
ChatPlayer mp = TBMCPlayerBase.getFromName(ign, ChatPlayer.class); // Loads player file
if (mp == null)
continue;
/*
* if (!JoinedBefore(mp, 2015, 6, 5)) continue;
*/
if (!mp.UserNames.get().contains(author))
mp.UserNames.get().add(author);
if (mp.FlairState.get().equals(FlairStates.NoComment)) {
mp.FlairState.set(FlairStates.Commented);
ConfirmUserMessage(mp);
}
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
}
} catch (Exception e) {
errorcount++;
@ -99,7 +98,7 @@ public class FlairComponent extends Component<PluginMain> {
errorcount = 0;
if (!e.getMessage().contains("Server returned HTTP response code")
&& !(e instanceof UnknownHostException))
TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e);
TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e, this);
}
}
try {
@ -108,11 +107,12 @@ public class FlairComponent extends Component<PluginMain> {
Thread.currentThread().interrupt();
}
}
}
void DownloadFlair(ChatPlayer mp) throws IOException {
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(":");
String flair;
if (flairdata.length > 1)
@ -124,12 +124,12 @@ public class FlairComponent extends Component<PluginMain> {
flairclass = flairdata[2];
else
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) {
p.UserName().set(username);
p.FlairState().set(FlairStates.Recognised);
private void SetFlair(ChatPlayer p, String text, String flairclass, String username) {
p.UserName.set(username);
p.FlairState.set(FlairStates.Recognised);
switch (flairclass) {
case "cheater":
p.SetFlair(Short.parseShort(text), true);
@ -145,9 +145,9 @@ public class FlairComponent extends Component<PluginMain> {
p.SetFlair(ChatPlayer.FlairTimeCantPress);
}
} catch (Exception e) {
p.FlairState().set(FlairStates.Commented); // Flair unknown
p.FlairState.set(FlairStates.Commented); // Flair unknown
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;
default:
@ -181,8 +181,8 @@ public class FlairComponent extends Component<PluginMain> {
public static void ConfirmUserMessage(ChatPlayer mp) {
Player p = Bukkit.getPlayer(mp.getUUID());
if (mp.FlairState().get().equals(FlairStates.Commented) && p != null)
if (mp.UserNames().size() > 1)
if (mp.FlairState.get().equals(FlairStates.Commented) && p != null)
if (mp.UserNames.get().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

View file

@ -15,18 +15,18 @@ public final class IgnoreCommand extends UCommandBase {
@Command2.Subcommand
public boolean def(Player player) {
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.");
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.");
return true;
}
if (!p.FlairState().get().equals(FlairStates.Ignored)) {
p.FlairState().set(FlairStates.Ignored);
if (!p.FlairState.get().equals(FlairStates.Ignored)) {
p.FlairState.set(FlairStates.Ignored);
p.SetFlair(ChatPlayer.FlairTimeNone);
p.UserName().set("");
p.UserName.set("");
player.sendMessage("§bYou have ignored the message.§r");
} else
player.sendMessage("§cYou already ignored the message.§r");

View file

@ -35,22 +35,22 @@ public class SetFlairCommand extends AdminCommandBase {
ft = Short.parseShort(flairtime);
} catch (Exception e) {
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;
}
}
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
mp.SetFlair(ft, cheater);
mp.FlairState().set(FlairStates.Accepted);
mp.FlairState.set(FlairStates.Accepted);
if (username == null)
mp.UserName().set("");
mp.UserName.set("");
else {
mp.UserName().set(username);
if (!mp.UserNames().contains(username))
mp.UserNames().add(username);
mp.UserName.set(username);
if (!mp.UserNames.get().contains(username))
mp.UserNames.get().add(username);
}
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;
}

View file

@ -199,7 +199,7 @@ public class ChatProcessing {
if (!VanillaUtils.tellRaw(p, jsonstr))
ChatUtils.sendChatMessage(channel, sender, message, p);
} 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.");
return true;
}

View file

@ -23,7 +23,7 @@ import java.util.stream.Collectors;
})
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 long lastcache = 0;

View file

@ -116,8 +116,8 @@ public class FunComponent extends Component<PluginMain> implements Listener {
Runnable tt = () -> {
if (ActiveF) {
ActiveF = false;
if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1)
FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size());
if (FPlayer != null && FPlayer.FCount.get() < Integer.MAX_VALUE - 1)
FPlayer.FCount.set(FPlayer.FCount.get() + Fs.size());
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL,
"§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
+ " paid their respects.§r", fTarget);
@ -131,7 +131,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
ActiveF = true;
Fs.clear();
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,
"§bPress F to pay respects.§r", fTarget);
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());
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
+ "'d " + target.getDisplayName(), unlolTarget);
}

View file

@ -11,7 +11,6 @@ import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
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|)");
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);
cp.save();
player.sendMessage("§bName colors set: " + player.getDisplayName());
return true;
}

View file

@ -10,7 +10,7 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ComponentMetadata;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.chat.Color;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import buttondevteam.lib.player.TBMCPlayer;
import com.earth2me.essentials.User;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
@ -22,7 +22,9 @@ import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import org.dynmap.towny.DTBridge;
@ -130,7 +132,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
nc = Color.White;
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc);
} 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),
c2i.apply(colors.length > 1 && nationcolor != null ? colors[1] : colors[0]));
} 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
len = name.length() / clrs.length;*/
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();
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
@ -224,8 +226,8 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
cp.FlairUpdate(); //Update in list
}
@EventHandler
public void onPlayerJoin(TBMCPlayerJoinEvent event) {
updatePlayerColors(event.getPlayer(), event.GetPlayer().asPluginPlayer(ChatPlayer.class));
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
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.FlairStates;
import buttondevteam.core.ComponentManager;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
import buttondevteam.lib.player.TBMCPlayerBase;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Timer;
public class PlayerJoinLeaveListener implements Listener {
@EventHandler
public void onPlayerLoad(TBMCPlayerLoadEvent e) {
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
cp.FlairUpdate();
}
@EventHandler
public void onPlayerTBMCJoin(TBMCPlayerJoinEvent e) {
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
ChatPlayer cp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
cp.FlairUpdate();
if (ComponentManager.isEnabled(FlairComponent.class)) {
if (!cp.FlairState().get().equals(FlairStates.NoComment)) {
if (!cp.FlairState.get().equals(FlairStates.NoComment)) {
FlairComponent.ConfirmUserMessage(cp);
Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@ -61,10 +56,6 @@ public class PlayerJoinLeaveListener implements Listener {
HistoryCommand.showHistory(e.getPlayer(), null);
}
@EventHandler
public void onPlayerSave(TBMCPlayerSaveEvent e) {
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
PlayerListener.nicknames.inverse().remove(event.getPlayer().getUniqueId());

View file

@ -53,21 +53,18 @@ public class PlayerListener implements Listener {
@EventHandler
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
try (ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class)) {
if (cp == null)
return;
e.addInfo("Minecraft name: " + cp.PlayerName().get());
if (cp.UserName().get() != null && cp.UserName().get().length() > 0)
e.addInfo("Reddit name: " + cp.UserName().get());
if (ComponentManager.isEnabled(FlairComponent.class)) {
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0)
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);
ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class);
if (cp == null)
return;
e.addInfo("Minecraft name: " + cp.PlayerName().get());
if (cp.UserName.get() != null && cp.UserName.get().length() > 0)
e.addInfo("Reddit name: " + cp.UserName.get());
if (ComponentManager.isEnabled(FlairComponent.class)) {
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0)
e.addInfo("/r/TheButton flair: " + flair);
}
e.addInfo(String.format("Respect: %.2f", cp.getF()));
}
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.");
}
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);
}
}