Skip to content

Commit 576ff0c

Browse files
committed
- Reset a player's cache when they are op'd or deop'd.
1 parent 2871f43 commit 576ff0c

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Towny/src/main/java/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import com.palmergames.util.StringMgmt;
4848

4949
import io.papermc.lib.PaperLib;
50+
51+
import org.bukkit.Bukkit;
5052
import org.bukkit.ChatColor;
5153
import org.bukkit.Location;
5254
import org.bukkit.Material;
@@ -1130,7 +1132,9 @@ public void onPlayerTakeLecternBookEvent(PlayerTakeLecternBookEvent event) {
11301132
public void onPlayerUsesCommand(PlayerCommandPreprocessEvent event) {
11311133
if (plugin.isError() || !TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld()))
11321134
return;
1133-
1135+
1136+
checkForOpDeOpCommand(event);
1137+
11341138
Resident resident = TownyUniverse.getInstance().getResident(event.getPlayer().getUniqueId());
11351139

11361140
// More than likely another plugin using a fake player to run a command or,
@@ -1157,6 +1161,31 @@ public void onPlayerUsesCommand(PlayerCommandPreprocessEvent event) {
11571161
event.setCancelled(true);
11581162
}
11591163

1164+
private void checkForOpDeOpCommand(PlayerCommandPreprocessEvent event) {
1165+
String[] args = CommandList.normalizeCommand(event.getMessage()).split(" ");
1166+
String command = args[0];
1167+
// Fail early if we aren't looking at /op|deop [playername]
1168+
if ((!command.equalsIgnoreCase("op") && !command.equalsIgnoreCase("deop")) || args.length != 2)
1169+
return;
1170+
1171+
// Get the target.
1172+
Player target = Bukkit.getPlayer(args[1]);
1173+
if (target == null || !target.isOnline())
1174+
return;
1175+
1176+
// Make sure they have the permission to run the command.
1177+
if (!event.getPlayer().hasPermission("minecraft.command." + command))
1178+
return;
1179+
1180+
// Make sure they're not running the command which will have no effect.
1181+
if (target.isOp() == "op".equalsIgnoreCase(command))
1182+
return;
1183+
1184+
// Delete the online player's cache because they have been op'd or deop'd.
1185+
Towny plugin = Towny.getPlugin();
1186+
plugin.getScheduler().runLater(target, () -> plugin.deleteCache(target), 1L);
1187+
}
1188+
11601189
public boolean blockWarPlayerCommand(Player player, Resident resident, String command) {
11611190
if (resident.hasTown() && resident.getTownOrNull().hasActiveWar() && blockedWarCommands.containsCommand(command)) {
11621191
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_command_war_blocked"));
@@ -1394,7 +1423,7 @@ public void onPlayerPickupItem(EntityPickupItemEvent event) {
13941423
}
13951424
}
13961425

1397-
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
1426+
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
13981427
public void onPlayerChangeGameMode(PlayerGameModeChangeEvent event) {
13991428
if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld()))
14001429
return;

Towny/src/main/resources/ChangeLog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9113,4 +9113,5 @@ v0.92.0.11:
91139113
0.99.6.0:
91149114
- Bump version number for release.
91159115
0.99.6.1:
9116-
- Reset a player's cache when they change gamemodes.
9116+
- Reset a player's cache when they change gamemodes.
9117+
- Reset a player's cache when they are op'd or deop'd.

0 commit comments

Comments
 (0)