Skip to content

Commit

Permalink
Added ability to edit the BlueprintBundle in IslandCreate/ResetEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Poslovitch committed Jul 4, 2019
1 parent 00ac8dd commit d9d4805
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;

import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.blueprints.Blueprint;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.lists.Flags;
Expand Down Expand Up @@ -177,9 +180,27 @@ public IslandUnbanEvent(Island island, UUID player, boolean admin, Location loca
*
*/
public static class IslandCreateEvent extends IslandBaseEvent {
private IslandCreateEvent(Island island, UUID player, boolean admin, Location location) {
private @NonNull BlueprintBundle blueprintBundle;

private IslandCreateEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.blueprintBundle = blueprintBundle;
}

/**
* @since 1.6.0
*/
@NonNull
public BlueprintBundle getBlueprintBundle() {
return blueprintBundle;
}

/**
* @since 1.6.0
*/
public void setBlueprintBundle(@NonNull BlueprintBundle blueprintBundle) {
this.blueprintBundle = blueprintBundle;
}
}
/**
Expand Down Expand Up @@ -307,9 +328,27 @@ private IslandUnlockEvent(Island island, UUID player, boolean admin, Location lo
* May be cancelled.
*/
public static class IslandResetEvent extends IslandBaseEvent {
private IslandResetEvent(Island island, UUID player, boolean admin, Location location) {
private @NonNull BlueprintBundle blueprintBundle;

private IslandResetEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.blueprintBundle = blueprintBundle;
}

/**
* @since 1.6.0
*/
@NonNull
public BlueprintBundle getBlueprintBundle() {
return blueprintBundle;
}

/**
* @since 1.6.0
*/
public void setBlueprintBundle(@NonNull BlueprintBundle blueprintBundle) {
this.blueprintBundle = blueprintBundle;
}
}
/**
Expand Down Expand Up @@ -341,6 +380,7 @@ public static class IslandEventBuilder {
private boolean admin;
private Location location;
private IslandDeletion deletedIslandInfo;
private BlueprintBundle blueprintBundle;

public IslandEventBuilder island(Island island) {
this.island = island;
Expand Down Expand Up @@ -385,6 +425,15 @@ public IslandEventBuilder deletedIslandInfo(IslandDeletion deletedIslandInfo) {
return this;
}

/**
* @since 1.6.0
*/
@NonNull
public IslandEventBuilder blueprintBundle(@NonNull BlueprintBundle blueprintBundle) {
this.blueprintBundle = blueprintBundle;
return this;
}

public IslandBaseEvent build() {
// Call the generic event for developers who just want one event and use the Reason enum
Bukkit.getServer().getPluginManager().callEvent(new IslandEvent(island, player, admin, location, reason));
Expand All @@ -399,7 +448,7 @@ public IslandBaseEvent build() {
Bukkit.getServer().getPluginManager().callEvent(ban);
return ban;
case CREATE:
IslandCreateEvent create = new IslandCreateEvent(island, player, admin, location);
IslandCreateEvent create = new IslandCreateEvent(island, player, admin, location, blueprintBundle);
Bukkit.getServer().getPluginManager().callEvent(create);
return create;
case CREATED:
Expand Down Expand Up @@ -431,7 +480,7 @@ public IslandBaseEvent build() {
Bukkit.getServer().getPluginManager().callEvent(lock);
return lock;
case RESET:
IslandResetEvent reset = new IslandResetEvent(island, player, admin, location);
IslandResetEvent reset = new IslandResetEvent(island, player, admin, location, blueprintBundle);
Bukkit.getServer().getPluginManager().callEvent(reset);
return reset;
case RESETTED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class NewIsland {
private final User user;
private final Reason reason;
private final World world;
private final String name;
private String name;
private final boolean noPaste;
private GameModeAddon addon;

Expand Down Expand Up @@ -185,10 +185,24 @@ public void newIsland(Island oldIsland) {
.reason(reason)
.island(island)
.location(island.getCenter())
.blueprintBundle(plugin.getBlueprintsManager().getBlueprintBundles(addon).get(name))
.build();
if (event.isCancelled()) {
return;
}

// Get the new BlueprintBundle if it was changed
switch (reason) {
case CREATE:
name = ((IslandEvent.IslandCreateEvent) event).getBlueprintBundle().getUniqueId();
break;
case RESET:
name = ((IslandEvent.IslandResetEvent) event).getBlueprintBundle().getUniqueId();
break;
default:
break;
}

// Task to run after creating the island
Runnable task = () -> {
// Set initial spawn point if one exists
Expand Down

0 comments on commit d9d4805

Please sign in to comment.