mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-27 11:37:36 +01:00
Updated EnterExitListener to fire IslandEnterEvent and IslandExitEvent
This commit is contained in:
parent
d04b286055
commit
bd2cc1b63e
@ -39,7 +39,8 @@ public class IslandEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an island is going to be created. May be canceled.
|
||||
* Fired when an island is going to be created.
|
||||
* May be cancelled.
|
||||
*
|
||||
*/
|
||||
public static class IslandCreateEvent extends IslandBaseEvent {
|
||||
@ -59,7 +60,8 @@ public class IslandEvent {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Fired when an island is going to be deleted. May be canceled.
|
||||
* Fired when an island is going to be deleted.
|
||||
* May be cancelled.
|
||||
*
|
||||
*/
|
||||
public static class IslandDeleteEvent extends IslandBaseEvent {
|
||||
@ -79,8 +81,8 @@ public class IslandEvent {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Fired when an a player enters an island
|
||||
*
|
||||
* Fired when an a player enters an island.
|
||||
* Cancellation has no effect.
|
||||
*/
|
||||
public static class IslandEnterEvent extends IslandBaseEvent {
|
||||
private IslandEnterEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
@ -89,8 +91,8 @@ public class IslandEvent {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Fired when a player exits and island
|
||||
*
|
||||
* Fired when a player exits an island.
|
||||
* Cancellation has no effect.
|
||||
*/
|
||||
public static class IslandExitEvent extends IslandBaseEvent {
|
||||
private IslandExitEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
@ -119,8 +121,8 @@ public class IslandEvent {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Fired when an island is going to be reset. May be canceled.
|
||||
*
|
||||
* Fired when an island is going to be reset.
|
||||
* May be cancelled.
|
||||
*/
|
||||
public static class IslandResetEvent extends IslandBaseEvent {
|
||||
private IslandResetEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
|
@ -10,6 +10,8 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.flags.AbstractFlagListener;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -34,8 +36,8 @@ public class EnterExitListener extends AbstractFlagListener {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Island> from = this.getIslands().getProtectedIslandAt(e.getFrom());
|
||||
Optional<Island> to = this.getIslands().getProtectedIslandAt(e.getTo());
|
||||
Optional<Island> from = getIslands().getProtectedIslandAt(e.getFrom());
|
||||
Optional<Island> to = getIslands().getProtectedIslandAt(e.getTo());
|
||||
|
||||
/*
|
||||
* Options:
|
||||
@ -51,14 +53,47 @@ public class EnterExitListener extends AbstractFlagListener {
|
||||
}
|
||||
|
||||
User user = User.getInstance(e.getPlayer());
|
||||
// Send message if island is owned by someone
|
||||
from.filter(i -> i.getOwner() != null).ifPresent(i -> user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
||||
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner()))));
|
||||
to.filter(i -> i.getOwner() != null).ifPresent(i -> user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
||||
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner()))));
|
||||
|
||||
// Send message if island is unowned, but has a name
|
||||
from.filter(i -> i.getOwner() == null && (i.getName() != null)).ifPresent(i -> user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, i.getName()));
|
||||
to.filter(i -> i.getOwner() == null && (i.getName() != null)).ifPresent(i -> user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, i.getName()));
|
||||
from.ifPresent(i -> {
|
||||
// Fire the IslandExitEvent
|
||||
new IslandEvent.IslandEventBuilder()
|
||||
.island(i)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.reason(IslandEvent.Reason.EXIT)
|
||||
.admin(false)
|
||||
.location(user.getLocation())
|
||||
.build();
|
||||
|
||||
// Send message if island is owned by someone
|
||||
if (i.getOwner() != null) {
|
||||
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
||||
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner())));
|
||||
}
|
||||
// Send message if island is unowned, but has a name
|
||||
else if (i.getName() != null) {
|
||||
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, i.getName());
|
||||
}
|
||||
});
|
||||
|
||||
to.ifPresent(i -> {
|
||||
// Fire the IslandEnterEvent
|
||||
new IslandEvent.IslandEventBuilder()
|
||||
.island(i)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.reason(IslandEvent.Reason.ENTER)
|
||||
.admin(false)
|
||||
.location(user.getLocation())
|
||||
.build();
|
||||
|
||||
// Send message if island is owned by someone
|
||||
if (i.getOwner() != null) {
|
||||
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (i.getName() != null) ? i.getName() :
|
||||
user.getTranslation("protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(i.getOwner())));
|
||||
}
|
||||
// Send message if island is unowned, but has a name
|
||||
else if (i.getName() != null) {
|
||||
user.notify("protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, i.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user