Compare commits

...

12 Commits
3.2.0 ... 3.3.0

Author SHA1 Message Date
Auxilor
128d473b33 Added direct mcMMO support 2021-01-24 16:04:40 +00:00
Auxilor
d5679dd58f Downgraded back to 3.2.2 2021-01-23 19:45:44 +00:00
Auxilor
b1e8165ecb Removed ReflectionUtils.java 2021-01-23 19:44:40 +00:00
Auxilor
d0a3d644f3 Updated to 3.3.0 2021-01-23 19:38:23 +00:00
Auxilor
35b060af53 Added ReflectionUtils to use Unsafe to set final fields 2021-01-23 19:38:06 +00:00
Auxilor
337dba23b4 Removed PacketPlayOutRecipeUpdateFix 2021-01-22 19:45:29 +00:00
Auxilor
433f9f53ab Revert "Revert "Changed the fix for PacketPlayOutRecipeUpdateFix""
This reverts commit 1365fdae
2021-01-22 19:29:46 +00:00
Auxilor
ba7a748efd Re-fixed the rework of the fix of the changed fix of the fix 2021-01-22 19:29:11 +00:00
Auxilor
1365fdae88 Revert "Changed the fix for PacketPlayOutRecipeUpdateFix"
This reverts commit 876343fa
2021-01-22 17:53:36 +00:00
Auxilor
6a159bf049 Changed PacketPlayOutRecipeUpdateFix 2021-01-22 10:29:05 +00:00
Auxilor
31e0e93951 Updated to 3.2.1 2021-01-21 08:38:38 +00:00
Auxilor
876343facb Changed the fix for PacketPlayOutRecipeUpdateFix 2021-01-21 08:38:28 +00:00
18 changed files with 123 additions and 266 deletions

View File

@@ -25,7 +25,7 @@ allprojects {
// NMS (for jitpack compilation)
maven { url 'https://repo.codemc.org/repository/nms/' }
// bStats
// bStats, mcMMO
maven { url 'https://repo.codemc.org/repository/maven-public' }
// Spigot API

View File

@@ -115,7 +115,6 @@
<!-- Checks for imports -->
<!-- See https://checkstyle.org/config_imports.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>

View File

@@ -1,46 +0,0 @@
package com.willfp.eco.proxy.v1_15_R1;
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
import net.minecraft.server.v1_15_R1.IRecipe;
import net.minecraft.server.v1_15_R1.PacketPlayOutRecipeUpdate;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@SuppressWarnings("unchecked")
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
@Override
public List<Object> splitPackets(@NotNull final Object object,
@NotNull final Player player) {
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
throw new IllegalArgumentException("Parameter not packet!");
}
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
List<IRecipe<?>> recipes = new ArrayList<>();
try {
Field f = oldPacket.getClass().getDeclaredField("a");
f.setAccessible(true);
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
List<Object> splitPackets = new ArrayList<>();
List<IRecipe<?>> splitRecipes = new ArrayList<>();
for (int i = 0; i < recipes.size(); i++) {
splitRecipes.add(recipes.get(i));
if (i % 100 == 0) {
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
splitPackets.add(newPacket);
splitRecipes.clear();
}
}
return splitPackets;
}
}

View File

@@ -1,46 +0,0 @@
package com.willfp.eco.proxy.v1_16_R1;
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
import net.minecraft.server.v1_16_R1.IRecipe;
import net.minecraft.server.v1_16_R1.PacketPlayOutRecipeUpdate;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@SuppressWarnings("unchecked")
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
@Override
public List<Object> splitPackets(@NotNull final Object object,
@NotNull final Player player) {
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
throw new IllegalArgumentException("Parameter not packet!");
}
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
List<IRecipe<?>> recipes = new ArrayList<>();
try {
Field f = oldPacket.getClass().getDeclaredField("a");
f.setAccessible(true);
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
List<Object> splitPackets = new ArrayList<>();
List<IRecipe<?>> splitRecipes = new ArrayList<>();
for (int i = 0; i < recipes.size(); i++) {
splitRecipes.add(recipes.get(i));
if (i % 100 == 0) {
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
splitPackets.add(newPacket);
splitRecipes.clear();
}
}
return splitPackets;
}
}

View File

@@ -1,46 +0,0 @@
package com.willfp.eco.proxy.v1_16_R2;
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
import net.minecraft.server.v1_16_R2.IRecipe;
import net.minecraft.server.v1_16_R2.PacketPlayOutRecipeUpdate;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@SuppressWarnings("unchecked")
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
@Override
public List<Object> splitPackets(@NotNull final Object object,
@NotNull final Player player) {
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
throw new IllegalArgumentException("Parameter not packet!");
}
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
List<IRecipe<?>> recipes = new ArrayList<>();
try {
Field f = oldPacket.getClass().getDeclaredField("a");
f.setAccessible(true);
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
List<Object> splitPackets = new ArrayList<>();
List<IRecipe<?>> splitRecipes = new ArrayList<>();
for (int i = 0; i < recipes.size(); i++) {
splitRecipes.add(recipes.get(i));
if (i % 100 == 0) {
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
splitPackets.add(newPacket);
splitRecipes.clear();
}
}
return splitPackets;
}
}

