mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-12-01 06:53:26 +01:00
Continue new APIs and their implementation
This commit is contained in:
parent
ce4ddae39f
commit
ffbaac5bb3
@ -5,10 +5,13 @@ import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||
import io.github.dre2n.dungeonsxl.reward.MoneyReward;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
|
||||
import net.milkbowl.vault.item.ItemInfo;
|
||||
import net.milkbowl.vault.item.Items;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
@ -19,6 +22,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class GameChest {
|
||||
|
||||
static DungeonsXL plugin = DungeonsXL.getPlugin();
|
||||
|
||||
// Variables
|
||||
private boolean used = false;
|
||||
private Chest chest;
|
||||
@ -50,8 +55,18 @@ public class GameChest {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean hasMoneyReward = false;
|
||||
|
||||
for (Reward reward : dGroup.getRewards()) {
|
||||
reward.giveTo(player);
|
||||
if (reward instanceof MoneyReward) {
|
||||
hasMoneyReward = true;
|
||||
((MoneyReward) reward).addMoney(moneyReward);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !hasMoneyReward) {
|
||||
Reward reward = Reward.create(RewardTypeDefault.MONEY);
|
||||
((MoneyReward) reward).addMoney(moneyReward);
|
||||
}
|
||||
|
||||
String msg = "";
|
||||
@ -62,16 +77,16 @@ public class GameChest {
|
||||
}
|
||||
|
||||
dPlayer.getTreasureInv().addItem(itemStack);
|
||||
String name;
|
||||
|
||||
if ( !itemStack.hasItemMeta()) {
|
||||
continue;
|
||||
}
|
||||
String name = null;
|
||||
|
||||
if (itemStack.hasItemMeta()) {
|
||||
if (itemStack.getItemMeta().hasDisplayName()) {
|
||||
name = itemStack.getItemMeta().getDisplayName();
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
if (name == null && Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
ItemInfo itemInfo = Items.itemByStack(itemStack);
|
||||
if (itemInfo != null) {
|
||||
name = itemInfo.getName();
|
||||
@ -80,14 +95,14 @@ public class GameChest {
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg + ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ",";
|
||||
msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ",";
|
||||
}
|
||||
|
||||
msg = msg.substring(0, msg.length() - 1);
|
||||
|
||||
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, msg));
|
||||
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, msg));
|
||||
if (moneyReward != 0) {
|
||||
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, String.valueOf(moneyReward)));
|
||||
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, String.valueOf(moneyReward)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,7 +117,7 @@ public class GameChest {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inventory.getTopInventory().getHolder() instanceof Chest) {
|
||||
if ( !(inventory.getTopInventory().getHolder() instanceof Chest)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -113,9 +128,8 @@ public class GameChest {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !gameChest.used) {
|
||||
MessageUtil
|
||||
.sendMessage(DungeonsXL.getPlugin().getServer().getPlayer(event.getPlayer().getUniqueId()), DungeonsXL.getPlugin().getDMessages().getMessage(Messages.ERROR_CHEST_IS_OPENED));
|
||||
if (gameChest.used) {
|
||||
MessageUtil.sendMessage(plugin.getServer().getPlayer(event.getPlayer().getUniqueId()), plugin.getDMessages().getMessage(Messages.ERROR_CHEST_IS_OPENED));
|
||||
event.setCancelled(true);
|
||||
continue;
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ public class DMessages {
|
||||
ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"),
|
||||
ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"),
|
||||
ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4You have to join a group first!"),
|
||||
ERROR_NOT_SAVED("Error_NotSaved", "&4The map &6&v1&4 has not been saved to the &6DungeonsXL/maps/ &4folder yet!"),
|
||||
ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"),
|
||||
ERROR_READY("Error_Ready", "&4Choose your class first!"),
|
||||
ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this Dungeon!"),
|
||||
@ -106,7 +107,9 @@ public class DMessages {
|
||||
HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"),
|
||||
HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"),
|
||||
HELP_CMD_TEST("Help_Cmd_Test", "/dxl test ([dungeon|map]) [name] - Tests a dungeon"),
|
||||
HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon");
|
||||
HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon"),
|
||||
|
||||
REWARD_MONEY("Reward_Money", "&6You received &4&v1 &6for finishing the dungeon.");
|
||||
|
||||
private String identifier;
|
||||
private String message;
|
||||
|
@ -211,11 +211,19 @@ public class DGroup {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rewards
|
||||
* the rewards to set
|
||||
* @param reward
|
||||
* the rewards to add
|
||||
*/
|
||||
public void setRewards(List<Reward> rewards) {
|
||||
this.rewards = rewards;
|
||||
public void addReward(Reward reward) {
|
||||
rewards.add(reward);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reward
|
||||
* the rewards to remove
|
||||
*/
|
||||
public void removeReward(Reward reward) {
|
||||
rewards.remove(reward);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,10 +253,6 @@ public class DGroup {
|
||||
MessageUtil.sendScreenMessage(player, "&4&l" + mapName.replaceAll("_", ""));
|
||||
}
|
||||
|
||||
if ( !DungeonsXL.getPlugin().getMainConfig().enableEconomy()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Requirement requirement : gameWorld.getConfig().getRequirements()) {
|
||||
requirement.demand(player);
|
||||
}
|
||||
|
@ -346,6 +346,10 @@ public class DPlayer {
|
||||
DPlayer dPlayer = getByPlayer(player);
|
||||
dPlayer.leave();
|
||||
}
|
||||
|
||||
for (Reward reward : dGroup.getRewards()) {
|
||||
reward.giveTo(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
|
@ -6,26 +6,35 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.event.requirement.RequirementRegistrationEvent;
|
||||
|
||||
public abstract class Requirement {
|
||||
|
||||
static DungeonsXL plugin = DungeonsXL.getPlugin();
|
||||
|
||||
public static Requirement create(RequirementType type) {
|
||||
Requirement requirement = null;
|
||||
|
||||
try {
|
||||
Constructor<? extends Requirement> constructor = type.getHandler().getConstructor(String.class);
|
||||
return constructor.newInstance();
|
||||
Constructor<? extends Requirement> constructor = type.getHandler().getConstructor();
|
||||
requirement = constructor.newInstance();
|
||||
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
plugin.getLogger().info("DungeonsXL could not find the handler class of the requirement " + type.getIdentifier() + ".");
|
||||
plugin.getLogger().info("An error occurred while accessing the handler class of the requirement " + type.getIdentifier() + ": " + exception.getClass().getSimpleName());
|
||||
if ( !(type instanceof RequirementTypeDefault)) {
|
||||
plugin.getLogger().info("Please note that this requirement is an unsupported feature added by an addon!");
|
||||
}
|
||||
}
|
||||
|
||||
RequirementRegistrationEvent event = new RequirementRegistrationEvent(requirement);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return requirement;
|
||||
}
|
||||
|
||||
// Abstract methods
|
||||
|
||||
public abstract boolean check(Player player);
|
||||
|
@ -1,5 +1,8 @@
|
||||
package io.github.dre2n.dungeonsxl.reward;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
||||
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MoneyReward extends Reward {
|
||||
@ -15,6 +18,14 @@ public class MoneyReward extends Reward {
|
||||
return money;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param money
|
||||
* the money to add
|
||||
*/
|
||||
public void addMoney(double money) {
|
||||
this.money += money;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param money
|
||||
* the money to set
|
||||
@ -28,6 +39,8 @@ public class MoneyReward extends Reward {
|
||||
if (plugin.getEconomyProvider() != null) {
|
||||
plugin.getEconomyProvider().depositPlayer(player, money);
|
||||
}
|
||||
|
||||
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.REWARD_MONEY, plugin.getEconomyProvider().format(money)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,6 +6,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.event.reward.RewardRegistrationEvent;
|
||||
import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardType;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardTypeDefault;
|
||||
@ -15,20 +16,28 @@ public abstract class Reward {
|
||||
static DungeonsXL plugin = DungeonsXL.getPlugin();
|
||||
|
||||
public static Reward create(RewardType type) {
|
||||
Reward reward = null;
|
||||
|
||||
try {
|
||||
Constructor<? extends Reward> constructor = type.getHandler().getConstructor();
|
||||
return constructor.newInstance();
|
||||
reward = constructor.newInstance();
|
||||
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
plugin.getLogger().info("DungeonsXL could not find the handler class of the reward " + type.getIdentifier() + ".");
|
||||
plugin.getLogger().info("An error occurred while accessing the handler class of the reward " + type.getIdentifier() + ": " + exception.getClass().getSimpleName());
|
||||
if ( !(type instanceof RewardTypeDefault)) {
|
||||
plugin.getLogger().info("Please note that this reward is an unsupported feature added by an addon!");
|
||||
}
|
||||
}
|
||||
|
||||
RewardRegistrationEvent event = new RewardRegistrationEvent(reward);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return reward;
|
||||
}
|
||||
|
||||
// Abstract methods
|
||||
|
||||
public abstract void giveTo(Player player);
|
||||
|
@ -2,7 +2,7 @@ package io.github.dre2n.dungeonsxl.reward;
|
||||
|
||||
public enum RewardTypeDefault implements RewardType {
|
||||
|
||||
MONEY("money", Reward.class),
|
||||
MONEY("money", MoneyReward.class),
|
||||
LOOT_INVENTORY("loot", Reward.class);
|
||||
|
||||
private String identifier;
|
||||
|
@ -2,6 +2,7 @@ package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||
import io.github.dre2n.dungeonsxl.event.dsign.DSignRegistrationEvent;
|
||||
import io.github.dre2n.dungeonsxl.trigger.Trigger;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@ -159,13 +160,19 @@ public abstract class DSign {
|
||||
dSign = constructor.newInstance(sign, gameWorld);
|
||||
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
plugin.getLogger().info("DungeonsXL could not find the handler class of the sign " + type.getName() + ".");
|
||||
plugin.getLogger().info("An error occurred while accessing the handler class of the sign " + type.getName() + ": " + exception.getClass().getSimpleName());
|
||||
if ( !(type instanceof DSignTypeDefault)) {
|
||||
plugin.getLogger().info("Please note that this sign is an unsupported feature added by an addon!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DSignRegistrationEvent event = new DSignRegistrationEvent(sign, gameWorld, dSign);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( !(dSign != null && gameWorld != null)) {
|
||||
return dSign;
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package io.github.dre2n.dungeonsxl.trigger;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSign;
|
||||
import io.github.dre2n.dungeonsxl.util.NumberUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -11,6 +14,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Trigger {
|
||||
|
||||
static DungeonsXL plugin = DungeonsXL.getPlugin();
|
||||
|
||||
private boolean triggered;
|
||||
private Player player; // Holds Player for Player specific Triggers
|
||||
|
||||
@ -89,43 +94,62 @@ public abstract class Trigger {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Dynamic checks
|
||||
public static Trigger getOrCreate(String type, String value, DSign dsign) {
|
||||
if (type.equalsIgnoreCase("R")) {
|
||||
public static Trigger getOrCreate(String identifier, String value, DSign dSign) {
|
||||
TriggerType type = plugin.getTriggers().getByIdentifier(identifier);
|
||||
|
||||
return RedstoneTrigger.getOrCreate(dsign.getSign(), dsign.getGameWorld());
|
||||
if (type == TriggerTypeDefault.REDSTONE) {
|
||||
|
||||
} else if (type.equalsIgnoreCase("D")) {
|
||||
return RedstoneTrigger.getOrCreate(dSign.getSign(), dSign.getGameWorld());
|
||||
|
||||
} else if (type == TriggerTypeDefault.DISTANCE) {
|
||||
|
||||
if (value != null) {
|
||||
return new DistanceTrigger(NumberUtil.parseInt(value), dsign.getSign().getLocation());
|
||||
return new DistanceTrigger(NumberUtil.parseInt(value), dSign.getSign().getLocation());
|
||||
|
||||
} else {
|
||||
return new DistanceTrigger(dsign.getSign().getLocation());
|
||||
return new DistanceTrigger(dSign.getSign().getLocation());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("T")) {
|
||||
} else if (type == TriggerTypeDefault.SIGN) {
|
||||
|
||||
if (value != null) {
|
||||
return SignTrigger.getOrCreate(NumberUtil.parseInt(value), dsign.getGameWorld());
|
||||
return SignTrigger.getOrCreate(NumberUtil.parseInt(value), dSign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("I")) {
|
||||
} else if (type == TriggerTypeDefault.INTERACT) {
|
||||
|
||||
if (value != null) {
|
||||
return InteractTrigger.getOrCreate(NumberUtil.parseInt(value), dsign.getGameWorld());
|
||||
return InteractTrigger.getOrCreate(NumberUtil.parseInt(value), dSign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("M")) {
|
||||
} else if (type == TriggerTypeDefault.MOB) {
|
||||
|
||||
if (value != null) {
|
||||
return MobTrigger.getOrCreate(value, dsign.getGameWorld());
|
||||
return MobTrigger.getOrCreate(value, dSign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (type.equalsIgnoreCase("U")) {
|
||||
} else if (type == TriggerTypeDefault.USE_ITEM) {
|
||||
|
||||
if (value != null) {
|
||||
return UseItemTrigger.getOrCreate(value, dsign.getGameWorld());
|
||||
return UseItemTrigger.getOrCreate(value, dSign.getGameWorld());
|
||||
}
|
||||
|
||||
} else if (type != null) {
|
||||
Trigger trigger = null;
|
||||
|
||||
Method method;
|
||||
try {
|
||||
method = type.getHandler().getDeclaredMethod("getOrCreate", String.class, GameWorld.class);
|
||||
trigger = (Trigger) method.invoke(value, dSign.getGameWorld());
|
||||
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
plugin.getLogger().info("An error occurred while accessing the handler class of the sign " + type.getIdentifier() + ": " + exception.getClass().getSimpleName());
|
||||
if ( !(type instanceof TriggerTypeDefault)) {
|
||||
plugin.getLogger().info("Please note that this trigger is an unsupported feature added by an addon!");
|
||||
}
|
||||
}
|
||||
|
||||
return trigger;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -13,6 +13,19 @@ public class Triggers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the trigger which has the identifier
|
||||
*/
|
||||
public TriggerType getByIdentifier(String identifier) {
|
||||
for (TriggerType trigger : triggers) {
|
||||
if (trigger.getIdentifier().equalsIgnoreCase(identifier)) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the triggers
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user