Nation color works!
Getting Essentials on enable Both nation and town colors are white by default
This commit is contained in:
parent
58d8d1276f
commit
241992571e
7 changed files with 102 additions and 16 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -78,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);
|
||||
|
|
|
@ -1,4 +1,49 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
public class NationColorCommand {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,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.");
|
||||
|
|
|
@ -1,4 +1,48 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
public class NationColorCommand { //TODO
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,16 +60,20 @@ public class TownColorCommand extends AdminCommandBase {
|
|||
return true;
|
||||
}
|
||||
|
||||
private static Optional<Color> getColorOrSendError(String name, CommandSender sender) {
|
||||
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(col -> String.format("§%x%s§r", col.ordinal(), col.getName())).collect(Collectors.joining(", ")));
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
@ -22,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;
|
||||
|
@ -36,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());
|
||||
|
||||
|
@ -95,9 +93,9 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
if (res == null || !res.hasTown())
|
||||
return name;
|
||||
try {
|
||||
val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase());
|
||||
if (clrs == null)
|
||||
return name;
|
||||
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();
|
||||
AtomicInteger prevlen = new AtomicInteger();
|
||||
BiFunction<Color, Integer, String> anyColoredNamePart = (c, len) -> "§" //Len==0 if last part
|
||||
|
|
Loading…
Reference in a new issue