mirror of
https://github.com/plexusorg/Blackout.git
synced 2024-12-28 02:24:26 +00:00
Merge branch 'master' of https://github.com/PlexDevelopment/Blackout
This commit is contained in:
commit
e779af42c5
3 changed files with 114 additions and 4 deletions
|
@ -2,10 +2,7 @@ package dev.plex;
|
|||
|
||||
import dev.plex.listener.PlayerListener;
|
||||
import dev.plex.packet.PacketManager;
|
||||
import dev.plex.packet.impl.EndermanPotionPatch;
|
||||
import dev.plex.packet.impl.KnowledgeBookPatch;
|
||||
import dev.plex.packet.impl.LecternPatch;
|
||||
import dev.plex.packet.impl.PaintingPatch;
|
||||
import dev.plex.packet.impl.*;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -41,6 +38,7 @@ public class Blackout extends JavaPlugin
|
|||
this.packetManager.registerListener(ServerboundUseItemOnPacket.class, new PaintingPatch());
|
||||
this.packetManager.registerListener(ServerboundUseItemOnPacket.class, new LecternPatch());
|
||||
this.packetManager.registerListener(ServerboundUseItemOnPacket.class, new KnowledgeBookPatch());
|
||||
this.packetManager.registerListener(ServerboundSetCreativeModeSlotPacket.class, new SkullOwnerPatch());
|
||||
this.packetManager.registerListener(ClientboundUpdateMobEffectPacket.class, new EndermanPotionPatch());
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
|
|
|
@ -5,6 +5,8 @@ import net.minecraft.network.protocol.Packet;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public interface IPacketListener<T extends Packet<?>> extends Listener
|
||||
{
|
||||
default boolean onReceive(Player player, T t)
|
||||
|
@ -16,4 +18,18 @@ public interface IPacketListener<T extends Packet<?>> extends Listener
|
|||
{
|
||||
return Blackout.getPlugin();
|
||||
}
|
||||
|
||||
default <J> J getFromField(Object object, String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field field = object.getClass().getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return (J) field.get(object);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
96
src/main/java/dev/plex/packet/impl/SkullOwnerPatch.java
Normal file
96
src/main/java/dev/plex/packet/impl/SkullOwnerPatch.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
package dev.plex.packet.impl;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import dev.plex.Blackout;
|
||||
import dev.plex.packet.IPacketListener;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SkullOwnerPatch implements IPacketListener<ServerboundSetCreativeModeSlotPacket>
|
||||
{
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event)
|
||||
{
|
||||
org.bukkit.inventory.ItemStack bukkitItem = event.getCurrentItem();
|
||||
|
||||
if (bukkitItem == null) return;
|
||||
if (event.getWhoClicked().getType() != EntityType.PLAYER) return;
|
||||
|
||||
checkItem(((CraftPlayer)event.getWhoClicked()).getHandle(), bukkitItem);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpen(InventoryOpenEvent event)
|
||||
{
|
||||
if (event.getView().getType() == InventoryType.PLAYER)
|
||||
{
|
||||
Blackout.debug("Checking all items...");
|
||||
Arrays.stream(event.getInventory().getContents()).forEach(item -> checkItem(((CraftPlayer)event.getPlayer()).getHandle(), item));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReceive(Player player, ServerboundSetCreativeModeSlotPacket serverboundSetCreativeModeSlotPacket)
|
||||
{
|
||||
return checkItem(player, serverboundSetCreativeModeSlotPacket.getItem().getBukkitStack());
|
||||
}
|
||||
|
||||
private boolean checkItem(Player player, org.bukkit.inventory.ItemStack bukkitItem)
|
||||
{
|
||||
Blackout.debug("Starting skull owner exploit patch...");
|
||||
if (bukkitItem == null) return true;
|
||||
ItemStack item = ((CraftItemStack)bukkitItem).handle;
|
||||
if (item.getBukkitStack().getType() != Material.PLAYER_HEAD) return true;
|
||||
|
||||
SkullMeta meta = (SkullMeta) item.getBukkitStack().getItemMeta();
|
||||
GameProfile profile = getFromField(meta, "profile");
|
||||
Blackout.debug(String.valueOf(profile == null));
|
||||
if (profile == null) return true;
|
||||
if (profile.getName() == null && profile.getId() == null) return true;
|
||||
if (profile.getName().isEmpty())
|
||||
{
|
||||
Blackout.debug("Patching invalid skull owner exploit!");
|
||||
player.getInventory().removeItem(item);
|
||||
return false;
|
||||
}
|
||||
if (!profile.getName().matches("\\p{Alpha}"))
|
||||
{
|
||||
Blackout.debug("Patching invalid skull owner exploit!");
|
||||
player.getInventory().removeItem(item);
|
||||
return false;
|
||||
}
|
||||
if (profile.getId().toString().isEmpty())
|
||||
{
|
||||
Blackout.debug("Patching invalid skull owner exploit!");
|
||||
player.getInventory().removeItem(item);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!item.hasTag()) return true;
|
||||
|
||||
CompoundTag tag = item.getTag();
|
||||
if (!tag.contains("SkullOwner")) return true;
|
||||
String owner = tag.getString("SkullOwner");
|
||||
if (!owner.matches("\\p{Alpha}"))
|
||||
{
|
||||
Blackout.debug("Patching invalid skull owner exploit!");
|
||||
player.getInventory().removeItem(item);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue