mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
!Block type refactor, moving libs to MMOLib
This commit is contained in:
parent
6f5049ff6a
commit
fff175294b
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
@ -134,7 +134,6 @@ public class MMOCore extends JavaPlugin {
|
||||
public final MMOLoadManager loadManager = new MMOLoadManager();
|
||||
public RPGUtilHandler rpgUtilHandler = new DefaultRPGUtilHandler();
|
||||
|
||||
private boolean miLoaded, miChecked;
|
||||
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
@ -424,13 +423,4 @@ public class MMOCore extends JavaPlugin {
|
||||
public boolean hasEconomy() {
|
||||
return economy != null && economy.isValid();
|
||||
}
|
||||
|
||||
public boolean isMILoaded() {
|
||||
if (!miChecked) {
|
||||
miLoaded = Bukkit.getPluginManager().isPluginEnabled("MMOItems");
|
||||
miChecked = true;
|
||||
}
|
||||
|
||||
return miLoaded;
|
||||
}
|
||||
}
|
||||
|
148
src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java
Normal file
148
src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java
Normal file
@ -0,0 +1,148 @@
|
||||
package net.Indyuce.mmocore.api.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class BlockInfo {
|
||||
private final BlockType block;
|
||||
private final DropTable table;
|
||||
private final boolean vanillaDrops;
|
||||
private final List<Trigger> triggers = new ArrayList<>();
|
||||
private final RegenInfo regen;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public BlockInfo(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load config");
|
||||
Validate.isTrue(config.contains("material"), "Could not find block type");
|
||||
|
||||
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("triggers")) {
|
||||
List<String> list = config.getStringList("triggers");
|
||||
Validate.notNull(list, "Could not load triggers");
|
||||
|
||||
for (String key : list)
|
||||
try {
|
||||
triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key)));
|
||||
} catch (MMOLoadException exception) {
|
||||
exception.printConsole("BlockRegen", "trigger");
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Trigger> opt = triggers.stream().filter(trigger -> (trigger instanceof ExperienceTrigger)).findFirst();
|
||||
experience = opt.isPresent() ? (ExperienceTrigger) opt.get() : null;
|
||||
}
|
||||
|
||||
public boolean hasVanillaDrops() {
|
||||
return vanillaDrops;
|
||||
}
|
||||
|
||||
public BlockType getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
/*
|
||||
* generates a key used to store the BlockInfo instance in the manager map,
|
||||
* the key depends on the block type to make sure there is no interference
|
||||
*/
|
||||
public String generateKey() {
|
||||
return block.generateKey();
|
||||
}
|
||||
|
||||
public DropTable getDropTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public List<ItemStack> collectDrops() {
|
||||
return hasDropTable() ? table.collect() : new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean hasDropTable() {
|
||||
return table != null;
|
||||
}
|
||||
|
||||
public boolean hasRegen() {
|
||||
return regen != null;
|
||||
}
|
||||
|
||||
public RegenInfo getRegenerationInfo() {
|
||||
return regen;
|
||||
}
|
||||
|
||||
public RegeneratingBlock startRegeneration(BlockData data, Location loc) {
|
||||
return new RegeneratingBlock(data, loc, this);
|
||||
}
|
||||
|
||||
public RegeneratingBlock startRegeneration(Location loc) {
|
||||
return new RegeneratingBlock(null, loc, this);
|
||||
}
|
||||
|
||||
public boolean hasExperience() {
|
||||
return experience != null;
|
||||
}
|
||||
|
||||
public ExperienceTrigger getExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
public boolean hasTriggers() {
|
||||
return !triggers.isEmpty();
|
||||
}
|
||||
|
||||
public List<Trigger> getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
|
||||
public class RegeneratingBlock {
|
||||
private final BlockData data;
|
||||
private final Location loc;
|
||||
private final BlockInfo regenerating;
|
||||
|
||||
private final long date = System.currentTimeMillis();
|
||||
|
||||
public RegeneratingBlock(BlockData data, Location loc, BlockInfo regenerating) {
|
||||
this.data = data;
|
||||
this.loc = loc;
|
||||
this.regenerating = regenerating;
|
||||
}
|
||||
|
||||
public boolean isTimedOut() {
|
||||
return date + regenerating.getRegenerationInfo().getTime() * 50 < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public BlockData getBlockData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public BlockInfo getRegeneratingBlock() {
|
||||
return regenerating;
|
||||
}
|
||||
}
|
||||
}
|
13
src/main/java/net/Indyuce/mmocore/api/block/BlockType.java
Normal file
13
src/main/java/net/Indyuce/mmocore/api/block/BlockType.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.Indyuce.mmocore.api.block;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
|
||||
|
||||
public interface BlockType {
|
||||
public void place(Location loc, RegeneratingBlock regenerating);
|
||||
|
||||
// public boolean matches(Block block);
|
||||
|
||||
public String generateKey();
|
||||
}
|
31
src/main/java/net/Indyuce/mmocore/api/block/RegenInfo.java
Normal file
31
src/main/java/net/Indyuce/mmocore/api/block/RegenInfo.java
Normal file
@ -0,0 +1,31 @@
|
||||
package net.Indyuce.mmocore.api.block;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class RegenInfo {
|
||||
private final BlockType temporary;
|
||||
private final int regenTime;
|
||||
|
||||
public RegenInfo(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not read regen info config");
|
||||
|
||||
temporary = config.contains("temp-block") ? MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(config.getString("temp-block"))) : null;
|
||||
regenTime = config.getInt("time", 2 * 60 * 20);
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return regenTime;
|
||||
}
|
||||
|
||||
public boolean hasTemporaryBlock() {
|
||||
return temporary != null;
|
||||
}
|
||||
|
||||
public BlockType getTemporaryBlock() {
|
||||
return temporary;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package net.Indyuce.mmocore.api.block;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
|
||||
public class SkullBlockType implements BlockType {
|
||||
private final String value;
|
||||
|
||||
public SkullBlockType(MMOLineConfig config) {
|
||||
config.validate("value");
|
||||
|
||||
value = config.getString("value");
|
||||
}
|
||||
|
||||
public SkullBlockType(Block block) {
|
||||
value = MMOLib.plugin.getNMS().getSkullValue(block);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(Location loc, RegeneratingBlock block) {
|
||||
|
||||
// save skull orientation if replaced block is a player head
|
||||
if (MMOCoreUtils.isPlayerHead(loc.getBlock().getType()) && MMOLib.plugin.getVersion().isStrictlyHigher(1, 12))
|
||||
loc.getBlock().setBlockData(block.getBlockData());
|
||||
|
||||
MMOLib.plugin.getNMS().setSkullValue(loc.getBlock(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateKey() {
|
||||
return "vanilla-skull-" + value;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package net.Indyuce.mmocore.api.block;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class VanillaBlockType implements BlockType {
|
||||
private final Material type;
|
||||
|
||||
public VanillaBlockType(MMOLineConfig config) {
|
||||
config.validate("type");
|
||||
|
||||
type = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
}
|
||||
|
||||
public VanillaBlockType(Block block) {
|
||||
type = block.getType();
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(Location loc, RegeneratingBlock block) {
|
||||
loc.getBlock().setType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateKey() {
|
||||
return "vanilla-block-" + type.name();
|
||||
}
|
||||
}
|
@ -11,8 +11,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class DropTable {
|
||||
private final String id;
|
||||
|
@ -1,11 +1,12 @@
|
||||
package net.Indyuce.mmocore.api.droptable.condition;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class BiomeCondition extends Condition {
|
||||
private final List<String> names;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.Indyuce.mmocore.api.droptable.condition;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public abstract class Condition {
|
||||
private final String id;
|
||||
|
@ -3,7 +3,7 @@ package net.Indyuce.mmocore.api.droptable.condition;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class WorldCondition extends Condition {
|
||||
private final List<String> names;
|
||||
|
@ -5,8 +5,8 @@ import java.util.Random;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public abstract class DropItem {
|
||||
protected static final Random random = new Random();
|
||||
|
@ -7,7 +7,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class DropTableDropItem extends DropItem {
|
||||
private DropTable dropTable;
|
||||
|
@ -4,8 +4,8 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class GoldDropItem extends DropItem {
|
||||
public GoldDropItem(MMOLineConfig config) {
|
||||
|
@ -14,7 +14,7 @@ import io.lumine.xikage.mythicmobs.drops.DropTable;
|
||||
import io.lumine.xikage.mythicmobs.drops.IItemDrop;
|
||||
import io.lumine.xikage.mythicmobs.drops.LootBag;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MMDropTableDropItem extends DropItem {
|
||||
private DropTable dropTable;
|
||||
|
@ -4,8 +4,8 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class NoteDropItem extends DropItem {
|
||||
private int min, max;
|
||||
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class VanillaDropItem extends DropItem {
|
||||
private final Material material;
|
||||
|
@ -7,8 +7,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class FishingDropItem {
|
||||
private final RandomAmount experience, tugs;
|
||||
|
@ -7,9 +7,9 @@ import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||
import net.Indyuce.mmocore.api.experience.ExperienceInfo;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo;
|
||||
|
||||
public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -9,9 +9,9 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
|
||||
public class Profession {
|
||||
|
@ -19,9 +19,9 @@ import org.bukkit.potion.PotionType;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class BrewPotionExperienceSource extends ExperienceSource<PotionMeta> {
|
||||
private final List<PotionType> types = new ArrayList<>();
|
||||
|
@ -8,9 +8,9 @@ import org.bukkit.event.inventory.CraftItemEvent;
|
||||
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class CraftItemExperienceSource extends SpecificExperienceSource<Material> {
|
||||
public final Material material;
|
||||
|
@ -15,9 +15,9 @@ import org.bukkit.event.enchantment.EnchantItemEvent;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
|
||||
public class EnchantItemExperienceSource extends ExperienceSource<Void> {
|
||||
|
@ -10,9 +10,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class FishItemExperienceSource extends SpecificExperienceSource<ItemStack> {
|
||||
private final Material material;
|
||||
|
@ -10,9 +10,9 @@ import org.bukkit.event.EventPriority;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.api.event.EntityKillEntityEvent;
|
||||
|
||||
public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
|
||||
|
@ -10,9 +10,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
|
||||
public class MineBlockExperienceSource extends SpecificExperienceSource<Material> {
|
||||
|
@ -8,9 +8,9 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class PlaceBlockExperienceSource extends SpecificExperienceSource<Material> {
|
||||
public final Material material;
|
||||
|
@ -13,9 +13,9 @@ import org.bukkit.inventory.meta.Damageable;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class RepairItemExperienceSource extends ExperienceSource<ItemStack> {
|
||||
private final Material material;
|
||||
|
@ -12,9 +12,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class SmeltItemExperienceSource extends SpecificExperienceSource<ItemStack> {
|
||||
private final Material material;
|
||||
|
@ -3,9 +3,9 @@ package net.Indyuce.mmocore.api.experience.source.type;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
|
||||
private final RandomAmount amount;
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.Indyuce.mmocore.api.load;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.BiomeCondition;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
import net.Indyuce.mmocore.api.block.SkullBlockType;
|
||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.BiomeCondition;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.WorldCondition;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
@ -35,8 +38,9 @@ import net.Indyuce.mmocore.api.quest.trigger.MessageTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.SoundTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.StelliumTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class DefaultMMOLoader implements MMOLoader {
|
||||
public class DefaultMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
@ -143,4 +147,13 @@ public class DefaultMMOLoader implements MMOLoader {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockType loadBlockType(MMOLineConfig config) {
|
||||
|
||||
if (config.getKey().equalsIgnoreCase("skull") || config.getKey().equals("head") || config.getKey().equals("playerhead"))
|
||||
return new SkullBlockType(config);
|
||||
|
||||
return new VanillaBlockType(config);
|
||||
}
|
||||
}
|
||||
|
@ -1,100 +0,0 @@
|
||||
package net.Indyuce.mmocore.api.load;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class MMOLineConfig {
|
||||
private final String key, value;
|
||||
private final String[] args;
|
||||
private JsonObject json;
|
||||
|
||||
public MMOLineConfig(String value) {
|
||||
this.value = value;
|
||||
|
||||
/*
|
||||
* if there is no config, no need to parse the json object. split,
|
||||
* define key and find arg
|
||||
*/
|
||||
if (!value.contains("{") || !value.contains("}")) {
|
||||
String[] split = value.split("\\ ");
|
||||
key = split[0];
|
||||
args = split.length > 1 ? value.replace(key + " ", "").split("\\ ") : new String[0];
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* load json and extra args
|
||||
*/
|
||||
int begin = value.indexOf("{"), end = value.lastIndexOf("}") + 1;
|
||||
key = value.substring(0, begin);
|
||||
|
||||
try {
|
||||
json = new JsonParser().parse(value.substring(begin, end)).getAsJsonObject();
|
||||
} catch (JsonParseException exception) {
|
||||
throw new IllegalArgumentException("Could not load config");
|
||||
}
|
||||
|
||||
String format = value.substring(Math.min(value.length(), end + 1));
|
||||
args = format.isEmpty() ? new String[0] : format.split("\\ ");
|
||||
}
|
||||
|
||||
/*
|
||||
* extra arguments outside the config brackets
|
||||
*/
|
||||
public String[] args() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return json.get(path).getAsString();
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return json.get(path).getAsDouble();
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return json.get(path).getAsInt();
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return json.has(path) ? getInt(path) : def;
|
||||
}
|
||||
|
||||
public long getLong(String path) {
|
||||
return json.get(path).getAsLong();
|
||||
}
|
||||
|
||||
public boolean getBoolean(String path) {
|
||||
return json.get(path).getAsBoolean();
|
||||
}
|
||||
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return json.has(path) ? getBoolean(path) : def;
|
||||
}
|
||||
|
||||
public boolean contains(String path) {
|
||||
return json.has(path);
|
||||
}
|
||||
|
||||
public void validate(String... paths) {
|
||||
for (String path : paths)
|
||||
Validate.isTrue(contains(path), "Config is missing parameter '" + path + "'");
|
||||
}
|
||||
|
||||
public void validateArgs(int count) {
|
||||
Validate.isTrue(args.length >= count, "Config must have at least " + count + " parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package net.Indyuce.mmocore.api.load;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MMOLoadException extends IllegalArgumentException {
|
||||
private static final long serialVersionUID = -8839506644440697800L;
|
||||
|
@ -2,21 +2,42 @@ package net.Indyuce.mmocore.api.load;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public interface MMOLoader {
|
||||
public Condition loadCondition(MMOLineConfig config);
|
||||
public class MMOLoader {
|
||||
|
||||
public Trigger loadTrigger(MMOLineConfig config);
|
||||
/*
|
||||
* MMOLoader was initially an interface but it is now a class so devs do not
|
||||
* have to add a new method everytime the class is updated.
|
||||
*/
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public DropItem loadDropItem(MMOLineConfig config);
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section);
|
||||
public DropItem loadDropItem(MMOLineConfig config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, Profession profession);
|
||||
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, Profession profession) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BlockType loadBlockType(MMOLineConfig config) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -80,17 +80,17 @@ public class PlayerSkillData {
|
||||
|
||||
public class CachedModifier {
|
||||
private final long date = System.currentTimeMillis();
|
||||
private final int value;
|
||||
private final double value;
|
||||
|
||||
public CachedModifier(double value) {
|
||||
this.value = (int) value;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isTimedOut() {
|
||||
return date + 1000 * 60 < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import com.mojang.authlib.properties.Property;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.AltChar;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.EventTrigger;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.ManaDisplayOptions;
|
||||
@ -38,6 +37,7 @@ import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
||||
import net.Indyuce.mmocore.api.util.math.particle.CastingParticle;
|
||||
import net.Indyuce.mmocore.manager.ClassManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
|
||||
public class PlayerClass {
|
||||
|
@ -7,9 +7,9 @@ import java.util.Set;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class EventTrigger {
|
||||
private final String event;
|
||||
|
@ -13,11 +13,11 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.manager.QuestManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class Quest {
|
||||
private final String id;
|
||||
|
@ -11,9 +11,9 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class ClickonObjective extends Objective {
|
||||
private final Location loc;
|
||||
|
@ -10,9 +10,9 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class GoToObjective extends Objective {
|
||||
private final Location loc;
|
||||
|
@ -5,9 +5,9 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.api.event.EntityKillEntityEvent;
|
||||
|
||||
public class KillMobObjective extends Objective {
|
||||
|
@ -7,9 +7,9 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MineBlockObjective extends Objective {
|
||||
private final Material block;
|
||||
|
@ -8,11 +8,11 @@ import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public abstract class Objective {
|
||||
private final String id, lore;
|
||||
|
@ -4,8 +4,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class CommandTrigger extends Trigger {
|
||||
private final String command;
|
||||
|
@ -5,9 +5,9 @@ import org.apache.commons.lang.Validate;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.ExperienceInfo;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class ExperienceTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
|
@ -3,9 +3,9 @@ package net.Indyuce.mmocore.api.quest.trigger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.item.SmartGive;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class ItemTrigger extends Trigger {
|
||||
private final Material material;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class ManaTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
|
@ -3,8 +3,8 @@ package net.Indyuce.mmocore.api.quest.trigger;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MessageTrigger extends Trigger {
|
||||
private final String message;
|
||||
|
@ -2,8 +2,8 @@ package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class SoundTrigger extends Trigger {
|
||||
private final Sound sound;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger.Operation;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class StelliumTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
|
@ -3,8 +3,8 @@ package net.Indyuce.mmocore.api.quest.trigger;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public abstract class Trigger {
|
||||
private final long delay;
|
||||
|
@ -22,6 +22,7 @@ import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
|
||||
public class MMOCoreUtils {
|
||||
public static boolean pluginItem(ItemStack item) {
|
||||
@ -48,6 +49,10 @@ public class MMOCoreUtils {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static boolean isPlayerHead(Material material) {
|
||||
return material == VersionMaterial.PLAYER_HEAD.toMaterial() || material == VersionMaterial.PLAYER_WALL_HEAD.toMaterial();
|
||||
}
|
||||
|
||||
public static ItemStack readIcon(String string) {
|
||||
try {
|
||||
Validate.notNull(string, "String cannot be null");
|
||||
|
@ -2,34 +2,11 @@ package net.Indyuce.mmocore.comp.citizens;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoader;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class CitizensMMOLoader implements MMOLoader {
|
||||
|
||||
@Override
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropItem loadDropItem(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
public class CitizensMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
|
||||
@ -42,10 +19,4 @@ public class CitizensMMOLoader implements MMOLoader {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, Profession profession) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class GetItemObjective extends Objective {
|
||||
private Material material;
|
||||
|
@ -4,10 +4,10 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class TalktoCitizenObjective extends Objective {
|
||||
private int id;
|
||||
|
@ -2,25 +2,17 @@ package net.Indyuce.mmocore.comp.mythicmobs;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoader;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicMobExperienceSource;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicMobObjective;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.load.MythicMobSkillTrigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MythicMobsMMOLoader implements MMOLoader {
|
||||
|
||||
@Override
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
public class MythicMobsMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
@ -31,12 +23,6 @@ public class MythicMobsMMOLoader implements MMOLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropItem loadDropItem(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
|
||||
|
||||
|
@ -8,9 +8,9 @@ import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class KillMythicMobExperienceSource extends SpecificExperienceSource<String> {
|
||||
private final String internalName;
|
||||
|
@ -6,10 +6,10 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class KillMythicMobObjective extends Objective {
|
||||
private final String internalName;
|
||||
|
@ -9,9 +9,9 @@ import org.bukkit.entity.Entity;
|
||||
|
||||
import io.lumine.xikage.mythicmobs.MythicMobs;
|
||||
import io.lumine.xikage.mythicmobs.skills.Skill;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MythicMobSkillTrigger extends Trigger {
|
||||
private final Skill skill;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.Indyuce.mmocore.comp.vault;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MoneyTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
|
@ -1,23 +1,10 @@
|
||||
package net.Indyuce.mmocore.comp.vault;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoader;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class VaultMMOLoader implements MMOLoader {
|
||||
|
||||
@Override
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
public class VaultMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
@ -27,22 +14,4 @@ public class VaultMMOLoader implements MMOLoader {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropItem loadDropItem(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, Profession profession) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class RegionCondition extends Condition {
|
||||
private final List<String> names;
|
||||
|
@ -1,17 +1,10 @@
|
||||
package net.Indyuce.mmocore.comp.worldguard;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoader;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class WorldGuardMMOLoader implements MMOLoader {
|
||||
public class WorldGuardMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
@ -21,28 +14,4 @@ public class WorldGuardMMOLoader implements MMOLoader {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropItem loadDropItem(MMOLineConfig config) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, Profession profession) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package net.Indyuce.mmocore.gui.api.item;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class TriggerItem extends InventoryPlaceholderItem {
|
||||
private final Trigger trigger;
|
||||
|
@ -18,12 +18,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||
import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.CustomBlockManager.BlockInfo;
|
||||
import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
@ -37,101 +35,91 @@ public class BlockListener implements Listener {
|
||||
|
||||
String savedData = MMOLib.plugin.getVersion().isStrictlyHigher(1, 12) ? event.getBlock().getBlockData().getAsString() : "";
|
||||
Block block = event.getBlock();
|
||||
|
||||
/*
|
||||
* if custom mining enabled, check for item breaking restrictions
|
||||
*/
|
||||
boolean customMine = MMOCore.plugin.mineManager.isEnabled(player, block.getLocation());
|
||||
if (!customMine)
|
||||
return;
|
||||
|
||||
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block);
|
||||
if (info == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* calls the event and listen for cancel & for drops changes... also
|
||||
* allows to apply tool durability & enchants to drops, etc.
|
||||
*/
|
||||
CustomBlockMineEvent called = new CustomBlockMineEvent(PlayerData.get(player), block, info);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType());
|
||||
if (perms == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (customMine) {
|
||||
if (!perms.canMine(info.getBlock())) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block);
|
||||
if (info == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* calls the event and listen for cancel & for drops changes... also
|
||||
* allows to apply tool durability & enchants to drops, etc.
|
||||
/*
|
||||
* remove vanilla drops if needed
|
||||
*/
|
||||
if (!info.hasVanillaDrops()) {
|
||||
// event.setDropItems(false); // May not work
|
||||
event.setCancelled(true);
|
||||
event.getBlock().setType(Material.AIR);
|
||||
}
|
||||
|
||||
/*
|
||||
* apply triggers, add experience info to the event so the other events
|
||||
* can give exp to other TOOLS and display HOLOGRAMS
|
||||
*/
|
||||
if (info.hasTriggers() && !block.hasMetadata("player_placed")) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
info.getTriggers().forEach(trigger -> trigger.apply(playerData));
|
||||
/**
|
||||
* if (!block.hasMetadata("player_placed") && info.hasExperience()
|
||||
* && MMOCore.plugin.hasHolograms())
|
||||
* MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5,
|
||||
* 1.5, .5),
|
||||
* MMOCore.plugin.configManager.getSimpleMessage("exp-hologram",
|
||||
* "exp", "" + called.getGainedExperience().getValue()).message(),
|
||||
* player);
|
||||
*/
|
||||
CustomBlockMineEvent called = new CustomBlockMineEvent(PlayerData.get(player), block, info);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType());
|
||||
if (perms == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* apply drop tables
|
||||
*/
|
||||
if (info.hasDropTable()) {
|
||||
Location dropLocation = getSafeDropLocation(block, true);
|
||||
for (ItemStack drop : called.getDrops())
|
||||
if (drop.getType() != Material.AIR && drop.getAmount() > 0)
|
||||
block.getWorld().dropItemNaturally(dropLocation, drop);
|
||||
}
|
||||
|
||||
if (!perms.canMine(getBlockName(block))) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* remove vanilla drops if needed
|
||||
*/
|
||||
if (!info.hasVanillaDrops()) {
|
||||
//event.setDropItems(false); // May not work
|
||||
event.setCancelled(true);
|
||||
event.getBlock().setType(Material.AIR);
|
||||
}
|
||||
|
||||
/*
|
||||
* apply triggers, add experience info to the event so the other
|
||||
* events can give exp to other TOOLS and display HOLOGRAMS
|
||||
*/
|
||||
if (info.hasTriggers() && !block.hasMetadata("player_placed")) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
info.getTriggers().forEach(trigger -> trigger.apply(playerData));
|
||||
/**
|
||||
* if (!block.hasMetadata("player_placed") &&
|
||||
* info.hasExperience() && MMOCore.plugin.hasHolograms())
|
||||
* MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5,
|
||||
* 1.5, .5),
|
||||
* MMOCore.plugin.configManager.getSimpleMessage("exp-hologram",
|
||||
* "exp", "" +
|
||||
* called.getGainedExperience().getValue()).message(), player);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* apply drop tables
|
||||
*/
|
||||
if (info.hasDropTable()) {
|
||||
Location dropLocation = getSafeDropLocation(block, true);
|
||||
for (ItemStack drop : called.getDrops())
|
||||
if (drop.getType() != Material.AIR && drop.getAmount() > 0)
|
||||
block.getWorld().dropItemNaturally(dropLocation, drop);
|
||||
}
|
||||
|
||||
/*
|
||||
* enable block regen.
|
||||
*/
|
||||
if (info.hasRegen()) {
|
||||
if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 12))
|
||||
MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(Bukkit.createBlockData(savedData), block.getLocation()));
|
||||
else
|
||||
MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(block.getLocation()));
|
||||
}
|
||||
/*
|
||||
* enable block regen.
|
||||
*/
|
||||
if (info.hasRegen()) {
|
||||
if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 12))
|
||||
MMOCore.plugin.mineManager.initialize(info.startRegeneration(Bukkit.createBlockData(savedData), block.getLocation()));
|
||||
else
|
||||
MMOCore.plugin.mineManager.initialize(info.startRegeneration(block.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
private String getBlockName(Block block) {
|
||||
if (MMOCore.plugin.isMILoaded())
|
||||
if (MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) {
|
||||
CustomBlock cblock = CustomBlock.getFromData(block.getBlockData());
|
||||
if (cblock != null)
|
||||
return "MICUSTOM_" + cblock.getId();
|
||||
}
|
||||
|
||||
return block.getType().toString();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void b(BlockPlaceEvent event) {
|
||||
|
@ -5,67 +5,85 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.droptable.DropTable;
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||
import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class CustomBlockManager extends MMOManager {
|
||||
|
||||
/*
|
||||
* registered block infos
|
||||
*/
|
||||
private final Map<String, BlockInfo> map = new HashMap<>();
|
||||
private final Set<RegenInfo> active = new HashSet<>();
|
||||
|
||||
/*
|
||||
* blocks that are regenerating and that must be refreshed whenever the
|
||||
* server reloads or shuts down not to hurt the world map
|
||||
*/
|
||||
private final Set<RegeneratingBlock> active = new HashSet<>();
|
||||
|
||||
/* list in which both block regen and block permissions are enabled. */
|
||||
private final List<Condition> customMineConditions = new ArrayList<>();
|
||||
|
||||
public void loadDropTables(ConfigurationSection config) {
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
BlockInfo info = new BlockInfo(config.getConfigurationSection(key));
|
||||
register(info.getHeadValue().isEmpty() ? info.getCustomBlockID() > 0 ? "mi-custom-" + info.getCustomBlockID() : info.getBlock().name() : info.getHeadValue(), info);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage());
|
||||
}
|
||||
/*
|
||||
* list of functions which let
|
||||
*/
|
||||
private final List<Function<Block, BlockType>> blockTypes = new ArrayList<>();
|
||||
|
||||
public CustomBlockManager() {
|
||||
registerBlockType(block -> MMOCoreUtils.isPlayerHead(block.getType()) ? new VanillaBlockType(block) : null);
|
||||
}
|
||||
|
||||
public void register(String key, BlockInfo regen) {
|
||||
map.put(key, regen);
|
||||
public void registerBlockType(Function<Block, BlockType> function) {
|
||||
blockTypes.add(function);
|
||||
}
|
||||
|
||||
public void register(BlockInfo regen) {
|
||||
map.put(regen.generateKey(), regen);
|
||||
}
|
||||
|
||||
public BlockInfo getInfo(Block block) {
|
||||
if(isPlayerSkull(block.getType())) {
|
||||
String skullValue = MMOLib.plugin.getNMS().getSkullValue(block);
|
||||
return map.getOrDefault(skullValue, map.getOrDefault(block.getType().name(), null));
|
||||
}
|
||||
if(MMOCore.plugin.isMILoaded())
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(block.getType())) {
|
||||
CustomBlock cblock = CustomBlock.getFromData(block.getBlockData());
|
||||
if(cblock != null)
|
||||
return map.getOrDefault("mi-custom-" + cblock.getId(), map.getOrDefault(block.getType().name(), null));
|
||||
}
|
||||
return map.getOrDefault(findBlockType(block).generateKey(), null);
|
||||
}
|
||||
|
||||
return map.getOrDefault(block.getType().name(), null);
|
||||
public BlockType findBlockType(Block block) {
|
||||
for (Function<Block, BlockType> blockType : blockTypes) {
|
||||
BlockType type = blockType.apply(block);
|
||||
if (type != null)
|
||||
return type;
|
||||
}
|
||||
|
||||
return new VanillaBlockType(block);
|
||||
}
|
||||
|
||||
public void initialize(RegeneratingBlock info) {
|
||||
active.add(info);
|
||||
if (info.getRegeneratingBlock().getRegenerationInfo().hasTemporaryBlock())
|
||||
info.getRegeneratingBlock().getRegenerationInfo().getTemporaryBlock().place(info.getLocation(), info);
|
||||
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> regen(info), info.getRegeneratingBlock().getRegenerationInfo().getTime());
|
||||
}
|
||||
|
||||
private void regen(RegeneratingBlock info) {
|
||||
info.getRegeneratingBlock().getBlock().place(info.getLocation(), info);
|
||||
active.remove(info);
|
||||
info.getLocation().getBlock().getState().update();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -73,36 +91,7 @@ public class CustomBlockManager extends MMOManager {
|
||||
* are reset and put back in place.
|
||||
*/
|
||||
public void resetRemainingBlocks() {
|
||||
active.forEach(info -> { regen(info); });
|
||||
}
|
||||
|
||||
public void initialize(RegenInfo info) {
|
||||
active.add(info);
|
||||
|
||||
if(MMOCore.plugin.isMILoaded() && info.getRegen().getCustomRegenBlockID() != 0) {
|
||||
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(info.getRegen().getCustomRegenBlockID());
|
||||
info.getLocation().getBlock().setType(block.getType());
|
||||
if(MMOLib.plugin.getVersion().isStrictlyHigher(1, 12)) info.getLocation().getBlock().setBlockData(block.getBlockData());
|
||||
}
|
||||
else info.getLocation().getBlock().setType(info.getRegen().getTemporaryBlock());
|
||||
if(isPlayerSkull(info.getLocation().getBlock().getType())) {
|
||||
if(isPlayerSkull(info.getRegen().getBlock()) && MMOLib.plugin.getVersion().isStrictlyHigher(1, 12)) info.getLocation().getBlock().setBlockData(info.getBlockData());
|
||||
MMOLib.plugin.getNMS().setSkullValue(info.getLocation().getBlock(), info.getRegen().getRegenHeadValue());
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() { regen(info); }
|
||||
}.runTaskLater(MMOCore.plugin, info.getRegen().getRegenTime());
|
||||
}
|
||||
|
||||
private void regen(RegenInfo info) {
|
||||
if(MMOLib.plugin.getVersion().isStrictlyHigher(1, 12))
|
||||
info.getLocation().getBlock().setBlockData(info.getBlockData());
|
||||
if(isPlayerSkull(info.getLocation().getBlock().getType()))
|
||||
MMOLib.plugin.getNMS().setSkullValue(info.getLocation().getBlock(), info.getRegen().getHeadValue());
|
||||
active.remove(info);
|
||||
|
||||
info.getLocation().getBlock().getState().update();
|
||||
active.forEach(info -> regen(info));
|
||||
}
|
||||
|
||||
public boolean isEnabled(Entity entity) {
|
||||
@ -118,162 +107,13 @@ public class CustomBlockManager extends MMOManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isPlayerSkull(Material block) {
|
||||
return block == VersionMaterial.PLAYER_HEAD.toMaterial() ||
|
||||
block == VersionMaterial.PLAYER_WALL_HEAD.toMaterial();
|
||||
}
|
||||
|
||||
public class BlockInfo {
|
||||
private final Material block;
|
||||
private final DropTable table;
|
||||
private final boolean vanillaDrops;
|
||||
private final String headValue;
|
||||
|
||||
private final List<Trigger> triggers = new ArrayList<>();
|
||||
private final ExperienceTrigger experience;
|
||||
private final int customBlockId;
|
||||
|
||||
/*
|
||||
* options for block regen.
|
||||
*/
|
||||
private Material temporary;
|
||||
private int regenTime = -1;
|
||||
private int regenCustomBlockId;
|
||||
private String regenHeadValue;
|
||||
|
||||
public BlockInfo(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load config");
|
||||
block = Material.valueOf(config.getString("material", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
customBlockId = config.getInt("mi-custom-block", 0);
|
||||
headValue = config.getString("head-value", "");
|
||||
table = config.contains("drop-table") ? MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")) : null;
|
||||
vanillaDrops = config.getBoolean("vanilla-drops", true);
|
||||
|
||||
if (config.contains("regen")) {
|
||||
temporary = Material.valueOf(config.getString("regen.temp-block", "BOOKSHELF").toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
regenCustomBlockId = config.getInt("regen.mi-custom-block", 0);
|
||||
regenHeadValue = config.getString("regen.head-value", "");
|
||||
|
||||
regenTime = config.getInt("regen.time");
|
||||
public void loadDropTables(ConfigurationSection config) {
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
register(new BlockInfo(config.getConfigurationSection(key)));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage());
|
||||
}
|
||||
|
||||
if (config.contains("triggers")) {
|
||||
List<String> list = config.getStringList("triggers");
|
||||
Validate.notNull(list, "Could not load triggers");
|
||||
|
||||
for (String key : list)
|
||||
try {
|
||||
triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key)));
|
||||
} catch (MMOLoadException exception) {
|
||||
exception.printConsole("BlockRegen", "trigger");
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Trigger> opt = triggers.stream().filter(trigger -> (trigger instanceof ExperienceTrigger)).findFirst();
|
||||
experience = opt.isPresent() ? (ExperienceTrigger) opt.get() : null;
|
||||
}
|
||||
|
||||
public String getHeadValue() {
|
||||
return headValue;
|
||||
}
|
||||
|
||||
public boolean hasVanillaDrops() {
|
||||
return vanillaDrops;
|
||||
}
|
||||
|
||||
public Material getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public DropTable getDropTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public List<ItemStack> collectDrops() {
|
||||
return hasDropTable() ? table.collect() : new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean hasDropTable() {
|
||||
return table != null;
|
||||
}
|
||||
|
||||
public boolean hasRegen() {
|
||||
return regenTime > 0;
|
||||
}
|
||||
|
||||
public int getRegenTime() {
|
||||
return regenTime;
|
||||
}
|
||||
|
||||
public Material getTemporaryBlock() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
public String getRegenHeadValue() {
|
||||
return regenHeadValue;
|
||||
}
|
||||
|
||||
public RegenInfo generateRegenInfo(BlockData data, Location loc) {
|
||||
return new RegenInfo(data, loc, this);
|
||||
}
|
||||
|
||||
public RegenInfo generateRegenInfo(Location loc) {
|
||||
return new RegenInfo(null, loc, this);
|
||||
}
|
||||
|
||||
public int getCustomBlockID() {
|
||||
return customBlockId;
|
||||
}
|
||||
|
||||
public int getCustomRegenBlockID() {
|
||||
return regenCustomBlockId;
|
||||
}
|
||||
|
||||
public boolean hasExperience() {
|
||||
return experience != null;
|
||||
}
|
||||
|
||||
public ExperienceTrigger getExperience() {
|
||||
return experience;
|
||||
}
|
||||
|
||||
public boolean hasTriggers() {
|
||||
return !triggers.isEmpty();
|
||||
}
|
||||
|
||||
public List<Trigger> getTriggers() {
|
||||
return triggers;
|
||||
}
|
||||
}
|
||||
|
||||
public class RegenInfo {
|
||||
private final BlockData data;
|
||||
private final Location loc;
|
||||
private final BlockInfo regen;
|
||||
|
||||
private final long date = System.currentTimeMillis();
|
||||
|
||||
public RegenInfo(BlockData data, Location loc, BlockInfo regen) {
|
||||
this.data = data;
|
||||
this.loc = loc;
|
||||
this.regen = regen;
|
||||
}
|
||||
|
||||
public boolean isTimedOut() {
|
||||
return date + regen.getRegenTime() * 50 < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public BlockData getBlockData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public BlockInfo getRegen() {
|
||||
return regen;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,20 +4,22 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.api.load.DefaultMMOLoader;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoader;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class MMOLoadManager {
|
||||
private final List<MMOLoader> loaders = new ArrayList<>();
|
||||
@ -27,27 +29,33 @@ public class MMOLoadManager {
|
||||
}
|
||||
|
||||
public void registerLoader(MMOLoader loader) {
|
||||
Validate.notNull(loader, "Loader must not be null");
|
||||
|
||||
loaders.add(loader);
|
||||
}
|
||||
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
return load(Condition.class, config, (loader) -> loader.loadCondition(config));
|
||||
return load(Condition.class, config, loader -> loader.loadCondition(config));
|
||||
}
|
||||
|
||||
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
|
||||
return load(Objective.class, config, (loader) -> loader.loadObjective(config, section));
|
||||
return load(Objective.class, config, loader -> loader.loadObjective(config, section));
|
||||
}
|
||||
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, Profession profession) {
|
||||
return load(ExperienceSource.class, config, (loader) -> loader.loadExperienceSource(config, profession));
|
||||
return load(ExperienceSource.class, config, loader -> loader.loadExperienceSource(config, profession));
|
||||
}
|
||||
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
return load(Trigger.class, config, (loader) -> loader.loadTrigger(config));
|
||||
return load(Trigger.class, config, loader -> loader.loadTrigger(config));
|
||||
}
|
||||
|
||||
public DropItem loadDropItem(MMOLineConfig config) {
|
||||
return load(DropItem.class, config, (loader) -> loader.loadDropItem(config));
|
||||
return load(DropItem.class, config, loader -> loader.loadDropItem(config));
|
||||
}
|
||||
|
||||
public BlockType loadBlockType(MMOLineConfig config) {
|
||||
return load(BlockType.class, config, loader -> loader.loadBlockType(config));
|
||||
}
|
||||
|
||||
private <T> T load(Class<T> c, MMOLineConfig config, Function<MMOLoader, T> func) {
|
||||
|
@ -12,9 +12,11 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class RestrictionManager {
|
||||
private Set<String> breakBlackList = new HashSet<>();
|
||||
// private Set<String> breakBlackList = new HashSet<>();
|
||||
private Map<Material, BlockPermissions> map = new HashMap<>();
|
||||
|
||||
public RestrictionManager(FileConfiguration config) {
|
||||
@ -37,20 +39,21 @@ public class RestrictionManager {
|
||||
public void register(BlockPermissions perms) {
|
||||
if (perms.isValid()) {
|
||||
map.put(perms.getTool(), perms);
|
||||
perms.getMinable().forEach(material -> breakBlackList.add(material));
|
||||
// perms.getMinable().forEach(material ->
|
||||
// breakBlackList.add(material));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBlackListed(String s) {
|
||||
return breakBlackList.contains(s);
|
||||
}
|
||||
// public boolean isBlackListed(String s) {
|
||||
// return breakBlackList.contains(s);
|
||||
// }
|
||||
|
||||
public BlockPermissions getPermissions(Material tool) {
|
||||
return map.containsKey(tool) ? map.get(tool) : null;
|
||||
}
|
||||
|
||||
public class BlockPermissions {
|
||||
private final Set<String> canMine = new HashSet<>();
|
||||
private final Set<BlockType> mineable = new HashSet<>();
|
||||
private final Material tool;
|
||||
|
||||
private BlockPermissions parent;
|
||||
@ -73,36 +76,21 @@ public class RestrictionManager {
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (loaded.contains("parent")) {
|
||||
String str = loaded.getString("parent").toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
Validate.notNull(str, "Could not load parent");
|
||||
parent = map.get(Material.valueOf(str));
|
||||
}
|
||||
|
||||
if (loaded.contains("parent"))
|
||||
parent = map.get(Material.valueOf(loaded.getString("parent", "???").toUpperCase().replace("-", "_").replace(" ", "_")));
|
||||
for (String key : loaded.getStringList("can-mine"))
|
||||
canMine.add(key.toUpperCase().replace("-", "_"));
|
||||
mineable.add(MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(key)));
|
||||
|
||||
loaded = null;
|
||||
}
|
||||
|
||||
public void setParent(BlockPermissions parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void addPermission(String s) {
|
||||
canMine.add(s);
|
||||
public void addPermission(BlockType block) {
|
||||
mineable.add(block);
|
||||
}
|
||||
|
||||
// recursive function to check for parent permissions
|
||||
public boolean canMine(String material) {
|
||||
return canMine.contains(material) || (parent != null && parent.canMine(material));
|
||||
}
|
||||
|
||||
public Set<String> getMinable() {
|
||||
Set<String> total = new HashSet<>(canMine);
|
||||
if (parent != null)
|
||||
total.addAll(parent.getMinable());
|
||||
return total;
|
||||
public boolean canMine(BlockType type) {
|
||||
return mineable.contains(type) || (parent != null && parent.canMine(type));
|
||||
}
|
||||
|
||||
public Material getTool() {
|
||||
|
@ -16,9 +16,9 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem;
|
||||
import net.Indyuce.mmocore.api.load.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.load.MMOLoadException;
|
||||
import net.Indyuce.mmocore.manager.MMOManager;
|
||||
import net.Indyuce.mmoitems.api.util.MMOLineConfig;
|
||||
|
||||
public class FishingManager extends MMOManager {
|
||||
private final Set<FishingDropTable> tables = new LinkedHashSet<>();
|
||||
|
Loading…
Reference in New Issue
Block a user