Skip to content

Commit

Permalink
feat: Potion effect
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Mar 11, 2024
1 parent e7a1dfb commit f5fbeaa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/main/java/io/wdsj/asw/manage/punish/Punishment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ public enum PunishmentType {

HOSTILE,

DAMAGE
DAMAGE,

EFFECT
}

0 comments on commit f5fbeaa

Please sign in to comment.