forked from Upstream/mmocore
!Removed unused deprecated methods
This commit is contained in:
parent
e2bf9ff034
commit
4472198da3
@ -1,12 +1,11 @@
|
||||
package net.Indyuce.mmocore.api.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.mmogroup.mmolib.api.condition.type.BlockCondition;
|
||||
import net.mmogroup.mmolib.api.condition.type.MMOCondition;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@ -17,24 +16,19 @@ import org.bukkit.inventory.ItemStack;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.mmogroup.mmolib.UtilityMethods;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.api.condition.type.BlockCondition;
|
||||
import net.mmogroup.mmolib.api.condition.type.MMOCondition;
|
||||
|
||||
public class BlockInfo {
|
||||
private final BlockType block;
|
||||
private final DropTable table;
|
||||
private final boolean vanillaDrops;
|
||||
private final RegenInfo regen;
|
||||
private final List<Trigger> triggers = new ArrayList<>();
|
||||
private final List<BlockCondition> conditions = new ArrayList<>();
|
||||
|
||||
/*
|
||||
* saved separately because MMOCore needs to display the experience gained,
|
||||
* since it requires a steam call it is better to cache right off the start
|
||||
*/
|
||||
private final ExperienceTrigger experience;
|
||||
private final Map<BlockInfoOption, Boolean> options = new HashMap<>();
|
||||
|
||||
public BlockInfo(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load config");
|
||||
@ -42,10 +36,19 @@ public class BlockInfo {
|
||||
|
||||
block = MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(config.getString("material")));
|
||||
table = config.contains("drop-table") ? MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")) : null;
|
||||
vanillaDrops = config.getBoolean("vanilla-drops", true);
|
||||
|
||||
regen = config.contains("regen") ? new RegenInfo(config.getConfigurationSection("regen")) : null;
|
||||
|
||||
if (config.contains("options"))
|
||||
for (String key : config.getConfigurationSection("options").getKeys(false))
|
||||
try {
|
||||
BlockInfoOption option = BlockInfoOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
options.put(option, config.getBoolean("options." + key));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING,
|
||||
"Could not load option '" + key + "' from block info '" + block.generateKey() + "': " + exception.getMessage());
|
||||
}
|
||||
|
||||
if (config.contains("triggers")) {
|
||||
List<String> list = config.getStringList("triggers");
|
||||
Validate.notNull(list, "Could not load triggers");
|
||||
@ -59,9 +62,6 @@ public class BlockInfo {
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Trigger> opt = triggers.stream().filter(trigger -> (trigger instanceof ExperienceTrigger)).findFirst();
|
||||
experience = (ExperienceTrigger) opt.orElse(null);
|
||||
|
||||
if (config.isList("conditions"))
|
||||
for (String key : config.getStringList("conditions")) {
|
||||
MMOCondition condition = UtilityMethods.getCondition(key);
|
||||
@ -71,8 +71,8 @@ public class BlockInfo {
|
||||
|
||||
}
|
||||
|
||||
public boolean hasVanillaDrops() {
|
||||
return vanillaDrops;
|
||||
public boolean getOption(BlockInfoOption option) {
|
||||
return options.getOrDefault(option, option.getDefault());
|
||||
}
|
||||
|
||||
public BlockType getBlock() {
|
||||
@ -107,14 +107,6 @@ public class BlockInfo {
|
||||
return new RegeneratingBlock(data, loc, this);
|
||||
}
|
||||
|
||||
public boolean hasExperience() {
|
||||
return experience != null;
|
||||
}
|
||||
|
||||
public ExperienceTrigger getExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
public boolean hasTriggers() {
|
||||
return !triggers.isEmpty();
|
||||
}
|
||||
@ -130,6 +122,29 @@ public class BlockInfo {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static enum BlockInfoOption {
|
||||
|
||||
/**
|
||||
* When disabled, removes the vanilla drops when a block is mined
|
||||
*/
|
||||
VANILLA_DROPS(true),
|
||||
|
||||
/**
|
||||
* When disabled, removes exp holograms when mined
|
||||
*/
|
||||
EXP_HOLOGRAMS(true);
|
||||
|
||||
private final boolean def;
|
||||
|
||||
private BlockInfoOption(boolean def) {
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public boolean getDefault() {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RegeneratingBlock {
|
||||
private final BlockData data;
|
||||
private final Location loc;
|
||||
|
@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||
import net.Indyuce.mmocore.api.experience.ExperienceInfo;
|
||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
|
||||
@ -20,7 +19,6 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
||||
private final Block block;
|
||||
private final BlockInfo info;
|
||||
private final List<ItemStack> drops;
|
||||
private final ExperienceInfo experience;
|
||||
|
||||
@Deprecated
|
||||
private boolean canBreak;
|
||||
@ -34,7 +32,6 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
||||
this.drops = (info.hasDropTable() && player.isOnline() && info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer())))
|
||||
? info.collectDrops(new LootBuilder(player, 0))
|
||||
: new ArrayList<>();
|
||||
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
||||
this.canBreak = canBreak;
|
||||
}
|
||||
|
||||
@ -50,14 +47,6 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
||||
return info;
|
||||
}
|
||||
|
||||
public boolean hasGainedExperience() {
|
||||
return experience != null;
|
||||
}
|
||||
|
||||
public ExperienceInfo getGainedExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean canBreak() {
|
||||
return canBreak;
|
||||
|
@ -23,6 +23,7 @@ import org.bukkit.metadata.FixedMetadataValue;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo.BlockInfoOption;
|
||||
import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
@ -104,7 +105,7 @@ public class BlockListener implements Listener {
|
||||
* MMOItems durability. It does not apply specific durability loss based
|
||||
* on block/tool broken yet simple compatibility stuff
|
||||
*/
|
||||
if (!info.hasVanillaDrops()) {
|
||||
if (!info.getOption(BlockInfoOption.VANILLA_DROPS)) {
|
||||
event.setCancelled(true);
|
||||
event.getBlock().setType(Material.AIR);
|
||||
MMOCoreUtils.decreaseDurability(player, EquipmentSlot.HAND, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user