Skip to content

Commit ce3d9f2

Browse files
authored
Permission check implementation
1 parent eb507be commit ce3d9f2

File tree

9 files changed

+25
-7
lines changed

9 files changed

+25
-7
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
393 Bytes
Binary file not shown.

build/resources/main/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ api-version: 1.20
55
commands:
66
numbness:
77
description: Gives the player temporary invincibility and then applies the damage that was taken during the invincibility.
8-
usage: /numbness <player>
8+
usage: /numbness <player> [duration]
-48 Bytes
Binary file not shown.

src/main/java/potioneffects/customeffects/DamageListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.event.entity.PlayerDeathEvent;
88
import org.bukkit.metadata.FixedMetadataValue;
99
import org.bukkit.plugin.java.JavaPlugin;
10+
import net.kyori.adventure.text.Component;
1011

1112
import java.util.HashMap;
1213
import java.util.UUID;
@@ -17,7 +18,7 @@ public class DamageListener implements Listener {
1718
private static JavaPlugin plugin;
1819

1920
public DamageListener(JavaPlugin plugin) {
20-
this.plugin = plugin; // Store the plugin instance
21+
DamageListener.plugin = plugin; // Store the plugin instance
2122
}
2223
public static void makeInvincible(Player player) {
2324
invinciblePlayers.put(player.getUniqueId(), 0.0);
@@ -55,7 +56,8 @@ public void onDeath(PlayerDeathEvent event) {
5556
Player player = event.getEntity();
5657
if (player.hasMetadata("LastDamageByInvincibility")) {
5758
// Set a custom death message
58-
event.setDeathMessage(player.getName() + " couldn't survive the aftermath of the numbness.");
59+
Component componentDeathMessage = Component.text(player.getName() + " couldn't survive the aftermath of the numbness.");
60+
event.deathMessage(componentDeathMessage);
5961

6062
}
6163
}

src/main/java/potioneffects/customeffects/NumbnessCommand.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ public NumbnessCommand(CustomEffects plugin) {
1616

1717
@Override
1818
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
19-
if (args.length != 1) {
20-
sender.sendMessage("Usage: /numbness <player>");
19+
// Check if the player has permission
20+
if (!sender.hasPermission("numbness.use")) {
21+
sender.sendMessage("You do not have permission to use this command.");
22+
return true;
23+
}
24+
if (args.length != 2) {
25+
sender.sendMessage("Usage: /numbness <player> [duration]");
2126
return true;
2227
}
2328
Player player = Bukkit.getPlayer(args[0]);
@@ -27,12 +32,23 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
2732
}
2833

2934
DamageListener.makeInvincible(player);
35+
36+
int duration;
37+
38+
try {
39+
duration = args[1] != null ? Integer.parseInt(args[1]) : 30;
40+
} catch (NumberFormatException e) {
41+
sender.sendMessage("Invalid duration. Please provide a valid number.");
42+
return true;
43+
}
44+
45+
int durationTicks = duration * 20; // 20 ticks = 1 second
3046
new BukkitRunnable() {
3147
@Override
3248
public void run() {
3349
DamageListener.applyRecordedDamage(player);
3450
}
35-
}.runTaskLater(plugin, 600); // 600 ticks = 30 seconds
51+
}.runTaskLater(plugin, durationTicks); // 600 ticks = 30 seconds
3652
return true;
3753
}
3854
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ api-version: 1.20
55
commands:
66
numbness:
77
description: Gives the player temporary invincibility and then applies the damage that was taken during the invincibility.
8-
usage: /numbness <player>
8+
usage: /numbness <player> [duration]

0 commit comments

Comments
 (0)