-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 重写检查更新,现在会在控制台输出当前版本到最新版本的更新内容并且OP每日第一次进游戏时会收到更新提醒. - 权限 servermonitor.use 更改为 servermonitor.admin
- Loading branch information
Showing
5 changed files
with
149 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/net/myunco/servermonitor/update/UpdateNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.myunco.servermonitor.update; | ||
|
||
import net.myunco.servermonitor.ServerMonitor; | ||
import net.myunco.servermonitor.config.Language; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.UUID; | ||
|
||
public class UpdateNotification implements Listener { | ||
private int day = LocalDate.now().getDayOfMonth(); | ||
private final ArrayList<UUID> notifiedPlayers = new ArrayList<>(); | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
public void onPlayerJoin(PlayerJoinEvent event) { | ||
if (UpdateChecker.isUpdateAvailable && event.getPlayer().hasPermission("servermonitor.admin")) { | ||
if (day != LocalDate.now().getDayOfMonth()) { | ||
day = LocalDate.now().getDayOfMonth(); | ||
if (!notifiedPlayers.isEmpty()) { | ||
notifiedPlayers.clear(); | ||
} | ||
} | ||
if (!notifiedPlayers.contains(event.getPlayer().getUniqueId())) { | ||
notifiedPlayers.add(event.getPlayer().getUniqueId()); | ||
ServerMonitor.getPlugin().getServer().getScheduler().runTaskLaterAsynchronously(ServerMonitor.getPlugin(), () -> { | ||
event.getPlayer().sendMessage(Language.messagePrefix + UpdateChecker.newVersion); | ||
event.getPlayer().sendMessage(Language.messagePrefix + UpdateChecker.downloadLink); | ||
}, 60); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters