Added /waitwhat, applied userdata changes, added format test, progressed with formatting #62

Merged
NorbiPeti merged 8 commits from dev into master 2017-04-15 11:58:13 +00:00
15 changed files with 158 additions and 182 deletions
Showing only changes of commit fa95891a6a - Show all commits

View file

@ -7,69 +7,42 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import buttondevteam.lib.chat.*;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.EnumPlayerData;
import buttondevteam.lib.player.PlayerClass;
import buttondevteam.lib.player.PlayerData;
import buttondevteam.lib.player.TBMCPlayerBase;
public class ChatPlayer extends TBMCPlayer {
public String getUserName() {
return getData();
@PlayerClass(pluginname = "ButtonChat")
public class ChatPlayer extends TBMCPlayerBase {
public PlayerData<String> UserName() {
return data();
}
public void setUserName(String name) {
setData(name);
public List<String> UserNames() {
PlayerData<List<String>> data = data();
if (data.get() == null)
data.set(new ArrayList<String>());
return data.get();
}
public List<String> getUserNames() {
List<String> data = getData();
if (data == null)
setUserNames(data = new ArrayList<String>());
return data;
public PlayerData<Integer> FlairTime() {
return data();
}
public void setUserNames(List<String> names) {
setData(names);
public EnumPlayerData<FlairStates> FlairState() {
return dataEnum(FlairStates.class);
}
public short getFlairTime() {
return getIntData(Short.class).orElse(FlairTimeNone);
public PlayerData<Integer> FCount() {
return data();
}
private void setFlairTime(short time) {
setIntData(time);
public PlayerData<Integer> FDeaths() {
return data();
}
public FlairStates getFlairState() {
FlairStates data = getEnumData(FlairStates.class);
if (data == null)
setFlairState(data = FlairStates.NoComment);
return data;
}
public void setFlairState(FlairStates state) {
setEnumData(state);
}
public int getFCount() {
return getIntData(Integer.class).orElse(0);
}
public void setFCount(int count) {
setIntData(count);
}
public int getFDeaths() {
return getIntData(Integer.class).orElse(0);
}
public void setFDeaths(int count) {
setIntData(count);
}
public boolean getFlairCheater() {
return getBoolData();
}
private void setFlairCheater(boolean cheater) {
setData(cheater);
public PlayerData<Boolean> FlairCheater() {
return data();
}
public boolean RPMode = true;
@ -83,9 +56,9 @@ public class ChatPlayer extends TBMCPlayer {
public boolean ChatOnly = false;
public int LoginWarningCount = 0;
public static final short FlairTimeNonPresser = -1;
public static final short FlairTimeCantPress = -2;
public static final short FlairTimeNone = -3;
public static final int FlairTimeNonPresser = -1;
public static final int FlairTimeCantPress = -2;
public static final int FlairTimeNone = -3;
/**
* Gets the player's flair, optionally formatting for Minecraft.
@ -95,14 +68,15 @@ public class ChatPlayer extends TBMCPlayer {
* @return The flair
*/
public String GetFormattedFlair(boolean noformats) {
if (getFlairTime() == FlairTimeCantPress)
int time = FlairTime().getOrDefault(FlairTimeNone);
if (time == FlairTimeCantPress)
return String.format(noformats ? "(can't press)" : "§r(--s)§r");
if (getFlairTime() == FlairTimeNonPresser)
if (time == FlairTimeNonPresser)
return String.format(noformats ? "(non-presser)" : "§7(--s)§r");
if (getFlairTime() == FlairTimeNone)
if (time == FlairTimeNone)
return "";
return noformats ? String.format("(%ss)", getFlairTime())
: String.format("§%x(%ss)§r", GetFlairColor(), getFlairTime());
return noformats ? String.format("(%ss)", FlairTime().get())
: String.format("§%x(%ss)§r", GetFlairColor(), FlairTime().get());
}
/**
@ -114,14 +88,14 @@ public class ChatPlayer extends TBMCPlayer {
return GetFormattedFlair(false);
}
public void SetFlair(short time) {
setFlairTime(time);
public void SetFlair(int time) {
FlairTime().set(time);
FlairUpdate();
}
public void SetFlair(short time, boolean cheater) {
setFlairTime(time);
setFlairCheater(cheater);
public void SetFlair(int time, boolean cheater) {
FlairTime().set(time);
FlairCheater().set(cheater);
FlairUpdate();
}
@ -129,29 +103,29 @@ public class ChatPlayer extends TBMCPlayer {
// Flairs from Command Block The Button - Teams
// PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add()
Player p = Bukkit.getPlayer(getUuid());
Player p = Bukkit.getPlayer(uuid);
if (p != null)
p.setPlayerListName(String.format("%s%s", p.getName(), GetFormattedFlair()));
}
public short GetFlairColor() {
if (getFlairCheater())
if (FlairCheater().get())
return 0x5;
if (getFlairTime() == -1)
if (FlairTime().get() == -1)
return 0x7;
else if (getFlairTime() == -2)
else if (FlairTime().get() == -2)
return 0xf;
else if (getFlairTime() <= 60 && getFlairTime() >= 52)
else if (FlairTime().get() <= 60 && FlairTime().get() >= 52)
return 0x5;
else if (getFlairTime() <= 51 && getFlairTime() >= 42)
else if (FlairTime().get() <= 51 && FlairTime().get() >= 42)
return 0x9;
else if (getFlairTime() <= 41 && getFlairTime() >= 32)
else if (FlairTime().get() <= 41 && FlairTime().get() >= 32)
return 0xa;
else if (getFlairTime() <= 31 && getFlairTime() >= 22)
else if (FlairTime().get() <= 31 && FlairTime().get() >= 22)
return 0xe;
else if (getFlairTime() <= 21 && getFlairTime() >= 11)
else if (FlairTime().get() <= 21 && FlairTime().get() >= 11)
return 0x6;
else if (getFlairTime() <= 11 && getFlairTime() >= 0)
else if (FlairTime().get() <= 11 && FlairTime().get() >= 0)
return 0xc;
return 0xf;
}

View file

@ -25,6 +25,7 @@ import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TellrawSerializableEnum;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.chat.*;
@ -91,7 +92,7 @@ public class ChatProcessing {
ChatPlayer mp = null;
if (player != null)
mp = TBMCPlayer.getPlayer(player).asPluginPlayer(ChatPlayer.class);
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
String msg = message.toLowerCase();
if (msg.contains("lol")) {
@ -162,7 +163,7 @@ public class ChatProcessing {
.warning("Error: Can't find player " + match + " but was reported as online.");
return "§c" + match + "§r";
}
ChatPlayer mpp = TBMCPlayer.getPlayer(p).asPluginPlayer(ChatPlayer.class);
ChatPlayer mpp = TBMCPlayer.getPlayer(p.getUniqueId(), ChatPlayer.class);
if (PlayerListener.NotificationSound == null)
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
else
@ -230,21 +231,21 @@ public class ChatProcessing {
.addExtra(new TellrawPart(String.format("World: %s\n",
(player != null ? player.getWorld().getName()
: "-"))))
.addExtra(
new TellrawPart(String.format("Respect: %s%s%s",
(mp != null ? (mp.getFCount()
/ (double) mp.getFDeaths())
: "Infinite"),
(mp != null && mp.getUserName() != null
&& !mp.getUserName().isEmpty()
? "\nUserName: "
+ mp.getUserName()
: ""),
(mp != null && mp.getPlayerName()
.equals("\nAlpha_Bacca44")
? "\nDeaths: "
+ PlayerListener.AlphaDeaths
: ""))))
.addExtra(new TellrawPart(String.format(
"Respect: %s%s%s",
(mp != null ? (mp.FCount().getOrDefault(0)
/ (double) mp.FDeaths().getOrDefault(0))
: "Infinite"),
(mp != null && mp.UserName().get() != null
&& !mp.UserName().get().isEmpty()
? "\nUserName: "
+ mp.UserName().get()
: ""),
(mp != null && mp.PlayerName().get()
.equals("\nAlpha_Bacca44")
? "\nDeaths: "
+ PlayerListener.AlphaDeaths
: ""))))
.addExtra(new TellrawPart("\nFor more, do /u info "
+ sender.getName())))));
json.addExtra(new TellrawPart("> "));

View file

@ -18,7 +18,7 @@ import buttondevteam.chat.commands.YeehawCommand;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
import com.earth2me.essentials.Essentials;
import com.google.gson.JsonArray;
@ -139,16 +139,16 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
ign = ign.trim();
if (PlayersWithFlairs.contains(ign))
continue;
try (ChatPlayer mp = TBMCPlayer.getFromName(ign).asPluginPlayer(ChatPlayer.class)) { // Loads player file
try (ChatPlayer mp = TBMCPlayerBase.getFromName(ign, 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);
if (!mp.UserNames().contains(author))
mp.UserNames().add(author);
if (mp.FlairState().getOrDefault(FlairStates.NoComment).equals(FlairStates.NoComment)) {
mp.FlairState().set(FlairStates.Commented);
ConfirmUserMessage(mp);
}
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
@ -176,8 +176,8 @@ 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.getUserName()).replace("\"", "")
.split(":");
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get())
.replace("\"", "").split(":");
String flair;
if (flairdata.length > 1)
flair = flairdata[1];
@ -188,12 +188,12 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
flairclass = flairdata[2];
else
flairclass = "unknown";
SetFlair(mp, flair, flairclass, mp.getUserName());
SetFlair(mp, flair, flairclass, mp.UserName().get());
}
private void SetFlair(ChatPlayer p, String text, String flairclass, String username) {
p.setUserName(username);
p.setFlairState(FlairStates.Recognised);
p.UserName().set(username);
p.FlairState().set(FlairStates.Recognised);
switch (flairclass) {
case "cheater":
p.SetFlair(Short.parseShort(text), true);
@ -209,9 +209,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
p.SetFlair(ChatPlayer.FlairTimeCantPress);
}
} catch (Exception e) {
p.setFlairState(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.getPlayerName() + "!", e);
TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName() + "!", e);
}
return;
default:
@ -225,7 +225,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.getUserName());
URL url = new URL("https://www.reddit.com/u/" + mp.UserName());
URLConnection con = url.openConnection();
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
InputStream in = con.getInputStream();
@ -243,9 +243,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
}
public static void ConfirmUserMessage(ChatPlayer mp) {
Player p = Bukkit.getPlayer(mp.getUuid());
if (mp.getFlairState().equals(FlairStates.Commented) && p != null)
if (mp.getUserNames().size() > 1)
Player p = Bukkit.getPlayer(mp.getUUID());
if (mp.FlairState().get().equals(FlairStates.Commented) && p != null)
if (mp.UserNames().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

@ -22,7 +22,7 @@ public final class ChatonlyCommand extends TBMCCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
p.ChatOnly = true;
player.setGameMode(GameMode.SPECTATOR);
player.sendMessage("§bChat-only mode enabled. You are now invincible.");

View file

@ -22,7 +22,7 @@ public final class OOCCommand extends TBMCCommandBase {
if (args.length == 0) {
return false;
} else {
final ChatPlayer cp = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
final ChatPlayer cp = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
cp.RPMode = false;
String message = "";
for (String arg : args)

View file

@ -17,7 +17,7 @@ public class WaitWhatCommand extends TBMCCommandBase {
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Channel channel;
if (sender instanceof Player && ((Player) sender).isOnline())
channel = TBMCPlayer.getPlayer((Player) sender).asPluginPlayer(ChatPlayer.class).CurrentChannel;
channel = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel;
else
channel = Channel.GlobalChat;
final String message;

View file

@ -23,7 +23,8 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase {
msg = args[i] + " " + msg;
if (sender instanceof Player)
TBMCChatAPI.SendChatMessage(
TBMCPlayer.getPlayer((Player) sender).asPluginPlayer(ChatPlayer.class).CurrentChannel, sender, msg);
TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel, sender,
msg);
else if (sender.isOp())
TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, sender, msg);
else

View file

@ -25,21 +25,21 @@ public class AcceptCommand extends UCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
final Player player = (Player) sender;
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
if (args.length < 1 && p.getUserNames().size() > 1) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
if (args.length < 1 && p.UserNames().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.getUserNames())
for (String username : p.UserNames())
sb.append(" ").append(username);
player.sendMessage(sb.toString());
return true;
}
if (p.getFlairState().equals(FlairStates.NoComment) || p.getUserNames().size() == 0) {
if (p.FlairState().get().equals(FlairStates.NoComment) || p.UserNames().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.getUserNames().contains(args[0])) {
if (args.length > 0 && !p.UserNames().contains(args[0])) {
player.sendMessage("§cError: Unknown name: " + args[0] + "§r");
return true;
}
@ -48,14 +48,14 @@ public class AcceptCommand extends UCommandBase {
return true;
}
if ((args.length > 0 ? args[0] : p.getUserNames().get(0)).equals(p.getUserName())) {
if ((args.length > 0 ? args[0] : p.UserNames().get(0)).equals(p.UserName().get())) {
player.sendMessage("§cYou already have this user's flair.§r");
return true;
}
if (args.length > 0)
p.setUserName(args[0]);
p.UserName().set(args[0]);
else
p.setUserName(p.getUserNames().get(0));
p.UserName().set(p.UserNames().get(0));
player.sendMessage("§bObtaining flair...");
p.Working = true;
@ -74,14 +74,14 @@ public class AcceptCommand extends UCommandBase {
return;
}
if (mp.getFlairState().equals(FlairStates.Commented)) {
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.setFlairState(FlairStates.Accepted);
mp.FlairState().set(FlairStates.Accepted);
PluginMain.ConfirmUserMessage(mp);
player.sendMessage("§bYour flair has been set:§r " + flair);
mp.Working = false;

View file

@ -19,7 +19,7 @@ public class CCommand extends UCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
ChatPlayer p = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
if (args.length < 1) {
if (PluginMain.permission.has(player, "tbmc.rainbow")) {
p.RainbowPresserColorMode = !p.RainbowPresserColorMode;

View file

@ -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 = TBMCPlayer.getPlayerAs(player, ChatPlayer.class);
if (p.getFlairState().equals(FlairStates.Accepted)) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
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.getFlairState().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.getFlairState().equals(FlairStates.Ignored)) {
p.setFlairState(FlairStates.Ignored);
if (!p.FlairState().get().equals(FlairStates.Ignored)) {
p.FlairState().set(FlairStates.Ignored);
p.SetFlair(ChatPlayer.FlairTimeNone);
p.setUserName("");
p.UserName().set("");
player.sendMessage("§bYou have ignored the message.§r");
} else
player.sendMessage("§cYou already ignored the message.§r");

View file

@ -2,8 +2,10 @@ package buttondevteam.chat.commands.ucmds;
import org.bukkit.command.CommandSender;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayer.InfoTarget;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import buttondevteam.lib.player.TBMCPlayerBase;
public class InfoCommand extends UCommandBase {
@ -12,7 +14,7 @@ public class InfoCommand extends UCommandBase {
return new String[] { //
"§6---- User information ----", //
"Get some information known about the user.", //
"Usage: /"+alias+" info <playername>" //
"Usage: /" + alias + " info <playername>" //
};
}
@ -27,15 +29,18 @@ public class InfoCommand extends UCommandBase {
return false;
if (args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("server")
|| args[0].equalsIgnoreCase("@console")) {
sender.sendMessage("The server console."); // TODO: Console login? The Discord thing might replace it
sender.sendMessage("The server console.");
return true;
}
try (TBMCPlayer p = TBMCPlayer.getFromName(args[0])) {
try (TBMCPlayer p = TBMCPlayerBase.getFromName(args[0], TBMCPlayer.class)) {
if (p == null) {
sender.sendMessage("§cThe specified player cannot be found");
return true;
}
sender.sendMessage(p.getInfo(InfoTarget.MCCommand));
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while getting player information!", e);
sender.sendMessage("§cError while getting player information!");
}
return true;
}

View file

@ -3,7 +3,7 @@ package buttondevteam.chat.commands.ucmds.admin;
import org.bukkit.command.CommandSender;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
public class PlayerInfoCommand extends AdminCommandBase {
@ -19,23 +19,23 @@ public class PlayerInfoCommand extends AdminCommandBase {
if (args.length == 0) {
return false;
}
ChatPlayer p = TBMCPlayer.getFromName(args[0]).asPluginPlayer(ChatPlayer.class);
ChatPlayer p = TBMCPlayerBase.getFromName(args[0], 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.getUserNames())
for (String username : p.UserNames())
sb.append(" ").append(username);
sender.sendMessage(new String[] { //
"Player name: " + p.getPlayerName(), //
"Player name: " + p.PlayerName(), //
"User flair: " + p.GetFormattedFlair(), //
"Username: " + p.getUserName(), //
"Flair state: " + p.getFlairState(), //
"Username: " + p.UserName(), //
"Flair state: " + p.FlairState(), //
sb.toString(), //
"FCount: " + p.getFCount(), //
"FDeaths: " + p.getFDeaths() //
"FCount: " + p.FCount(), //
"FDeaths: " + p.FDeaths() //
});
return true;
}

View file

@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.FlairStates;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
public class SetFlairCommand extends AdminCommandBase {
@ -53,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 = TBMCPlayer.getPlayerAs(p, ChatPlayer.class);
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
mp.SetFlair(flairtime, cheater);
mp.setFlairState(FlairStates.Accepted);
mp.FlairState().set(FlairStates.Accepted);
if (args.length < 4)
mp.setUserName("");
mp.UserName().set("");
else {
mp.setUserName(args[3]);
if (!mp.getUserNames().contains(args[3]))
mp.getUserNames().add(args[3]);
mp.UserName().set(args[3]);
if (!mp.UserNames().contains(args[3]))
mp.UserNames().add(args[3]);
}
sender.sendMessage(
"§bThe flair has been set. Player: " + mp.getPlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
"§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
return true;
}

View file

@ -1,6 +1,5 @@
package buttondevteam.chat.listener;
import java.util.ArrayList;
import java.util.Timer;
import java.util.UUID;
@ -17,7 +16,6 @@ import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.FlairStates;
import buttondevteam.chat.PlayerJoinTimerTask;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.player.TBMCPlayerAddEvent;
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
@ -35,9 +33,9 @@ public class PlayerJoinLeaveListener implements Listener {
if (PluginMain.essentials == null)
PluginMain.essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"));
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
Player p = Bukkit.getPlayer(cp.getUuid());
Player p = Bukkit.getPlayer(cp.getUUID());
if (!cp.getFlairState().equals(FlairStates.NoComment)) {
if (!cp.FlairState().get().equals(FlairStates.NoComment)) {
PluginMain.ConfirmUserMessage(cp);
Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@ -49,26 +47,26 @@ public class PlayerJoinLeaveListener implements Listener {
tt.mp = cp;
timer.schedule(tt, 1000);
} else {
if (cp.getFlairTime() == 0x00)
if (cp.FlairTime().get() == 0x00)
cp.SetFlair(ChatPlayer.FlairTimeNone);
Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@Override
public void run() {
Player player = Bukkit.getPlayer(mp.getPlayerName());
Player player = Bukkit.getPlayer(mp.PlayerName().get());
if (player == null)
return;
if (mp.getFlairState().equals(FlairStates.NoComment)) {
if (mp.FlairState().get().equals(FlairStates.NoComment)) {
String json = String.format(
"[\"\",{\"text\":\"If you're from Reddit and you'd like your /r/TheButton flair displayed ingame, write your Minecraft name to \",\"color\":\"aqua\"},{\"text\":\"[this thread].\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]",
PluginMain.FlairThreadURL);
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
"tellraw " + mp.getPlayerName() + " " + json);
"tellraw " + mp.PlayerName() + " " + json);
json = "[\"\",{\"text\":\"If you aren't from Reddit or don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
"tellraw " + mp.getPlayerName() + " " + json);
"tellraw " + mp.PlayerName() + " " + json);
}
}
};
@ -101,14 +99,6 @@ public class PlayerJoinLeaveListener implements Listener {
public void onPlayerSave(TBMCPlayerSaveEvent e) {
}
@EventHandler
public void onPlayerAdd(TBMCPlayerAddEvent event) {
ChatPlayer cp = event.GetPlayer().asPluginPlayer(ChatPlayer.class);
cp.SetFlair(ChatPlayer.FlairTimeNone);
cp.setFlairState(FlairStates.NoComment);
cp.setUserNames(new ArrayList<>());
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
String deletenick = null;

View file

@ -35,7 +35,7 @@ import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
import buttondevteam.lib.player.TBMCPlayer.InfoTarget;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
@ -71,7 +71,7 @@ public class PlayerListener implements Listener {
if (event.isCancelled())
return;
TBMCChatAPI.SendChatMessage(
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class).CurrentChannel,
event.getPlayer(), event.getMessage());
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
}
@ -81,7 +81,7 @@ public class PlayerListener implements Listener {
if (event.getMessage().length() < 2)
return;
int index = event.getMessage().indexOf(" ");
ChatPlayer mp = TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class);
ChatPlayer mp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class);
String cmd = "";
if (index == -1) {
cmd = event.getMessage().substring(1);
@ -212,8 +212,8 @@ public class PlayerListener implements Listener {
Ftimer.cancel();
ActiveF = true;
Fs.clear();
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId()).asPluginPlayer(ChatPlayer.class);
FPlayer.setFDeaths(FPlayer.getFDeaths() + 1);
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class);
FPlayer.FDeaths().set(FPlayer.FDeaths().get() + 1);
Bukkit.broadcastMessage("§bPress F to pay respects.§r");
Ftimer = new Timer();
TimerTask tt = new TimerTask() {
@ -221,8 +221,8 @@ public class PlayerListener implements Listener {
public void run() {
if (ActiveF) {
ActiveF = false;
if (FPlayer != null && FPlayer.getFCount() < Integer.MAX_VALUE - 1)
FPlayer.setFCount(FPlayer.getFCount() + Fs.size());
if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1)
FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size());
Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
+ " paid their respects.§r");
Fs.clear();
@ -250,14 +250,14 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
ChatPlayer mp = TBMCPlayer.getPlayerAs(e.getPlayer(), ChatPlayer.class);
ChatPlayer mp = TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class);
if (mp.ChatOnly)
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerTeleport(PlayerTeleportEvent e) {
if (TBMCPlayer.getPlayerAs(e.getPlayer(), ChatPlayer.class).ChatOnly) {
if (TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class).ChatOnly) {
e.setCancelled(true);
e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode.");
}
@ -319,14 +319,19 @@ public class PlayerListener implements Listener {
@EventHandler
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
ChatPlayer cp = e.getPlayer().asPluginPlayer(ChatPlayer.class);
e.addInfo("Minecraft name: " + cp.getPlayerName());
if (cp.getUserName() != null && cp.getUserName().length() > 0)
e.addInfo("Reddit name: " + cp.getUserName());
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0)
e.addInfo("/r/TheButton flair: " + flair);
e.addInfo("Respect: " + (double) cp.getFCount() / (double) cp.getFDeaths());
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());
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0)
e.addInfo("/r/TheButton flair: " + flair);
e.addInfo("Respect: " + (double) cp.FCount().get() / (double) cp.FDeaths().get());
} catch (Exception ex) {
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
}
}
@EventHandler