mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 05:05:18 +01:00
Added IslandExitEvent#getToIsland() and IslandEnterEvent#getFromIsland() (#1557)
* Added IslandExitEvent#getToIsland() and IslandEnterEvent#getFromIsland() * Added IslandEventBuilder#rawEvent(Event) and IslandBaseEvent#getRawEvent()
This commit is contained in:
parent
cf394eae9f
commit
1a9f9e7b21
@ -4,6 +4,8 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
||||
@ -17,6 +19,7 @@ public class IslandBaseEvent extends BentoBoxEvent implements Cancellable {
|
||||
protected final UUID playerUUID;
|
||||
protected final boolean admin;
|
||||
protected final Location location;
|
||||
protected final Event rawEvent;
|
||||
|
||||
public IslandBaseEvent(Island island) {
|
||||
super();
|
||||
@ -24,6 +27,7 @@ public class IslandBaseEvent extends BentoBoxEvent implements Cancellable {
|
||||
playerUUID = island == null ? null : island.getOwner();
|
||||
admin = false;
|
||||
location = island == null ? null : island.getCenter();
|
||||
rawEvent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,6 +42,23 @@ public class IslandBaseEvent extends BentoBoxEvent implements Cancellable {
|
||||
this.playerUUID = playerUUID;
|
||||
this.admin = admin;
|
||||
this.location = location;
|
||||
rawEvent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param island - island
|
||||
* @param playerUUID - the player's UUID
|
||||
* @param admin - true if ths is due to an admin event
|
||||
* @param location - the location
|
||||
* @param rawEvent - the raw event
|
||||
*/
|
||||
public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location, Event rawEvent) {
|
||||
super();
|
||||
this.island = island;
|
||||
this.playerUUID = playerUUID;
|
||||
this.admin = admin;
|
||||
this.location = location;
|
||||
this.rawEvent = rawEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,6 +96,14 @@ public class IslandBaseEvent extends BentoBoxEvent implements Cancellable {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the raw event
|
||||
*/
|
||||
@Nullable
|
||||
public Event getRawEvent() {
|
||||
return rawEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
@ -4,7 +4,9 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||
@ -362,9 +364,18 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
* Cancellation has no effect.
|
||||
*/
|
||||
public static class IslandEnterEvent extends IslandBaseEvent {
|
||||
private IslandEnterEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
|
||||
private final @Nullable Island fromIsland;
|
||||
|
||||
private IslandEnterEvent(Island island, UUID player, boolean admin, Location location, Island fromIsland, Event rawEvent) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
super(island, player, admin, location, rawEvent);
|
||||
this.fromIsland = fromIsland;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Island getFromIsland() {
|
||||
return fromIsland;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -372,10 +383,22 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
* Cancellation has no effect.
|
||||
*/
|
||||
public static class IslandExitEvent extends IslandBaseEvent {
|
||||
private IslandExitEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
|
||||
private final @Nullable Island toIsland;
|
||||
|
||||
|
||||
private IslandExitEvent(Island island, UUID player, boolean admin, Location location, Island toIsland, Event rawEvent) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
super(island, player, admin, location, rawEvent);
|
||||
this.toIsland = toIsland;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Island getToIsland() {
|
||||
return toIsland;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Fired when an island is locked
|
||||
@ -573,6 +596,7 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
private Location location;
|
||||
private IslandDeletion deletedIslandInfo;
|
||||
private BlueprintBundle blueprintBundle;
|
||||
private Event rawEvent;
|
||||
|
||||
/**
|
||||
* Stores new protection range for island.
|
||||
@ -648,6 +672,11 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IslandEventBuilder rawEvent(Event event) {
|
||||
rawEvent = event;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IslandEventBuilder deletedIslandInfo(IslandDeletion deletedIslandInfo) {
|
||||
this.deletedIslandInfo = deletedIslandInfo;
|
||||
return this;
|
||||
@ -724,11 +753,11 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
Bukkit.getPluginManager().callEvent(deleted);
|
||||
return deleted;
|
||||
case ENTER:
|
||||
IslandEnterEvent enter = new IslandEnterEvent(island, player, admin, location);
|
||||
IslandEnterEvent enter = new IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent);
|
||||
Bukkit.getPluginManager().callEvent(enter);
|
||||
return enter;
|
||||
case EXIT:
|
||||
IslandExitEvent exit = new IslandExitEvent(island, player, admin, location);
|
||||
IslandExitEvent exit = new IslandExitEvent(island, player, admin, location, oldIsland, rawEvent);
|
||||
Bukkit.getPluginManager().callEvent(exit);
|
||||
return exit;
|
||||
case LOCK:
|
||||
|
@ -28,15 +28,15 @@ public class EnterExitListener extends FlagListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
handleEnterExit(User.getInstance(e.getPlayer()), e.getFrom(), e.getTo());
|
||||
handleEnterExit(User.getInstance(e.getPlayer()), e.getFrom(), e.getTo(), e);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
handleEnterExit(User.getInstance(e.getPlayer()), e.getFrom(), e.getTo());
|
||||
handleEnterExit(User.getInstance(e.getPlayer()), e.getFrom(), e.getTo(), e);
|
||||
}
|
||||
|
||||
private void handleEnterExit(@NonNull User user, @NonNull Location from, @NonNull Location to) {
|
||||
private void handleEnterExit(@NonNull User user, @NonNull Location from, @NonNull Location to, @NonNull PlayerMoveEvent e) {
|
||||
// Only process if there is a change in X or Z coords
|
||||
if (from.getWorld() != null && from.getWorld().equals(to.getWorld())
|
||||
&& from.toVector().multiply(XZ).equals(to.toVector().multiply(XZ))) {
|
||||
@ -63,10 +63,12 @@ public class EnterExitListener extends FlagListener {
|
||||
// Fire the IslandExitEvent
|
||||
new IslandEvent.IslandEventBuilder()
|
||||
.island(i)
|
||||
.oldIsland(islandTo.isPresent() ? islandTo.get() : null)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.reason(IslandEvent.Reason.EXIT)
|
||||
.admin(false)
|
||||
.location(user.getLocation())
|
||||
.rawEvent(e)
|
||||
.build();
|
||||
|
||||
sendExitNotification(user, i);
|
||||
@ -76,10 +78,12 @@ public class EnterExitListener extends FlagListener {
|
||||
// Fire the IslandEnterEvent
|
||||
new IslandEvent.IslandEventBuilder()
|
||||
.island(i)
|
||||
.oldIsland(islandFrom.isPresent() ? islandFrom.get() : null)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.reason(IslandEvent.Reason.ENTER)
|
||||
.admin(false)
|
||||
.location(user.getLocation())
|
||||
.rawEvent(e)
|
||||
.build();
|
||||
|
||||
sendEnterNotification(user, i);
|
||||
|
Loading…
Reference in New Issue
Block a user