Skip to content

Commit 1cf6b62

Browse files
authored
gui perms fixed
Each punishment type now requires its specific permission (weguardian.ban, weguardian.tempban, weguardian.mute, weguardian.tempmute, weguardian.kick) to be used through the GUI, matching the behavior of the command-based system.
1 parent 776d44c commit 1cf6b62

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

src/main/java/me/wethink/weguardian/gui/DurationGUI.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
import org.bukkit.entity.Player;
1212
import org.bukkit.inventory.ItemStack;
1313

14-
1514
public class DurationGUI extends FastInv {
1615

17-
1816
private static ItemStack GLASS_PANE;
1917
private static ItemStack BACK_BUTTON;
2018
private static ItemStack PERM_ITEM;
@@ -36,7 +34,6 @@ public class DurationGUI extends FastInv {
3634
private static long DURATION_30D;
3735
private static long DURATION_90D;
3836

39-
4037
public static void initializeIcons() {
4138
DURATION_1H = TimeUtil.parseDuration("1h");
4239
DURATION_6H = TimeUtil.parseDuration("6h");
@@ -84,7 +81,6 @@ public static void initializeIcons() {
8481
DAYS_90 = createDurationItem(Material.BLUE_DYE, "&990 Days", DURATION_90D);
8582
}
8683

87-
8884
private static ItemStack createDurationItem(Material material, String name, long durationMs) {
8985
return new ItemBuilder(material)
9086
.name(MessageUtil.colorize(name))
@@ -96,7 +92,6 @@ private static ItemStack createDurationItem(Material material, String name, long
9692
.build();
9793
}
9894

99-
10095
private final WeGuardian plugin;
10196
private final Player staff;
10297
private final OfflinePlayer target;
@@ -111,7 +106,6 @@ public DurationGUI(WeGuardian plugin, Player staff, OfflinePlayer target, Punish
111106
this.type = type;
112107
}
113108

114-
115109
public void build() {
116110
for (int i = 0; i < 9; i++) {
117111
setItem(i, GLASS_PANE);
@@ -129,6 +123,10 @@ public void build() {
129123
setItem(22, PERM_ITEM, e -> {
130124
staff.closeInventory();
131125
PunishmentType permType = type == PunishmentType.TEMPBAN ? PunishmentType.BAN : PunishmentType.MUTE;
126+
if (!staff.hasPermission(permType.getPermission())) {
127+
staff.sendMessage(MessageUtil.toComponent("&cYou don't have permission to use permanent punishments!"));
128+
return;
129+
}
132130
new ReasonInputHandler(plugin, staff, target, permType, -1).start();
133131
});
134132

@@ -140,8 +138,6 @@ public void build() {
140138
setItem(27, BACK_BUTTON, e -> PunishmentGUI.openAsync(plugin, staff, target));
141139
}
142140

143-
144-
145141
private void selectDuration(long durationMs) {
146142
staff.closeInventory();
147143
new ReasonInputHandler(plugin, staff, target, type, durationMs).start();
@@ -151,7 +147,6 @@ public void open() {
151147
open(staff);
152148
}
153149

154-
155150
public static void openAsync(WeGuardian plugin, Player staff, OfflinePlayer target, PunishmentType type) {
156151
plugin.getSchedulerManager().runAsync(() -> {
157152
DurationGUI gui = new DurationGUI(plugin, staff, target, type);

src/main/java/me/wethink/weguardian/gui/PunishmentGUI.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
import java.util.function.Consumer;
1414

15-
1615
public class PunishmentGUI extends FastInv {
1716

18-
1917
private static ItemStack GLASS_PANE;
2018
private static ItemStack BAN_ITEM;
2119
private static ItemStack TEMP_BAN_ITEM;
@@ -25,7 +23,6 @@ public class PunishmentGUI extends FastInv {
2523
private static ItemStack HISTORY_ITEM;
2624
private static ItemStack CLOSE_ITEM;
2725

28-
2926
public static void initializeIcons() {
3027
GLASS_PANE = new ItemBuilder(Material.GRAY_STAINED_GLASS_PANE)
3128
.name(" ")
@@ -99,16 +96,13 @@ public static void initializeIcons() {
9996
.build();
10097
}
10198

102-
10399
private static final Consumer<org.bukkit.event.inventory.InventoryClickEvent> CLOSE_HANDLER = e -> e
104100
.getWhoClicked().closeInventory();
105101

106-
107102
private final WeGuardian plugin;
108103
private final Player staff;
109104
private final OfflinePlayer target;
110105

111-
112106
public PunishmentGUI(WeGuardian plugin, Player staff, OfflinePlayer target) {
113107
super(45, MessageUtil.colorize("&c&lPunish &8» &e" + target.getName()));
114108

@@ -117,7 +111,6 @@ public PunishmentGUI(WeGuardian plugin, Player staff, OfflinePlayer target) {
117111
this.target = target;
118112
}
119113

120-
121114
public void build() {
122115
for (int i = 0; i < 9; i++) {
123116
setItem(i, GLASS_PANE);
@@ -130,11 +123,21 @@ public void build() {
130123
setItem(27, GLASS_PANE);
131124
setItem(35, GLASS_PANE);
132125

133-
setItem(11, BAN_ITEM, e -> openReasonInput(PunishmentType.BAN, -1));
134-
setItem(12, TEMP_BAN_ITEM, e -> openDurationGUIAsync(PunishmentType.TEMPBAN));
135-
setItem(13, KICK_ITEM, e -> openReasonInput(PunishmentType.KICK, -1));
136-
setItem(14, MUTE_ITEM, e -> openReasonInput(PunishmentType.MUTE, -1));
137-
setItem(15, TEMP_MUTE_ITEM, e -> openDurationGUIAsync(PunishmentType.TEMPMUTE));
126+
if (staff.hasPermission(PunishmentType.BAN.getPermission())) {
127+
setItem(11, BAN_ITEM, e -> openReasonInput(PunishmentType.BAN, -1));
128+
}
129+
if (staff.hasPermission(PunishmentType.TEMPBAN.getPermission())) {
130+
setItem(12, TEMP_BAN_ITEM, e -> openDurationGUIAsync(PunishmentType.TEMPBAN));
131+
}
132+
if (staff.hasPermission(PunishmentType.KICK.getPermission())) {
133+
setItem(13, KICK_ITEM, e -> openReasonInput(PunishmentType.KICK, -1));
134+
}
135+
if (staff.hasPermission(PunishmentType.MUTE.getPermission())) {
136+
setItem(14, MUTE_ITEM, e -> openReasonInput(PunishmentType.MUTE, -1));
137+
}
138+
if (staff.hasPermission(PunishmentType.TEMPMUTE.getPermission())) {
139+
setItem(15, TEMP_MUTE_ITEM, e -> openDurationGUIAsync(PunishmentType.TEMPMUTE));
140+
}
138141

139142
setItem(31, HISTORY_ITEM, e -> {
140143
staff.closeInventory();
@@ -165,8 +168,13 @@ public void build() {
165168
setItem(4, headItem);
166169
}
167170

168-
169171
private void openDurationGUIAsync(PunishmentType type) {
172+
if (!staff.hasPermission(type.getPermission())) {
173+
staff.closeInventory();
174+
staff.sendMessage(
175+
MessageUtil.toComponent("&cYou don't have permission to use this punishment!"));
176+
return;
177+
}
170178
staff.closeInventory();
171179
plugin.getSchedulerManager().runAsync(() -> {
172180
DurationGUI gui = new DurationGUI(plugin, staff, target, type);
@@ -176,6 +184,12 @@ private void openDurationGUIAsync(PunishmentType type) {
176184
}
177185

178186
private void openReasonInput(PunishmentType type, long durationMs) {
187+
if (!staff.hasPermission(type.getPermission())) {
188+
staff.closeInventory();
189+
staff.sendMessage(
190+
MessageUtil.toComponent("&cYou don't have permission to use this punishment!"));
191+
return;
192+
}
179193
staff.closeInventory();
180194
new ReasonInputHandler(plugin, staff, target, type, durationMs).start();
181195
}
@@ -184,7 +198,6 @@ public void open() {
184198
open(staff);
185199
}
186200

187-
188201
public static void openAsync(WeGuardian plugin, Player staff, OfflinePlayer target) {
189202
plugin.getSchedulerManager().runAsync(() -> {
190203
PunishmentGUI gui = new PunishmentGUI(plugin, staff, target);

src/main/java/me/wethink/weguardian/gui/ReasonInputHandler.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.UUID;
1919
import java.util.concurrent.TimeUnit;
2020

21-
2221
public class ReasonInputHandler implements Listener {
2322

2423
private static final String STAFF_PREFIX = "&8[&cWeGuardian&8] ";
@@ -42,6 +41,11 @@ public ReasonInputHandler(WeGuardian plugin, Player staff, OfflinePlayer target,
4241
}
4342

4443
public void start() {
44+
if (!staff.hasPermission(type.getPermission())) {
45+
staff.sendMessage(MessageUtil.toComponent("&cYou don't have permission to use this punishment!"));
46+
return;
47+
}
48+
4549
plugin.getServer().getPluginManager().registerEvents(this, plugin);
4650

4751
String typeDisplay = type.getColor() + type.getDisplayName();
@@ -61,7 +65,6 @@ public void start() {
6165
plugin.getSchedulerManager().runAsyncLater(this::handleTimeout, 60, TimeUnit.SECONDS);
6266
}
6367

64-
6568
private void handleTimeout() {
6669
if (!completed) {
6770
cleanup();
@@ -99,6 +102,12 @@ public void onQuit(PlayerQuitEvent event) {
99102
}
100103

101104
private void executePunishment(String reason) {
105+
if (!staff.hasPermission(type.getPermission())) {
106+
plugin.getSchedulerManager().runForEntity(staff, () -> staff
107+
.sendMessage(MessageUtil.toComponent("&cYou don't have permission to use this punishment!")));
108+
return;
109+
}
110+
102111
UUID staffUUID = staff.getUniqueId();
103112
String staffName = staff.getName();
104113

@@ -138,7 +147,6 @@ private void executePunishment(String reason) {
138147
});
139148
}
140149

141-
142150
private void broadcastToStaff(String message) {
143151
Collection<? extends Player> players = plugin.getServer().getOnlinePlayers();
144152
for (Player p : players) {

src/main/java/me/wethink/weguardian/model/PunishmentType.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package me.wethink.weguardian.model;
22

3-
43
public enum PunishmentType {
54
BAN("Ban", "§c", true),
65
TEMPBAN("Temporary Ban", "§6", true),
@@ -57,4 +56,18 @@ public boolean isIpMute() {
5756
public boolean isIpBased() {
5857
return isIpBan() || isIpMute();
5958
}
59+
60+
public String getPermission() {
61+
return switch (this) {
62+
case BAN -> "weguardian.ban";
63+
case TEMPBAN -> "weguardian.tempban";
64+
case BANIP -> "weguardian.banip";
65+
case TEMPBANIP -> "weguardian.tempbanip";
66+
case MUTE -> "weguardian.mute";
67+
case TEMPMUTE -> "weguardian.tempmute";
68+
case MUTEIP -> "weguardian.muteip";
69+
case TEMPMUTEIP -> "weguardian.tempmuteip";
70+
case KICK -> "weguardian.kick";
71+
};
72+
}
6073
}

0 commit comments

Comments
 (0)