View File

@@ -1,46 +0,0 @@
package com.willfp.eco.proxy.v1_16_R3;
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
import net.minecraft.server.v1_16_R3.IRecipe;
import net.minecraft.server.v1_16_R3.PacketPlayOutRecipeUpdate;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@SuppressWarnings("unchecked")
public final class PacketPlayOutRecipeUpdateFix implements PacketPlayOutRecipeUpdateFixProxy {
@Override
public List<Object> splitPackets(@NotNull final Object object,
@NotNull final Player player) {
if (!(object instanceof PacketPlayOutRecipeUpdate)) {
throw new IllegalArgumentException("Parameter not packet!");
}
PacketPlayOutRecipeUpdate oldPacket = (PacketPlayOutRecipeUpdate) object;
List<IRecipe<?>> recipes = new ArrayList<>();
try {
Field f = oldPacket.getClass().getDeclaredField("a");
f.setAccessible(true);
recipes.addAll((Collection<? extends IRecipe<?>>) f.get(oldPacket));
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
List<Object> splitPackets = new ArrayList<>();
List<IRecipe<?>> splitRecipes = new ArrayList<>();
for (int i = 0; i < recipes.size(); i++) {
splitRecipes.add(recipes.get(i));
if (i % 100 == 0) {
PacketPlayOutRecipeUpdate newPacket = new PacketPlayOutRecipeUpdate(splitRecipes);
splitPackets.add(newPacket);
splitRecipes.clear();
}
}
return splitPackets;
}
}

View File

@@ -14,6 +14,7 @@ dependencies {
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.157'
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
}

View File

@@ -1,6 +1,5 @@
package com.willfp.eco.spigot;
import com.comphenix.protocol.ProtocolLibrary;
import com.willfp.eco.spigot.display.packets.PacketAutoRecipe;
import com.willfp.eco.spigot.display.packets.PacketChat;
import com.willfp.eco.spigot.display.packets.PacketOpenWindowMerchant;
@@ -16,6 +15,7 @@ import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefKingdoms;
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefLands;
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefTowny;
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefWorldGuard;
import com.willfp.eco.spigot.integrations.mcmmo.plugins.McmmoIntegrationImpl;
import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
import com.willfp.eco.util.events.armorequip.ArmorListener;
@@ -25,9 +25,9 @@ import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainListeners;
import com.willfp.eco.util.integrations.IntegrationLoader;
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
import com.willfp.eco.util.integrations.mcmmo.McmmoManager;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.eco.util.recipe.RecipeListener;
import lombok.Getter;
import org.bukkit.event.Listener;
@@ -57,8 +57,6 @@ public class EcoPlugin extends AbstractEcoPlugin {
this.getEventManager().registerListener(new ArmorListener());
this.getEventManager().registerListener(new DispenserArmorListener());
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
this.getEventManager().registerListener(new RecipeListener(this));
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketPlayOutRecipeUpdateFix(this));
}
@Override
@@ -95,7 +93,10 @@ public class EcoPlugin extends AbstractEcoPlugin {
// Anticheat
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP()))
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())),
// Misc
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
);
}

View File

