Added /press command, Dynmap NC support

#40
Both tested and work
This commit is contained in:
Norbi Peti 2019-01-30 21:16:02 +01:00
parent 3a29010042
commit f12912c735
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
15 changed files with 137 additions and 65 deletions

View file

@ -7,7 +7,7 @@ import buttondevteam.chat.formatting.TellrawEvent;
import buttondevteam.chat.formatting.TellrawPart;
import buttondevteam.chat.formatting.TellrawSerializer;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.component.channel.Channel;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCChatEventBase;
import buttondevteam.lib.TBMCCoreAPI;

View file

@ -3,12 +3,13 @@ package buttondevteam.chat;
import buttondevteam.chat.commands.YeehawCommand;
import buttondevteam.chat.components.announce.AnnouncerComponent;
import buttondevteam.chat.components.flair.FlairComponent;
import buttondevteam.chat.components.fun.FunComponent;
import buttondevteam.chat.components.towncolors.TownColorComponent;
import buttondevteam.chat.components.towncolors.TownyListener;
import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.component.channel.Channel;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.ButtonPlugin;
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 FlairComponent()); //The original purpose of this plugin
Component.registerComponent(this, new AnnouncerComponent());
Component.registerComponent(this, new FunComponent());
}
public static Essentials essentials = null;

View file

@ -1,6 +1,6 @@
package buttondevteam.chat.commands;
import buttondevteam.component.channel.Channel;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCChatEventBase;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCCommandBase;

View file

@ -1,6 +1,6 @@
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.CommandClass;
import lombok.RequiredArgsConstructor;

View file

@ -1,40 +1,40 @@
package buttondevteam.chat.commands.ucmds.admin;
import buttondevteam.chat.PluginMain;
import buttondevteam.component.updater.PluginUpdater;
import buttondevteam.lib.TBMCCoreAPI;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
public class UpdatePlugin extends AdminCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { //
"§6---- Update plugin ----", //
"This command downloads the latest version of a TBMC plugin from GitHub", //
"To update a plugin: /" + alias + " <plugin>", //
"To list the plugin names: /" + alias //
};
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
if (args.length == 0) {
sender.sendMessage("Downloading plugin names...");
boolean first = true;
for (String plugin : PluginUpdater.GetPluginNames()) {
if (first) {
sender.sendMessage("§6---- Plugin names ----");
first = false;
}
sender.sendMessage("- " + plugin);
}
} else
TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]);
});
return true;
}
}
package buttondevteam.chat.commands.ucmds.admin;
import buttondevteam.chat.PluginMain;
import buttondevteam.core.component.updater.PluginUpdater;
import buttondevteam.lib.TBMCCoreAPI;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
public class UpdatePlugin extends AdminCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { //
"§6---- Update plugin ----", //
"This command downloads the latest version of a TBMC plugin from GitHub", //
"To update a plugin: /" + alias + " <plugin>", //
"To list the plugin names: /" + alias //
};
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
if (args.length == 0) {
sender.sendMessage("Downloading plugin names...");
boolean first = true;
for (String plugin : PluginUpdater.GetPluginNames()) {
if (first) {
sender.sendMessage("§6---- Plugin names ----");
first = false;
}
sender.sendMessage("- " + plugin);
}
} else
TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]);
});
return true;
}
}

View file

@ -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() {
}
}

View file

@ -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();
}
}

View file

@ -77,8 +77,17 @@ public class TownColorComponent extends Component {
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
if (dtp == null)
return;
for (val entry : TownColors.entrySet())
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue());
for (val entry : TownColors.entrySet()) {
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());
@ -104,11 +113,11 @@ public class TownColorComponent extends Component {
* @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();
try {
DTBridge.setTownColor(dtp, town, c2i.apply(colors[0]),
c2i.apply(colors.length > 1 ? colors[1] : colors[0]));
DTBridge.setTownColor(dtp, town, c2i.apply(nationcolor == null ? colors[0] : nationcolor),
c2i.apply(colors.length > 1 && nationcolor != null ? colors[1] : colors[0]));
} catch (Exception e) {
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e);
}

View file

@ -54,7 +54,7 @@ public class NationColorCommand extends AdminCommandBase {
for (Town t : nation.getTowns())
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;
}
}

View file

@ -50,20 +50,21 @@ public class TownColorCommand extends AdminCommandBase {
return true;
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()) {
Color nc, tnc;
Color nc;
try {
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
nc = null;
}
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())) {
int C = 0;
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!");
return true;
}
TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs);
TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs, tnc);
sender.sendMessage("§bColor(s) set.");
return true;
}

View file

@ -2,7 +2,7 @@ package buttondevteam.chat.components.towny;
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.PluginMain;
import buttondevteam.component.channel.Channel;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.chat.TBMCChatAPI;
import com.palmergames.bukkit.towny.TownyLogger;
import lombok.val;

View file

@ -1,7 +1,7 @@
package buttondevteam.chat.components.towny;
import buttondevteam.chat.PluginMain;
import buttondevteam.component.channel.Channel;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI;

View file

@ -6,10 +6,10 @@ import buttondevteam.chat.PluginMain;
import buttondevteam.chat.commands.ucmds.HistoryCommand;
import buttondevteam.chat.components.flair.FlairComponent;
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.component.channel.Channel;
import buttondevteam.core.component.channel.ChatChannelRegisterEvent;
import buttondevteam.core.component.channel.ChatRoom;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.ChatMessage;

View file

@ -36,7 +36,7 @@ depend:
- Towny
- Votifier
- Vault
- ButtonCore
- ThorpeCore
soft-depend:
- Minigames
- Dynmap-Towny

View file

@ -7,8 +7,8 @@ import buttondevteam.chat.formatting.TellrawEvent;
import buttondevteam.chat.formatting.TellrawEvent.ClickAction;
import buttondevteam.chat.formatting.TellrawEvent.HoverAction;
import buttondevteam.chat.formatting.TellrawPart;
import buttondevteam.component.channel.Channel;
import buttondevteam.core.TestPrepare;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.chat.Color;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.command.CommandSender;