Skip to content

Commit

Permalink
Update check for illegal potion consume & illegal potion effects get …
Browse files Browse the repository at this point in the history
…by dipenser
  • Loading branch information
Dreeam-qwq committed Feb 7, 2024
1 parent 42d5d31 commit a9270f8
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ public void onThrow(PotionSplashEvent event) {
}
}

// Player consume potion
// Player consume Potion with illegal potion effects
// Dreeam TODO: Check wheter need add foods with illegal effects
@EventHandler(ignoreCancelled = true)
public void PlayerInteractEvent(PlayerItemConsumeEvent e) {
if (!e.getItem().getType().equals(Material.POTION)) {
return;
}
if (!e.getItem().hasItemMeta()) {
if (!e.getItem().getType().equals(Material.POTION) || !e.getItem().hasItemMeta()) {
return;
}

PotionMeta potion = (PotionMeta) e.getItem().getItemMeta();

for (PotionEffect pe : potion.getCustomEffects()) {
if (pe.getAmplifier() > 5
|| pe.getDuration() > 12000) {
Expand All @@ -94,11 +94,13 @@ public void PlayerInteractEvent(PlayerItemConsumeEvent e) {
}
}

// Potion/Arrow/Trident despense from dispenser
// Check Potion/Arrow/Trident with illegal potion effects dispense from dispenser
@EventHandler(ignoreCancelled = true)
public void onDispense(BlockDispenseEvent event) {
String material = event.getItem().getType().name();

// Needs to add more items if they are added in newer MC version,
// or remove material check
if (material.contains("POTION")|| material.contains("ARROW") || material.contains("TRIDENT")) {
Dispenser disp = (Dispenser) event.getBlock().getState();
PotionMeta pot = (PotionMeta) event.getItem().getItemMeta();
Expand All @@ -108,6 +110,7 @@ public void onDispense(BlockDispenseEvent event) {
|| effects.getDuration() > 12000) {
event.setCancelled(true);
disp.getInventory().remove(event.getItem());
Utils.println(ConfigCache.IllegalPotionMessage);
// One illegal potion effect appear, remove whole item
// then break the for loop.
break;
Expand Down

0 comments on commit a9270f8

Please sign in to comment.