Fixed respect, town colors etc.

Fixed respect display to 2 decimals
(Fixed a "critical" bug in... 25 days) #73
Fixed town colors hopefully (#74)
Fixed /u ncolor requiring the ~
Added support for colons for ncolor

Yesterday I already woke up by this time and I'm still not sleeping now
This commit is contained in:
Norbi Peti 2018-05-21 03:55:41 +02:00
parent ef2328e126
commit 68de2f36cf
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
6 changed files with 54 additions and 32 deletions

View file

@ -106,7 +106,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
if (dtp == null)
return;
for (val entry : TownColors.entrySet())
setTownColor(dtp, entry.getKey(), entry.getValue());
setTownColor(dtp, buttondevteam.chat.commands.ucmds.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue());
});
if (!setupEconomy() || !setupPermissions())
@ -116,15 +116,22 @@ 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);
}
}
/**
* Sets a town's color on Dynmap.
*
* @param dtp A reference for the Dynmap-Towny plugin
* @param town The town's name using the correct casing
* @param colors The town's colors
*/
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;
@ -272,7 +279,10 @@ 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;
public static Map<String, Color[]> TownColors = new HashMap<>();
/**
* Names lowercased
*/
public static Map<String, Color[]> TownColors = new HashMap<>();
@SuppressWarnings("unchecked")
public static void LoadFiles() {

View file

@ -36,8 +36,16 @@ public class FTopCommand extends TBMCCommandBase {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
.map(f -> TBMCPlayerBase.getPlayer(
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class))
.filter(f -> f.getName().length() > 4)
.map(f -> {
try {
return TBMCPlayerBase.getPlayer(
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class);
} catch (Exception e) {
return null;
}
})
.filter(Objects::nonNull)
.sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF()))
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
lastcache = System.nanoTime();

View file

@ -45,28 +45,29 @@ public class NColorCommand extends UCommandBase {
}
if (args.length == 0)
return false;
String arg = player.getDisplayName().startsWith("~") ? "~" + args[0] : args[0]; //Add ~ for nicknames
if (!args[0].replace("|", "").equalsIgnoreCase(ChatColor.stripColor(player.getDisplayName()))) {
final String name = ChatColor.stripColor(player.getDisplayName());
String arg = name.startsWith("~") ? "~" + args[0] : args[0]; //Add ~ for nicknames
if (!arg.replace("|", "").replace(":", "").equalsIgnoreCase(name)) {
player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use "
+ ChatColor.stripColor(player.getDisplayName()) + "§c with added vertical lines (|).");
+ name + "§c with added vertical lines (|) or colons (:).");
return true;
}
String[] nameparts = args[0].split("\\|");
String[] nameparts = arg.split("\\|");
Color[] towncolors = PluginMain.TownColors.get(town.getName().toLowerCase());
if (towncolors == null) {
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
return true;
}
if (nameparts.length < towncolors.length) {
player.sendMessage("§cYou need more vertical lines (|) in your name. (Should have " + (towncolors.length - 1) + ")");
player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")");
return true;
}
if (nameparts.length > towncolors.length * 2) {
player.sendMessage("§cYou have waay too many vertical lines (|) in your name. (Should have " + (towncolors.length - 1) + ")");
player.sendMessage("§cYou have waay too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")");
return true;
}
if (nameparts.length > towncolors.length) {
player.sendMessage("§cYou have too many vertical lines (|) in your name. (Should have " + (towncolors.length - 1) + ")");
player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")");
return true;
}
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()

View file

@ -67,8 +67,12 @@ public class TownColorCommand extends AdminCommandBase {
PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!");
return true;
}
PluginMain.setTownColor(dtp, args[0].toLowerCase(), clrs);
PluginMain.setTownColor(dtp, getTownNameCased(args[0]), clrs);
sender.sendMessage("§bColor(s) set.");
return true;
}
public static String getTownNameCased(String name) {
return PluginMain.TU.getTownsMap().get(name.toLowerCase()).getName();
}
}

View file

@ -53,7 +53,7 @@ public class PlayerListener implements Listener {
public static boolean ShowRPTag = false;
public final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", "kek", "lmao", "hue", "hah" };
public final static String[] LaughStrings = new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"};
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
@ -262,7 +262,7 @@ public class PlayerListener implements Listener {
final String flair = cp.GetFormattedFlair(e.getTarget() != InfoTarget.MCCommand);
if (flair.length() > 0)
e.addInfo("/r/TheButton flair: " + flair);
e.addInfo("Respect: " + cp.getF());
e.addInfo(String.format("Respect: %.2f", cp.getF()));
} catch (Exception ex) {
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
}

View file

@ -1,16 +1,15 @@
package org.dynmap.towny;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.dynmap.bukkit.DynmapPlugin;
import org.dynmap.markers.MarkerAPI;
import lombok.val;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
public class DTBridge {
/**
@ -19,7 +18,7 @@ public class DTBridge {
* @param dtp
* The Dynmap-Towny plugin
* @param townname
* The name of the town
* The name of the town, using correct casing
* @param strokecolor
* The stroke color in RGB format
* @param fillcolor
@ -32,14 +31,14 @@ public class DTBridge {
IllegalAccessException, NoSuchMethodException, InstantiationException, InvocationTargetException {
Class<?> cl = Class.forName(DynmapTownyPlugin.class.getName() + "$AreaStyle");
Field field = DynmapTownyPlugin.class.getDeclaredField("cusstyle");
field.setAccessible(true); // DOesn't allow accessing it from the same package, if it's from a different plugin
field.setAccessible(true); // Doesn't allow accessing it from the same package, if it's from a different plugin
@SuppressWarnings("unchecked")
val map = (Map<String, Object>) field.get(dtp);
Object style = map.get(townname);
if (style == null) {
Constructor<?> c = cl.getDeclaredConstructor(FileConfiguration.class, String.class, MarkerAPI.class);
c.setAccessible(true);
style = c.newInstance(dtp.getConfig(), "custstyle" + townname,
style = c.newInstance(dtp.getConfig(), "custstyle." + townname,
((DynmapPlugin) Bukkit.getPluginManager().getPlugin("dynmap")).getMarkerAPI());
map.put(townname, style);
}