Nation color, /tableflip fix, improvements and other fixes #92
4 changed files with 107 additions and 51 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
|
public class NationColorCommand {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
|
public class NationColorCommand {
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
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.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
@ -40,6 +40,7 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Color[] clrs = null; //Add nation color as well
|
Color[] clrs = null; //Add nation color as well
|
||||||
|
boolean hasNationColor = false;
|
||||||
Town targetTown = PluginMain.TU.getTownsMap().get(args[0].toLowerCase());
|
Town targetTown = PluginMain.TU.getTownsMap().get(args[0].toLowerCase());
|
||||||
try {
|
try {
|
||||||
Color c; //TODO: Add command for nation color
|
Color c; //TODO: Add command for nation color
|
||||||
|
@ -47,30 +48,20 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
&& (c = PluginMain.NationColor.get(targetTown.getNation().getName().toLowerCase())) != null) {
|
&& (c = PluginMain.NationColor.get(targetTown.getNation().getName().toLowerCase())) != null) {
|
||||||
clrs = new Color[args.length];
|
clrs = new Color[args.length];
|
||||||
clrs[0] = c;
|
clrs[0] = c;
|
||||||
|
hasNationColor = true;
|
||||||
}
|
}
|
||||||
} catch (NotRegisteredException ignored) {
|
} catch (NotRegisteredException ignored) {
|
||||||
}
|
}
|
||||||
if (clrs == null)
|
if (!hasNationColor)
|
||||||
clrs = new Color[args.length - 1];
|
clrs = new Color[args.length - 1];
|
||||||
for (int i = 1; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
val c = getColor(args[i]);
|
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[hasNationColor ? i : i - 1] = c.get();
|
||||||
clrs[i - 1] = c.get();
|
|
||||||
}
|
}
|
||||||
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> {
|
TownyListener.updateTownMembers(targetTown);
|
||||||
try {
|
|
||||||
Town t = PluginMain.TU.getResidentMap().get(p.getName().toLowerCase()).getTown();
|
|
||||||
if (t != null && t.getName().equalsIgnoreCase(args[0]))
|
|
||||||
PlayerJoinLeaveListener.updatePlayerColors(p);
|
|
||||||
} catch (NotRegisteredException ignored) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||||
if (dtp == null) {
|
if (dtp == null) {
|
||||||
|
@ -78,13 +69,19 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<Color> getColor(String name) {
|
private static Optional<Color> getColorOrSendError(String name, CommandSender sender) {
|
||||||
return Arrays.stream(Color.values()).skip(1).filter(cc -> cc.getName().equalsIgnoreCase(name)).findAny();
|
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(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 c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTownNameCased(String name) {
|
public static String getTownNameCased(String name) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package buttondevteam.chat.listener;
|
package buttondevteam.chat.listener;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.chat.commands.ucmds.admin.TownColorCommand;
|
||||||
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 com.palmergames.bukkit.towny.object.Town;
|
||||||
|
@ -38,7 +39,57 @@ public class TownyListener implements Listener {
|
||||||
updateTownMembers(event.getTown());
|
updateTownMembers(event.getTown());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTownMembers(Town town) { //TODO: Update (or remove) nation color from town color
|
public static void updateTownMembers(Town town) { //TODO: Update (or remove) nation color from town color
|
||||||
|
town.getResidents().stream().map(r -> Bukkit.getPlayer(r.getName()))
|
||||||
|
.filter(Objects::nonNull).forEach(PlayerJoinLeaveListener::updatePlayerColors);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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("~", "")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
TownColorCommand.SetTownColor()
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler //Gets called on town load as well
|
||||||
|
public void onNationJoin(NationAddTownEvent event) {
|
||||||
|
updateTownMembers(event.getTown());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler //Gets called on town load as well
|
||||||
|
public void onNationLeave(NationRemoveTownEvent event) {
|
||||||
|
updateTownMembers(event.getTown());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTownMembers(Town town) {
|
||||||
town.getResidents().stream().map(r -> Bukkit.getPlayer(r.getName()))
|
town.getResidents().stream().map(r -> Bukkit.getPlayer(r.getName()))
|
||||||
.filter(Objects::nonNull).forEach(PlayerJoinLeaveListener::updatePlayerColors);
|
.filter(Objects::nonNull).forEach(PlayerJoinLeaveListener::updatePlayerColors);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue