Inst. update on Dynmap, cmd for mayors, fix

Well, update every ~5 mins on Dynmap, as DT updates
Command for setting town color count added too
This commit is contained in:
Norbi Peti 2017-10-01 20:07:15 +02:00
parent b5e8e0f93c
commit 06ea519987
4 changed files with 123 additions and 11 deletions

View file

@ -18,6 +18,7 @@ import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import buttondevteam.chat.commands.YeehawCommand;
import buttondevteam.chat.commands.ucmds.TownColorCommand;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel;
@ -115,15 +116,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
if (dtp == null)
return;
for (val entry : TownColors.entrySet()) {
Function<Color, Integer> c2i = c -> c.getRed() << 4 | c.getGreen() << 2 | c.getBlue();
try {
DTBridge.setTownColor(dtp, entry.getKey(), c2i.apply(entry.getValue()[0]),
c2i.apply(entry.getValue().length > 1 ? entry.getValue()[1] : entry.getValue()[0]));
} catch (Exception e) {
TBMCCoreAPI.SendException("Failed to set town color for town " + entry.getKey() + "!", e);
}
}
for (val entry : TownColors.entrySet())
setTownColor(dtp, entry.getKey(), entry.getValue());
});
setupChat();
@ -134,6 +128,16 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
new Thread(new AnnouncerThread()).start();
}
public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors) {
Function<Color, Integer> c2i = c -> c.getRed() << 16 | c.getGreen() << 8 | c.getBlue();
try {
DTBridge.setTownColor(dtp, town, c2i.apply(colors[0]),
c2i.apply(colors.length > 1 ? colors[1] : colors[0]));
} catch (Exception e) {
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e);
}
}
public Boolean stop = false;
public static Essentials essentials = null;
@ -300,6 +304,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
TownColors.putAll(cs.getValues(true).entrySet().stream()
.collect(Collectors.toMap(k -> k.getKey(), v -> ((List<String>) v.getValue()).stream()
.map(c -> Color.valueOf(c)).toArray(Color[]::new))));
TownColorCommand.ColorCount = (byte) yc.getInt("towncolorcount", 1);
}
PluginMain.Instance.getLogger().info("Loaded files!");
} catch (Exception e) {
@ -319,6 +324,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(k -> k.getKey(),
v -> Arrays.stream(v.getValue()).map(c -> c.toString()).toArray(String[]::new))));
yc.set("towncolorcount", TownColorCommand.ColorCount);
yc.save(file);
PluginMain.Instance.getLogger().info("Saved files!");
} catch (Exception e) {

View file

@ -0,0 +1,67 @@
package buttondevteam.chat.commands.ucmds;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.dynmap.towny.DynmapTownyPlugin;
import com.mysql.fabric.xmlrpc.base.Array;
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.Color;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
import lombok.val;
@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>";
for (int i = 2; i <= ColorCount; i++)
cns += " [colorname" + i + "]";
return new String[] { //
"§6---- Town Color ----", //
"This command allows setting a color for a town.", //
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
"The colors will split the name evenly.", //
"Usage: /" + GetCommandPath() + cns, //
"Example: /" + GetCommandPath() + " blue" //
};
}
public static byte ColorCount;
@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.");
return true;
}
if (args.length > ColorCount) {
player.sendMessage("You can only use " + ColorCount + " color" + (ColorCount > 1 ? "(s)" : "") + ".");
return true;
}
String[] a = new String[args.length + 1];
System.arraycopy(args, 0, a, 1, args.length);
try {
a[0] = res.getTown().getName().toLowerCase();
} catch (NotRegisteredException e) {
TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e);
player.sendMessage("§cCouldn't find your town... Error reported.");
return true;
}
return buttondevteam.chat.commands.ucmds.admin.TownColorCommand.SetTownColor(player, alias, a);
}
}

View file

@ -0,0 +1,27 @@
package buttondevteam.chat.commands.ucmds.admin;
import org.bukkit.command.CommandSender;
public class TCCount extends AdminCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { //
"§6---- Town Color Count", //
"Sets how many colors can be used for a town." //
};
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
byte count;
try {
if (args.length == 0 || (count = Byte.parseByte(args[0])) <= 0)
return false;
} catch (NumberFormatException e) {
return false;
}
buttondevteam.chat.commands.ucmds.TownColorCommand.ColorCount = count;
sender.sendMessage("Color count set to " + count);
return true;
}
}

View file

@ -2,7 +2,9 @@ package buttondevteam.chat.commands.ucmds.admin;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.dynmap.towny.DynmapTownyPlugin;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.Color;
@ -23,9 +25,13 @@ public class TownColorCommand extends AdminCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
return SetTownColor(sender, alias, args);
}
public static boolean SetTownColor(CommandSender sender, String alias, String[] args) {
if (args.length < 2)
return false;
if (!PluginMain.TU.getTownsMap().containsKey(args[0])) {
if (!PluginMain.TU.getTownsMap().containsKey(args[0].toLowerCase())) {
sender.sendMessage("§cThe town '" + args[0] + "' cannot be found.");
return true;
}
@ -39,7 +45,13 @@ public class TownColorCommand extends AdminCommandBase {
}
clrs[i - 1] = c.get();
}
PluginMain.TownColors.put(args[0], clrs);
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
if (dtp == null) {
sender.sendMessage("§cDynmap-Towny couldn'5 be found to set town color.");
return true;
}
PluginMain.setTownColor(dtp, args[0].toLowerCase(), clrs);
sender.sendMessage("§bColor(s) set.");
return true;
}