*Hacked* town colors into Dynmap-Towny
This commit is contained in:
parent
9abcde610e
commit
b5e8e0f93c
5 changed files with 89 additions and 0 deletions
10
pom.xml
10
pom.xml
|
@ -195,6 +195,16 @@
|
|||
<version>1.12.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap-Towny</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>ButtonChat</artifactId>
|
||||
<organization>
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.dynmap.towny.DTBridge;
|
||||
import org.dynmap.towny.DynmapTownyPlugin;
|
||||
import org.htmlcleaner.HtmlCleaner;
|
||||
import org.htmlcleaner.TagNode;
|
||||
|
||||
|
@ -53,6 +55,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||
|
@ -108,6 +111,21 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
return true; // TODO: Allow hiding it
|
||||
}, "You need to show the RP chat in order to speak in it.")));
|
||||
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setupChat();
|
||||
setupEconomy();
|
||||
setupPermissions();
|
||||
|
|
4
src/main/java/com/palmergames/bukkit/TownyChat/Chat.java
Normal file
4
src/main/java/com/palmergames/bukkit/TownyChat/Chat.java
Normal file
|
@ -0,0 +1,4 @@
|
|||
package com.palmergames.bukkit.TownyChat;
|
||||
|
||||
public class Chat {
|
||||
}
|
56
src/main/java/org/dynmap/towny/DTBridge.java
Normal file
56
src/main/java/org/dynmap/towny/DTBridge.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package org.dynmap.towny;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.dynmap.bukkit.DynmapPlugin;
|
||||
import org.dynmap.markers.MarkerAPI;
|
||||
|
||||
import lombok.val;
|
||||
|
||||
public class DTBridge {
|
||||
/**
|
||||
* Sets the town color on Dynmap.
|
||||
*
|
||||
* @param dtp
|
||||
* The Dynmap-Towny plugin
|
||||
* @param townname
|
||||
* The name of the town
|
||||
* @param strokecolor
|
||||
* The stroke color in RGB format
|
||||
* @param fillcolor
|
||||
* The fill color in RGB format
|
||||
* @throws Exception
|
||||
* When couldn't set the town color
|
||||
*/
|
||||
public static void setTownColor(DynmapTownyPlugin dtp, String townname, int strokecolor, int fillcolor)
|
||||
throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, // Keeping these because why not
|
||||
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
|
||||
@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,
|
||||
((DynmapPlugin) Bukkit.getPluginManager().getPlugin("dynmap")).getMarkerAPI());
|
||||
map.put(townname, style);
|
||||
}
|
||||
set(cl, style, "fillcolor", fillcolor);
|
||||
set(cl, style, "strokecolor", strokecolor);
|
||||
}
|
||||
|
||||
private static <T> void set(Class<?> cl, Object style, String fieldname, T value)
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
Field field = cl.getDeclaredField(fieldname);
|
||||
field.setAccessible(true);
|
||||
field.set(style, value);
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ depend:
|
|||
- Votifier
|
||||
- Vault
|
||||
- ButtonCore
|
||||
- Dynmap-Towny
|
||||
soft-depend:
|
||||
- Minigames
|
||||
permissions:
|
||||
|
|
Loading…
Reference in a new issue