2 Commits
Author SHA1 Message Date
dniym 43b46001ff forgot these 2023-06-12 07:56:25 -04:00
dniym 48e7e1f014 Async Rewrite 2023-06-12 07:55:08 -04:00
15 changed files with 783 additions and 51 deletions

No files matched your search

+3 -3
View File
@@ -38,12 +38,12 @@ repositories {
}
dependencies {
compileOnly("org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:4.7.0-SNAPSHOT")
implementation("com.elmakers.mine.bukkit:MagicAPI:8.6")
implementation("de.tr7zw:item-nbt-api-plugin:2.8.0")
implementation("com.github.TheBusyBiscuit:Slimefun4:RC-30")
implementation("io.netty:netty-all:4.1.65.Final")
implementation("io.netty:netty-all:4.1.86.Final")
implementation("com.gmail.nossr50.mcMMO:mcMMO:2.1.200") { isTransitive = false }
@@ -67,7 +67,7 @@ tasks.compileJava.configure {
options.release.set(8)
}
version = "2.7.1"
version = "2.8"
tasks.named<Copy>("processResources") {
filesMatching("plugin.yml") {
+2 -2
View File
@@ -2,9 +2,9 @@ main: main.java.me.dniym.IllegalStack
name: IllegalStack
version: "${version}"
api-version: 1.13
description: Closes some dupe bugs still present in vanilla minecraft.
description: Closes some dupe bugs still present in vanilla minecraft.
author: dNiym
softdepend: [Magic, Factions, NBTAPI, ProtocolLib, CraftingStore, DynamicShop, ClueScrolls, mcMMO, JetsMinions, SmartInvs, FactionsX]
softdepend: [Magic, Factions, NBTAPI, ProtocolLib, CraftingStore, DynamicShop, ClueScrolls, mcMMO, JetsMinions, SmartInvs, FactionsX]
loadbefore: [MythicDrops]
website: https://www.spigotmc.org/resources/44411/
commands:
@@ -10,6 +10,7 @@ import main.java.me.dniym.listeners.ProtectionListener;
import main.java.me.dniym.listeners.fListener;
import main.java.me.dniym.listeners.mcMMOListener;
import main.java.me.dniym.listeners.pLisbListener;
import main.java.me.dniym.timers.asyncProtectionTimer;
import main.java.me.dniym.timers.fTimer;
import main.java.me.dniym.timers.sTimer;
import org.apache.logging.log4j.LogManager;
@@ -25,6 +26,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@@ -66,7 +68,7 @@ public class IllegalStack extends JavaPlugin {
private static String version = "";
private int ScanTimer = 0;
private BukkitTask ScanTimer = null;
private int SignTimer = 0;
// private static NMSEntityVillager nmsTrader= null;
@@ -126,6 +128,11 @@ public class IllegalStack extends JavaPlugin {
if (fListener.getInstance() == null) {
plugin.getServer().getPluginManager().registerEvents(new fListener(plugin), plugin);
}
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new asyncProtectionTimer(plugin), 10, 10);
//plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new syncEventHandler(plugin), 10, 10);
/*
if (Protections.RemoveOverstackedItems.isEnabled()) {
if (plugin.ScanTimer == 0) {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new fTimer(plugin), 10, 10);
@@ -136,7 +143,7 @@ public class IllegalStack extends JavaPlugin {
plugin.getServer().getScheduler().cancelTask(plugin.ScanTimer);
}
}
*/
if (Protections.RemoveBooksNotMatchingCharset.isEnabled() && !fListener.getInstance().is113() && !fListener.is18()) {
if (plugin.SignTimer == 0) {
@@ -448,6 +455,7 @@ public class IllegalStack extends JavaPlugin {
this.getServer().getPluginManager().registerEvents(new ProtectionListener(this), this);
}
/*
if (Protections.RemoveOverstackedItems.isEnabled() || Protections.PreventVibratingBlocks.isEnabled()) {
ScanTimer = getServer().getScheduler().scheduleSyncRepeatingTask(
this,
@@ -456,7 +464,9 @@ public class IllegalStack extends JavaPlugin {
Protections.ItemScanTimer.getIntValue()
);
}
*/
ScanTimer = getServer().getScheduler().runTaskTimerAsynchronously(plugin, new asyncProtectionTimer(plugin), 10, 10);
if (Protections.RemoveBooksNotMatchingCharset.isEnabled() && !fListener.getInstance().is113() && !fListener.is18()) {
SignTimer = getServer().getScheduler().scheduleSyncRepeatingTask(this, new sTimer(), 10, 10);
}
@@ -890,7 +900,8 @@ public class IllegalStack extends JavaPlugin {
@Override
public void onDisable() {
getServer().getScheduler().cancelTask(ScanTimer);
//getServer().getScheduler().cancelTask(ScanTimer);
ScanTimer.cancel();
getServer().getScheduler().cancelTask(SignTimer);
getServer().getScheduler().cancelTasks(this);
writeConfig();
@@ -0,0 +1,198 @@
package main.java.me.dniym.actions;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Container;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import de.tr7zw.nbtapi.NBTCompoundList;
import de.tr7zw.nbtapi.NBTItem;
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.NBTApiStuff;
public class Actions {
public static void handleHeadInBlock(Player p) {
fListener.getLog().append(Msg.HeadInsideSolidBlock2.getValue(p, p.getEyeLocation().getBlock().getType().name()), Protections.PreventHeadInsideBlock);
p.getEyeLocation().getBlock().breakNaturally();
}
public static void fixNegativeDurability(Player p, ItemStack is) {
Damageable dmg = (Damageable) is.getItemMeta();
fListener.getLog().append(Msg.IllegalStackDurability.getValue(p, is), Protections.FixNegativeDurability);
dmg.setDamage(is.getType().getMaxDurability());
is.setItemMeta((ItemMeta) dmg);
}
public static void removeItemOfType(Player p, ItemStack is) {
if (Protections.RemoveItemTypes.notifyOnly()) {
fListener.getLog().notify(
Protections.RemoveItemTypes,
" Triggered by: " + p.getName() + " with item: " + is.getType().name()
);
} else {
fListener.getLog().append(Msg.ItemTypeRemovedPlayer.getValue(p, is), Protections.RemoveItemTypes);
p.getInventory().remove(is);
}
}
public static void removeRenamedItem(Player p, ItemStack is) {
fListener.getLog().append(Msg.RemovedRenamedItem.getValue(p, is), Protections.RemoveAllRenamedItems);
p.getInventory().removeItem(is);
}
//
public static void removePlayerItem(Player p, ItemStack is, Msg msg, Protections prot) {
fListener.getLog().append(msg.getValue(p, is),prot);
is.setAmount(0);
is.setType(Material.AIR);
}
public static void handleOverstackedItem(Player p, ItemStack is, boolean isOffhand) {
if (Protections.RemoveOverstackedItems.notifyOnly())
return;
if (!Protections.IllegalStackMode.isEnabled() && Protections.AllowStack.isWhitelisted(is.getType().name(), null)) { //in blacklist mode and on the blacklist
if (Protections.FixOverstackedItemInstead.isEnabled())
Actions.fixPlayerItem(p,is,Msg.IllegalStackShorten,Protections.RemoveOverstackedItems);
else
Actions.removePlayerItem(p, is, Msg.IllegalStackItemScan, Protections.RemoveOverstackedItems);
}
//Checks to do if we're in whitelist mode
if (Protections.AllowStack.isWhitelisted(is.getType().name(), null))
return;
if (Protections.FixOverstackedItemInstead.isEnabled())
Actions.fixPlayerItem(p, is, Msg.IllegalStackShorten,Protections.RemoveOverstackedItems);
else if (!isOffhand)
Actions.removePlayerItem(p, is, Msg.IllegalStackItemScan,Protections.RemoveOverstackedItems);
else
Actions.removeOffhandItem(p,is,Msg.IllegalStackOffhand, Protections.RemoveOverstackedItems);
}
private static void removeOffhandItem(Player p, ItemStack is, Msg msg,Protections prot) {
fListener.getLog().append(msg.getValue(p, is),prot);
p.getInventory().setItemInOffHand(new ItemStack(Material.ROTTEN_FLESH, 1));
}
private static void fixPlayerItem(Player p, ItemStack is, Msg msg, Protections prot) {
fListener.getLog().append(msg.getValue(p, is),prot);
is.setAmount(is.getType().getMaxStackSize());
}
public static void handleIllegallyEnchantedItem(Player p, ItemStack is, HashMap<Enchantment, String> replace) {
for (Enchantment en : replace.keySet()) {
fListener.getLog().append(replace.get(en), Protections.FixIllegalEnchantmentLevels);
is.removeEnchantment(en);
p.updateInventory();
if (en.canEnchantItem(is)) {
new org.bukkit.scheduler.BukkitRunnable() {
@Override
public void run() {
is.addEnchantment(en, Protections.CustomEnchantOverride.getMaxAllowedEnchantLevel(en));
}
}.runTaskLater(IllegalStack.getPlugin(), 1);
}
}
}
public static void handleUnrebakableFlag(Player p, ItemStack is, Msg msg, Protections prot) {
ItemMeta im = is.getItemMeta();
if (Protections.AllowBypass.isEnabled() && p.hasPermission("illegalstack.enchantbypass"))
return;
fListener.getLog().append(msg.getValue(p, is),prot);
im.setUnbreakable(false);
is.setItemMeta(im);
}
public static void handleBadAttributesNBTAPI(Player p, ItemStack is, HashSet<Attribute> toRemove) {
NBTItem nbti = new NBTItem(is);
NBTCompoundList itemTag = nbti.getCompoundList("AttributeModifiers");
if (itemTag == null)
return;
if (itemTag.size() > 0) {
itemTag.clear();
nbti.setObject("AttributeModifiers", itemTag);
StringBuilder attribs = new StringBuilder();
attribs.append("Custom Attribute Data");
fListener.getLog().append(Msg.CustomAttribsRemoved3.getValue(is, p.getInventory(), attribs), Protections.RemoveCustomAttributes);
p.getInventory().remove(is);
}
}
public static void handleBadAttributes(Player p, ItemStack is, HashSet<Attribute> toRemove) {
ItemMeta itemMeta = is.getItemMeta();
StringBuilder attribs = new StringBuilder();
attribs.append("Custom Attribute Data");
if (IllegalStack.isHasAttribAPI()) {
fListener.getLog().append(Msg.CustomAttribsRemoved3.getValue(is, p.getInventory(), attribs),Protections.RemoveCustomAttributes);
for (Attribute remove : toRemove)
itemMeta.removeAttributeModifier(remove);
for (ItemFlag iFlag : itemMeta.getItemFlags())
itemMeta.removeItemFlags(iFlag);
is.setItemMeta(itemMeta);
} else if (IllegalStack.isNbtAPI()) {
handleBadAttributesNBTAPI(p,is,toRemove);
} else {
fListener.getLog().append(Msg.StaffNoNBTAPI.getValue(Protections.RemoveCustomAttributes.name()), Protections.RemoveCustomAttributes);
}
}
public static void handleBadPotion(Player p, ItemStack is, Msg msg, Protections prot) {
PotionMeta potion = ((PotionMeta)is.getItemMeta());
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.getValue(p, efx.toString()), prot);
p.getInventory().remove(is);
}
}
@@ -47,6 +47,29 @@ public class BadAttributeCheck {
return is != null && is.getType() != Material.AIR && checkForBadCustomData(is, obj);
}
public static HashSet<Attribute> getBadAttributes(ItemStack is, Player p) {
HashSet<Attribute> toRemove = new HashSet<Attribute>();
if (Protections.AllowBypass.isEnabled() && p.hasPermission("illegalstack.enchantbypass"))
return toRemove;
ItemMeta itemMeta = is.getItemMeta();
if (IllegalStack.isHasAttribAPI()) {
if (itemMeta.hasAttributeModifiers()) {
StringBuilder attribs = new StringBuilder();
for (Attribute a : itemMeta.getAttributeModifiers().keySet()) {
for (AttributeModifier st : itemMeta.getAttributeModifiers(a)) {
attribs.append(" ").append(st.getName()).append(" value: ").append(st.getAmount());
}
toRemove.add(a);
}
}
}
return toRemove;
}
public static boolean checkForBadCustomData(ItemStack itemStack, Object obj) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (IllegalStack.isHasAttribAPI()) {
@@ -4,6 +4,7 @@ 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.listeners.mcMMOListener;
import main.java.me.dniym.utils.SlimefunCompat;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -13,6 +14,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.HashSet;
public class IllegalEnchantCheck {
@@ -50,6 +52,59 @@ public class IllegalEnchantCheck {
return invalid;
}
public static HashMap<Enchantment,String> checkEnchants (ItemStack is,Player p) {
HashMap<Enchantment,String> replace = new HashMap<Enchantment,String>();
if (!mcMMOListener.ismcMMOActive(p)) {
if (!Protections.OnlyFunctionInWorlds.getTxtSet().isEmpty()) //world list isn't empty
if (!Protections.OnlyFunctionInWorlds.getTxtSet().contains(p.getWorld().getName())) //isn't in a checked world
return replace;
if (Protections.AllowBypass.isEnabled() && p.hasPermission("illegalstack.enchantbypass"))
return replace;
if (is != null && !is.getEnchantments().isEmpty()) {
for (Enchantment en : is.getEnchantments().keySet()) {
if (is.getEnchantmentLevel(en) > en.getMaxLevel()) {
if (SlimefunCompat.isValid(is, en))
continue;
if (IllegalStack.isClueScrolls() && en == Enchantment.DURABILITY && is.getType() == Material.PAPER)
continue;
if (IllegalStack.isEpicRename() && ((en == Enchantment.LURE || en == Enchantment.ARROW_INFINITE) && is
.getEnchantmentLevel(en) == 4341))
continue;
if (Protections.EnchantedItemWhitelist.isWhitelisted(is))
break;
if (Protections.CustomEnchantOverride.isAllowedEnchant(en, is.getEnchantmentLevel(en)))
continue;
replace.put(en,Msg.IllegalEnchantLevel.getValue(p,is,en));
} else {
if (!en.canEnchantItem(is)) {
if (Protections.EnchantedItemWhitelist.isWhitelisted(is))
continue;
if (SlimefunCompat.isValid(is, en))
continue;
replace.put(en,Msg.IllegalEnchantType.getValue(p,is,en));
}
}
}
}
}
return replace;
}
public static boolean isIllegallyEnchanted(ItemStack itemStack, Object obj) {
return isIllegallyEnchanted(itemStack, obj, false);
}
@@ -138,7 +193,9 @@ public class IllegalEnchantCheck {
for (Enchantment en : replace) {
itemStack.removeEnchantment(en);
if (en.canEnchantItem(itemStack)) {
itemStack.addEnchantment(en, en.getMaxLevel());
int maxLevel = Protections.CustomEnchantOverride.getMaxAllowedEnchantLevel(en);
itemStack.addEnchantment(en, maxLevel);
}
}
}
@@ -43,6 +43,10 @@ public class OverstackedItemCheck {
return CheckContainer(itemStack, obj, false);
}
public static boolean isOverstacked(ItemStack is) {
return is.getAmount() > is.getMaxStackSize();
}
public static boolean CheckContainer(ItemStack is, Object obj, Boolean silent) {
if (is == null) {
return false;
@@ -671,7 +671,7 @@ public enum Protections {
8,
true,
"Destroy Rail / Carpet Dupers",
"1.12/1.13/1.14/1.15/1.16/1.17/1.18/1.19",
"> 1.12",
"Exploits.Other.PreventRailDupe",
"Prevent redstone machines designed to dupe carpets and rails, these items are usually duped to provide infinite fuel for furnaces or to sell for in game money in shops.",
"",
@@ -953,7 +953,7 @@ public enum Protections {
19,
true,
"Prevent Villager Trade Cheesing",
"1.14 / 1.15 / 1.16 / 1.17 / 1.18 / 1.19",
"> 1.14",
"Exploits.1_14_Exploits.Traders.BlockVillagerTradeCheesing",
"Prevents players from placing / breaking a villagers work station over and over which forces them to get new trades, typically people abuse this to make sure they get specific enchantments or items from a villager rather than it being a random mechanic.",
"",
@@ -995,7 +995,7 @@ public enum Protections {
46,
true,
"Prevent Tripwire Dupe",
"1.15 / 1.16 / 1.17 / 1.18 / 1.19",
"> 1.15",
"Exploits.1_15_Exploits.Dupes.PreventTripwireDupe",
"Prevents players from using trapdoors to dupe tripwire hooks.",
"",
@@ -1037,7 +1037,7 @@ public enum Protections {
33,
false,
"Force Spawner Resets",
"> 1.12",
"ALL",
"UserRequested.Spawners.SpawnerReset",
"Options for resetting spawners of a specific type",
"",
@@ -1493,7 +1493,7 @@ public enum Protections {
for (Enchantment removeEnchantment : replace) {
itemStack.removeEnchantment(removeEnchantment);
if (removeEnchantment.canEnchantItem(itemStack)) {
itemStack.addEnchantment(removeEnchantment, removeEnchantment.getMaxLevel());
itemStack.addEnchantment(removeEnchantment, Protections.CustomEnchantOverride.getMaxAllowedEnchantLevel(removeEnchantment));
player.sendMessage(Msg.StaffEnchantFixed.getValue(player, itemStack, removeEnchantment));
}
}
@@ -1641,6 +1641,10 @@ public enum Protections {
return false; //must be a child node
}
if (this.getVersion().contains("< 1.20")) {
return !serverVersion.contains("1.20");
}
if (this.getVersion().contains("< 1.19")) {
return !serverVersion.contains("1.19");
}
@@ -1655,7 +1659,7 @@ public enum Protections {
if (this.getVersion().contains("< 1.15")) {
return !serverVersion.contains("1.15") && !serverVersion.contains("1.16") && !serverVersion.contains("1.17") && !serverVersion.contains("1.18")
&& !serverVersion.contains("1.19");
&& !serverVersion.contains("1.19") && !serverVersion.contains("1.20");
}
if (this.getVersion().equalsIgnoreCase("1.14.4") && !serverVersion.contains("1.14.R4")) {
@@ -1670,6 +1674,10 @@ public enum Protections {
return true;
}
if (this.getVersion().equalsIgnoreCase("1.20") && serverVersion.contains("1.20")) {
return true;
}
if (this.getVersion().equalsIgnoreCase("1.19") && serverVersion.contains("1.19")) {
return true;
}
@@ -1718,15 +1726,25 @@ public enum Protections {
return true;
}
if (this.getVersion().contains("> 1.12")) {
if (serverVersion.contains("1.19") || serverVersion.contains("1.18") || serverVersion.contains("1.17") || serverVersion.contains("1.16") || serverVersion.contains("1.15") || serverVersion
.contains("1.14") || serverVersion.contains("1.13") || serverVersion.contains("1.12")) {
return true;
}
if (this.getVersion().contains("1.20") && serverVersion.contains("1.20")) {
return true;
}
if (serverVersion.contains("1.20") || serverVersion.contains("1.19") || serverVersion.contains("1.18") || serverVersion.contains("1.17") || serverVersion.contains("1.16") || serverVersion.contains("1.15") || serverVersion
.contains("1.14") || serverVersion.contains("1.13") || serverVersion.contains("1.12")) {
return true;
}
if (this.getVersion().contains("> 1.12")) {
if (serverVersion.contains("1.20") || serverVersion.contains("1.19") || serverVersion.contains("1.18") || serverVersion.contains("1.17") || serverVersion.contains("1.16") || serverVersion.contains("1.15") || serverVersion
.contains("1.14") || serverVersion.contains("1.13") || serverVersion.contains("1.12")) {
return true;
}
}
if (this.getVersion().contains("> 1.9")) {
if (serverVersion.contains("1.19") || serverVersion.contains("1.18") || serverVersion.contains("1.17") || serverVersion.contains("1.16") || serverVersion.contains("1.15") || serverVersion
if (serverVersion.contains("1.20") || serverVersion.contains("1.19") || serverVersion.contains("1.18") || serverVersion.contains("1.17") || serverVersion.contains("1.16") || serverVersion.contains("1.15") || serverVersion
.contains("1.14") || serverVersion.contains("1.13") || serverVersion.contains("1.12") || serverVersion.contains(
"1.11") ||
this.serverVersion.contains("1.10") || this.serverVersion.contains("1.9")) {
@@ -1735,7 +1753,7 @@ public enum Protections {
}
if (this.getVersion().contains("> 1.11")) {
if (serverVersion.contains("1.19") || serverVersion.contains("1.18") || serverVersion.contains("1.17") || serverVersion.contains("1.16") || serverVersion.contains("1.15") || serverVersion
if (serverVersion.contains("1.20") || serverVersion.contains("1.19") || serverVersion.contains("1.18") || serverVersion.contains("1.17") || serverVersion.contains("1.16") || serverVersion.contains("1.15") || serverVersion
.contains("1.14") || serverVersion.contains("1.13") || serverVersion.contains("1.12") || serverVersion.contains(
"1.11")) {
return true;
@@ -1757,7 +1775,6 @@ public enum Protections {
return Material.matchMaterial("CAVE_AIR") == null;
}
return false;
}
@@ -1767,6 +1784,12 @@ public enum Protections {
return false;
}
if (this.getVersion().equals("1.20")) {
if (serverVersion.contains("v1_20")) {
return true;
}
}
if (this.getVersion().equals("1.19")) {
if (serverVersion.contains("v1_19")) {
return true;
@@ -1805,6 +1828,11 @@ public enum Protections {
if (this.getVersion().equals("1.14.3")) {
return serverVersion.contains("v1_14_R3");
}
if (serverVersion.contains("v1_20") && this.getVersion().contains("1.20")) {
return true;
}
if (serverVersion.contains("v1_19") && this.getVersion().contains("1.19")) {
return true;
}
@@ -2184,7 +2212,7 @@ public enum Protections {
if (this == Protections.ResetSpawnersOfTypeOnSpawn && et != null)
{
for(String s:Protections.ResetSpawnersOfTypeOnSpawn.getTxtSet())
if(s.contains("*") || s.toLowerCase().contains(et.name().toLowerCase()))
if(s.contains("*") || s.toLowerCase().equals(et.name().toLowerCase()))
return true;
}
@@ -2353,6 +2381,38 @@ public enum Protections {
return children;
}
public int getMaxAllowedEnchantLevel(Enchantment en) {
for (String s : this.getTxtSet()) {
String[] val = s.split("\\.");
if (val.length < 2) {
LOGGER.error(
"Unable to translate an enchantment/level from the {} path please check the config.yml!",
this.getConfigPath()
);
return en.getMaxLevel();
}
Enchantment ench = Enchantment.getByName(val[0]);
int level = Integer.parseInt(val[1]);
if (ench == null) {
LOGGER.error(
"Unable to locate enchantment: {} please check your config.yml at section: {} and verify that you are using a valid enchantment.",
val[0],
this.getConfigPath()
);
return en.getMaxLevel();
}
if (en != ench) //not a overridden enchantment
{
continue;
}
//level higher than override.
return level;
//otherwise enchant is good
}
return en.getMaxLevel();
}
public boolean isAllowedEnchant(Enchantment en, int lvl) {
@@ -0,0 +1,27 @@
package main.java.me.dniym.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import main.java.me.dniym.enums.Protections;
public class playerAboveNetherEvent extends Event {
private static final HandlerList HANDLERS = new HandlerList();
public playerAboveNetherEvent(Player p) {
if(this.isAsynchronous()) {
return;
} else {
p.damage(Protections.AboveNetherDamageAmount.getIntValue());
}
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
}
@@ -44,6 +44,7 @@ public class Listener113 implements Listener {
CreatureSpawner cs = e.getSpawner();
EntityType et = e.getEntityType();
if(et != null && Protections.ResetSpawnersOfTypeOnSpawn.isWhitelisted(et))
{
e.setCancelled(true);
@@ -294,7 +294,7 @@ public class fListener implements Listener {
}
}
if (!ver.contains("v1_14") && !ver.contains("v1_15") && !ver.contains("v1_16") && !ver.contains("v1_17") && !ver.contains("v1_18")) {
if (!ver.contains("v1_14") && !ver.contains("v1_15") && !ver.contains("v1_16") && !ver.contains("v1_17") && !ver.contains("v1_18") && !ver.contains("v1_19")) {
if (ver.contains("v1_13")) {
LOGGER.info("MC Version 1.13+ detected!");
@@ -667,6 +667,7 @@ public class fListener implements Listener {
}
}
if (Protections.DisableRidingExploitableMobs.isEnabled()) {
if (IllegalStack.hasChestedAnimals()) {
if ((e.getMount() instanceof Mule || e.getMount() instanceof Donkey || e.getMount() instanceof ChestedHorse) ||
@@ -1262,7 +1263,7 @@ public class fListener implements Listener {
for (Enchantment en : replace) {
is.removeEnchantment(en);
if (en.canEnchantItem(is)) {
is.addEnchantment(en, en.getMaxLevel());
is.addEnchantment(en, Protections.CustomEnchantOverride.getMaxAllowedEnchantLevel(en));
}
}
}
@@ -2794,7 +2795,7 @@ public class fListener implements Listener {
for (Enchantment en : replace) {
is.removeEnchantment(en);
if (en.canEnchantItem(is)) {
is.addEnchantment(en, en.getMaxLevel());
is.addEnchantment(en, Protections.CustomEnchantOverride.getMaxAllowedEnchantLevel(en));
}
}
}
@@ -2920,7 +2921,7 @@ public class fListener implements Listener {
for (Enchantment en : replace) {
is.removeEnchantment(en);
if (en.canEnchantItem(is)) {
is.addEnchantment(en, en.getMaxLevel());
is.addEnchantment(en, Protections.CustomEnchantOverride.getMaxAllowedEnchantLevel(en));
}
}
}
@@ -3175,7 +3176,7 @@ public class fListener implements Listener {
for (Enchantment en : replace) {
is.removeEnchantment(en);
if (en.canEnchantItem(is)) {
is.addEnchantment(en, en.getMaxLevel());
is.addEnchantment(en, Protections.CustomEnchantOverride.getMaxAllowedEnchantLevel(en));
}
}
}
@@ -0,0 +1,348 @@
package main.java.me.dniym.timers;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Event;
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.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import io.netty.util.internal.ThreadLocalRandom;
import main.java.me.dniym.IllegalStack;
import main.java.me.dniym.actions.Actions;
import main.java.me.dniym.checks.BadAttributeCheck;
import main.java.me.dniym.checks.IllegalEnchantCheck;
import main.java.me.dniym.checks.OverstackedItemCheck;
import main.java.me.dniym.enums.Msg;
import main.java.me.dniym.enums.Protections;
import main.java.me.dniym.events.playerAboveNetherEvent;
import main.java.me.dniym.listeners.fListener;
import main.java.me.dniym.listeners.mcMMOListener;
import main.java.me.dniym.utils.NBTStuff;
import main.java.me.dniym.utils.SlimefunCompat;
import main.java.me.dniym.utils.SpigotMethods;
public class asyncProtectionTimer implements Runnable {
private static final HashMap<FallingBlock, Long> fbTracker = new HashMap<>();
private static final HashMap<Projectile, Long> projTracker = new HashMap<>();
private static final Logger LOGGER = LogManager.getLogger("IllegalStack/" + asyncProtectionTimer.class.getSimpleName());
private static long endScanFinish = 0L;
private static World dragon = null;
private static HashMap<Player, Entity> punish = new HashMap<>();
private final long scanDelay = 1;
private final IllegalStack plugin;
private final boolean is1_8;
private long nextScan;
private long longScan;
private long endScan = 0L;
private long nextNetherDamage = 0L;
public asyncProtectionTimer(IllegalStack illegalStack) {
this.plugin = illegalStack;
this.nextScan = System.currentTimeMillis() + (scanDelay * 6000);
if(Protections.DamagePlayersAboveNether.isEnabled()) {
if(Protections.AboveNetherDamageAmount.getIntValue() < 1)
Protections.AboveNetherDamageAmount.setIntValue(1);
if(Protections.AboveNetherDamageDelay.getIntValue() < 1)
Protections.AboveNetherDamageDelay.setIntValue(1);
this.nextNetherDamage = System.currentTimeMillis() + (Protections.AboveNetherDamageDelay.getIntValue() * 1000);
}
String version = IllegalStack.getPlugin().getServer().getClass().getPackage().getName().replace(".", ",")
.split(",")[3];
is1_8 = version.equalsIgnoreCase("v1_8_R3") || version.contains("v1_8");
if (is1_8) {
LOGGER.info("Minecraft 1.8 detected not checking offhand slot for overstacked items.");
}
if (is1_8 || version.equalsIgnoreCase("v1_9_R4") || version.equalsIgnoreCase("v1_10_R2")) {
LOGGER.info("Version < 1.11 found, not checking for shulker boxes");
}
LOGGER.info("Starting asyncProtectionTimer - " + version.toString());
this.longScan = System.currentTimeMillis() + 10000L;
}
@Override
public void run() {
//handle player punishments.
for (Player p : punish.keySet()) {
fListener.punishPlayer(p, punish.get(p));
}
punish.clear();
if (Protections.DamagePlayersAboveNether.isEnabled() && System.currentTimeMillis() >= nextNetherDamage) {
nextNetherDamage = System.currentTimeMillis() + (Protections.AboveNetherDamageDelay.getIntValue() * 1000);
for(World w:plugin.getServer().getWorlds())
if(w.getName().toLowerCase().contains("nether") || w.getEnvironment() == Environment.NETHER)
for(Player p:w.getPlayers())
if(p.isOp() || p.hasPermission("illegalstack.notify"))
continue;
else if (p.getLocation().getY() >= Protections.NetherYLevel.getIntValue())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Bukkit.getPluginManager().callEvent(new playerAboveNetherEvent(p)), 2);
}
for (Player p : plugin.getServer().getOnlinePlayers()) {
if (SpigotMethods.isNPC(p))
continue;
if (Protections.PreventHeadInsideBlock.isEnabled() && p.getGameMode() == GameMode.SURVIVAL) {
Material type = p.getEyeLocation().getBlock().getType();
if (Protections.AlsoPreventHeadInside.isWhitelisted(type) || type.isSolid())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleHeadInBlock(p), 1);
}
for (ItemStack is : p.getInventory().getContents()) {
if(is == null)
continue;
if (Protections.FixNegativeDurability.isEnabled() && NBTStuff.hasNegativeDurability(is,p))
if(NBTStuff.hasNegativeDurability(is, p))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.fixNegativeDurability(p,is), 1);
if (is != null && !p.isOp())
if (Protections.RemoveItemTypes.isWhitelisted(is))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removeItemOfType(p,is), 1);
if (Protections.RemoveAllRenamedItems.isEnabled())
if (!p.hasPermission("IllegalStack.RenameBypass"))
if (is != null && is.hasItemMeta() && is.getItemMeta().hasDisplayName())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removeRenamedItem(p,is), 1);
if (Protections.RemoveItemsMatchingName.isEnabled() && (!Protections.BlockEnchantingInstead.isEnabled() && !Protections.BlockRepairsInstead
.isEnabled())) {
if (is != null && is.hasItemMeta())
{
ItemMeta im = is.getItemMeta();
for (String ignored : Protections.ItemNamesToRemove.getTxtSet())
if (Protections.RemoveItemsMatchingName.loreNameMatch(im))
{
if (!Protections.RemoveItemsMatchingName.notifyOnly())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removePlayerItem(p,is,Msg.NamedItemRemovalPlayer, Protections.RemoveItemsMatchingName), 1);
break;
}
}
}
if (is.hasItemMeta()) { //checks that depend on item meta
ItemMeta im = is.getItemMeta();
if (Protections.RemoveUnbreakableFlag.isEnabled() && IllegalStack.hasUnbreakable())
if (im.isUnbreakable())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleUnrebakableFlag(p,is,Msg.UnbreakableItemCleared, Protections.RemoveUnbreakableFlag), 1);
if (Protections.RemoveCustomAttributes.isEnabled()) {
HashSet<Attribute> badAttributes = BadAttributeCheck.getBadAttributes(is, p);
if(!badAttributes.isEmpty())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleBadAttributes(p,is,badAttributes), 1);
}
if (Protections.PreventInvalidPotions.isEnabled() && im instanceof PotionMeta)
if(!isIllegalPotion(p, is, ((PotionMeta)im)))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleBadPotion(p,is,Msg.InvalidPotionRemoved, Protections.PreventInvalidPotions), 1);
}
if(OverstackedItemCheck.isOverstacked(is))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleOverstackedItem(p, is,false),1);
HashMap<Enchantment,String> illegalEnchants = IllegalEnchantCheck.checkEnchants(is,p);
if(!illegalEnchants.isEmpty()) {
if(Protections.FixIllegalEnchantmentLevels.isEnabled())
if(Protections.DestroyIllegallyEnchantedItemsInstead.isEnabled())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removePlayerItem(p,is,Msg.DestroyedEnchantedItem,Protections.DestroyIllegallyEnchantedItemsInstead), 1);
else
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleIllegallyEnchantedItem(p,is,illegalEnchants), 1);
}
} //end of normal inventory loop
//check offhand items needs to check enchants and all that crap
checkOffhandItems(p);
//end offhand item checking
//check worn items and handle them
for (ItemStack is : p.getInventory().getArmorContents()) {
if(is == null)
continue;
if (Protections.FixNegativeDurability.isEnabled() && NBTStuff.hasNegativeDurability(is,p))
if(NBTStuff.hasNegativeDurability(is, p))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.fixNegativeDurability(p,is), 1);
if (!p.isOp())
if (Protections.RemoveItemTypes.isWhitelisted(is))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removeItemOfType(p,is), 1);
if (Protections.RemoveAllRenamedItems.isEnabled())
if (!p.hasPermission("IllegalStack.RenameBypass"))
if (is != null && is.hasItemMeta() && is.getItemMeta().hasDisplayName())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removeRenamedItem(p,is), 1);
if (Protections.RemoveItemsMatchingName.isEnabled() && (!Protections.BlockEnchantingInstead.isEnabled() && !Protections.BlockRepairsInstead
.isEnabled())) {
if (is != null && is.hasItemMeta())
{
ItemMeta im = is.getItemMeta();
for (String ignored : Protections.ItemNamesToRemove.getTxtSet())
if (Protections.RemoveItemsMatchingName.loreNameMatch(im))
{
if (!Protections.RemoveItemsMatchingName.notifyOnly())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removePlayerItem(p,is,Msg.NamedItemRemovalPlayer, Protections.RemoveItemsMatchingName), 1);
break;
}
}
}
if(OverstackedItemCheck.isOverstacked(is))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleOverstackedItem(p, is,false),1);
HashMap<Enchantment,String> illegalEnchants = IllegalEnchantCheck.checkEnchants(is,p);
if(!illegalEnchants.isEmpty()) {
if(Protections.FixIllegalEnchantmentLevels.isEnabled())
if(Protections.DestroyIllegallyEnchantedItemsInstead.isEnabled())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removePlayerItem(p,is,Msg.DestroyedEnchantedItem,Protections.DestroyIllegallyEnchantedItemsInstead), 1);
else
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleIllegallyEnchantedItem(p,is,illegalEnchants), 1);
}
}
}
}
private boolean isIllegalPotion(Player p, ItemStack is, PotionMeta potionMeta) {
if (Protections.AllowBypass.isEnabled() && p.hasPermission("illegalstack.enchantbypass"))
return false;
if (IllegalStack.isHasMCMMO()) {
if (NBTStuff.hasNbtTag("IllegalStack", is, "mcmmoitem", Protections.PreventInvalidPotions)) {
return false;
}
}
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 false;
return true;
}
return false;
}
private void checkOffhandItems(Player p) {
if (is1_8 || Protections.DisableInWorlds.getTxtSet().contains(p.getWorld().getName())) //no offhand items in 1.8
return;
ItemStack is = p.getInventory().getItemInOffHand();
if(is == null)
return;
if (Protections.FixNegativeDurability.isEnabled() && NBTStuff.hasNegativeDurability(is, p))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.fixNegativeDurability(p,is), 1);
//overstacked item check
if(OverstackedItemCheck.isOverstacked(is))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.handleOverstackedItem(p,is, true), 1);
if (!p.isOp())
if (Protections.RemoveItemTypes.isWhitelisted(is))
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removeItemOfType(p,is), 1);
if (Protections.RemoveAllRenamedItems.isEnabled())
if (!p.hasPermission("IllegalStack.RenameBypass"))
if (is != null && is.hasItemMeta() && is.getItemMeta().hasDisplayName())
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Actions.removeRenamedItem(p,is), 1);
}
public static void trackBlock(FallingBlock fb) {
fbTracker.put(fb, System.currentTimeMillis() + 4000L);
}
public static void trackProjectile(Projectile proj) {
projTracker.put(proj, System.currentTimeMillis() + 14000L);
}
public static long getEndScanFinish() {
return endScanFinish;
}
public static void setEndScanFinish(long endScan) {
endScanFinish = endScan;
}
public static HashMap<Player, Entity> getPunish() {
return punish;
}
public static void setPunish(HashMap<Player, Entity> toPunish) {
punish = toPunish;
}
public World getDragon() {
return dragon;
}
public static void setDragon(World world) {
dragon = world;
}
}
@@ -113,7 +113,7 @@ public class fTimer implements Runnable {
fListener.punishPlayer(p, punish.get(p));
}
punish.clear();
/*
if (Protections.DamagePlayersAboveNether.isEnabled() && System.currentTimeMillis() >= nextNetherDamage) {
nextNetherDamage = System.currentTimeMillis() + (Protections.AboveNetherDamageDelay.getIntValue() * 1000);
for(World w:plugin.getServer().getWorlds())
@@ -126,6 +126,8 @@ public class fTimer implements Runnable {
}
*/
if (Protections.BlockNonPlayersInEndPortal.isEnabled() && getDragon() != null && System.currentTimeMillis() > endScan) {
endScan = System.currentTimeMillis() + 500L;
if (getDragon().getEnvironment() == Environment.THE_END) {
@@ -233,6 +235,7 @@ public class fTimer implements Runnable {
}
}
/*
for (Player p : plugin.getServer().getOnlinePlayers()) {
if (SpigotMethods.isNPC(p)) {
continue;
@@ -713,7 +716,7 @@ public class fTimer implements Runnable {
}
}
}
}
}*/
}
}
@@ -1,6 +1,7 @@
package main.java.me.dniym.utils;
import main.java.me.dniym.IllegalStack;
import main.java.me.dniym.actions.Actions;
import main.java.me.dniym.enums.Msg;
import main.java.me.dniym.enums.Protections;
import main.java.me.dniym.listeners.fListener;
@@ -173,24 +174,6 @@ public class NBTStuff {
return false;
}
public static void checkForNegativeDurability(ItemStack is, Player p) {
if (is == null) {
return;
}
if (IllegalStack.isHasAttribAPI()) {
if (is.hasItemMeta() && is.getItemMeta() instanceof Damageable) {
Damageable dmg = (Damageable) is.getItemMeta();
if (dmg.getDamage() > is.getType().getMaxDurability()) {
fListener.getLog().append(Msg.IllegalStackDurability.getValue(p, is), Protections.FixNegativeDurability);
dmg.setDamage(is.getType().getMaxDurability());
is.setItemMeta((ItemMeta) dmg);
}
}
}
}
public static void checkForBadCustomData(ItemStack is, Player p, boolean sendToPlayer) {
if(!is.hasItemMeta())
@@ -259,4 +242,20 @@ public class NBTStuff {
}
public static boolean hasNegativeDurability(ItemStack is, Player p) {
if (is == null) {
return false;
}
if (IllegalStack.isHasAttribAPI()) {
if (is.hasItemMeta() && is.getItemMeta() instanceof Damageable) {
Damageable dmg = (Damageable) is.getItemMeta();
if (dmg.getDamage() > is.getType().getMaxDurability())
return true;
}
}
return false;
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ main: main.java.me.dniym.IllegalStack
name: IllegalStack
version: "${version}"
api-version: 1.13
description: Closes some dupe bugs still present in vanilla minecraft.
description: Closes some dupe bugs still present in vanilla minecraft.
author: dNiym
softdepend: [Magic, Factions, NBTAPI, ProtocolLib, Slimefun, CraftingStore, DynamicShop, ClueScrolls, mcMMO, JetsMinions, SmartInvs, FactionsX]
loadbefore: [MythicDrops]