Skip to content

Commit

Permalink
Add in-chat update alerts.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Oct 1, 2024
1 parent 5c39d76 commit 5757601
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/lewmc/essence/Essence.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public class Essence extends JavaPlugin {
*/
public List<String> disabledCommands;

/**
* Stores update status.
*/
public boolean hasPendingUpdate = false;

/**
* This function runs when Essence is enabled.
*/
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/lewmc/essence/events/JoinEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public void onPlayerJoin(PlayerJoinEvent event) {
this.spawn(event, log);
}

if (this.plugin.hasPendingUpdate) {
this.showUpdateAlert(event);
}

FileUtil playerFile = new FileUtil(plugin);
String playerDataFile = playerFile.playerDataFile(event.getPlayer());

Expand Down Expand Up @@ -178,4 +182,17 @@ private void playerJoinMessage(PlayerJoinEvent event) {
event.setJoinMessage(tag.doReplacement(this.plugin.getConfig().getString("broadcasts.first-join")));
}
}

/**
* Displays the update alert.
* @param event PlayerJoinEvent - The event
*/
private void showUpdateAlert(PlayerJoinEvent event) {
MessageUtil msg = new MessageUtil(event.getPlayer(), this.plugin);
PermissionHandler perms = new PermissionHandler(event.getPlayer(), msg);
if (perms.has("essence.admin.updates") && this.plugin.hasPendingUpdate) {
msg.send("other", "updatemsg");
msg.send("other", "updatemore");
}
}
}
1 change: 1 addition & 0 deletions src/main/java/net/lewmc/essence/utils/UpdateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void VersionCheck() {
log.warn("UPDATE > Your version: "+this.plugin.getDescription().getVersion()+" - latest version: "+response);
log.warn("UPDATE > You can download the latest version from lewmc.net/essence");
this.log.info("");
this.plugin.hasPendingUpdate = true;
}
} else {
log.severe("Unable to perform update check: There was no response from the server.");
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/language/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ generic:
other:
respawnset: "§6[Essence] §eRespawn point set."
rule: "§a{{1}}"
updatemsg: "§4[Essence] §cYour version of Essence is out of date!"
updatemore: "§4[Essence] §cSee the server console for more information."
help:
page: "§6[Essence] ----------------- Page {{1}}/{{2}} -----------------"
inventory: "§6[Essence] --------- Essence Help - Inventory ---------"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ permissions:
essence.admin.reload: true
essence.admin.import: true
essence.admin.invisible: true
essence.admin.updates: true
essence.admin.seen:
description: Allows players to see when the player was last online.
essence.admin.info:
Expand All @@ -522,5 +523,7 @@ permissions:
description: Allows players to reload Essence.
essence.admin.invisible:
description: Toggles invisibility.
essence.admin.updates:
description: Toggles invisibility.
essence.rules:
description: Allows players to view the server rules.

0 comments on commit 5757601

Please sign in to comment.