Added /press command, Dynmap nation color support #97
15 changed files with 141 additions and 69 deletions
|
@ -7,7 +7,7 @@ import buttondevteam.chat.formatting.TellrawEvent;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.formatting.TellrawPart;
|
||||||
import buttondevteam.chat.formatting.TellrawSerializer;
|
import buttondevteam.chat.formatting.TellrawSerializer;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import buttondevteam.chat.listener.PlayerListener;
|
||||||
import buttondevteam.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCChatEventBase;
|
import buttondevteam.lib.TBMCChatEventBase;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
|
|
@ -3,12 +3,13 @@ package buttondevteam.chat;
|
||||||
import buttondevteam.chat.commands.YeehawCommand;
|
import buttondevteam.chat.commands.YeehawCommand;
|
||||||
import buttondevteam.chat.components.announce.AnnouncerComponent;
|
import buttondevteam.chat.components.announce.AnnouncerComponent;
|
||||||
import buttondevteam.chat.components.flair.FlairComponent;
|
import buttondevteam.chat.components.flair.FlairComponent;
|
||||||
|
import buttondevteam.chat.components.fun.FunComponent;
|
||||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||||
import buttondevteam.chat.components.towncolors.TownyListener;
|
import buttondevteam.chat.components.towncolors.TownyListener;
|
||||||
import buttondevteam.chat.components.towny.TownyComponent;
|
import buttondevteam.chat.components.towny.TownyComponent;
|
||||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import buttondevteam.chat.listener.PlayerListener;
|
||||||
import buttondevteam.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.architecture.ButtonPlugin;
|
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
|
@ -67,6 +68,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
|
||||||
Component.registerComponent(this, new TownColorComponent());
|
Component.registerComponent(this, new TownColorComponent());
|
||||||
Component.registerComponent(this, new FlairComponent()); //The original purpose of this plugin
|
Component.registerComponent(this, new FlairComponent()); //The original purpose of this plugin
|
||||||
Component.registerComponent(this, new AnnouncerComponent());
|
Component.registerComponent(this, new AnnouncerComponent());
|
||||||
|
Component.registerComponent(this, new FunComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Essentials essentials = null;
|
public static Essentials essentials = null;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package buttondevteam.chat.commands;
|
package buttondevteam.chat.commands;
|
||||||
|
|
||||||
import buttondevteam.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.TBMCChatEventBase;
|
import buttondevteam.lib.TBMCChatEventBase;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package buttondevteam.chat.commands.ucmds;
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
import buttondevteam.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.chat.ChatMessage;
|
import buttondevteam.lib.chat.ChatMessage;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
@ -43,7 +43,7 @@ public class HistoryCommand extends UCommandBase {
|
||||||
} else {
|
} else {
|
||||||
Optional<Channel> och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(args[0])).findAny();
|
Optional<Channel> och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(args[0])).findAny();
|
||||||
if (!och.isPresent()) {
|
if (!och.isPresent()) {
|
||||||
sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " ooc");
|
sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " g");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
stream = Stream.of(och.get());
|
stream = Stream.of(och.get());
|
||||||
|
|
|
@ -1,40 +1,40 @@
|
||||||
package buttondevteam.chat.commands.ucmds.admin;
|
package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.component.updater.PluginUpdater;
|
import buttondevteam.core.component.updater.PluginUpdater;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class UpdatePlugin extends AdminCommandBase {
|
public class UpdatePlugin extends AdminCommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] GetHelpText(String alias) {
|
public String[] GetHelpText(String alias) {
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
"§6---- Update plugin ----", //
|
"§6---- Update plugin ----", //
|
||||||
"This command downloads the latest version of a TBMC plugin from GitHub", //
|
"This command downloads the latest version of a TBMC plugin from GitHub", //
|
||||||
"To update a plugin: /" + alias + " <plugin>", //
|
"To update a plugin: /" + alias + " <plugin>", //
|
||||||
"To list the plugin names: /" + alias //
|
"To list the plugin names: /" + alias //
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage("Downloading plugin names...");
|
sender.sendMessage("Downloading plugin names...");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (String plugin : PluginUpdater.GetPluginNames()) {
|
for (String plugin : PluginUpdater.GetPluginNames()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
sender.sendMessage("§6---- Plugin names ----");
|
sender.sendMessage("§6---- Plugin names ----");
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
sender.sendMessage("- " + plugin);
|
sender.sendMessage("- " + plugin);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]);
|
TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]);
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package buttondevteam.chat.components.fun;
|
||||||
|
|
||||||
|
import buttondevteam.lib.architecture.Component;
|
||||||
|
import lombok.val;
|
||||||
|
|
||||||
|
public class FunComponent extends Component {
|
||||||
|
@Override
|
||||||
|
protected void enable() {
|
||||||
|
val pc = new PressCommand();
|
||||||
|
registerCommand(pc);
|
||||||
|
registerListener(pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void disable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package buttondevteam.chat.components.fun;
|
||||||
|
|
||||||
|
import buttondevteam.core.component.restart.ScheduledRestartCommand;
|
||||||
|
import buttondevteam.lib.ScheduledServerRestartEvent;
|
||||||
|
import buttondevteam.lib.ThorpeUtils;
|
||||||
|
import buttondevteam.lib.chat.Command2MC;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
@CommandClass
|
||||||
|
public class PressCommand extends Command2MC implements Listener {
|
||||||
|
private HashSet<CommandSender> pressers; //Will be cleared with this class on shutdown/disable
|
||||||
|
private ScheduledRestartCommand command;
|
||||||
|
private int startTicks;
|
||||||
|
|
||||||
|
@Subcommand
|
||||||
|
public void def(CommandSender sender) {
|
||||||
|
if (command == null) {
|
||||||
|
sender.sendMessage("§cThe timer isn't ticking... yet.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pressers.contains(sender)) {
|
||||||
|
sender.sendMessage("§cYou cannot press more than once.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pressers.add(sender);
|
||||||
|
Bukkit.broadcastMessage(String.format("§b-- %s §bpressed at %.0fs", ThorpeUtils.getDisplayName(sender), command.getRestartCounter() / 20f));
|
||||||
|
command.setRestartCounter(startTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void restartEvent(ScheduledServerRestartEvent event) {
|
||||||
|
command = event.getCommand();
|
||||||
|
pressers = new HashSet<>();
|
||||||
|
startTicks = event.getRestartTicks();
|
||||||
|
}
|
||||||
|
}
|
|
@ -77,8 +77,17 @@ public class TownColorComponent extends Component {
|
||||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||||
if (dtp == null)
|
if (dtp == null)
|
||||||
return;
|
return;
|
||||||
for (val entry : TownColors.entrySet())
|
for (val entry : TownColors.entrySet()) {
|
||||||
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue());
|
try {
|
||||||
|
val nation = TownyComponent.TU.getTownsMap().get(entry.getKey()).getNation();
|
||||||
|
Color nc;
|
||||||
|
if (nation == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null)
|
||||||
|
nc = Color.White;
|
||||||
|
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc);
|
||||||
|
} catch (Exception e) {
|
||||||
|
TBMCCoreAPI.SendException("Error while setting town color for town " + entry.getKey() + "!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
registerCommand(new TownColorCommand());
|
registerCommand(new TownColorCommand());
|
||||||
|
@ -104,11 +113,11 @@ public class TownColorComponent extends Component {
|
||||||
* @param colors The town's colors
|
* @param colors The town's colors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors) {
|
public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors, Color nationcolor) {
|
||||||
Function<Color, Integer> c2i = c -> c.getRed() << 16 | c.getGreen() << 8 | c.getBlue();
|
Function<Color, Integer> c2i = c -> c.getRed() << 16 | c.getGreen() << 8 | c.getBlue();
|
||||||
try {
|
try {
|
||||||
DTBridge.setTownColor(dtp, town, c2i.apply(colors[0]),
|
DTBridge.setTownColor(dtp, town, c2i.apply(nationcolor == null ? colors[0] : nationcolor),
|
||||||
c2i.apply(colors.length > 1 ? colors[1] : colors[0]));
|
c2i.apply(colors.length > 1 && nationcolor != null ? colors[1] : colors[0]));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e);
|
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,9 @@ public class NationColorCommand extends AdminCommandBase {
|
||||||
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
||||||
if (!c.isPresent()) return true;
|
if (!c.isPresent()) return true;
|
||||||
if (!c.get().getName().equals(Color.White.getName())) { //Default nation color
|
if (!c.get().getName().equals(Color.White.getName())) { //Default nation color
|
||||||
for (val nc : TownColorComponent.NationColor.values()) {
|
for (val e : TownColorComponent.NationColor.entrySet()) {
|
||||||
if (nc.getName().equals(c.get().getName())) {
|
if (e.getValue().getName().equals(c.get().getName())) {
|
||||||
sender.sendMessage("§cAnother nation already uses this color!");
|
sender.sendMessage("§The nation " + e.getKey() + " already uses this color!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class NationColorCommand extends AdminCommandBase {
|
||||||
for (Town t : nation.getTowns())
|
for (Town t : nation.getTowns())
|
||||||
TownyListener.updateTownMembers(t);
|
TownyListener.updateTownMembers(t);
|
||||||
});
|
});
|
||||||
sender.sendMessage("§bNation color set to §" + TownColorCommand.getColorText(c.get()));
|
sender.sendMessage("§bNation color set to " + TownColorCommand.getColorText(c.get()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,20 +50,21 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
return true;
|
return true;
|
||||||
clrs[i - 1] = c.get();
|
clrs[i - 1] = c.get();
|
||||||
}
|
}
|
||||||
|
Color tnc;
|
||||||
|
try {
|
||||||
|
tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase());
|
||||||
|
} catch (Exception e) {
|
||||||
|
tnc = null;
|
||||||
|
}
|
||||||
|
if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable
|
||||||
for (Map.Entry<String, Color[]> other : TownColorComponent.TownColors.entrySet()) {
|
for (Map.Entry<String, Color[]> other : TownColorComponent.TownColors.entrySet()) {
|
||||||
Color nc, tnc;
|
Color nc;
|
||||||
try {
|
try {
|
||||||
nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
|
nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
|
||||||
} catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways
|
} catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways
|
||||||
nc = null;
|
nc = null;
|
||||||
}
|
}
|
||||||
if (nc == null) nc = Color.White; //Default nation color
|
if (nc == null) nc = Color.White; //Default nation color
|
||||||
try {
|
|
||||||
tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase());
|
|
||||||
} catch (Exception e) {
|
|
||||||
tnc = null;
|
|
||||||
}
|
|
||||||
if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable
|
|
||||||
if (nc.getName().equals(tnc.getName())) {
|
if (nc.getName().equals(tnc.getName())) {
|
||||||
int C = 0;
|
int C = 0;
|
||||||
if (clrs.length == other.getValue().length)
|
if (clrs.length == other.getValue().length)
|
||||||
|
@ -86,7 +87,7 @@ 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;
|
||||||
}
|
}
|
||||||
TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs);
|
TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs, tnc);
|
||||||
sender.sendMessage("§bColor(s) set.");
|
sender.sendMessage("§bColor(s) set.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package buttondevteam.chat.components.towny;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatProcessing;
|
import buttondevteam.chat.ChatProcessing;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import com.palmergames.bukkit.towny.TownyLogger;
|
import com.palmergames.bukkit.towny.TownyLogger;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package buttondevteam.chat.components.towny;
|
package buttondevteam.chat.components.towny;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
|
|
@ -6,10 +6,10 @@ import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||||
import buttondevteam.chat.components.flair.FlairComponent;
|
import buttondevteam.chat.components.flair.FlairComponent;
|
||||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||||
import buttondevteam.component.channel.Channel;
|
|
||||||
import buttondevteam.component.channel.ChatChannelRegisterEvent;
|
|
||||||
import buttondevteam.component.channel.ChatRoom;
|
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
|
import buttondevteam.core.component.channel.Channel;
|
||||||
|
import buttondevteam.core.component.channel.ChatChannelRegisterEvent;
|
||||||
|
import buttondevteam.core.component.channel.ChatRoom;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.ChatMessage;
|
import buttondevteam.lib.chat.ChatMessage;
|
||||||
|
|
|
@ -36,7 +36,7 @@ depend:
|
||||||
- Towny
|
- Towny
|
||||||
- Votifier
|
- Votifier
|
||||||
- Vault
|
- Vault
|
||||||
- ButtonCore
|
- ThorpeCore
|
||||||
soft-depend:
|
soft-depend:
|
||||||
- Minigames
|
- Minigames
|
||||||
- Dynmap-Towny
|
- Dynmap-Towny
|
||||||
|
|
|
@ -7,8 +7,8 @@ import buttondevteam.chat.formatting.TellrawEvent;
|
||||||
import buttondevteam.chat.formatting.TellrawEvent.ClickAction;
|
import buttondevteam.chat.formatting.TellrawEvent.ClickAction;
|
||||||
import buttondevteam.chat.formatting.TellrawEvent.HoverAction;
|
import buttondevteam.chat.formatting.TellrawEvent.HoverAction;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.formatting.TellrawPart;
|
||||||
import buttondevteam.component.channel.Channel;
|
|
||||||
import buttondevteam.core.TestPrepare;
|
import buttondevteam.core.TestPrepare;
|
||||||
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
Loading…
Reference in a new issue