-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified the invalid potion protection
this is to prevent spawned invalid potions from being thrown before the item scanner has a chance to delete them. Moved the invalid potion check to its own class in Checks, and added a new message since the detection is slightly different.
- Loading branch information
Showing
5 changed files
with
124 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/main/java/main/java/me/dniym/checks/BadPotionCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package main.java.me.dniym.checks; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.entity.Projectile; | ||
import org.bukkit.entity.ThrownPotion; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.bukkit.inventory.meta.PotionMeta; | ||
import org.bukkit.potion.PotionData; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionType; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import main.java.me.dniym.IllegalStack; | ||
import main.java.me.dniym.enums.Msg; | ||
import main.java.me.dniym.enums.Protections; | ||
import main.java.me.dniym.listeners.fListener; | ||
import main.java.me.dniym.utils.NBTStuff; | ||
|
||
public class BadPotionCheck { | ||
|
||
public static void checkPotion(ItemStack is, Player p) { | ||
if(!is.hasItemMeta()) | ||
return; | ||
ItemMeta im = is.getItemMeta(); | ||
if (Protections.PreventInvalidPotions.isEnabled() && im instanceof PotionMeta) { | ||
if (Protections.AllowBypass.isEnabled() && p.hasPermission("illegalstack.enchantbypass")) | ||
return; | ||
|
||
|
||
if(IllegalStack.isHasMCMMO() && NBTStuff.hasNbtTag("IllegalStack", is, "mcmmoitem", Protections.PreventInvalidPotions)) | ||
return; | ||
|
||
|
||
PotionMeta potion = (PotionMeta) is.getItemMeta(); | ||
PotionData pd = potion.getBasePotionData(); | ||
if (pd.getType() == PotionType.UNCRAFTABLE || (potion.hasCustomEffects() && !potion | ||
.getCustomEffects() | ||
.isEmpty())) { | ||
|
||
if (pd.getType() == PotionType.UNCRAFTABLE && potion.getCustomEffects().isEmpty()) | ||
return; | ||
|
||
|
||
p.getInventory().remove(is); | ||
StringBuilder efx = new StringBuilder(); | ||
for (PotionEffect ce : potion.getCustomEffects()) { | ||
efx | ||
.append(ce.getType().getName()) | ||
.append(" amplifier: ") | ||
.append(ce.getAmplifier()) | ||
.append( | ||
" duration: ") | ||
.append(ce.getDuration()) | ||
.append(","); | ||
} | ||
fListener.getLog().append(Msg.InvalidPotionRemoved.getValue(p, efx.toString()), Protections.PreventInvalidPotions); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
public static boolean isInvalidPotion(@NotNull Projectile proj) { | ||
|
||
if(proj instanceof ThrownPotion) { | ||
ThrownPotion tp = (ThrownPotion)proj; | ||
Player p = null; | ||
if(proj.getShooter() instanceof Player) | ||
p = ((Player)proj.getShooter()); | ||
|
||
if (p != null && Protections.AllowBypass.isEnabled() && p.hasPermission("illegalstack.enchantbypass")) | ||
return false; | ||
|
||
|
||
PotionMeta potion = (PotionMeta) tp.getPotionMeta(); | ||
PotionData pd = potion.getBasePotionData(); | ||
if (pd.getType() == PotionType.UNCRAFTABLE || (potion.hasCustomEffects() && !potion | ||
.getCustomEffects() | ||
.isEmpty())) { | ||
|
||
if (pd.getType() == PotionType.UNCRAFTABLE && potion.getCustomEffects().isEmpty()) | ||
return false; | ||
|
||
|
||
//p.getInventory().remove(is); | ||
StringBuilder efx = new StringBuilder(); | ||
for (PotionEffect ce : potion.getCustomEffects()) { | ||
efx | ||
.append(ce.getType().getName()) | ||
.append(" amplifier: ") | ||
.append(ce.getAmplifier()) | ||
.append( | ||
" duration: ") | ||
.append(ce.getDuration()) | ||
.append(","); | ||
} | ||
|
||
fListener.getLog().append(Msg.InvalidThrownPotionRemoved.getValue(p, efx.toString()), Protections.PreventInvalidPotions); | ||
return true; | ||
} | ||
|
||
} | ||
return false; | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters