From f5fbeaaf963b696c694eec2be2743df6e7646946 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Tue, 12 Mar 2024 01:52:01 +0800 Subject: [PATCH] feat: Potion effect --- .../io/wdsj/asw/manage/punish/Punishment.java | 26 ++++++++++++++++++- .../asw/manage/punish/PunishmentType.java | 4 ++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/wdsj/asw/manage/punish/Punishment.java b/src/main/java/io/wdsj/asw/manage/punish/Punishment.java index d5f8f9a..ca1efed 100644 --- a/src/main/java/io/wdsj/asw/manage/punish/Punishment.java +++ b/src/main/java/io/wdsj/asw/manage/punish/Punishment.java @@ -5,6 +5,8 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import java.util.List; import java.util.Locale; @@ -40,10 +42,32 @@ public static void punish(Player player) { } break; case COMMAND: - if (normalPunish.length != 2) throw new IllegalArgumentException("Not enough args"); + if (normalPunish.length < 2) throw new IllegalArgumentException("Not enough args"); String command = normalPunish[1].replace("%player%", player.getName()).replace("%PLAYER%", player.getName()); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); break; + case EFFECT: + if (normalPunish.length < 2) throw new IllegalArgumentException("Not enough args"); + String effect = normalPunish[1]; + PotionEffectType potionEffect = PotionEffectType.getByName(effect.toUpperCase(Locale.ROOT)); + if (potionEffect == null) throw new IllegalArgumentException("Unknown potion effect"); + switch (normalPunish.length) { + case 2: + player.addPotionEffect(new PotionEffect(potionEffect, 10, 0)); + break; + case 3: + int duration_3 = Integer.parseInt(normalPunish[2]); + player.addPotionEffect(new PotionEffect(potionEffect, duration_3 * 20, 0)); + break; + case 4: + int duration_4 = Integer.parseInt(normalPunish[2]); + int amplifier = Integer.parseInt(normalPunish[3]); + player.addPotionEffect(new PotionEffect(potionEffect, duration_4 * 20, amplifier)); + break; + default: + throw new IllegalArgumentException("Too many args"); + } + break; default: throw new IllegalArgumentException("Unknown punishment type"); } diff --git a/src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java b/src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java index 390b102..4773d63 100644 --- a/src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java +++ b/src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java @@ -5,5 +5,7 @@ public enum PunishmentType { HOSTILE, - DAMAGE + DAMAGE, + + EFFECT }