use of org.bukkit.craftbukkit.v1_13_R1.CraftServer in project LoliServer by Loli-Server.
the class CraftEventFactory method callEntityTameEvent.
/**
* EntityTameEvent
*/
public static EntityTameEvent callEntityTameEvent(MobEntity entity, PlayerEntity tamer) {
org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
org.bukkit.entity.AnimalTamer bukkitTamer = (tamer != null ? tamer.getBukkitEntity() : null);
CraftServer craftServer = (CraftServer) bukkitEntity.getServer();
entity.persistenceRequired = true;
EntityTameEvent event = new EntityTameEvent((org.bukkit.entity.LivingEntity) bukkitEntity, bukkitTamer);
craftServer.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftServer in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method callInventoryOpenEvent.
public static Container callInventoryOpenEvent(ServerPlayerEntity player, Container container, boolean cancelled) {
if (player.containerMenu != player.inventoryMenu) {
// fire INVENTORY_CLOSE if one already open
player.connection.handleContainerClose(new CCloseWindowPacket(player.containerMenu.containerId));
}
CraftServer server = player.level.getServerCB();
CraftPlayer craftPlayer = player.getBukkitEntity();
try {
player.containerMenu.transferTo(container, craftPlayer);
} catch (AbstractMethodError e) {
// Magma - modded
}
InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
event.setCancelled(cancelled);
if (container.getBukkitView() != null) {
server.getPluginManager().callEvent(event);
}
if (event.isCancelled()) {
container.transferTo(player.containerMenu, craftPlayer);
if (!cancelled) {
// fire INVENTORY_CLOSE if one already open
player.containerMenu = container;
player.closeContainer();
player.containerMenu = player.inventoryMenu;
}
return null;
}
return container;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftServer in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method callBlockPlaceEvent.
public static BlockPlaceEvent callBlockPlaceEvent(ServerWorld world, PlayerEntity who, Hand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
CraftWorld craftWorld = world.getWorldCB();
CraftServer craftServer = world.getServerCB();
Player player = (Player) who.getBukkitEntity();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
Block placedBlock = replacedBlockState.getBlock();
boolean canBuild = canBuild(world, player, placedBlock.getX(), placedBlock.getZ());
org.bukkit.inventory.ItemStack item;
EquipmentSlot equipmentSlot;
if (hand == Hand.MAIN_HAND) {
item = player.getInventory().getItemInMainHand();
equipmentSlot = EquipmentSlot.HAND;
} else {
item = player.getInventory().getItemInOffHand();
equipmentSlot = EquipmentSlot.OFF_HAND;
}
BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild, equipmentSlot);
craftServer.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftServer in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method canBuild.
// helper methods
private static boolean canBuild(World world, Player player, int x, int z) {
int spawnSize = Bukkit.getServer().getSpawnRadius();
if (world.dimension() != World.OVERWORLD)
return true;
if (spawnSize <= 0)
return true;
if (((CraftServer) Bukkit.getServer()).getHandle().getOps().isEmpty())
return true;
if (player.isOp())
return true;
BlockPos chunkcoordinates = getSharedSpawnPos(world);
int distanceFromSpawn = Math.max(Math.abs(x - chunkcoordinates.getX()), Math.abs(z - chunkcoordinates.getZ()));
return distanceFromSpawn > spawnSize;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftServer in project Magma-1.16.x by magmafoundation.
the class CraftEventFactory method callBlockDamageEvent.
/**
* BlockDamageEvent
*/
public static BlockDamageEvent callBlockDamageEvent(PlayerEntity who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = craftWorld.getBlockAt(x, y, z);
BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
craftServer.getPluginManager().callEvent(event);
return event;
}
Aggregations