forked from Upstream/mmocore
Custom mining now only works in custom mining regions
Also added Playerhead regen
This commit is contained in:
parent
5c608b8439
commit
4b409b6e7c
@ -51,6 +51,9 @@ public class Profession {
|
||||
|
||||
if (config.contains("on-mine"))
|
||||
MMOCore.plugin.mineManager.loadDropTables(config.getConfigurationSection("on-mine"));
|
||||
|
||||
if (config.contains("on-mine-playerhead"))
|
||||
MMOCore.plugin.mineManager.loadPHDropTables(config.getConfigurationSection("on-mine-playerhead"));
|
||||
|
||||
if (config.contains("alchemy-experience")) {
|
||||
|
||||
|
@ -37,12 +37,14 @@ public class BlockListener implements Listener {
|
||||
*/
|
||||
boolean customMine = MMOCore.plugin.mineManager.isEnabled(player);
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block.getType());
|
||||
if (info == null)
|
||||
return;
|
||||
|
||||
if (customMine) {
|
||||
|
||||
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.
|
||||
@ -98,13 +100,13 @@ public class BlockListener implements Listener {
|
||||
if (drop.getType() != Material.AIR && drop.getAmount() > 0)
|
||||
block.getWorld().dropItemNaturally(dropLocation, drop);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* enable block regen only if custom mine is enabled.
|
||||
*/
|
||||
if (customMine && info.hasRegen())
|
||||
MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(event.getBlock().getLocation()));
|
||||
/*
|
||||
* enable block regen.
|
||||
*/
|
||||
if (info.hasRegen())
|
||||
MMOCore.plugin.mineManager.initialize(info.generateRegenInfo(event.getBlock().getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
|
@ -12,6 +12,7 @@ import java.util.logging.Level;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -25,9 +26,11 @@ 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.mmocore.version.VersionMaterial;
|
||||
|
||||
public class CustomBlockManager extends MMOManager {
|
||||
private final Map<Material, BlockInfo> map = new HashMap<>();
|
||||
private final Map<String, BlockInfo> headmap = new HashMap<>();
|
||||
private final Set<RegenInfo> active = new HashSet<>();
|
||||
|
||||
/*
|
||||
@ -38,18 +41,38 @@ public class CustomBlockManager extends MMOManager {
|
||||
public void loadDropTables(ConfigurationSection config) {
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
register(new BlockInfo(config.getConfigurationSection(key)));
|
||||
register(new BlockInfo(config.getConfigurationSection(key), false));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void loadPHDropTables(ConfigurationSection config) {
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
register(new BlockInfo(config.getConfigurationSection(key), true));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load custom block '" + key + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void register(BlockInfo regen) {
|
||||
map.put(regen.getBlock(), regen);
|
||||
if(!regen.headValue.isEmpty()) {
|
||||
MMOCore.log("Reistered Head Value: " + regen.headValue);
|
||||
headmap.put(regen.headValue, regen);
|
||||
}
|
||||
else
|
||||
map.put(regen.getBlock(), regen);
|
||||
}
|
||||
|
||||
public BlockInfo getInfo(Material material) {
|
||||
return map.containsKey(material) ? map.get(material) : null;
|
||||
public BlockInfo getInfo(Block block) {
|
||||
if(block.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||
String skullValue = MMOCore.plugin.nms.getSkullValue(block);
|
||||
|
||||
return headmap.containsKey(skullValue) ? headmap.get(skullValue) : null;
|
||||
}
|
||||
|
||||
return map.containsKey(block.getType()) ? map.get(block.getType()) : null;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -64,11 +87,17 @@ public class CustomBlockManager extends MMOManager {
|
||||
|
||||
active.add(info);
|
||||
info.getLocation().getBlock().setType(info.getRegen().getTemporaryBlock());
|
||||
if(info.getRegen().getTemporaryBlock() == Material.PLAYER_HEAD)
|
||||
MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().regenHeadValue);
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
active.remove(info);
|
||||
info.getLocation().getBlock().setType(info.getRegen().getBlock());
|
||||
if(info.getRegen().getBlock() == Material.PLAYER_HEAD) {
|
||||
MMOCore.plugin.nms.setSkullValue(info.getLocation().getBlock(), info.getRegen().headValue);
|
||||
info.getLocation().getBlock().getState().update();
|
||||
}
|
||||
}
|
||||
}.runTaskLater(MMOCore.plugin, info.getRegen().getRegenTime());
|
||||
}
|
||||
@ -91,6 +120,7 @@ public class CustomBlockManager extends MMOManager {
|
||||
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;
|
||||
@ -100,18 +130,22 @@ public class CustomBlockManager extends MMOManager {
|
||||
*/
|
||||
private Material temporary;
|
||||
private int regenTime = -1;
|
||||
private String regenHeadValue;
|
||||
|
||||
public BlockInfo(ConfigurationSection config) {
|
||||
public BlockInfo(ConfigurationSection config, boolean isPlayerHead) {
|
||||
Validate.notNull(config, "Could not load config");
|
||||
block = Material.valueOf(config.getName().toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
block = isPlayerHead ? Material.PLAYER_HEAD : Material.valueOf(config.getName().toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
headValue = isPlayerHead ? config.getString("head-value") : "";
|
||||
table = config.contains("drop-table") ? MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")) : null;
|
||||
vanillaDrops = config.contains("vanilla-drops") ? config.getBoolean("vanilla-drops") : true;
|
||||
vanillaDrops = config.getBoolean("vanilla-drops", true);
|
||||
|
||||
if (config.contains("regen")) {
|
||||
String format = config.getString("regen.temp-block");
|
||||
Validate.notNull(config, "Could not load temporary block");
|
||||
temporary = Material.valueOf(format.toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
|
||||
temporary = isPlayerHead ? Material.PLAYER_HEAD : Material.valueOf(format.toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
if(temporary == Material.PLAYER_HEAD)
|
||||
regenHeadValue = config.getString("regen.head-value");
|
||||
|
||||
regenTime = config.getInt("regen.time");
|
||||
}
|
||||
|
||||
@ -131,6 +165,10 @@ public class CustomBlockManager extends MMOManager {
|
||||
experience = opt.isPresent() ? (ExperienceTrigger) opt.get() : null;
|
||||
}
|
||||
|
||||
public String getHeadValue() {
|
||||
return headValue;
|
||||
}
|
||||
|
||||
public boolean hasVanillaDrops() {
|
||||
return vanillaDrops;
|
||||
}
|
||||
@ -162,6 +200,10 @@ public class CustomBlockManager extends MMOManager {
|
||||
public Material getTemporaryBlock() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
public String getRegenHeadValue() {
|
||||
return regenHeadValue;
|
||||
}
|
||||
|
||||
public RegenInfo generateRegenInfo(Location loc) {
|
||||
return new RegenInfo(loc, this);
|
||||
@ -223,5 +265,6 @@ public class CustomBlockManager extends MMOManager {
|
||||
@Override
|
||||
public void clear() {
|
||||
map.clear();
|
||||
headmap.clear();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.version.nms;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -38,4 +39,8 @@ public interface NMSHandler {
|
||||
Object newContainerAnvil(Player player);
|
||||
|
||||
BoundingBox getBoundingBox(Entity target);
|
||||
|
||||
String getSkullValue(Block block);
|
||||
|
||||
void setSkullValue(Block block, String value);
|
||||
}
|
||||
|
@ -1,14 +1,20 @@
|
||||
package net.Indyuce.mmocore.version.nms;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
|
||||
import net.Indyuce.mmocore.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
@ -27,6 +33,7 @@ import net.minecraft.server.v1_12_R1.PacketPlayOutCloseWindow;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||
import net.minecraft.server.v1_12_R1.TileEntitySkull;
|
||||
|
||||
public class NMSHandler_1_12_R1 implements NMSHandler {
|
||||
@Override
|
||||
@ -182,4 +189,19 @@ public class NMSHandler_1_12_R1 implements NMSHandler {
|
||||
AxisAlignedBB aabb = ((Entity) target).getBoundingBox();
|
||||
return new BoundingBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSkullValue(Block block) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if(skullTile.getGameProfile() == null) return "";
|
||||
return skullTile.getGameProfile().getProperties().get("textures").iterator().next().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkullValue(Block block, String value) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
profile.getProperties().put("textures", new Property("textures", value));
|
||||
skullTile.setGameProfile(profile);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,21 @@
|
||||
package net.Indyuce.mmocore.version.nms;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
|
||||
import net.Indyuce.mmocore.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_13_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R1.Blocks;
|
||||
@ -26,6 +32,7 @@ import net.minecraft.server.v1_13_R1.PacketPlayOutCloseWindow;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||
import net.minecraft.server.v1_13_R1.TileEntitySkull;
|
||||
|
||||
public class NMSHandler_1_13_R1 implements NMSHandler {
|
||||
@Override
|
||||
@ -180,4 +187,19 @@ public class NMSHandler_1_13_R1 implements NMSHandler {
|
||||
public BoundingBox getBoundingBox(Entity target) {
|
||||
return target.getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSkullValue(Block block) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if(skullTile.getGameProfile() == null) return "";
|
||||
return skullTile.getGameProfile().getProperties().get("textures").iterator().next().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkullValue(Block block, String value) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
profile.getProperties().put("textures", new Property("textures", value));
|
||||
skullTile.setGameProfile(profile);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package net.Indyuce.mmocore.version.nms;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||
@ -10,6 +13,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
|
||||
import net.Indyuce.mmocore.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.Blocks;
|
||||
@ -26,6 +32,7 @@ import net.minecraft.server.v1_13_R2.PacketPlayOutCloseWindow;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutTitle.EnumTitleAction;
|
||||
import net.minecraft.server.v1_13_R2.TileEntitySkull;
|
||||
|
||||
public class NMSHandler_1_13_R2 implements NMSHandler {
|
||||
@Override
|
||||
@ -181,4 +188,19 @@ public class NMSHandler_1_13_R2 implements NMSHandler {
|
||||
public BoundingBox getBoundingBox(Entity target) {
|
||||
return target.getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSkullValue(Block block) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if(skullTile.getGameProfile() == null) return "";
|
||||
return skullTile.getGameProfile().getProperties().get("textures").iterator().next().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkullValue(Block block, String value) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
profile.getProperties().put("textures", new Property("textures", value));
|
||||
skullTile.setGameProfile(profile);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package net.Indyuce.mmocore.version.nms;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.reflect.FieldUtils;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
||||
@ -13,6 +15,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
|
||||
import net.Indyuce.mmocore.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_14_R1.ChatMessage;
|
||||
@ -30,6 +35,7 @@ import net.minecraft.server.v1_14_R1.PacketPlayOutCloseWindow;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||
import net.minecraft.server.v1_14_R1.TileEntitySkull;
|
||||
|
||||
public class NMSHandler_1_14_R1 implements NMSHandler {
|
||||
@Override
|
||||
@ -204,4 +210,19 @@ public class NMSHandler_1_14_R1 implements NMSHandler {
|
||||
public BoundingBox getBoundingBox(Entity target) {
|
||||
return target.getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSkullValue(Block block) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
if(skullTile.gameProfile == null) return "";
|
||||
return skullTile.gameProfile.getProperties().get("textures").iterator().next().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkullValue(Block block, String value) {
|
||||
TileEntitySkull skullTile = (TileEntitySkull)((CraftWorld)block.getWorld()).getHandle().getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
profile.getProperties().put("textures", new Property("textures", value));
|
||||
skullTile.setGameProfile(profile);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user