Skip to content

Commit

Permalink
Rework BiomeUnlockedEvent.
Browse files Browse the repository at this point in the history
Use user, island and biomesObjects instead of their uuids.
  • Loading branch information
BONNe committed Jan 18, 2022
1 parent a8c167e commit 1d7defb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
package world.bentobox.biomes.events;


import org.bukkit.block.Biome;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;

Expand All @@ -21,7 +23,7 @@
/**
* This event is fired when user is trying to unlock biome. It is cancellable.
*/
public class BiomeUnlockEvent extends BentoBoxEvent implements Cancellable
public class BiomeUnlockedEvent extends BentoBoxEvent implements Cancellable
{
/**
* Instantiates a new biome unlock event.
Expand All @@ -30,79 +32,82 @@ public class BiomeUnlockEvent extends BentoBoxEvent implements Cancellable
* @param user the user
* @param island the island
*/
public BiomeUnlockEvent(BiomesObject biome, @Nullable User user, Island island)
public BiomeUnlockedEvent(@NotNull BiomesObject biome,
@Nullable User user,
@NotNull Island island)
{
this.biome = biome.getFriendlyName();
this.biomeId = biome.getUniqueId();

this.targetPlayer = user == null ? null : user.getUniqueId();
this.islandUUID = island.getUniqueId();
this.biomesObject = biome;
this.user = user;
this.island = island;
}


/**
* Gets target player.
* Gets user.
*
* @return the target player
* @return the user
*/
public UUID getTargetPlayer()
@Nullable
public User getUser()
{
return targetPlayer;
return this.user;
}


/**
* Sets target player.
* Gets user uuid.
*
* @param targetPlayer the target player
* @return the user uuid
*/
public void setTargetPlayer(UUID targetPlayer)
public UUID getUserUUID()
{
this.targetPlayer = targetPlayer;
return this.user == null ? null : this.user.getUniqueId();
}


/**
* Gets island uuid.
* Gets island.
*
* @return the island uuid
* @return the island
*/
public String getIslandUUID()
@NotNull
public Island getIsland()
{
return islandUUID;
return this.island;
}


/**
* Sets island uuid.
* Gets island uuid.
*
* @param islandUUID the island uuid
* @return the island uuid
*/
public void setIslandUUID(String islandUUID)
public String getIslandUUID()
{
this.islandUUID = islandUUID;
return this.island.getUniqueId();
}


/**
* Gets biome.
* Gets biomes object.
*
* @return the biome
* @return the biomes object
*/
public String getBiome()
@NotNull
public BiomesObject getBiomesObject()
{
return biome;
return this.biomesObject;
}


/**
* Sets biome.
* Gets biome.
*
* @param biome the biome
* @return the biome
*/
public void setBiome(String biome)
public Biome getBiome()
{
this.biome = biome;
return this.biomesObject.getBiome();
}


Expand All @@ -113,18 +118,7 @@ public void setBiome(String biome)
*/
public String getBiomeId()
{
return biomeId;
}


/**
* Sets biome id.
*
* @param biomeId the biome id
*/
public void setBiomeId(String biomeId)
{
this.biomeId = biomeId;
return this.biomesObject.getUniqueId();
}


Expand Down Expand Up @@ -167,7 +161,7 @@ public void setCancelled(boolean cancel)
@Override
public HandlerList getHandlers()
{
return BiomeUnlockEvent.handlers;
return BiomeUnlockedEvent.handlers;
}


Expand All @@ -178,7 +172,7 @@ public HandlerList getHandlers()
*/
public static HandlerList getHandlerList()
{
return BiomeUnlockEvent.handlers;
return BiomeUnlockedEvent.handlers;
}


Expand All @@ -187,24 +181,22 @@ public static HandlerList getHandlerList()
// ---------------------------------------------------------------------

/**
* Player who unlocks biome.
*/
private UUID targetPlayer;

/**
* Island Id.
* The User.
*/
private String islandUUID;
@Nullable
private final User user;

/**
* Friendly name for biome.
* The Island.
*/
private String biome;
@NotNull
private final Island island;

/**
* Biome ID.
* The Biomes object.
*/
private String biomeId;
@NotNull
private final BiomesObject biomesObject;

/**
* Boolean that indicates if event is cancelled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import world.bentobox.biomes.database.objects.BiomesBundleObject;
import world.bentobox.biomes.database.objects.BiomesIslandDataObject;
import world.bentobox.biomes.database.objects.BiomesObject;
import world.bentobox.biomes.events.BiomeUnlockEvent;
import world.bentobox.biomes.events.BiomeUnlockedEvent;
import world.bentobox.biomes.events.BiomePurchasedEvent;
import world.bentobox.biomes.utils.Constants;
import world.bentobox.biomes.utils.Utils;
Expand Down Expand Up @@ -710,7 +710,7 @@ public void unlockBiome(@NotNull BiomesIslandDataObject dataObject,
}

// Create and call bukkit event to check if unlocking should be cancelled.
BiomeUnlockEvent event = new BiomeUnlockEvent(biomesObject, user, island);
BiomeUnlockedEvent event = new BiomeUnlockedEvent(biomesObject, user, island);
Bukkit.getPluginManager().callEvent(event);

if (!event.isCancelled())
Expand Down

0 comments on commit 1d7defb

Please sign in to comment.