Skip to content

Commit

Permalink
Merge changes from fork (#4)
Browse files Browse the repository at this point in the history
* Fix a bug with Vault Economy not found in loading process.

If plugin that enables Vault do it after BentoBox, then a lot of addons disabled their economy settings. This should fix it.

* Fixes #3

Mistake in displaying amount of cost for visiting an island.

* Fixes #2

Implement delayed teleportation mechanics from BentoBox core. It now will respect falling deny settings and delay option from core.

* Fixes multi-gamemode crash, when opening Visit Panel.

* Migrate to BentoBox 1.15 API

* Fixes some small bugs with GUIs.

- Add missing gui.player.title.configure translation.
- Fixed incorrect translation for enable button.
- Fixed issue when GUI buttons did not update after change.
- Fixed issue when `|` did not split text in new line
- Fixed issue when color codes did not work properly in description.
- Add border around admin GUI.
  • Loading branch information
BONNe committed Nov 17, 2020
1 parent 2e6d164 commit 4590672
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 93 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
<powermock.version>1.7.4</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.14.0</bentobox.version>
<!-- BentoBox API version -->
<bentobox.version>1.15.0</bentobox.version>
<vault.version>1.7</vault.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/world/bentobox/visit/VisitAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ public void onEnable()
// Even if Vault is installed, it does not mean that economy can be used. It is
// necessary to check it via VaultHook#hook() method.

if (!this.vaultHook.isPresent() || !this.vaultHook.get().hook())
if (!this.vaultHook.isPresent())
{
this.logWarning("Economy plugin not found by Visit Addon!");
this.logWarning("Vault plugin not found. Economy will not work!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.UUID;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.DelayedTeleportCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand All @@ -17,7 +18,7 @@
/**
* This class process /{player_command} visit command call.
*/
public class VisitPlayerCommand extends CompositeCommand
public class VisitPlayerCommand extends DelayedTeleportCommand
{
/**
* This is simple constructor for initializing /{player_command} visit command.
Expand Down Expand Up @@ -68,26 +69,11 @@ public void setup()
*/
@Override
public boolean canExecute(User user, String label, List<String> args)
{
return true;
}


/**
* Defines what will be executed when this command is run.
*
* @param user the {@link User} who is executing this command.
* @param label the label which has been used to execute this command. It can be
* {@link CompositeCommand#getLabel()} or an alias.
* @param args the command arguments.
* @return {@code true} if the command executed successfully, {@code false} otherwise.
*/
@Override
public boolean execute(User user, String label, List<String> args)
{
if (args.isEmpty())
{
VisitPanel.openPanel(this.getAddon(), this.getWorld(), user);
// Open panel. No checks required.
return true;
}
else if (args.size() == 1)
{
Expand All @@ -96,24 +82,54 @@ else if (args.size() == 1)
if (targetUUID == null)
{
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
else
{
// Use getIsland as it returns island even if player is in team.
Island island = this.getIslands().getIsland(this.getWorld(), targetUUID);
this.island = this.getIslands().getIsland(this.getWorld(), targetUUID);

if (island == null)
if (this.island == null)
{
// There is no place to teleport.
user.sendMessage("general.errors.player-has-no-island");
return false;
}
else
{
// Process teleporation
this.<VisitAddon>getAddon().getAddonManager().processTeleportation(user, island);
// Return preprocess result from teleportation.
return this.<VisitAddon>getAddon().getAddonManager().
preprocessTeleportation(user, this.island);
}
}
}

return true;
}


/**
* Defines what will be executed when this command is run.
*
* @param user the {@link User} who is executing this command.
* @param label the label which has been used to execute this command. It can be
* {@link CompositeCommand#getLabel()} or an alias.
* @param args the command arguments.
* @return {@code true} if the command executed successfully, {@code false} otherwise.
*/
@Override
public boolean execute(User user, String label, List<String> args)
{
if (args.isEmpty())
{
VisitPanel.openPanel(this.getAddon(), this.getWorld(), user, this.getTopLabel());
}
else if (args.size() == 1)
{
// Process teleportation
this.delayCommand(user, () ->
this.<VisitAddon>getAddon().getAddonManager().processTeleportation(user, this.island));
}
else
{
this.showHelp(this, user);
Expand All @@ -139,4 +155,10 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
// TODO: nice addition would be to autocomplete user names.
return super.tabComplete(user, alias, args);
}


/**
* Island instance to which player will be teleported.
*/
private Island island;
}
108 changes: 75 additions & 33 deletions src/main/java/world/bentobox/visit/managers/VisitAddonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
import world.bentobox.visit.VisitAddon;
Expand Down Expand Up @@ -342,6 +343,56 @@ public boolean withdrawCredits(User user, double credits)
// ---------------------------------------------------------------------


/**
* This method checks if teleportation can be performed.
* @param user Targeted user who need to be teleported.
* @param island Island where user need to be teleported.
* @return {@code true} if teleportation can be performed, {@code false} otherwise.
*/
public boolean preprocessTeleportation(User user, Island island)
{
return this.preprocessTeleportation(user, island, this.getIslandVisitSettings(island));
}


/**
* This method checks if teleportation can be performed.
* @param user Targeted user who need to be teleported.
* @param island Island where user need to be teleported.
* @param settings Island Visit Settings object.
* @return {@code true} if teleportation can be performed, {@code false} otherwise.
*/
public boolean preprocessTeleportation(User user, Island island, IslandVisitSettings settings)
{
double payment = settings.getPayment() + this.addon.getSettings().getTaxAmount();

if (Flags.PREVENT_TELEPORT_WHEN_FALLING.isSetForWorld(user.getWorld()) && user.getPlayer().getFallDistance() > 0)
{
// We're sending the "hint" to the player to tell them they cannot teleport while falling.
user.sendMessage(Flags.PREVENT_TELEPORT_WHEN_FALLING.getHintReference());
}
else if (payment > 0 && !this.hasCredits(user, payment))
{
// Send a message that player has not enough credits.
user.sendMessage("visit.error.not-enough-credits",
"[credits]", String.valueOf(payment));
}
else if (!this.canVisitOffline(island, settings))
{
// Send a message that there are no online players on island.
user.sendMessage("visit.error.noone-is-online");
}
else
{
// All other checks failed. Teleportation can be performed.
return true;
}

// Return statement at the end is always false.
return false;
}


/**
* This method checks if any island member is online or offline visiting option is
* enabled.
Expand Down Expand Up @@ -383,20 +434,12 @@ public void processTeleportation(User user,
{
double payment = settings.getPayment() + this.addon.getSettings().getTaxAmount();

if (payment > 0 && !this.hasCredits(user, payment))
{
user.sendMessage("visit.error.not-enough-credits",
"[credits]", String.valueOf(payment));
}
else if (!this.canVisitOffline(island, settings))
{
user.sendMessage("visit.error.noone-is-online");
}
else if (payment > 0 && !this.withdrawCredits(user, payment))
if (payment > 0 && !this.withdrawCredits(user, payment))
{
// error on withdrawing credits. Cancelling
user.sendMessage("visit.error.cannot-withdraw-credits",
"[credits]", String.valueOf(payment));
return;
}
else if (settings.getPayment() > 0 && !this.depositCredits(User.getInstance(island.getOwner()), settings.getPayment()))
{
Expand All @@ -405,33 +448,32 @@ else if (settings.getPayment() > 0 && !this.depositCredits(User.getInstance(isla

user.sendMessage("visit.error.cannot-deposit-credits",
"[credits]", String.valueOf(settings.getPayment()));
return;
}
else

// Call visit event.
VisitEvent event = new VisitEvent(user.getUniqueId(), island);
Bukkit.getPluginManager().callEvent(event);

// If event is not cancelled, then teleport player.
if (!event.isCancelled())
{
// Call visit event.
VisitEvent event = new VisitEvent(user.getUniqueId(), island);
Bukkit.getPluginManager().callEvent(event);
Location location = island.getSpawnPoint(World.Environment.NORMAL);

// If event is not cancelled, then teleport player.
if (!event.isCancelled())
if (location == null || !this.addon.getIslands().isSafeLocation(location))
{
Location location = island.getSpawnPoint(World.Environment.NORMAL);

if (location == null || !this.addon.getIslands().isSafeLocation(location))
{
// Use SafeSpotTeleport builder to avoid issues with players spawning in
// bad spot.
new SafeSpotTeleport.Builder(this.addon.getPlugin()).
entity(user.getPlayer()).
location(location == null ? island.getCenter() : location).
failureMessage(user.getTranslation("general.errors.no-safe-location-found")).
build();
}
else
{
// Teleport player async to island spawn point.
Util.teleportAsync(user.getPlayer(), location);
}
// Use SafeSpotTeleport builder to avoid issues with players spawning in
// bad spot.
new SafeSpotTeleport.Builder(this.addon.getPlugin()).
entity(user.getPlayer()).
location(location == null ? island.getCenter() : location).
failureMessage(user.getTranslation("general.errors.no-safe-location-found")).
build();
}
else
{
// Teleport player async to island spawn point.
Util.teleportAsync(user.getPlayer(), location);
}
}
}
Expand Down

0 comments on commit 4590672

Please sign in to comment.