Skip to content

Commit

Permalink
Allow MOTD to be changed dynamically
Browse files Browse the repository at this point in the history
Signed-off-by: ChemistryX <[email protected]>
  • Loading branch information
chemistryx authored and Electroid committed Nov 1, 2019
1 parent 95d91ab commit dd95d58
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/tc/oc/pgm/commands/AdminCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ public static void cancel(CommandSender sender, Match match) {
ChatColor.GREEN + AllTranslations.get().translate("command.admin.cancel.success", sender));
}

@Command(
aliases = {"pgm"},
desc = "Reload the PGM configuration",
perms = Permissions.RELOAD)
public void pgm(CommandSender sender) {
PGM.get().reloadConfig();
sender.sendMessage(
ChatColor.GREEN + AllTranslations.get().translate("command.admin.pgm", sender));
}

private static Map<String, Competitor> getCompetitorMap(CommandSender sender, Match match) {
return match.getCompetitors().stream()
.map(competitor -> new AbstractMap.SimpleEntry<>(competitor.getName(sender), competitor))
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/tc/oc/pgm/listeners/MotdListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;
import tc.oc.pgm.Config;
import tc.oc.pgm.events.ConfigLoadEvent;
import tc.oc.pgm.events.MatchLoadEvent;
import tc.oc.pgm.events.MatchStateChangeEvent;

Expand All @@ -21,7 +22,7 @@ public class MotdListener implements Listener {
private static final String STATE_NAME_LOWER_KEY = "state.name-lower";

private static final Map<String, String> MOTD_DATA = Maps.newHashMap();
private final String format;
private String format;

// Show the default MOTD until a match has loaded
private boolean ready = false;
Expand All @@ -44,6 +45,11 @@ public void onServerListPing(ServerListPingEvent event) {
event.setMotd(motd);
}

@EventHandler
public void onConfigReload(ConfigLoadEvent event) {
this.format = Config.Motd.format();
}

@EventHandler
public void onLoad(MatchLoadEvent event) {
MOTD_DATA.put(MAP_NAME_KEY, event.getMatch().getMapInfo().name);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/tc/oc/server/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface Permissions {
String DEFUSE = ROOT + ".defuse"; // Defuse tnt from observers using shears
String DEBUG = ROOT + ".debug"; // Errors from map loading and debug commands
String STAFF = ROOT + ".staff"; // Considered apart of the staff team
String RELOAD = ROOT + ".reload"; // Reload the PGM configuration

// Role-specific permission nodes
Permission DEFAULT =
Expand Down Expand Up @@ -69,6 +70,7 @@ public interface Permissions {
.putAll(MODERATOR.getChildren())
.put(GAMEPLAY, true)
.put(DEBUG, true)
.put(RELOAD, true)
.build());

Permission ALL = new Permission("pgm.*", PermissionDefault.OP, DEVELOPER.getChildren());
Expand Down

0 comments on commit dd95d58

Please sign in to comment.