mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-05 07:58:11 +01:00
Added new island create/created/reset/resetted events
Removed debug.
This commit is contained in:
parent
6d6f8954d2
commit
09ac5c439e
@ -24,6 +24,7 @@ import us.tastybento.bskyblock.BSkyBlock;
|
|||||||
import us.tastybento.bskyblock.api.commands.AbstractCommand;
|
import us.tastybento.bskyblock.api.commands.AbstractCommand;
|
||||||
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
|
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
|
||||||
import us.tastybento.bskyblock.api.commands.CanUseResp;
|
import us.tastybento.bskyblock.api.commands.CanUseResp;
|
||||||
|
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||||
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
@ -334,6 +335,7 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
try {
|
try {
|
||||||
NewIsland.builder()
|
NewIsland.builder()
|
||||||
.player(player)
|
.player(player)
|
||||||
|
.reason(Reason.RESET)
|
||||||
.oldIsland(oldIsland)
|
.oldIsland(oldIsland)
|
||||||
.build();
|
.build();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -1527,6 +1529,7 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
try {
|
try {
|
||||||
NewIsland.builder()
|
NewIsland.builder()
|
||||||
.player(player)
|
.player(player)
|
||||||
|
.reason(Reason.CREATE)
|
||||||
.build();
|
.build();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().severe("Could not create island for player.");
|
plugin.getLogger().severe("Could not create island for player.");
|
||||||
|
@ -893,6 +893,7 @@ public class IslandsManager {
|
|||||||
Runnable save = () -> {
|
Runnable save = () -> {
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for(Island island : collection){
|
for(Island island : collection){
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: saving island async " + index++);
|
plugin.getLogger().info("DEBUG: saving island async " + index++);
|
||||||
try {
|
try {
|
||||||
handler.saveObject(island);
|
handler.saveObject(island);
|
||||||
@ -905,6 +906,7 @@ public class IslandsManager {
|
|||||||
} else {
|
} else {
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for(Island island : collection){
|
for(Island island : collection){
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: saving island " + index++);
|
plugin.getLogger().info("DEBUG: saving island " + index++);
|
||||||
try {
|
try {
|
||||||
handler.saveObject(island);
|
handler.saveObject(island);
|
||||||
|
@ -7,6 +7,8 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
import us.tastybento.bskyblock.api.events.island.IslandEvent;
|
||||||
|
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||||
@ -23,10 +25,12 @@ public class NewIsland {
|
|||||||
private final BSkyBlock plugin = BSkyBlock.getPlugin();
|
private final BSkyBlock plugin = BSkyBlock.getPlugin();
|
||||||
private Island island;
|
private Island island;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
private final Reason reason;
|
||||||
|
|
||||||
private NewIsland(Island oldIsland, Player player) {
|
private NewIsland(Island oldIsland, Player player, Reason reason) {
|
||||||
super();
|
super();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.reason = reason;
|
||||||
newIsland();
|
newIsland();
|
||||||
if (oldIsland != null) {
|
if (oldIsland != null) {
|
||||||
// Delete the old island
|
// Delete the old island
|
||||||
@ -57,6 +61,7 @@ public class NewIsland {
|
|||||||
public static class Builder {
|
public static class Builder {
|
||||||
private Island oldIsland;
|
private Island oldIsland;
|
||||||
private Player player;
|
private Player player;
|
||||||
|
private Reason reason;
|
||||||
|
|
||||||
public Builder oldIsland(Island oldIsland) {
|
public Builder oldIsland(Island oldIsland) {
|
||||||
this.oldIsland = oldIsland;
|
this.oldIsland = oldIsland;
|
||||||
@ -69,9 +74,14 @@ public class NewIsland {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder reason(Reason reason) {
|
||||||
|
this.reason = reason;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Island build() throws IOException {
|
public Island build() throws IOException {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
NewIsland newIsland = new NewIsland(oldIsland, player);
|
NewIsland newIsland = new NewIsland(oldIsland, player, reason);
|
||||||
return newIsland.getIsland();
|
return newIsland.getIsland();
|
||||||
}
|
}
|
||||||
throw new IOException("Insufficient parameters. Must have a schematic and a player");
|
throw new IOException("Insufficient parameters. Must have a schematic and a player");
|
||||||
@ -110,6 +120,15 @@ public class NewIsland {
|
|||||||
// Set home loction
|
// Set home loction
|
||||||
plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
|
plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
|
||||||
|
|
||||||
|
// Fire event
|
||||||
|
IslandEvent event = IslandEvent.builder()
|
||||||
|
.involvedPlayer(player.getUniqueId())
|
||||||
|
.reason(reason)
|
||||||
|
.island(island)
|
||||||
|
.location(island.getCenter())
|
||||||
|
.build();
|
||||||
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
// Create island
|
// Create island
|
||||||
new IslandBuilder(island)
|
new IslandBuilder(island)
|
||||||
.setPlayer(player)
|
.setPlayer(player)
|
||||||
@ -131,6 +150,26 @@ public class NewIsland {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Fire exit event
|
||||||
|
Reason reasonDone = Reason.CREATED;
|
||||||
|
switch (reason) {
|
||||||
|
case CREATE:
|
||||||
|
reasonDone = Reason.CREATED;
|
||||||
|
break;
|
||||||
|
case RESET:
|
||||||
|
reasonDone = Reason.RESETTED;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
event = IslandEvent.builder()
|
||||||
|
.involvedPlayer(player.getUniqueId())
|
||||||
|
.reason(reasonDone)
|
||||||
|
.island(island)
|
||||||
|
.location(island.getCenter())
|
||||||
|
.build();
|
||||||
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the location of next free island spot
|
* Get the location of next free island spot
|
||||||
|
@ -25,7 +25,7 @@ public class DeleteIslandChunks {
|
|||||||
* @param island
|
* @param island
|
||||||
*/
|
*/
|
||||||
public DeleteIslandChunks(final BSkyBlock plugin, final Island island) {
|
public DeleteIslandChunks(final BSkyBlock plugin, final Island island) {
|
||||||
plugin.getLogger().info("DEBUG: deleting the island");
|
//plugin.getLogger().info("DEBUG: deleting the island");
|
||||||
// Fire event
|
// Fire event
|
||||||
IslandEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
|
IslandEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user