Merge pull request #64 from BONNe/develop

Fix some bugs.
This commit is contained in:
tastybento 2019-01-28 20:28:42 -08:00 committed by GitHub
commit 44ab03819c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 37 deletions

View File

@ -40,9 +40,8 @@ public class ChallengesAddon extends Addon {
/**
* VaultHook that process economy.
* todo: because of BentoBox limitations.
*/
private Optional<VaultHook> vaultHook = null;
private VaultHook vaultHook;
/**
* Level addon.
@ -132,19 +131,18 @@ public class ChallengesAddon extends Addon {
this.levelAddon = (Level) level.get();
}
// BentoBox limitation. Cannot check hooks, as HookManager is created after loading addons.
// Optional<VaultHook> vault = this.getPlugin().getVault();
//
// if (!vault.isPresent() || !vault.get().hook())
// {
// this.vaultHook = null;
// this.logWarning("Economy plugin not found so money options will not work!");
// }
// else
// {
// this.economyProvided = true;
// this.vaultHook = vault.get();
// }
Optional<VaultHook> vault = this.getPlugin().getVault();
if (!vault.isPresent() || !vault.get().hook())
{
this.vaultHook = null;
this.logWarning("Economy plugin not found so money options will not work!");
}
else
{
this.economyProvided = true;
this.vaultHook = vault.get();
}
// Register the reset listener
this.registerListener(new ResetListener(this));
@ -247,12 +245,6 @@ public class ChallengesAddon extends Addon {
*/
public boolean isEconomyProvided()
{
if (!this.economyProvided && this.getPlugin().getVault().isPresent() && this.vaultHook == null)
{
this.vaultHook = this.getPlugin().getVault();
this.economyProvided = this.vaultHook.get().hook();
}
return this.economyProvided;
}
@ -264,7 +256,7 @@ public class ChallengesAddon extends Addon {
*/
public VaultHook getEconomyProvider()
{
return vaultHook.orElseGet(null);
return vaultHook;
}

View File

@ -152,7 +152,7 @@ public class ChallengesPanels2 {
} else {
// Player click
itemBuilder.clickHandler((panel, player, c, s) -> {
new TryToComplete(addon, player, challenge, world, label, permPrefix);
new TryToComplete(addon, player, challenge, world, label, permPrefix).build();
return true;
});
}

View File

@ -161,8 +161,28 @@ public class TryToComplete
this.manager = addon.getChallengesManager();
this.challenge = challenge;
this.topLabel = topLabel;
}
this.build();
/**
* This static method allows complete challenge and get result about completion.
* @param addon - Challenges Addon.
* @param user - User who performs challenge.
* @param challenge - Challenge that should be completed.
* @param world - World where completion may occur.
* @param topLabel - Label of the top command.
* @param permissionPrefix - Permission prefix for GameMode addon.
* @return true, if challenge is completed, otherwise false.
*/
public static boolean complete(ChallengesAddon addon,
User user,
Challenge challenge,
World world,
String topLabel,
String permissionPrefix)
{
return new TryToComplete(addon, user, challenge, world, topLabel, permissionPrefix).
build().meetsRequirements;
}
@ -210,10 +230,14 @@ public class TryToComplete
if (this.addon.getChallengesSettings().isBroadcastMessages())
{
for (Player p : this.addon.getServer().getOnlinePlayers())
for (Player player : this.addon.getServer().getOnlinePlayers())
{
User.getInstance(p).sendMessage("challenges.name-has-completed",
"[name]", this.user.getName(), "[challenge]", this.challenge.getFriendlyName());
// Only other players should see message.
if (!player.getUniqueId().equals(this.user.getUniqueId()))
{
User.getInstance(player).sendMessage("challenges.name-has-completed",
"[name]", this.user.getName(), "[challenge]", this.challenge.getFriendlyName());
}
}
}
}
@ -275,10 +299,14 @@ public class TryToComplete
if (this.addon.getChallengesSettings().isBroadcastMessages())
{
for (Player p : this.addon.getServer().getOnlinePlayers())
for (Player player : this.addon.getServer().getOnlinePlayers())
{
User.getInstance(p).sendMessage("challenges.name-has-completed-level",
"[name]", this.user.getName(), "[level]", level.getFriendlyName());
// Only other players should see message.
if (!player.getUniqueId().equals(this.user.getUniqueId()))
{
User.getInstance(player).sendMessage("challenges.name-has-completed-level",
"[name]", this.user.getName(), "[level]", level.getFriendlyName());
}
}
}

View File

@ -5,7 +5,6 @@ import org.apache.commons.lang.WordUtils;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import world.bentobox.bentobox.api.panels.PanelItem;
@ -61,6 +60,7 @@ public class ManageEntitiesGUI extends CommonGUI
panelBuilder.item(3, this.createButton(Button.ADD));
panelBuilder.item(5, this.createButton(Button.REMOVE));
panelBuilder.item(8, this.createButton(Button.SWITCH));
final int MAX_ELEMENTS = 21;
@ -119,7 +119,7 @@ public class ManageEntitiesGUI extends CommonGUI
builder.name(this.user.getTranslation("challenges.gui.button.add"));
builder.icon(Material.BUCKET);
builder.clickHandler((panel, user1, clickType, slot) -> {
new SelectEntityGUI(this.user, (status, entity) -> {
new SelectEntityGUI(this.user, Collections.emptySet(), this.asEggs, (status, entity) -> {
if (status)
{
if (!this.requiredEntities.containsKey(entity))
@ -144,6 +144,15 @@ public class ManageEntitiesGUI extends CommonGUI
return true;
});
break;
case SWITCH:
builder.name(this.user.getTranslation("challenges.gui.button.show-eggs"));
builder.icon(this.asEggs ? Material.EGG : Material.PLAYER_HEAD);
builder.clickHandler((panel, user1, clickType, slot) -> {
this.asEggs = !this.asEggs;
this.build();
return true;
});
break;
}
return builder.build();
@ -204,7 +213,8 @@ public class ManageEntitiesGUI extends CommonGUI
private enum Button
{
ADD,
REMOVE
REMOVE,
SWITCH
}

View File

@ -325,12 +325,16 @@ public class ChallengesGUI extends CommonGUI
name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()).
description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))).
clickHandler((panel, user1, clickType, slot) -> {
new TryToComplete(this.addon,
if (TryToComplete.complete(this.addon,
this.user,
challenge,
this.world,
this.topLabel,
this.permissionPrefix);
this.permissionPrefix))
{
this.build();
}
return true;
}).
glow(this.challengesManager.isChallengeComplete(this.user, challenge)).

View File

@ -148,8 +148,8 @@ challenges:
free-challenges: This indicate if free challenges must be at the start (true) or at the end (false) of list.
glow: Add enchanted glow to completed challenges
in_world: In World
inventory: This type of challenges allows to define blocks and entities on island requirements.
island: This type of challenges allows to define inventory item requirements.
inventory: This type of challenges allows to define inventory item requirements.
island: This type of challenges allows to define blocks and entities on island requirements.
nether: Nether
normal: Normal
online: Online
@ -177,6 +177,7 @@ challenges:
button:
add: Add
remove-selected: Remove Selected
show-eggs: Toogle Mob View
buttons:
back: Return
next: Next