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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
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();
}
Aggregations