Added new island create/created/reset/resetted events

Removed debug.
This commit is contained in:
Tastybento 2017-12-09 12:27:01 -08:00
parent 6d6f8954d2
commit 09ac5c439e
4 changed files with 63 additions and 19 deletions

View File

@ -24,6 +24,7 @@ import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.AbstractCommand;
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
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.TeamReason;
import us.tastybento.bskyblock.config.Settings;
@ -334,6 +335,7 @@ public class IslandCommand extends AbstractCommand {
try {
NewIsland.builder()
.player(player)
.reason(Reason.RESET)
.oldIsland(oldIsland)
.build();
} catch (IOException e) {
@ -1527,6 +1529,7 @@ public class IslandCommand extends AbstractCommand {
try {
NewIsland.builder()
.player(player)
.reason(Reason.CREATE)
.build();
} catch (IOException e) {
plugin.getLogger().severe("Could not create island for player.");

View File

@ -893,6 +893,7 @@ public class IslandsManager {
Runnable save = () -> {
int index = 1;
for(Island island : collection){
if (DEBUG)
plugin.getLogger().info("DEBUG: saving island async " + index++);
try {
handler.saveObject(island);
@ -905,6 +906,7 @@ public class IslandsManager {
} else {
int index = 1;
for(Island island : collection){
if (DEBUG)
plugin.getLogger().info("DEBUG: saving island " + index++);
try {
handler.saveObject(island);

View File

@ -7,6 +7,8 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
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.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
@ -23,10 +25,12 @@ public class NewIsland {
private final BSkyBlock plugin = BSkyBlock.getPlugin();
private Island island;
private final Player player;
private final Reason reason;
private NewIsland(Island oldIsland, Player player) {
private NewIsland(Island oldIsland, Player player, Reason reason) {
super();
this.player = player;
this.reason = reason;
newIsland();
if (oldIsland != null) {
// Delete the old island
@ -57,6 +61,7 @@ public class NewIsland {
public static class Builder {
private Island oldIsland;
private Player player;
private Reason reason;
public Builder oldIsland(Island oldIsland) {
this.oldIsland = oldIsland;
@ -69,9 +74,14 @@ public class NewIsland {
return this;
}
public Builder reason(Reason reason) {
this.reason = reason;
return this;
}
public Island build() throws IOException {
if (player != null) {
NewIsland newIsland = new NewIsland(oldIsland, player);
NewIsland newIsland = new NewIsland(oldIsland, player, reason);
return newIsland.getIsland();
}
throw new IOException("Insufficient parameters. Must have a schematic and a player");
@ -110,6 +120,15 @@ public class NewIsland {
// Set home loction
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
new IslandBuilder(island)
.setPlayer(player)
@ -131,6 +150,26 @@ public class NewIsland {
.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

View File

@ -25,7 +25,7 @@ public class DeleteIslandChunks {
* @param 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
IslandEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
plugin.getServer().getPluginManager().callEvent(event);