Search in sources :

Example 11 with WorldServer

use of net.minecraft.server.level.WorldServer in project Panilla by ds58.

the class PacketInspector method checkPacketPlayOutSpawnEntity.

@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException {
    if (_packet instanceof PacketPlayOutSpawnEntity) {
        PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;
        try {
            Field typeField = PacketPlayOutSpawnEntity.class.getDeclaredField("d");
            typeField.setAccessible(true);
            UUID entityId = (UUID) typeField.get(packet);
            Entity entity = null;
            for (WorldServer worldServer : MinecraftServer.getServer().F()) {
                entity = worldServer.O.d().a(entityId);
                if (entity != null)
                    break;
            }
            if (entity != null) {
                if (entity instanceof EntityItem) {
                    EntityItem item = (EntityItem) entity;
                    if (item.h() == null) {
                        return;
                    }
                    if (!item.h().r()) {
                        return;
                    }
                    INbtTagCompound tag = new NbtTagCompound(item.h().t());
                    String itemName = item.h().c().a();
                    FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
                    if (FailedNbt.fails(failedNbt)) {
                        throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, entity.W().getWorld().getName());
                    }
                }
            }
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) Entity(net.minecraft.world.entity.Entity) EntityNbtNotPermittedException(com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_18_R2.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) WorldServer(net.minecraft.server.level.WorldServer) Field(java.lang.reflect.Field) PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) UUID(java.util.UUID) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt) EntityItem(net.minecraft.world.entity.item.EntityItem)

Example 12 with WorldServer

use of net.minecraft.server.level.WorldServer in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_18_R1 method setBlock.

