Added #getOldIsland() in island reset-related events (#1179)

* Reaching Old Island information in Island reset events

* Added javadocs since tags

* added javadoc since tags for new field/method in builder

Co-authored-by: Florian CUNY <poslovitch@bentobox.world>
This commit is contained in:
Draww 2020-02-19 23:36:05 +02:00 committed by GitHub
parent 795925f0cd
commit 1e71d67a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 4 deletions

View File

@ -337,12 +337,29 @@ public class IslandEvent extends IslandBaseEvent {
* May be cancelled.
*/
public static class IslandResetEvent extends IslandBaseEvent {
private @NonNull Island oldIsland;
private @NonNull BlueprintBundle blueprintBundle;
private IslandResetEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle) {
private IslandResetEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle, @NonNull Island oldIsland) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.blueprintBundle = blueprintBundle;
this.oldIsland = oldIsland;
}
/**
* @since 1.12.0
*/
@NonNull
public Island getOldIsland() {
return oldIsland;
}
/**
* @since 1.12.0
*/
public void setOldIsland(Island oldIsland) {
this.oldIsland = oldIsland;
}
/**
@ -365,9 +382,27 @@ public class IslandEvent extends IslandBaseEvent {
*
*/
public static class IslandResettedEvent extends IslandBaseEvent {
private IslandResettedEvent(Island island, UUID player, boolean admin, Location location) {
private @NonNull Island oldIsland;
private IslandResettedEvent(Island island, UUID player, boolean admin, Location location, Island oldIsland) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.oldIsland = oldIsland;
}
/**
* @since 1.12.0
*/
@NonNull
public Island getOldIsland() {
return oldIsland;
}
/**
* @since 1.12.0
*/
public void setOldIsland(Island oldIsland) {
this.oldIsland = oldIsland;
}
}
/**
@ -472,11 +507,27 @@ public class IslandEvent extends IslandBaseEvent {
*/
private int oldRange;
/**
* Stores old island object
* @since 1.12.0
*/
private Island oldIsland;
public IslandEventBuilder island(Island island) {
this.island = island;
return this;
}
/**
* @param oldIsland old island object
* @return IslandEventBuilder
* @since 1.12.0
*/
public IslandEventBuilder oldIsland(Island oldIsland) {
this.oldIsland = oldIsland;
return this;
}
/**
* True if this is an admin driven event
* @param admin - true if due to admin event
@ -585,11 +636,11 @@ public class IslandEvent extends IslandBaseEvent {
Bukkit.getPluginManager().callEvent(lock);
return lock;
case RESET:
IslandResetEvent reset = new IslandResetEvent(island, player, admin, location, blueprintBundle);
IslandResetEvent reset = new IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland);
Bukkit.getPluginManager().callEvent(reset);
return reset;
case RESETTED:
IslandResettedEvent resetted = new IslandResettedEvent(island, player, admin, location);
IslandResettedEvent resetted = new IslandResettedEvent(island, player, admin, location, oldIsland);
Bukkit.getPluginManager().callEvent(resetted);
return resetted;
case UNBAN:

View File

@ -207,6 +207,7 @@ public class NewIsland {
.island(island)
.location(island.getCenter())
.blueprintBundle(plugin.getBlueprintsManager().getBlueprintBundles(addon).get(name))
.oldIsland(oldIsland)
.build();
if (event.isCancelled()) {
return;
@ -267,6 +268,7 @@ public class NewIsland {
.reason(reasonDone)
.island(island)
.location(island.getCenter())
.oldIsland(oldIsland)
.build();
};
if (noPaste) {