Nation color, /tableflip fix, improvements and other fixes #92
15 changed files with 325 additions and 217 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -131,7 +131,7 @@ publish/
|
||||||
*.publishproj
|
*.publishproj
|
||||||
|
|
||||||
# NuGet Packages Directory
|
# NuGet Packages Directory
|
||||||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
|
## TO!DO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||||
#packages/
|
#packages/
|
||||||
|
|
||||||
# Windows Azure Build Output
|
# Windows Azure Build Output
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -92,6 +92,8 @@
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<testFailureIgnore>true</testFailureIgnore>
|
<testFailureIgnore>true</testFailureIgnore>
|
||||||
|
<useSystemClassLoader>false
|
||||||
|
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||||
|
@ -163,7 +165,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||||
<artifactId>Towny</artifactId>
|
<artifactId>Towny</artifactId>
|
||||||
<version>master-SNAPSHOT</version>
|
<version>8d3b6b6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.vexsoftware</groupId>
|
<groupId>com.vexsoftware</groupId>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
import buttondevteam.lib.chat.Channel;
|
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import buttondevteam.lib.player.EnumPlayerData;
|
import buttondevteam.lib.player.EnumPlayerData;
|
||||||
import buttondevteam.lib.player.PlayerClass;
|
import buttondevteam.lib.player.PlayerClass;
|
||||||
|
@ -50,7 +49,6 @@ public class ChatPlayer extends TBMCPlayerBase {
|
||||||
public Location SavedLocation;
|
public Location SavedLocation;
|
||||||
public boolean Working;
|
public boolean Working;
|
||||||
// public int Tables = 10;
|
// public int Tables = 10;
|
||||||
public Channel CurrentChannel = Channel.GlobalChat;
|
|
||||||
public boolean SendingLink = false;
|
public boolean SendingLink = false;
|
||||||
public boolean RainbowPresserColorMode = false;
|
public boolean RainbowPresserColorMode = false;
|
||||||
public Color OtherColorMode = null;
|
public Color OtherColorMode = null;
|
||||||
|
|
|
@ -14,7 +14,6 @@ import buttondevteam.lib.chat.*;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
@ -94,8 +93,6 @@ public class ChatProcessing {
|
||||||
CommandSender sender = e.getSender();
|
CommandSender sender = e.getSender();
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
long processstart = System.nanoTime();
|
long processstart = System.nanoTime();
|
||||||
if (PluginMain.essentials == null)
|
|
||||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
|
||||||
Player player = (sender instanceof Player ? (Player) sender : null);
|
Player player = (sender instanceof Player ? (Player) sender : null);
|
||||||
User user = PluginMain.essentials.getUser(player);
|
User user = PluginMain.essentials.getUser(player);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.htmlcleaner.TagNode;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
@ -54,16 +53,16 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
public static PluginMain Instance;
|
public static PluginMain Instance;
|
||||||
public static ConsoleCommandSender Console;
|
public static ConsoleCommandSender Console;
|
||||||
public final static String FlairThreadURL = "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/";
|
private final static String FlairThreadURL = "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/";
|
||||||
|
|
||||||
public static Scoreboard SB;
|
public static Scoreboard SB;
|
||||||
public static TownyUniverse TU;
|
public static TownyUniverse TU;
|
||||||
public static ArrayList<Town> Towns;
|
private static ArrayList<Town> Towns;
|
||||||
public static ArrayList<Nation> Nations;
|
private static ArrayList<Nation> Nations;
|
||||||
|
|
||||||
public static Channel TownChat;
|
public static Channel TownChat;
|
||||||
public static Channel NationChat;
|
public static Channel NationChat;
|
||||||
public static Channel RPChannel;
|
private static Channel RPChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -79,6 +78,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||||
|
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this);
|
||||||
|
@ -88,20 +88,17 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
|
|
||||||
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
|
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
|
||||||
TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse();
|
TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse();
|
||||||
Towns = new ArrayList<Town>(TU.getTownsMap().values()); // Creates a snapshot of towns, new towns will be added when needed
|
Towns = new ArrayList<>(TU.getTownsMap().values()); // Creates a snapshot of towns, new towns will be added when needed
|
||||||
Nations = new ArrayList<Nation>(TU.getNationsMap().values()); // Same here but with nations
|
Nations = new ArrayList<>(TU.getNationsMap().values()); // Same here but with nations
|
||||||
|
|
||||||
TownColors.keySet().removeIf(t -> !TU.getTownsMap().containsKey(t.toLowerCase())); // Removes town colors for deleted/renamed towns
|
TownColors.keySet().removeIf(t -> !TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns
|
||||||
|
NationColor.keySet().removeIf(n -> !TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations
|
||||||
|
|
||||||
TBMCChatAPI.RegisterChatChannel(
|
TBMCChatAPI.RegisterChatChannel(
|
||||||
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
|
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
|
||||||
TBMCChatAPI.RegisterChatChannel(
|
TBMCChatAPI.RegisterChatChannel(
|
||||||
NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true)));
|
NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true)));
|
||||||
TBMCChatAPI.RegisterChatChannel(RPChannel = new Channel("§7RP§f", Color.Gray, "rp", Channel.noScoreResult(s -> {
|
TBMCChatAPI.RegisterChatChannel(RPChannel = new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
|
||||||
if (s instanceof ConsoleCommandSender)
|
|
||||||
return true;
|
|
||||||
return true; // TODO: Allow hiding it
|
|
||||||
}, "You need to show the RP chat in order to speak in it.")));
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(this, () -> {
|
Bukkit.getScheduler().runTask(this, () -> {
|
||||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||||
|
@ -201,7 +198,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DownloadFlair(ChatPlayer mp) throws MalformedURLException, IOException {
|
public 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(":");
|
||||||
|
@ -247,11 +244,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
p.SetFlair(Short.parseShort(text));
|
p.SetFlair(Short.parseShort(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean CheckForJoinDate(ChatPlayer mp) throws Exception {
|
private static boolean CheckForJoinDate(ChatPlayer mp) throws Exception {
|
||||||
return JoinedBefore(mp, 2015, 4, 1);
|
return JoinedBefore(mp, 2015, 4, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean JoinedBefore(ChatPlayer mp, int year, int month, int day) throws Exception {
|
private 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.UserName());
|
||||||
URLConnection con = url.openConnection();
|
URLConnection con = url.openConnection();
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
@ -281,13 +278,17 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
|
|
||||||
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
|
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
|
||||||
public static int AnnounceTime = 15 * 60 * 1000;
|
public static int AnnounceTime = 15 * 60 * 1000;
|
||||||
/**
|
/**
|
||||||
* Names lowercased
|
* Names lowercased
|
||||||
*/
|
*/
|
||||||
public static Map<String, Color[]> TownColors = new HashMap<>();
|
public static Map<String, Color[]> TownColors = new HashMap<>();
|
||||||
|
/**
|
||||||
|
* Names lowercased - nation color gets added to town colors when needed
|
||||||
|
*/
|
||||||
|
public static Map<String, Color> NationColor = new HashMap<>();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void LoadFiles() {
|
private static void LoadFiles() {
|
||||||
PluginMain.Instance.getLogger().info("Loading files...");
|
PluginMain.Instance.getLogger().info("Loading files...");
|
||||||
try {
|
try {
|
||||||
File file = new File("TBMC/chatsettings.yml");
|
File file = new File("TBMC/chatsettings.yml");
|
||||||
|
@ -305,6 +306,10 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
|
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
|
||||||
.map(Color::valueOf).toArray(Color[]::new))));
|
.map(Color::valueOf).toArray(Color[]::new))));
|
||||||
TownColorCommand.ColorCount = (byte) yc.getInt("towncolorcount", 1);
|
TownColorCommand.ColorCount = (byte) yc.getInt("towncolorcount", 1);
|
||||||
|
val ncs = yc.getConfigurationSection("nationcolors");
|
||||||
|
if (ncs != null)
|
||||||
|
NationColor.putAll(ncs.getValues(true).entrySet().stream()
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue()))));
|
||||||
PluginMain.Instance.getLogger().info("Loaded files!");
|
PluginMain.Instance.getLogger().info("Loaded files!");
|
||||||
} else
|
} else
|
||||||
PluginMain.Instance.getLogger().info("No files to load, first run probably.");
|
PluginMain.Instance.getLogger().info("No files to load, first run probably.");
|
||||||
|
@ -323,9 +328,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
yc.set("announcetime", AnnounceTime);
|
yc.set("announcetime", AnnounceTime);
|
||||||
yc.set("announcements", AnnounceMessages);
|
yc.set("announcements", AnnounceMessages);
|
||||||
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
|
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
|
||||||
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(k -> k.getKey(),
|
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||||
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
|
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
|
||||||
yc.set("towncolorcount", TownColorCommand.ColorCount);
|
yc.set("towncolorcount", TownColorCommand.ColorCount);
|
||||||
|
yc.createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||||
|
v -> v.getValue().toString())));
|
||||||
yc.save(file);
|
yc.save(file);
|
||||||
PluginMain.Instance.getLogger().info("Saved files!");
|
PluginMain.Instance.getLogger().info("Saved files!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package buttondevteam.chat.commands;
|
package buttondevteam.chat.commands;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
|
|
||||||
import buttondevteam.lib.TBMCChatEventBase;
|
import buttondevteam.lib.TBMCChatEventBase;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@CommandClass(modOnly = false)
|
@CommandClass(modOnly = false)
|
||||||
public final class UnlolCommand extends TBMCCommandBase {
|
public final class UnlolCommand extends TBMCCommandBase {
|
||||||
|
@ -31,7 +31,7 @@ public final class UnlolCommand extends TBMCCommandBase {
|
||||||
@Override
|
@Override
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||||
LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender))
|
LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender))
|
||||||
.max((lld1, lld2) -> Long.compare(lld1.Loltime, lld2.Loltime)).orElse(null);
|
.max(Comparator.comparingLong(lld -> lld.Loltime)).orElse(null);
|
||||||
if (lol == null)
|
if (lol == null)
|
||||||
return true;
|
return true;
|
||||||
if (lol.Lolowner instanceof Player)
|
if (lol.Lolowner instanceof Player)
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package buttondevteam.chat.commands;
|
package buttondevteam.chat.commands;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
import buttondevteam.lib.player.TBMCYEEHAWEvent;
|
import buttondevteam.lib.player.TBMCYEEHAWEvent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandClass(modOnly = false)
|
@CommandClass(modOnly = false)
|
||||||
public class YeehawCommand extends TBMCCommandBase {
|
public class YeehawCommand extends TBMCCommandBase {
|
||||||
|
@ -22,9 +21,9 @@ public class YeehawCommand extends TBMCCommandBase {
|
||||||
+ (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs.";
|
+ (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs.";
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f);
|
p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f);
|
||||||
|
p.sendMessage(message); //Not broadcasting, so the Discord plugin can handle the event in a special way
|
||||||
} // Even a cmdblock could yeehaw in theory
|
} // Even a cmdblock could yeehaw in theory
|
||||||
// Or anyone from Discord
|
// Or anyone from Discord
|
||||||
Bukkit.broadcastMessage(message);
|
|
||||||
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
|
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package buttondevteam.chat.commands.appendtext;
|
package buttondevteam.chat.commands.appendtext;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.lib.chat.ChatMessage;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.*;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandClass(modOnly = false, excludeFromPath = true)
|
@CommandClass(modOnly = false, excludeFromPath = true)
|
||||||
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||||
|
@ -18,20 +16,12 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||||
String msg = GetAppendedText();
|
StringBuilder msg = new StringBuilder();
|
||||||
for (int i = args.length - 1; i >= 0; i--)
|
for (String arg : args) msg.append(arg).append(" ");
|
||||||
msg = args[i] + " " + msg;
|
msg.append(GetAppendedText());
|
||||||
ChatPlayer cp;
|
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender,
|
||||||
if (sender instanceof Player)
|
ChromaGamerBase.getFromSender(sender), msg.toString())
|
||||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(
|
.fromCommand(true).build());
|
||||||
(cp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class)).CurrentChannel, sender,
|
|
||||||
cp, msg).fromCommand(true).build());
|
|
||||||
else if (sender.isOp())
|
|
||||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(PlayerListener.ConsoleChannel, sender,
|
|
||||||
(cp = TBMCPlayer.getPlayer(new UUID(0, 0), ChatPlayer.class)), msg).build());
|
|
||||||
else
|
|
||||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(Channel.GlobalChat, sender,
|
|
||||||
(cp = TBMCPlayer.getPlayer(new UUID(0, 0), ChatPlayer.class)), msg).build()); //TODO
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandClass
|
||||||
|
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||||
|
public class NationColorCommand extends UCommandBase {
|
||||||
|
@Override
|
||||||
|
public String[] GetHelpText(String alias) {
|
||||||
|
return new String[]{ //
|
||||||
|
"§6---- Nation Color ----", //
|
||||||
|
"This command allows setting a color for a nation.", //
|
||||||
|
"Each town in the nation will have it's first color (border) set to this color.", //
|
||||||
|
"See the help text for /u towncolor for more details.", //
|
||||||
|
"Usage: /" + GetCommandPath() + " <colorname>", //
|
||||||
|
"Example: /" + GetCommandPath() + " blue" //
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||||
|
Resident res;
|
||||||
|
if (!(PluginMain.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
||||||
|
&& (res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase())).isKing())) {
|
||||||
|
player.sendMessage("§cYou need to be the king of a nation to set it's colors.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length > 1) {
|
||||||
|
player.sendMessage("You can only use one color.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String[] a = new String[args.length + 1];
|
||||||
|
System.arraycopy(args, 0, a, 1, args.length);
|
||||||
|
try {
|
||||||
|
a[0] = res.getTown().getNation().getName();
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
TBMCCoreAPI.SendException("Failed to set nation color for player " + player + "!", e);
|
||||||
|
player.sendMessage("§cCouldn't find your town/nation... Error reported.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return buttondevteam.chat.commands.ucmds.admin.NationColorCommand.SetNationColor(player, alias, a);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,22 +1,21 @@
|
||||||
package buttondevteam.chat.commands.ucmds;
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandClass // TODO: /u u when annotation not present
|
@CommandClass // TODO: /u u when annotation not present
|
||||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||||
public class TownColorCommand extends UCommandBase {
|
public class TownColorCommand extends UCommandBase {
|
||||||
@Override
|
@Override
|
||||||
public String GetHelpText(String alias)[] {
|
public String GetHelpText(String alias)[] {
|
||||||
String cns = " <colorname1>";
|
StringBuilder cns = new StringBuilder(" <colorname1>");
|
||||||
for (int i = 2; i <= ColorCount; i++)
|
for (int i = 2; i <= ColorCount; i++)
|
||||||
cns += " [colorname" + i + "]";
|
cns.append(" [colorname").append(i).append("]");
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
"§6---- Town Color ----", //
|
"§6---- Town Color ----", //
|
||||||
"This command allows setting a color for a town.", //
|
"This command allows setting a color for a town.", //
|
||||||
|
@ -32,9 +31,6 @@ public class TownColorCommand extends UCommandBase {
|
||||||
@Override
|
@Override
|
||||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||||
Resident res;
|
Resident res;
|
||||||
// System.out.println("contains: " + PluginMain.TU.getResidentMap().contains(player.getName().toLowerCase()));
|
|
||||||
// System.out.println("res: " + PluginMain.TU.getResidentMap().get(player.getName().toLowerCase()));
|
|
||||||
// System.out.println("mayor: " + PluginMain.TU.getResidentMap().get(player.getName().toLowerCase()).isMayor());
|
|
||||||
if (!(PluginMain.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
if (!(PluginMain.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
||||||
&& (res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase())).isMayor())) {
|
&& (res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase())).isMayor())) {
|
||||||
player.sendMessage("§cYou need to be the mayor of a town to set it's colors.");
|
player.sendMessage("§cYou need to be the mayor of a town to set it's colors.");
|
||||||
|
@ -47,7 +43,7 @@ public class TownColorCommand extends UCommandBase {
|
||||||
String[] a = new String[args.length + 1];
|
String[] a = new String[args.length + 1];
|
||||||
System.arraycopy(args, 0, a, 1, args.length);
|
System.arraycopy(args, 0, a, 1, args.length);
|
||||||
try {
|
try {
|
||||||
a[0] = res.getTown().getName().toLowerCase();
|
a[0] = res.getTown().getName();
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e);
|
TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e);
|
||||||
player.sendMessage("§cCouldn't find your town... Error reported.");
|
player.sendMessage("§cCouldn't find your town... Error reported.");
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.chat.listener.TownyListener;
|
||||||
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import lombok.val;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class NationColorCommand extends AdminCommandBase {
|
||||||
|
@Override
|
||||||
|
public String[] GetHelpText(String alias) {
|
||||||
|
return new String[]{ //
|
||||||
|
"§6---- Nation color ----", //
|
||||||
|
"Sets the color of the nation.", //
|
||||||
|
"Usage: /u admin nationcolor <color>" //
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||||
|
return SetNationColor(sender, alias, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean SetNationColor(CommandSender sender, String alias, String[] args) {
|
||||||
|
if (args.length < 2)
|
||||||
|
return false;
|
||||||
|
if (args.length > 2) {
|
||||||
|
sender.sendMessage("§cYou can only use one color as a nation color.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
final Nation nation = PluginMain.TU.getNationsMap().get(args[0].toLowerCase());
|
||||||
|
if (nation == null) {
|
||||||
|
sender.sendMessage("§cThe nation '" + args[0] + "' cannot be found.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
||||||
|
if (!c.isPresent()) return true;
|
||||||
|
PluginMain.NationColor.put(args[0].toLowerCase(), c.get());
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||||
|
for (Town t : nation.getTowns())
|
||||||
|
TownyListener.updateTownMembers(t);
|
||||||
|
});
|
||||||
|
sender.sendMessage("§bNation color set to §" + TownColorCommand.getColorText(c.get()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
package buttondevteam.chat.commands.ucmds.admin;
|
package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
import buttondevteam.chat.listener.TownyListener;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -11,6 +10,7 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.dynmap.towny.DynmapTownyPlugin;
|
import org.dynmap.towny.DynmapTownyPlugin;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TownColorCommand extends AdminCommandBase {
|
public class TownColorCommand extends AdminCommandBase {
|
||||||
|
@ -38,28 +38,16 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
sender.sendMessage("§cThe town '" + args[0] + "' cannot be found.");
|
sender.sendMessage("§cThe town '" + args[0] + "' cannot be found.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
val clrs = new Color[args.length - 1];
|
Color[] clrs = new Color[args.length - 1];
|
||||||
for (int i = 1; i < args.length; i++) {
|
Town targetTown = PluginMain.TU.getTownsMap().get(args[0].toLowerCase());
|
||||||
val ii = i;
|
for (int i = 1; i < args.length; i++) {
|
||||||
val c = Arrays.stream(Color.values()).skip(1).filter(cc -> cc.getName().equalsIgnoreCase(args[ii])).findAny();
|
val c = getColorOrSendError(args[i], sender);
|
||||||
if (!c.isPresent()) { //^^ Skip black
|
if (!c.isPresent())
|
||||||
sender.sendMessage("§cThe color '" + args[i] + "' cannot be found."); //ˇˇ Skip black
|
|
||||||
sender.sendMessage("§cAvailable colors: " + Arrays.stream(Color.values()).skip(1).map(col -> String.format("§%x%s§r", col.ordinal(), col.getName())).collect(Collectors.joining(", ")));
|
|
||||||
sender.sendMessage("§cMake sure to type them exactly as shown above.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
clrs[i - 1] = c.get();
|
||||||
clrs[i - 1] = c.get();
|
|
||||||
}
|
}
|
||||||
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
||||||
//PluginMain.TU.getTownsMap().get(args[0].toLowerCase()).getResidents().forEach(r->{
|
TownyListener.updateTownMembers(targetTown);
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> {
|
|
||||||
try {
|
|
||||||
Town t = PluginMain.TU.getResidentMap().get(p.getName().toLowerCase()).getTown();
|
|
||||||
if (t != null && t.getName().equalsIgnoreCase(args[0]))
|
|
||||||
PlayerJoinLeaveListener.updatePlayerColors(p);
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||||
if (dtp == null) {
|
if (dtp == null) {
|
||||||
|
@ -67,12 +55,26 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!");
|
PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PluginMain.setTownColor(dtp, getTownNameCased(args[0]), clrs);
|
PluginMain.setTownColor(dtp, targetTown.getName(), clrs);
|
||||||
sender.sendMessage("§bColor(s) set.");
|
sender.sendMessage("§bColor(s) set.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTownNameCased(String name) {
|
public static Optional<Color> getColorOrSendError(String name, CommandSender sender) {
|
||||||
|
val c = Arrays.stream(Color.values()).skip(1).filter(cc -> cc.getName().equalsIgnoreCase(name)).findAny();
|
||||||
|
if (!c.isPresent()) { //^^ Skip black
|
||||||
|
sender.sendMessage("§cThe color '" + name + "' cannot be found."); //ˇˇ Skip black
|
||||||
|
sender.sendMessage("§cAvailable colors: " + Arrays.stream(Color.values()).skip(1).map(TownColorCommand::getColorText).collect(Collectors.joining(", ")));
|
||||||
|
sender.sendMessage("§cMake sure to type them exactly as shown above.");
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getColorText(Color col) {
|
||||||
|
return String.format("§%x%s§r", col.ordinal(), col.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTownNameCased(String name) {
|
||||||
return PluginMain.TU.getTownsMap().get(name.toLowerCase()).getName();
|
return PluginMain.TU.getTownsMap().get(name.toLowerCase()).getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@ import buttondevteam.chat.FlairStates;
|
||||||
import buttondevteam.chat.PlayerJoinTimerTask;
|
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.commands.UnlolCommand;
|
import buttondevteam.chat.commands.UnlolCommand;
|
||||||
|
import buttondevteam.lib.chat.Color;
|
||||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||||
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
||||||
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
|
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
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 lombok.val;
|
import lombok.val;
|
||||||
|
@ -21,6 +21,7 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
@ -35,8 +36,6 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerTBMCJoin(TBMCPlayerJoinEvent e) {
|
public void onPlayerTBMCJoin(TBMCPlayerJoinEvent e) {
|
||||||
if (PluginMain.essentials == null)
|
|
||||||
PluginMain.essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"));
|
|
||||||
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
|
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
|
||||||
Player p = Bukkit.getPlayer(cp.getUUID());
|
Player p = Bukkit.getPlayer(cp.getUUID());
|
||||||
|
|
||||||
|
@ -51,31 +50,7 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
};
|
};
|
||||||
tt.mp = cp;
|
tt.mp = cp;
|
||||||
timer.schedule(tt, 1000);
|
timer.schedule(tt, 1000);
|
||||||
} else {
|
} //TODO: Better Reddit integration (OAuth)
|
||||||
/*Timer timer = new Timer();
|
|
||||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Player player = Bukkit.getPlayer(mp.PlayerName().get());
|
|
||||||
if (player == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
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.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.PlayerName() + " " + json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
tt.mp = cp;
|
|
||||||
timer.schedule(tt, 15 * 1000);*/ //TODO: Better Reddit integration (OAuth)
|
|
||||||
}
|
|
||||||
|
|
||||||
String nwithoutformatting = PluginMain.essentials.getUser(p).getNickname();
|
String nwithoutformatting = PluginMain.essentials.getUser(p).getNickname();
|
||||||
|
|
||||||
|
@ -109,32 +84,45 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
|
UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPlayerNickname(Player player, User user) {
|
private static String getPlayerNickname(Player player, User user, ChatPlayer cp) {
|
||||||
String nickname = user.getNick(true);
|
String nickname = user.getNick(true);
|
||||||
if (nickname.contains("~")) //StartsWith doesn't work because of color codes
|
if (nickname.contains("~")) //StartsWith doesn't work because of color codes
|
||||||
nickname = nickname.replace("~", ""); //It gets stacked otherwise
|
nickname = nickname.replace("~", ""); //It gets stacked otherwise
|
||||||
|
String name = ChatColor.stripColor(nickname); //Enforce "town colors" on non-members
|
||||||
val res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase());
|
val res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase());
|
||||||
if (res == null || !res.hasTown())
|
if (res == null || !res.hasTown())
|
||||||
return nickname;
|
return name;
|
||||||
try {
|
try {
|
||||||
val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase());
|
Color[] clrs = Optional.ofNullable(
|
||||||
if (clrs == null)
|
PluginMain.TownColors.get(res.getTown().getName().toLowerCase())
|
||||||
return nickname;
|
).orElse(new Color[]{Color.White}); //Use white as default town color
|
||||||
StringBuilder ret = new StringBuilder();
|
StringBuilder ret = new StringBuilder();
|
||||||
String name = ChatColor.stripColor(nickname);
|
|
||||||
AtomicInteger prevlen = new AtomicInteger();
|
AtomicInteger prevlen = new AtomicInteger();
|
||||||
BiFunction<Integer, Integer, String> coloredNamePart = (len, i) -> "§"
|
BiFunction<Color, Integer, String> anyColoredNamePart = (c, len) -> "§" //Len==0 if last part
|
||||||
+ Integer.toHexString(clrs[i].ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
|
+ Integer.toHexString(c.ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
|
||||||
+ (i + 1 == clrs.length ? name.substring(prevlen.get())
|
+ (len == 0 ? name.substring(prevlen.get())
|
||||||
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
||||||
int len = name.length() / clrs.length;
|
BiFunction<Integer, Integer, String> coloredNamePart = (len, i)
|
||||||
val nclar = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get();
|
-> anyColoredNamePart.apply(clrs[i], i + 1 == clrs.length ? 0 : len);
|
||||||
|
final int len = name.length() / (clrs.length + 1); //The above param is needed because this isn't always passed
|
||||||
|
Color nc;
|
||||||
|
/*if(res.getTown().hasNation()
|
||||||
|
&&(nc=PluginMain.NationColor.get(res.getTown().getNation().getName().toLowerCase()))!=null)
|
||||||
|
len = name.length() / (clrs.length+1);
|
||||||
|
else
|
||||||
|
len = name.length() / clrs.length;*/
|
||||||
|
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))
|
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length))
|
||||||
ncl = null; // Reset if name length changed
|
ncl = null; // Reset if name length changed
|
||||||
//System.out.println("ncl: "+Arrays.toString(ncl)+" - sum: "+Arrays.stream(ncl).sum()+" - name len: "+name.length());
|
//System.out.println("ncl: "+Arrays.toString(ncl)+" - sum: "+Arrays.stream(ncl).sum()+" - name len: "+name.length());
|
||||||
|
if (!res.getTown().hasNation()
|
||||||
|
|| (nc = PluginMain.NationColor.get(res.getTown().getNation().getName().toLowerCase())) == null)
|
||||||
|
nc = Color.White;
|
||||||
|
ret.append(anyColoredNamePart.apply(nc, ncl == null ? len : ncl[0])); //Make first color the nation color
|
||||||
for (int i = 0; i < clrs.length; i++)
|
for (int i = 0; i < clrs.length; i++)
|
||||||
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i], i));
|
//ret.append(coloredNamePart.apply(ncl == null ? len : (nc==null?ncl[i]:ncl[i+1]), i));
|
||||||
|
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i + 1], i));
|
||||||
return ret.toString();
|
return ret.toString();
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
return nickname;
|
return nickname;
|
||||||
|
@ -145,10 +133,11 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class));
|
updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
@SuppressWarnings("WeakerAccess")
|
||||||
User user = PluginMain.essentials.getUser(player);
|
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
||||||
user.setNickname(getPlayerNickname(player, user));
|
User user = PluginMain.essentials.getUser(player);
|
||||||
user.setDisplayNick(); //These won't fire the nick change event
|
user.setNickname(getPlayerNickname(player, user, cp));
|
||||||
cp.FlairUpdate(); //Update in list
|
user.setDisplayNick(); //These won't fire the nick change event
|
||||||
}
|
cp.FlairUpdate(); //Update in list
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.*;
|
import buttondevteam.lib.chat.*;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||||
|
@ -13,6 +14,7 @@ import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.vexsoftware.votifier.model.Vote;
|
import com.vexsoftware.votifier.model.Vote;
|
||||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||||
|
import lombok.val;
|
||||||
import net.ess3.api.events.NickChangeEvent;
|
import net.ess3.api.events.NickChangeEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -28,12 +30,14 @@ import org.bukkit.event.server.ServerCommandEvent;
|
||||||
import org.bukkit.help.HelpTopic;
|
import org.bukkit.help.HelpTopic;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +61,7 @@ public class PlayerListener implements Listener {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
ChatPlayer cp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class);
|
ChatPlayer cp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class);
|
||||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(cp.CurrentChannel, event.getPlayer(), cp, event.getMessage()).build());
|
TBMCChatAPI.SendChatMessage(ChatMessage.builder(event.getPlayer(), cp, event.getMessage()).build());
|
||||||
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,11 +75,7 @@ public class PlayerListener implements Listener {
|
||||||
if (message.length() < 2)
|
if (message.length() < 2)
|
||||||
return false;
|
return false;
|
||||||
int index = message.indexOf(" ");
|
int index = message.indexOf(" ");
|
||||||
ChatPlayer mp;
|
val mp = ChromaGamerBase.getFromSender(sender);
|
||||||
if (sender instanceof Player)
|
|
||||||
mp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class);
|
|
||||||
else
|
|
||||||
mp = TBMCPlayer.getPlayer(new UUID(0, 0), ChatPlayer.class); //Use 0, 0 for console and whatever - TODO: Refactor console stuff
|
|
||||||
String cmd;
|
String cmd;
|
||||||
final BiPredicate<Channel, String> checkchid = (chan, cmd1) -> cmd1.equalsIgnoreCase(chan.ID) || (chan.IDs != null && Arrays.stream(chan.IDs).anyMatch(cmd1::equalsIgnoreCase));
|
final BiPredicate<Channel, String> checkchid = (chan, cmd1) -> cmd1.equalsIgnoreCase(chan.ID) || (chan.IDs != null && Arrays.stream(chan.IDs).anyMatch(cmd1::equalsIgnoreCase));
|
||||||
if (index == -1) { // Only the command is run
|
if (index == -1) { // Only the command is run
|
||||||
|
@ -85,24 +85,17 @@ public class PlayerListener implements Listener {
|
||||||
cmd = sender instanceof ConsoleCommandSender ? message : message.substring(1);
|
cmd = sender instanceof ConsoleCommandSender ? message : message.substring(1);
|
||||||
for (Channel channel : Channel.getChannels()) {
|
for (Channel channel : Channel.getChannels()) {
|
||||||
if (checkchid.test(channel, cmd)) {
|
if (checkchid.test(channel, cmd)) {
|
||||||
Supplier<Channel> getch = () -> sender instanceof Player ? mp.CurrentChannel : ConsoleChannel;
|
Channel oldch = mp.channel().get();
|
||||||
Consumer<Channel> setch = ch -> {
|
|
||||||
if (sender instanceof Player)
|
|
||||||
mp.CurrentChannel = ch;
|
|
||||||
else
|
|
||||||
ConsoleChannel = ch;
|
|
||||||
};
|
|
||||||
Channel oldch = getch.get();
|
|
||||||
if (oldch instanceof ChatRoom)
|
if (oldch instanceof ChatRoom)
|
||||||
((ChatRoom) oldch).leaveRoom(sender);
|
((ChatRoom) oldch).leaveRoom(sender);
|
||||||
if (oldch.equals(channel))
|
if (oldch.equals(channel))
|
||||||
setch.accept(Channel.GlobalChat);
|
mp.channel().set(Channel.GlobalChat);
|
||||||
else {
|
else {
|
||||||
setch.accept(channel);
|
mp.channel().set(channel);
|
||||||
if (channel instanceof ChatRoom)
|
if (channel instanceof ChatRoom)
|
||||||
((ChatRoom) channel).joinRoom(sender);
|
((ChatRoom) channel).joinRoom(sender);
|
||||||
}
|
}
|
||||||
sender.sendMessage("§6You are now talking in: §b" + getch.get().DisplayName);
|
sender.sendMessage("§6You are now talking in: §b" + mp.channel().get().DisplayName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +127,7 @@ public class PlayerListener implements Listener {
|
||||||
} else
|
} else
|
||||||
for (Channel channel : Channel.getChannels()) {
|
for (Channel channel : Channel.getChannels()) {
|
||||||
if (checkchid.test(channel, cmd)) { //Apparently method references don't require final variables
|
if (checkchid.test(channel, cmd)) { //Apparently method references don't require final variables
|
||||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(channel, sender, mp, message.substring(index + 1)).build());
|
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, mp, message.substring(index + 1)).build(), channel);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +167,7 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
public static boolean ActiveF = false;
|
public static boolean ActiveF = false;
|
||||||
public static ChatPlayer FPlayer = null;
|
public static ChatPlayer FPlayer = null;
|
||||||
private Timer Ftimer;
|
public static BukkitTask Ftask = null;
|
||||||
public static int AlphaDeaths;
|
public static int AlphaDeaths;
|
||||||
public static ArrayList<CommandSender> Fs = new ArrayList<>();
|
public static ArrayList<CommandSender> Fs = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -184,28 +177,26 @@ public class PlayerListener implements Listener {
|
||||||
AlphaDeaths++;
|
AlphaDeaths++;
|
||||||
// MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity());
|
// MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity());
|
||||||
if (/* (mgp != null && !mgp.isInMinigame()) && */ new Random().nextBoolean()) { // Don't store Fs for NPCs
|
if (/* (mgp != null && !mgp.isInMinigame()) && */ new Random().nextBoolean()) { // Don't store Fs for NPCs
|
||||||
if (Ftimer != null)
|
Runnable tt = () -> {
|
||||||
Ftimer.cancel();
|
if (ActiveF) {
|
||||||
|
ActiveF = false;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (Ftask != null) {
|
||||||
|
Ftask.cancel();
|
||||||
|
tt.run(); //Finish previous one
|
||||||
|
}
|
||||||
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);
|
||||||
Bukkit.broadcastMessage("§bPress F to pay respects.§r");
|
Bukkit.broadcastMessage("§bPress F to pay respects.§r");
|
||||||
Ftimer = new Timer();
|
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20);
|
||||||
TimerTask tt = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (ActiveF) {
|
|
||||||
ActiveF = false;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ftimer.schedule(tt, 15 * 1000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,8 +230,6 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Channel ConsoleChannel = Channel.GlobalChat;
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onConsoleCommand(ServerCommandEvent event) {
|
public void onConsoleCommand(ServerCommandEvent event) {
|
||||||
if (onCommandPreprocess(event.getSender(), event.getCommand()))
|
if (onCommandPreprocess(event.getSender(), event.getCommand()))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package buttondevteam.chat.listener;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.palmergames.bukkit.towny.event.*;
|
import com.palmergames.bukkit.towny.event.*;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -10,39 +11,80 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class TownyListener implements Listener {
|
public class TownyListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onTownRename(RenameTownEvent event) {
|
public void onTownRename(RenameTownEvent event) {
|
||||||
val clrs = PluginMain.TownColors.remove(event.getOldName().toLowerCase());
|
val clrs = PluginMain.TownColors.remove(event.getOldName().toLowerCase());
|
||||||
if (clrs != null)
|
if (clrs != null)
|
||||||
PluginMain.TownColors.put(event.getTown().getName().toLowerCase(), clrs);
|
PluginMain.TownColors.put(event.getTown().getName().toLowerCase(), clrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler //Gets called on town load as well
|
@EventHandler //Gets called on town load as well
|
||||||
public void onTownJoin(TownAddResidentEvent event) {
|
public void onTownJoin(TownAddResidentEvent event) {
|
||||||
Player p = Bukkit.getPlayer(event.getResident().getName());
|
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||||
if (p != null)
|
if (p != null)
|
||||||
PlayerJoinLeaveListener.updatePlayerColors(p);
|
PlayerJoinLeaveListener.updatePlayerColors(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
public static void updateTownMembers(Town town) {
|
||||||
public void onTownLeave(TownRemoveResidentEvent event) {
|
town.getResidents().stream().map(r -> Bukkit.getPlayer(r.getName()))
|
||||||
Player p = Bukkit.getPlayer(event.getResident().getName());
|
.filter(Objects::nonNull).forEach(PlayerJoinLeaveListener::updatePlayerColors);
|
||||||
if (p != null) {
|
}
|
||||||
User user = PluginMain.essentials.getUser(p);
|
|
||||||
user.setNickname(ChatColor.stripColor(user.getNick(true).replace("~", "")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onTownDelete(DeleteTownEvent event) {
|
public void onTownLeave(TownRemoveResidentEvent event) {
|
||||||
PluginMain.TownColors.remove(event.getTownName().toLowerCase());
|
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||||
}
|
if (p != null)
|
||||||
|
resetNameColor(p);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
private void resetNameColor(Player p) {
|
||||||
public void onTownCreate(NewTownEvent event) {
|
User user = PluginMain.essentials.getUser(p);
|
||||||
Player p = Bukkit.getPlayer(event.getTown().getMayor().getName());
|
user.setNickname(ChatColor.stripColor(user.getNick(true).replace("~", "")));
|
||||||
if (p != null)
|
}
|
||||||
p.sendMessage("§6Use /u towncolor <color1> [color2] to set a color for the town.");
|
|
||||||
}
|
@EventHandler
|
||||||
|
public void onTownDelete(DeleteTownEvent event) {
|
||||||
|
PluginMain.TownColors.remove(event.getTownName().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTownCreate(NewTownEvent event) {
|
||||||
|
Player p = Bukkit.getPlayer(event.getTown().getMayor().getName());
|
||||||
|
if (p != null)
|
||||||
|
p.sendMessage("§6Use /u towncolor to set a color for the town.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onNationRename(RenameNationEvent event) {
|
||||||
|
val clrs = PluginMain.NationColor.remove(event.getOldName().toLowerCase());
|
||||||
|
if (clrs != null)
|
||||||
|
PluginMain.NationColor.put(event.getNation().getName().toLowerCase(), clrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler //Gets called on town load as well
|
||||||
|
public void onNationJoin(NationAddTownEvent event) {
|
||||||
|
updateTownMembers(event.getTown());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onNationLeave(NationRemoveTownEvent event) {
|
||||||
|
updateTownMembers(event.getTown()); //The town still has it's colours
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onNationDelete(DeleteNationEvent event) {
|
||||||
|
PluginMain.NationColor.remove(event.getNationName().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onNationCreate(NewNationEvent event) {
|
||||||
|
Player p = Bukkit.getPlayer(event.getNation().getCapital().getMayor().getName());
|
||||||
|
if (p != null)
|
||||||
|
p.sendMessage("§6Use /u nationcolor to set a color for the nation.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue