mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-30 21:07:47 +01:00
commit
44ab03819c
@ -40,9 +40,8 @@ public class ChallengesAddon extends Addon {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* VaultHook that process economy.
|
* VaultHook that process economy.
|
||||||
* todo: because of BentoBox limitations.
|
|
||||||
*/
|
*/
|
||||||
private Optional<VaultHook> vaultHook = null;
|
private VaultHook vaultHook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Level addon.
|
* Level addon.
|
||||||
@ -132,19 +131,18 @@ public class ChallengesAddon extends Addon {
|
|||||||
this.levelAddon = (Level) level.get();
|
this.levelAddon = (Level) level.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// BentoBox limitation. Cannot check hooks, as HookManager is created after loading addons.
|
Optional<VaultHook> vault = this.getPlugin().getVault();
|
||||||
// Optional<VaultHook> vault = this.getPlugin().getVault();
|
|
||||||
//
|
if (!vault.isPresent() || !vault.get().hook())
|
||||||
// if (!vault.isPresent() || !vault.get().hook())
|
{
|
||||||
// {
|
this.vaultHook = null;
|
||||||
// this.vaultHook = null;
|
this.logWarning("Economy plugin not found so money options will not work!");
|
||||||
// this.logWarning("Economy plugin not found so money options will not work!");
|
}
|
||||||
// }
|
else
|
||||||
// else
|
{
|
||||||
// {
|
this.economyProvided = true;
|
||||||
// this.economyProvided = true;
|
this.vaultHook = vault.get();
|
||||||
// this.vaultHook = vault.get();
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// Register the reset listener
|
// Register the reset listener
|
||||||
this.registerListener(new ResetListener(this));
|
this.registerListener(new ResetListener(this));
|
||||||
@ -247,12 +245,6 @@ public class ChallengesAddon extends Addon {
|
|||||||
*/
|
*/
|
||||||
public boolean isEconomyProvided()
|
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;
|
return this.economyProvided;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +256,7 @@ public class ChallengesAddon extends Addon {
|
|||||||
*/
|
*/
|
||||||
public VaultHook getEconomyProvider()
|
public VaultHook getEconomyProvider()
|
||||||
{
|
{
|
||||||
return vaultHook.orElseGet(null);
|
return vaultHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class ChallengesPanels2 {
|
|||||||
} else {
|
} else {
|
||||||
// Player click
|
// Player click
|
||||||
itemBuilder.clickHandler((panel, player, c, s) -> {
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -161,8 +161,28 @@ public class TryToComplete
|
|||||||
this.manager = addon.getChallengesManager();
|
this.manager = addon.getChallengesManager();
|
||||||
this.challenge = challenge;
|
this.challenge = challenge;
|
||||||
this.topLabel = topLabel;
|
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())
|
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",
|
// Only other players should see message.
|
||||||
"[name]", this.user.getName(), "[challenge]", this.challenge.getFriendlyName());
|
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())
|
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",
|
// Only other players should see message.
|
||||||
"[name]", this.user.getName(), "[level]", level.getFriendlyName());
|
if (!player.getUniqueId().equals(this.user.getUniqueId()))
|
||||||
|
{
|
||||||
|
User.getInstance(player).sendMessage("challenges.name-has-completed-level",
|
||||||
|
"[name]", this.user.getName(), "[level]", level.getFriendlyName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import org.apache.commons.lang.WordUtils;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
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(3, this.createButton(Button.ADD));
|
||||||
panelBuilder.item(5, this.createButton(Button.REMOVE));
|
panelBuilder.item(5, this.createButton(Button.REMOVE));
|
||||||
|
panelBuilder.item(8, this.createButton(Button.SWITCH));
|
||||||
|
|
||||||
final int MAX_ELEMENTS = 21;
|
final int MAX_ELEMENTS = 21;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class ManageEntitiesGUI extends CommonGUI
|
|||||||
builder.name(this.user.getTranslation("challenges.gui.button.add"));
|
builder.name(this.user.getTranslation("challenges.gui.button.add"));
|
||||||
builder.icon(Material.BUCKET);
|
builder.icon(Material.BUCKET);
|
||||||
builder.clickHandler((panel, user1, clickType, slot) -> {
|
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 (status)
|
||||||
{
|
{
|
||||||
if (!this.requiredEntities.containsKey(entity))
|
if (!this.requiredEntities.containsKey(entity))
|
||||||
@ -144,6 +144,15 @@ public class ManageEntitiesGUI extends CommonGUI
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
break;
|
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();
|
return builder.build();
|
||||||
@ -204,7 +213,8 @@ public class ManageEntitiesGUI extends CommonGUI
|
|||||||
private enum Button
|
private enum Button
|
||||||
{
|
{
|
||||||
ADD,
|
ADD,
|
||||||
REMOVE
|
REMOVE,
|
||||||
|
SWITCH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -325,12 +325,16 @@ public class ChallengesGUI extends CommonGUI
|
|||||||
name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()).
|
name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()).
|
||||||
description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))).
|
description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))).
|
||||||
clickHandler((panel, user1, clickType, slot) -> {
|
clickHandler((panel, user1, clickType, slot) -> {
|
||||||
new TryToComplete(this.addon,
|
if (TryToComplete.complete(this.addon,
|
||||||
this.user,
|
this.user,
|
||||||
challenge,
|
challenge,
|
||||||
this.world,
|
this.world,
|
||||||
this.topLabel,
|
this.topLabel,
|
||||||
this.permissionPrefix);
|
this.permissionPrefix))
|
||||||
|
{
|
||||||
|
this.build();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}).
|
}).
|
||||||
glow(this.challengesManager.isChallengeComplete(this.user, challenge)).
|
glow(this.challengesManager.isChallengeComplete(this.user, challenge)).
|
||||||
|
@ -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.
|
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
|
glow: Add enchanted glow to completed challenges
|
||||||
in_world: In World
|
in_world: In World
|
||||||
inventory: This type of challenges allows to define blocks and entities on island requirements.
|
inventory: This type of challenges allows to define inventory item requirements.
|
||||||
island: 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
|
nether: Nether
|
||||||
normal: Normal
|
normal: Normal
|
||||||
online: Online
|
online: Online
|
||||||
@ -177,6 +177,7 @@ challenges:
|
|||||||
button:
|
button:
|
||||||
add: Add
|
add: Add
|
||||||
remove-selected: Remove Selected
|
remove-selected: Remove Selected
|
||||||
|
show-eggs: Toogle Mob View
|
||||||
buttons:
|
buttons:
|
||||||
back: Return
|
back: Return
|
||||||
next: Next
|
next: Next
|
||||||
|
Loading…
Reference in New Issue
Block a user