Merge pull request #92 from TBMCPlugins/dev
Nation color, /tableflip fix, improvements and other fixes
This commit is contained in:
commit
304f5c562d
15 changed files with 325 additions and 217 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -131,7 +131,7 @@ publish/
|
|||
*.publishproj
|
||||
|
||||
# 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/
|
||||
|
||||
# Windows Azure Build Output
|
||||
|
@ -221,4 +221,4 @@ TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar
|
|||
*.name
|
||||
.idea/compiler.xml
|
||||
*.xml
|
||||
/.apt_generated/
|
||||
/.apt_generated/
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -92,6 +92,8 @@
|
|||
</executions>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
<useSystemClassLoader>false
|
||||
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||
|
@ -163,7 +165,7 @@
|
|||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
<version>8d3b6b6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vexsoftware</groupId>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.player.EnumPlayerData;
|
||||
import buttondevteam.lib.player.PlayerClass;
|
||||
|
@ -50,7 +49,6 @@ public class ChatPlayer extends TBMCPlayerBase {
|
|||
public Location SavedLocation;
|
||||
public boolean Working;
|
||||
// public int Tables = 10;
|
||||
public Channel CurrentChannel = Channel.GlobalChat;
|
||||
public boolean SendingLink = false;
|
||||
public boolean RainbowPresserColorMode = false;
|
||||
public Color OtherColorMode = null;
|
||||
|
|
|
@ -14,7 +14,6 @@ import buttondevteam.lib.chat.*;
|
|||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
|
@ -94,8 +93,6 @@ public class ChatProcessing {
|
|||
CommandSender sender = e.getSender();
|
||||
String message = e.getMessage();
|
||||
long processstart = System.nanoTime();
|
||||
if (PluginMain.essentials == null)
|
||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
Player player = (sender instanceof Player ? (Player) sender : null);
|
||||
User user = PluginMain.essentials.getUser(player);
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.htmlcleaner.TagNode;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
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/
|
||||
public static PluginMain Instance;
|
||||
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 TownyUniverse TU;
|
||||
public static ArrayList<Town> Towns;
|
||||
public static ArrayList<Nation> Nations;
|
||||
private static ArrayList<Town> Towns;
|
||||
private static ArrayList<Nation> Nations;
|
||||
|
||||
public static Channel TownChat;
|
||||
public static Channel NationChat;
|
||||
public static Channel RPChannel;
|
||||
private static Channel RPChannel;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -79,6 +78,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
@Override
|
||||
public void onEnable() {
|
||||
Instance = this;
|
||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), 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_...]
|
||||
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
|
||||
Nations = new ArrayList<Nation>(TU.getNationsMap().values()); // Same here but with nations
|
||||
Towns = new ArrayList<>(TU.getTownsMap().values()); // Creates a snapshot of towns, new towns will be added when needed
|
||||
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(
|
||||
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
|
||||
TBMCChatAPI.RegisterChatChannel(
|
||||
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 -> {
|
||||
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.")));
|
||||
TBMCChatAPI.RegisterChatChannel(RPChannel = new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
|
||||
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
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
|
||||
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get())
|
||||
.replace("\"", "").split(":");
|
||||
|
@ -247,11 +244,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
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);
|
||||
}
|
||||
|
||||
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());
|
||||
URLConnection con = url.openConnection();
|
||||
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 int AnnounceTime = 15 * 60 * 1000;
|
||||
/**
|
||||
* Names lowercased
|
||||
*/
|
||||
public static Map<String, Color[]> TownColors = new HashMap<>();
|
||||
/**
|
||||
* Names lowercased
|
||||
*/
|
||||
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")
|
||||
public static void LoadFiles() {
|
||||
private static void LoadFiles() {
|
||||
PluginMain.Instance.getLogger().info("Loading files...");
|
||||
try {
|
||||
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()
|
||||
.map(Color::valueOf).toArray(Color[]::new))));
|
||||
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!");
|
||||
} else
|
||||
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("announcements", AnnounceMessages);
|
||||
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))));
|
||||
yc.set("towncolorcount", TownColorCommand.ColorCount);
|
||||
yc.createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||
v -> v.getValue().toString())));
|
||||
yc.save(file);
|
||||
PluginMain.Instance.getLogger().info("Saved files!");
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
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.chat.Channel;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
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)
|
||||
public final class UnlolCommand extends TBMCCommandBase {
|
||||
|
@ -31,7 +31,7 @@ public final class UnlolCommand extends TBMCCommandBase {
|
|||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
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)
|
||||
return true;
|
||||
if (lol.Lolowner instanceof Player)
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
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.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCYEEHAWEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public class YeehawCommand extends TBMCCommandBase {
|
||||
|
@ -22,9 +21,9 @@ public class YeehawCommand extends TBMCCommandBase {
|
|||
+ (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs.";
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
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
|
||||
// Or anyone from Discord
|
||||
Bukkit.broadcastMessage(message);
|
||||
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.lib.chat.*;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandClass(modOnly = false, excludeFromPath = true)
|
||||
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||
|
@ -18,20 +16,12 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
|||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
String msg = GetAppendedText();
|
||||
for (int i = args.length - 1; i >= 0; i--)
|
||||
msg = args[i] + " " + msg;
|
||||
ChatPlayer cp;
|
||||
if (sender instanceof Player)
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(
|
||||
(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
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (String arg : args) msg.append(arg).append(" ");
|
||||
msg.append(GetAppendedText());
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender,
|
||||
ChromaGamerBase.getFromSender(sender), msg.toString())
|
||||
.fromCommand(true).build());
|
||||
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;
|
||||
|
||||
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.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 // TODO: /u u when annotation not present
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
public class TownColorCommand extends UCommandBase {
|
||||
@Override
|
||||
public String GetHelpText(String alias)[] {
|
||||
String cns = " <colorname1>";
|
||||
StringBuilder cns = new StringBuilder(" <colorname1>");
|
||||
for (int i = 2; i <= ColorCount; i++)
|
||||
cns += " [colorname" + i + "]";
|
||||
cns.append(" [colorname").append(i).append("]");
|
||||
return new String[] { //
|
||||
"§6---- Town Color ----", //
|
||||
"This command allows setting a color for a town.", //
|
||||
|
@ -32,9 +31,6 @@ public class TownColorCommand extends UCommandBase {
|
|||
@Override
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
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())
|
||||
&& (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.");
|
||||
|
@ -47,7 +43,7 @@ public class TownColorCommand extends UCommandBase {
|
|||
String[] a = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, a, 1, args.length);
|
||||
try {
|
||||
a[0] = res.getTown().getName().toLowerCase();
|
||||
a[0] = res.getTown().getName();
|
||||
} catch (NotRegisteredException e) {
|
||||
TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e);
|
||||
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;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||
import buttondevteam.chat.listener.TownyListener;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -11,6 +10,7 @@ import org.bukkit.command.CommandSender;
|
|||
import org.dynmap.towny.DynmapTownyPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TownColorCommand extends AdminCommandBase {
|
||||
|
@ -38,28 +38,16 @@ public class TownColorCommand extends AdminCommandBase {
|
|||
sender.sendMessage("§cThe town '" + args[0] + "' cannot be found.");
|
||||
return true;
|
||||
}
|
||||
val clrs = new Color[args.length - 1];
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
val ii = i;
|
||||
val c = Arrays.stream(Color.values()).skip(1).filter(cc -> cc.getName().equalsIgnoreCase(args[ii])).findAny();
|
||||
if (!c.isPresent()) { //^^ Skip black
|
||||
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.");
|
||||
Color[] clrs = new Color[args.length - 1];
|
||||
Town targetTown = PluginMain.TU.getTownsMap().get(args[0].toLowerCase());
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
val c = getColorOrSendError(args[i], sender);
|
||||
if (!c.isPresent())
|
||||
return true;
|
||||
}
|
||||
clrs[i - 1] = c.get();
|
||||
clrs[i - 1] = c.get();
|
||||
}
|
||||
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
||||
//PluginMain.TU.getTownsMap().get(args[0].toLowerCase()).getResidents().forEach(r->{
|
||||
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) {
|
||||
}
|
||||
});
|
||||
TownyListener.updateTownMembers(targetTown);
|
||||
|
||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||
if (dtp == null) {
|
||||
|
@ -67,12 +55,26 @@ public class TownColorCommand extends AdminCommandBase {
|
|||
PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!");
|
||||
return true;
|
||||
}
|
||||
PluginMain.setTownColor(dtp, getTownNameCased(args[0]), clrs);
|
||||
PluginMain.setTownColor(dtp, targetTown.getName(), clrs);
|
||||
sender.sendMessage("§bColor(s) set.");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import buttondevteam.chat.FlairStates;
|
|||
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.commands.UnlolCommand;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import lombok.val;
|
||||
|
@ -21,6 +21,7 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Timer;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
@ -35,8 +36,6 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onPlayerTBMCJoin(TBMCPlayerJoinEvent e) {
|
||||
if (PluginMain.essentials == null)
|
||||
PluginMain.essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
ChatPlayer cp = e.GetPlayer().asPluginPlayer(ChatPlayer.class);
|
||||
Player p = Bukkit.getPlayer(cp.getUUID());
|
||||
|
||||
|
@ -51,31 +50,7 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
};
|
||||
tt.mp = cp;
|
||||
timer.schedule(tt, 1000);
|
||||
} else {
|
||||
/*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)
|
||||
}
|
||||
} //TODO: Better Reddit integration (OAuth)
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
private static String getPlayerNickname(Player player, User user) {
|
||||
private static String getPlayerNickname(Player player, User user, ChatPlayer cp) {
|
||||
String nickname = user.getNick(true);
|
||||
if (nickname.contains("~")) //StartsWith doesn't work because of color codes
|
||||
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());
|
||||
if (res == null || !res.hasTown())
|
||||
return nickname;
|
||||
return name;
|
||||
try {
|
||||
val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase());
|
||||
if (clrs == null)
|
||||
return nickname;
|
||||
Color[] clrs = Optional.ofNullable(
|
||||
PluginMain.TownColors.get(res.getTown().getName().toLowerCase())
|
||||
).orElse(new Color[]{Color.White}); //Use white as default town color
|
||||
StringBuilder ret = new StringBuilder();
|
||||
String name = ChatColor.stripColor(nickname);
|
||||
AtomicInteger prevlen = new AtomicInteger();
|
||||
BiFunction<Integer, Integer, String> coloredNamePart = (len, i) -> "§"
|
||||
+ Integer.toHexString(clrs[i].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())
|
||||
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
||||
int len = name.length() / clrs.length;
|
||||
val nclar = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get();
|
||||
BiFunction<Color, Integer, String> anyColoredNamePart = (c, len) -> "§" //Len==0 if last part
|
||||
+ Integer.toHexString(c.ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
|
||||
+ (len == 0 ? name.substring(prevlen.get())
|
||||
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
||||
BiFunction<Integer, Integer, String> coloredNamePart = (len, i)
|
||||
-> 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();
|
||||
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length))
|
||||
ncl = null; // Reset if name length changed
|
||||
//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++)
|
||||
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();
|
||||
} catch (NotRegisteredException e) {
|
||||
return nickname;
|
||||
|
@ -145,10 +133,11 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class));
|
||||
}
|
||||
|
||||
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
||||
User user = PluginMain.essentials.getUser(player);
|
||||
user.setNickname(getPlayerNickname(player, user));
|
||||
user.setDisplayNick(); //These won't fire the nick change event
|
||||
cp.FlairUpdate(); //Update in list
|
||||
}
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
||||
User user = PluginMain.essentials.getUser(player);
|
||||
user.setNickname(getPlayerNickname(player, user, cp));
|
||||
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.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.*;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||
|
@ -13,6 +14,7 @@ import com.google.common.collect.BiMap;
|
|||
import com.google.common.collect.HashBiMap;
|
||||
import com.vexsoftware.votifier.model.Vote;
|
||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
import lombok.val;
|
||||
import net.ess3.api.events.NickChangeEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -28,12 +30,14 @@ import org.bukkit.event.server.ServerCommandEvent;
|
|||
import org.bukkit.help.HelpTopic;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
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.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
/**
|
||||
|
@ -57,7 +61,7 @@ public class PlayerListener implements Listener {
|
|||
if (event.isCancelled())
|
||||
return;
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -71,11 +75,7 @@ public class PlayerListener implements Listener {
|
|||
if (message.length() < 2)
|
||||
return false;
|
||||
int index = message.indexOf(" ");
|
||||
ChatPlayer mp;
|
||||
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
|
||||
val mp = ChromaGamerBase.getFromSender(sender);
|
||||
String cmd;
|
||||
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
|
||||
|
@ -85,24 +85,17 @@ public class PlayerListener implements Listener {
|
|||
cmd = sender instanceof ConsoleCommandSender ? message : message.substring(1);
|
||||
for (Channel channel : Channel.getChannels()) {
|
||||
if (checkchid.test(channel, cmd)) {
|
||||
Supplier<Channel> getch = () -> sender instanceof Player ? mp.CurrentChannel : ConsoleChannel;
|
||||
Consumer<Channel> setch = ch -> {
|
||||
if (sender instanceof Player)
|
||||
mp.CurrentChannel = ch;
|
||||
else
|
||||
ConsoleChannel = ch;
|
||||
};
|
||||
Channel oldch = getch.get();
|
||||
Channel oldch = mp.channel().get();
|
||||
if (oldch instanceof ChatRoom)
|
||||
((ChatRoom) oldch).leaveRoom(sender);
|
||||
if (oldch.equals(channel))
|
||||
setch.accept(Channel.GlobalChat);
|
||||
mp.channel().set(Channel.GlobalChat);
|
||||
else {
|
||||
setch.accept(channel);
|
||||
mp.channel().set(channel);
|
||||
if (channel instanceof ChatRoom)
|
||||
((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;
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +127,7 @@ public class PlayerListener implements Listener {
|
|||
} else
|
||||
for (Channel channel : Channel.getChannels()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +167,7 @@ public class PlayerListener implements Listener {
|
|||
|
||||
public static boolean ActiveF = false;
|
||||
public static ChatPlayer FPlayer = null;
|
||||
private Timer Ftimer;
|
||||
public static BukkitTask Ftask = null;
|
||||
public static int AlphaDeaths;
|
||||
public static ArrayList<CommandSender> Fs = new ArrayList<>();
|
||||
|
||||
|
@ -184,28 +177,26 @@ public class PlayerListener implements Listener {
|
|||
AlphaDeaths++;
|
||||
// MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity());
|
||||
if (/* (mgp != null && !mgp.isInMinigame()) && */ new Random().nextBoolean()) { // Don't store Fs for NPCs
|
||||
if (Ftimer != null)
|
||||
Ftimer.cancel();
|
||||
Runnable tt = () -> {
|
||||
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;
|
||||
Fs.clear();
|
||||
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() {
|
||||
@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);
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,8 +230,6 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
public static Channel ConsoleChannel = Channel.GlobalChat;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onConsoleCommand(ServerCommandEvent event) {
|
||||
if (onCommandPreprocess(event.getSender(), event.getCommand()))
|
||||
|
|
|
@ -3,6 +3,7 @@ package buttondevteam.chat.listener;
|
|||
import buttondevteam.chat.PluginMain;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.palmergames.bukkit.towny.event.*;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -10,39 +11,80 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class TownyListener implements Listener {
|
||||
@EventHandler
|
||||
public void onTownRename(RenameTownEvent event) {
|
||||
val clrs = PluginMain.TownColors.remove(event.getOldName().toLowerCase());
|
||||
if (clrs != null)
|
||||
PluginMain.TownColors.put(event.getTown().getName().toLowerCase(), clrs);
|
||||
}
|
||||
@EventHandler
|
||||
public void onTownRename(RenameTownEvent event) {
|
||||
val clrs = PluginMain.TownColors.remove(event.getOldName().toLowerCase());
|
||||
if (clrs != null)
|
||||
PluginMain.TownColors.put(event.getTown().getName().toLowerCase(), clrs);
|
||||
}
|
||||
|
||||
@EventHandler //Gets called on town load as well
|
||||
public void onTownJoin(TownAddResidentEvent event) {
|
||||
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||
if (p != null)
|
||||
PlayerJoinLeaveListener.updatePlayerColors(p);
|
||||
}
|
||||
@EventHandler //Gets called on town load as well
|
||||
public void onTownJoin(TownAddResidentEvent event) {
|
||||
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||
if (p != null)
|
||||
PlayerJoinLeaveListener.updatePlayerColors(p);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTownLeave(TownRemoveResidentEvent event) {
|
||||
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||
if (p != null) {
|
||||
User user = PluginMain.essentials.getUser(p);
|
||||
user.setNickname(ChatColor.stripColor(user.getNick(true).replace("~", "")));
|
||||
}
|
||||
}
|
||||
public static void updateTownMembers(Town town) {
|
||||
town.getResidents().stream().map(r -> Bukkit.getPlayer(r.getName()))
|
||||
.filter(Objects::nonNull).forEach(PlayerJoinLeaveListener::updatePlayerColors);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTownDelete(DeleteTownEvent event) {
|
||||
PluginMain.TownColors.remove(event.getTownName().toLowerCase());
|
||||
}
|
||||
@EventHandler
|
||||
public void onTownLeave(TownRemoveResidentEvent event) {
|
||||
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||
if (p != null)
|
||||
resetNameColor(p);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTownCreate(NewTownEvent event) {
|
||||
Player p = Bukkit.getPlayer(event.getTown().getMayor().getName());
|
||||
if (p != null)
|
||||
p.sendMessage("§6Use /u towncolor <color1> [color2] to set a color for the town.");
|
||||
}
|
||||
private void resetNameColor(Player p) {
|
||||
User user = PluginMain.essentials.getUser(p);
|
||||
user.setNickname(ChatColor.stripColor(user.getNick(true).replace("~", "")));
|
||||
}
|
||||
|
||||
@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