@@ -1,44 +0,0 @@
package com.willfp.eco.spigot;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.willfp.eco.proxy.proxies.PacketPlayOutRecipeUpdateFixProxy;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
public class PacketPlayOutRecipeUpdateFix extends PacketAdapter {
/**
* Create new fixer for PacketPlayOutRecipeUpdate.
*
* @param plugin Plugin.
*/
public PacketPlayOutRecipeUpdateFix(@NotNull final AbstractEcoPlugin plugin) {
super(plugin, PacketType.Play.Server.RECIPE_UPDATE);
}
@Override
public void onPacketSending(@NotNull final PacketEvent event) {
PacketContainer packet = event.getPacket();
Player player = event.getPlayer();
List<Object> packets = InternalProxyUtils.getProxy(PacketPlayOutRecipeUpdateFixProxy.class).splitPackets(packet.getHandle(), player);
if (packets.size() > 1) {
event.setCancelled(true);
for (Object o : packets) {
PacketContainer container = PacketContainer.fromPacket(o);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, container);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}

View File

@@ -0,0 +1,26 @@
package com.willfp.eco.spigot.integrations.mcmmo.plugins;
import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
import com.gmail.nossr50.events.fake.FakeEvent;
import com.gmail.nossr50.mcMMO;
import com.willfp.eco.util.integrations.mcmmo.McmmoWrapper;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
public class McmmoIntegrationImpl implements McmmoWrapper {
@Override
public int getBonusDropCount(@NotNull final Block block) {
if (block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
BonusDropMeta bonusDropMeta = (BonusDropMeta) block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
return bonusDropMeta.asInt();
}
return 0;
}
@Override
public boolean isFake(@NotNull final Event event) {
return event instanceof FakeEvent;
}
}

View File

@@ -23,4 +23,5 @@ softdepend:
- AAC
- Matrix
- Spartan
- PlaceholderAPI
- PlaceholderAPI
- mcMMO

View File

@@ -1,20 +0,0 @@
package com.willfp.eco.proxy.proxies;
import com.willfp.eco.util.proxy.AbstractProxy;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface PacketPlayOutRecipeUpdateFixProxy extends AbstractProxy {
/**
* Split recipe update packet into smaller packets.
*
* @param object The packet.
* @param player The player.
* @return The packets, split up.
*/
List<Object> splitPackets(@NotNull Object object,
@NotNull Player player);
}

View File

@@ -88,6 +88,7 @@ public class Display {
* Display on ItemStacks.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack display(@NotNull final ItemStack itemStack) {
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) {
@@ -107,6 +108,7 @@ public class Display {
* Display on ItemStacks and then finalize.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
return finalize(display(itemStack));
@@ -116,6 +118,7 @@ public class Display {
* Revert on ItemStacks.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack revert(@NotNull final ItemStack itemStack) {
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) {
@@ -128,6 +131,7 @@ public class Display {
* Finalize an ItemStacks.
*
* @param itemStack The item.
* @return The itemstack.
*/
public ItemStack finalize(@NotNull final ItemStack itemStack) {
for (Function<ItemStack, ItemStack> function : FINALIZE_FUNCTIONS) {
@@ -140,6 +144,7 @@ public class Display {
* Finalize an ItemStacks.
*
* @param itemStack The item.
* @return If finalized.
*/
public boolean isFinalized(@NotNull final ItemStack itemStack) {
for (Predicate<ItemStack> function : FINALIZE_TEST_FUNCTIONS) {

View File

@@ -0,0 +1,52 @@
package com.willfp.eco.util.integrations.mcmmo;
import lombok.experimental.UtilityClass;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
public class McmmoManager {
/**
* A set of all registered integrations.
*/
private final Set<McmmoWrapper> regsistered = new HashSet<>();
/**
* Register a new integration.
*
* @param integration The integration to register.
*/
public void register(@NotNull final McmmoWrapper integration) {
regsistered.add(integration);
}
/**
* Get bonus drop count from block.
*
* @param block The block.
* @return The bonus drop count.
*/
public int getBonusDropCount(@NotNull final Block block) {
for (McmmoWrapper mcmmoWrapper : regsistered) {
return mcmmoWrapper.getBonusDropCount(block);
}
return 0;
}
/**
* Get if event is fake.
*
* @param event The event to check.
* @return If the event is fake.
*/
public boolean isFake(@NotNull final Event event) {
for (McmmoWrapper mcmmoWrapper : regsistered) {
return mcmmoWrapper.isFake(event);
}
return false;
}
}

View File

@@ -0,0 +1,23 @@
package com.willfp.eco.util.integrations.mcmmo;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
public interface McmmoWrapper {
/**
* Get bonus drop count of block.
*
* @param block The block.
* @return The drop multiplier.
*/
int getBonusDropCount(@NotNull Block block);
/**
* Get if event is fake.
*
* @param event The event.
* @return If is fake.
*/
boolean isFake(@NotNull Event event);
}

View File

@@ -250,14 +250,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
Prerequisite.update();
if (ClassUtils.exists("com.comphenix.protocol.events.PacketAdapter")) {
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
if (!abstractPacketAdapter.isPostLoad()) {
abstractPacketAdapter.register();
}
});
}
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
if (!abstractPacketAdapter.isPostLoad()) {
abstractPacketAdapter.register();
}
});
updatableClasses.addAll(this.getUpdatableClasses());

View File

@@ -52,8 +52,8 @@ public class RecipeManager extends PluginDependent {
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(recipe.getDisplayedAtIndex(i)));
}
Bukkit.getServer().addRecipe(displayedRecipe);
Bukkit.getServer().addRecipe(shapedRecipe);
Bukkit.getServer().addRecipe(displayedRecipe);
}
/**

View File

@@ -1,2 +1,2 @@
version = 3.2.0
version = 3.3.0
plugin-name = eco