@Override
public void setBlock(Location location, Material type, byte data, String nbt) {
    assert location.getWorld() != null;
    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    worldServer.m(blockPosition);
    location.getBlock().setType(type);
    if (nbt != null) {
        try {
            ArgumentBlock argumentBlock = new ArgumentBlock(new StringReader(nbt), false).a(true);
            IBlockData blockData = argumentBlock.b();
            if (blockData != null) {
                ArgumentTileLocation tileLocation = new ArgumentTileLocation(blockData, argumentBlock.a().keySet(), argumentBlock.c());
                tileLocation.a(worldServer, blockPosition, 2);
                worldServer.a(blockPosition, tileLocation.a().b());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : ArgumentTileLocation(net.minecraft.commands.arguments.blocks.ArgumentTileLocation) IBlockData(net.minecraft.world.level.block.state.IBlockData) ArgumentBlock(net.minecraft.commands.arguments.blocks.ArgumentBlock) BlockPosition(net.minecraft.core.BlockPosition) StringReader(com.mojang.brigadier.StringReader) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 13 with WorldServer

use of net.minecraft.server.level.WorldServer in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_17_R1 method setBlock.

@Override
public void setBlock(Location location, Material type, byte data, String nbt) {
    assert location.getWorld() != null;
    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    worldServer.removeTileEntity(blockPosition);
    location.getBlock().setType(type);
    if (nbt != null) {
        try {
            ArgumentBlock argumentBlock = new ArgumentBlock(new StringReader(nbt), false).a(true);
            ArgumentTileLocation tileLocation = new ArgumentTileLocation(argumentBlock.getBlockData(), argumentBlock.getStateMap().keySet(), argumentBlock.c());
            tileLocation.a(worldServer, blockPosition, 2);
            worldServer.update(blockPosition, tileLocation.a().getBlock());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : ArgumentTileLocation(net.minecraft.commands.arguments.blocks.ArgumentTileLocation) ArgumentBlock(net.minecraft.commands.arguments.blocks.ArgumentBlock) BlockPosition(net.minecraft.core.BlockPosition) StringReader(com.mojang.brigadier.StringReader) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 14 with WorldServer

use of net.minecraft.server.level.WorldServer in project TerraPlusMinus by Build-the-Earth-Germany.

the class NMSInjector method attemptInject.

public void attemptInject(World world) {
    CraftWorld cw = (CraftWorld) world;
    WorldServer ws = cw.getHandle();
    // getDimensionManager
    DimensionManager delegate = ws.q_();
    DimensionManager replacement = DimensionManager.a((OptionalLong) queryDimensionManagerPrivateField("w", delegate), (boolean) queryDimensionManagerPrivateField("x", delegate), (boolean) queryDimensionManagerPrivateField("y", delegate), (boolean) queryDimensionManagerPrivateField("z", delegate), (boolean) queryDimensionManagerPrivateField("A", delegate), (double) queryDimensionManagerPrivateField("B", delegate), (boolean) queryDimensionManagerPrivateField("C", delegate), (boolean) queryDimensionManagerPrivateField("D", delegate), (boolean) queryDimensionManagerPrivateField("E", delegate), (boolean) queryDimensionManagerPrivateField("F", delegate), (boolean) queryDimensionManagerPrivateField("G", delegate), // minY
    Terraplusminus.config.getInt("min-height"), // Height
    Terraplusminus.config.getInt("max-height"), // Logical Height
    Terraplusminus.config.getInt("max-height"), (MinecraftKey) queryDimensionManagerPrivateField("K", delegate), (MinecraftKey) queryDimensionManagerPrivateField("L", delegate), (float) queryDimensionManagerPrivateField("M", delegate));
    try {
        Terraplusminus.privateFieldHandler.injectField(ws, net.minecraft.world.level.World.class.getDeclaredField("C"), replacement);
        System.out.println("&aSuccessfully injected custom world height!");
        System.out.println("&aNew Heights (WorldServer, Bukkit World):");
        System.out.println("- minY " + ws.q_().k() + "   " + world.getMinHeight());
        System.out.println("- Height " + ws.q_().l() + "   " + world.getMaxHeight());
        System.out.println("- LogicalHeight " + ws.q_().m() + "   " + world.getLogicalHeight());
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : WorldServer(net.minecraft.server.level.WorldServer) DimensionManager(net.minecraft.world.level.dimension.DimensionManager) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 15 with WorldServer

use of net.minecraft.server.level.WorldServer in project BedWars1058 by andrei1058.

the class IGolem method spawn.

public static LivingEntity spawn(Location loc, ITeam bedWarsTeam, double speed, double health, int despawn) {
    WorldServer mcWorld = ((CraftWorld) Objects.requireNonNull(loc.getWorld())).getHandle();
    IGolem customEnt = new IGolem(EntityTypes.P, mcWorld, bedWarsTeam);
    customEnt.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    ((CraftLivingEntity) customEnt.getBukkitEntity()).setRemoveWhenFarAway(false);
    customEnt.setCustomNameVisible(true);
    customEnt.setPersistent();
    Objects.requireNonNull(customEnt.getAttributeInstance(GenericAttributes.a)).setValue(health);
    Objects.requireNonNull(customEnt.getAttributeInstance(GenericAttributes.d)).setValue(speed);
    mcWorld.addEntity(customEnt, CreatureSpawnEvent.SpawnReason.CUSTOM);
    customEnt.getBukkitEntity().setCustomName(Language.getDefaultLanguage().m(Messages.SHOP_UTILITY_NPC_IRON_GOLEM_NAME).replace("{despawn}", String.valueOf(despawn).replace("{health}", StringUtils.repeat(Language.getDefaultLanguage().m(Messages.FORMATTING_DESPAWNABLE_UTILITY_NPC_HEALTH) + " ", 10)).replace("{TeamColor}", bedWarsTeam.getColor().chat().toString())));
    return (LivingEntity) customEnt.getBukkitEntity();
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) WorldServer(net.minecraft.server.level.WorldServer) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Aggregations

WorldServer (net.minecraft.server.level.WorldServer)27 EntityItem (net.minecraft.world.entity.item.EntityItem)9 BlockPosition (net.minecraft.core.BlockPosition)8 EntityPlayer (net.minecraft.server.level.EntityPlayer)7 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)6 Field (java.lang.reflect.Field)5 PacketPlayOutSpawnEntity (net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity)5 Entity (net.minecraft.world.entity.Entity)5 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)5 Method (java.lang.reflect.Method)4 World (org.bukkit.World)4 LivingEntity (org.bukkit.entity.LivingEntity)4 PacketType (com.comphenix.protocol.PacketType)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 InteractionVisualizer (com.loohp.interactionvisualizer.InteractionVisualizer)3 BlockPosition (com.loohp.interactionvisualizer.objectholders.BlockPosition)3 BoundingBox (com.loohp.interactionvisualizer.objectholders.BoundingBox)3 ChunkPosition (com.loohp.interactionvisualizer.objectholders.ChunkPosition)3 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)3 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)3