#724: Re-implement player portal event search radius and creation API
This also fixes that the nether/end portals would be created even if the event was cancelled as well as that the EntityPortalEvent would be called for player portal usage which is not according to its API specification By: Phoenix616 <max@themoep.de>
This commit is contained in:
@@ -1572,22 +1572,6 @@ public class CraftEventFactory {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* EntityPortalEvent
|
||||
*/
|
||||
public static EntityPortalEvent callEntityPortalEvent(Entity entity, World exitWorld, BlockPosition exitPosition, int searchRadius) {
|
||||
org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
|
||||
Location enter = bukkitEntity.getLocation();
|
||||
Location exit = new Location(exitWorld.getWorld(), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ());
|
||||
|
||||
EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius);
|
||||
event.getEntity().getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !entity.isAlive()) {
|
||||
return null;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootTableInfo lootInfo, List<ItemStack> loot, boolean plugin) {
|
||||
CraftWorld world = lootInfo.getWorld().getWorld();
|
||||
Entity entity = lootInfo.getContextParameter(LootContextParameters.THIS_ENTITY);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.bukkit.craftbukkit.event;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.entity.EntityPortalEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
|
||||
/**
|
||||
* Helper class to hold information from the {@link PlayerPortalEvent} and {@link EntityPortalEvent}
|
||||
*/
|
||||
public class CraftPortalEvent {
|
||||
private final Location to;
|
||||
private final int searchRadius;
|
||||
private final int creationRadius;
|
||||
|
||||
private final boolean canCreatePortal;
|
||||
private final boolean cancelled;
|
||||
|
||||
public CraftPortalEvent(EntityPortalEvent portalEvent) {
|
||||
to = portalEvent.getTo();
|
||||
searchRadius = portalEvent.getSearchRadius();
|
||||
cancelled = portalEvent.isCancelled();
|
||||
creationRadius = 0;
|
||||
canCreatePortal = false;
|
||||
}
|
||||
|
||||
public CraftPortalEvent(PlayerPortalEvent portalEvent) {
|
||||
to = portalEvent.getTo();
|
||||
searchRadius = portalEvent.getSearchRadius();
|
||||
creationRadius = portalEvent.getCreationRadius();
|
||||
canCreatePortal = portalEvent.getCanCreatePortal();
|
||||
cancelled = portalEvent.isCancelled();
|
||||
}
|
||||
|
||||
public Location getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public int getSearchRadius() {
|
||||
return searchRadius;
|
||||
}
|
||||
|
||||
public int getCreationRadius() {
|
||||
return creationRadius;
|
||||
}
|
||||
|
||||
public boolean getCanCreatePortal() {
|
||||
return canCreatePortal;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user