Skip to content

Commit

Permalink
Add IslandSubmittedEvent
Browse files Browse the repository at this point in the history
This event will be called upon player submits his island.
Change that submission always contains "owner" id.
  • Loading branch information
BONNe committed May 18, 2022
1 parent 1891647 commit f27dfca
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package world.bentobox.checkmeout.commands.island;

import org.bukkit.Bukkit;
import java.util.List;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.checkmeout.CheckMeOut;
import world.bentobox.checkmeout.events.IslandSubmittedEvent;
import world.bentobox.checkmeout.panels.Utils;


Expand Down Expand Up @@ -60,8 +63,11 @@ public boolean canExecute(User user, String label, List<String> args)
@Override
public boolean execute(User user, String label, List<String> args)
{
if (this.<CheckMeOut>getAddon().getSubmissionsManager().addSubmission(user.getUniqueId(),
this.getIslands().getHomeLocation(this.getWorld(), user.getUniqueId())))
Island island = this.getIslands().getIsland(this.getWorld(), user.getUniqueId());

if (island != null &&
this.<CheckMeOut>getAddon().getSubmissionsManager().addSubmission(island.getOwner(),
this.getIslands().getHomeLocation(this.getWorld(), user.getUniqueId())))
{
Utils.sendMessage(user, "general.success");
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Created by BONNe
// Copyright - 2022
//


package world.bentobox.checkmeout.events;


import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

import world.bentobox.bentobox.api.events.BentoBoxEvent;


/**
* The type Island submitted event.
*/
public class IslandSubmittedEvent extends BentoBoxEvent
{
/**
* Instantiates a new Island submitted event.
*
* @param uuid the uuid
* @param location the location
*/
public IslandSubmittedEvent(@NotNull UUID uuid, @NotNull Location location)
{
this.location = location;
this.uuid = uuid;
}


/**
* Gets location.
*
* @return the location
*/
@NotNull
public Location getLocation()
{
return location;
}


/**
* Gets uuid.
*
* @return the uuid
*/
@NotNull
public UUID getUuid()
{
return uuid;
}


/**
* The Location of submission.
*/
@NotNull
private final Location location;

/**
* The submitter.
*/
@NotNull
private final UUID uuid;

/**
* Event listener list for current
*/
private static final HandlerList handlers = new HandlerList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.UUID;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
Expand All @@ -23,6 +24,7 @@
import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
import world.bentobox.checkmeout.CheckMeOut;
import world.bentobox.checkmeout.events.IslandSubmittedEvent;
import world.bentobox.checkmeout.objects.SubmissionData;

/**
Expand Down Expand Up @@ -81,6 +83,10 @@ public boolean addSubmission(final UUID playerUUID, final Location loc) {
}
getSubmissionsMap(loc.getWorld()).put(playerUUID, loc);
saveSubmissions();

// Call submitted event.
Bukkit.getServer().getPluginManager().callEvent(new IslandSubmittedEvent(playerUUID, loc));

return true;
}

Expand Down

0 comments on commit f27dfca

Please sign in to comment.