mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
!Everything needed for Custom Blocks
This commit is contained in:
parent
31ca777678
commit
503a4fbfdd
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.Indyuce</groupId>
|
||||
<artifactId>MMOItems</artifactId>
|
||||
<version>4.7.21-SNAPSHOT</version>
|
||||
<version>4.8-BETA</version>
|
||||
<name>MMOItems</name>
|
||||
<description>A great item solution for your RPG server.</description>
|
||||
|
||||
|
@ -44,6 +44,7 @@ import net.Indyuce.mmoitems.comp.rpg.RPGHandler;
|
||||
import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
import net.Indyuce.mmoitems.gui.listener.GuiListener;
|
||||
import net.Indyuce.mmoitems.listener.AdvancedWorkbenchListener;
|
||||
import net.Indyuce.mmoitems.listener.CustomBlockListener;
|
||||
import net.Indyuce.mmoitems.listener.CustomDurability;
|
||||
import net.Indyuce.mmoitems.listener.CustomSoundListener;
|
||||
import net.Indyuce.mmoitems.listener.DisableInteractions;
|
||||
@ -54,6 +55,7 @@ import net.Indyuce.mmoitems.listener.OrnamentTypeListener;
|
||||
import net.Indyuce.mmoitems.listener.PlayerListener;
|
||||
import net.Indyuce.mmoitems.listener.version.Listener_v1_13;
|
||||
import net.Indyuce.mmoitems.manager.AbilityManager;
|
||||
import net.Indyuce.mmoitems.manager.BlockManager;
|
||||
import net.Indyuce.mmoitems.manager.ConfigManager;
|
||||
import net.Indyuce.mmoitems.manager.CraftingManager;
|
||||
import net.Indyuce.mmoitems.manager.DamageManager;
|
||||
@ -68,6 +70,7 @@ import net.Indyuce.mmoitems.manager.TierManager;
|
||||
import net.Indyuce.mmoitems.manager.TypeManager;
|
||||
import net.Indyuce.mmoitems.manager.UpdaterManager;
|
||||
import net.Indyuce.mmoitems.manager.UpgradeManager;
|
||||
import net.Indyuce.mmoitems.manager.WorldGenManager;
|
||||
import net.Indyuce.mmoitems.version.ServerVersion;
|
||||
import net.Indyuce.mmoitems.version.SpigotPlugin;
|
||||
import net.Indyuce.mmoitems.version.nms.NMSHandler;
|
||||
@ -88,6 +91,8 @@ public class MMOItems extends JavaPlugin {
|
||||
private ItemManager itemManager;
|
||||
private SetManager setManager;
|
||||
private UpgradeManager upgradeManager;
|
||||
private WorldGenManager worldGenManager;
|
||||
private BlockManager blockManager;
|
||||
private AbilityManager abilityManager = new AbilityManager();
|
||||
private CraftingManager stationRecipeManager = new CraftingManager();
|
||||
private PluginUpdateManager pluginUpdateManager = new PluginUpdateManager();
|
||||
@ -146,6 +151,8 @@ public class MMOItems extends JavaPlugin {
|
||||
tierManager = new TierManager();
|
||||
setManager = new SetManager();
|
||||
upgradeManager = new UpgradeManager();
|
||||
worldGenManager = new WorldGenManager();
|
||||
blockManager = new BlockManager();
|
||||
|
||||
getLogger().log(Level.INFO, "Loading crafting stations, please wait..");
|
||||
stationRecipeManager.reload();
|
||||
@ -157,6 +164,7 @@ public class MMOItems extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new ItemUse(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new MitigationListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomBlockListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomSoundListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomDurability(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new DisableInteractions(), this);
|
||||
@ -365,6 +373,14 @@ public class MMOItems extends JavaPlugin {
|
||||
return abilityManager;
|
||||
}
|
||||
|
||||
public BlockManager getCustomBlocks() {
|
||||
return blockManager;
|
||||
}
|
||||
|
||||
public WorldGenManager getWorldGen() {
|
||||
return worldGenManager;
|
||||
}
|
||||
|
||||
public RecipeManager getRecipes() {
|
||||
return recipeManager;
|
||||
}
|
||||
|
142
src/main/java/net/Indyuce/mmoitems/api/CustomBlock.java
Normal file
142
src/main/java/net/Indyuce/mmoitems/api/CustomBlock.java
Normal file
@ -0,0 +1,142 @@
|
||||
package net.Indyuce.mmoitems.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.util.MushroomState;
|
||||
import net.Indyuce.mmoitems.manager.BlockManager;
|
||||
import net.Indyuce.mmoitems.version.nms.ItemTag;
|
||||
|
||||
public class CustomBlock {
|
||||
MushroomState state;
|
||||
|
||||
private final int id;
|
||||
private String blockName = ChatColor.RESET + "Custom Block";
|
||||
private String templateName = "";
|
||||
private List<String> lore = new ArrayList<String>();
|
||||
private int minXP = 0;
|
||||
private int maxXP = 0;
|
||||
private int requiredPower = 0;
|
||||
|
||||
public CustomBlock(int id, MushroomState state, ConfigurationSection config) {
|
||||
this.id = id;
|
||||
this.state = state;
|
||||
|
||||
if(config != null) {
|
||||
if(config.contains("display-name")) blockName = ChatColor.translateAlternateColorCodes('&', config.getString("display-name"));
|
||||
if(config.contains("lore"))
|
||||
for(String s : config.getStringList("lore"))
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||
if(config.contains("min-xp")) minXP = config.getInt("min-xp");
|
||||
if(config.contains("max-xp")) maxXP = config.getInt("max-xp");
|
||||
if(config.contains("required-power")) requiredPower = config.getInt("required-power");
|
||||
if(config.contains("gen-template")) {
|
||||
templateName = config.getString("gen-template");
|
||||
|
||||
MMOItems.plugin.getWorldGen().register(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Depending on the id, return the mushroom type this block
|
||||
//is supposed to feature.
|
||||
public Material getType() {
|
||||
return MMOItems.plugin.getCustomBlocks().getType(id);
|
||||
}
|
||||
|
||||
//From the Id, check which sides to apply data to.
|
||||
//This will return the blockstate of the blocks id.
|
||||
public BlockData getBlockData() {
|
||||
MultipleFacing mfData = (MultipleFacing) getType().createBlockData();
|
||||
|
||||
mfData.setFace(BlockFace.UP, state.up);
|
||||
mfData.setFace(BlockFace.DOWN, state.down);
|
||||
mfData.setFace(BlockFace.NORTH, state.north);
|
||||
mfData.setFace(BlockFace.SOUTH, state.south);
|
||||
mfData.setFace(BlockFace.EAST, state.east);
|
||||
mfData.setFace(BlockFace.WEST, state.west);
|
||||
|
||||
return mfData;
|
||||
}
|
||||
|
||||
//Convert block data into Item
|
||||
public ItemStack getItem() {
|
||||
ItemStack item = new ItemStack(Material.CLAY_BALL);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(blockName);
|
||||
meta.setLore(lore);
|
||||
meta.setUnbreakable(true);
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
|
||||
if(MMOItems.plugin.getVersion().isBelowOrEqual(1, 13)) ((Damageable) meta).setDamage(id);
|
||||
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return MMOItems.plugin.getNMS().getNBTItem(item)
|
||||
.addTag(new ItemTag("MMOITEMS_DISABLE_CRAFTING", true),
|
||||
new ItemTag("MMOITEMS_DISABLE_SMITHING", true),
|
||||
new ItemTag("MMOITEMS_DISABLE_ENCHANTING", true),
|
||||
new ItemTag("MMOITEMS_DISABLE_REPAIRING", true),
|
||||
new ItemTag("MMOITEMS_BLOCK_ID", id),
|
||||
new ItemTag("CustomModelData", id + 1000))
|
||||
.toItem();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
ConfigurationSection config = MMOItems.plugin.getCustomBlocks().getConfig().getConfigurationSection(id + "");
|
||||
lore.clear();
|
||||
|
||||
if(config != null) {
|
||||
blockName = ChatColor.translateAlternateColorCodes('&', config.getString("display-name", "&rCustom Block"));
|
||||
for(String s : config.getStringList("lore"))
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||
minXP = config.getInt("min-xp", 0);
|
||||
maxXP = config.getInt("max-xp", 0);
|
||||
requiredPower = config.getInt("required-power", 0);
|
||||
templateName = config.getString("gen-template", "");
|
||||
}
|
||||
else {
|
||||
blockName = ChatColor.RESET + "Custom Block";
|
||||
templateName = "";
|
||||
minXP = 0; maxXP = 0; requiredPower = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets a new CustomBlock instance from a mushroom blockstate.
|
||||
public static CustomBlock getFromData(BlockData data) {
|
||||
if(!(data instanceof MultipleFacing)) return null;
|
||||
MultipleFacing mfData = (MultipleFacing) data;
|
||||
MushroomState state = new MushroomState(data.getMaterial(), mfData.hasFace(BlockFace.UP), mfData.hasFace(BlockFace.DOWN),
|
||||
mfData.hasFace(BlockFace.WEST), mfData.hasFace(BlockFace.EAST), mfData.hasFace(BlockFace.SOUTH), mfData.hasFace(BlockFace.NORTH));
|
||||
|
||||
BlockManager manager = MMOItems.plugin.getCustomBlocks();
|
||||
return manager.isVanilla(state) ? null : manager.getBlock(state);
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{ return id; }
|
||||
public String getName()
|
||||
{ return blockName; }
|
||||
public String getTemplateName()
|
||||
{ return templateName; }
|
||||
public List<String> getLore()
|
||||
{ return lore; }
|
||||
public int getMinXPDrop()
|
||||
{ return minXP; }
|
||||
public int getMaxXPDrop()
|
||||
{ return maxXP; }
|
||||
public int getRequiredPower()
|
||||
{ return requiredPower; }
|
||||
}
|
@ -13,6 +13,7 @@ public class DropItem {
|
||||
private final String id;
|
||||
private final double unidentification, drop;
|
||||
private final int min, max;
|
||||
private final int blockId;
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
@ -20,13 +21,18 @@ public class DropItem {
|
||||
* used in MythicDrops drop tables.
|
||||
*/
|
||||
public DropItem(Type type, String id, double unidentification) {
|
||||
this(type, id, 100, unidentification, 1, 1);
|
||||
this(type, id, 0, 100, unidentification, 1, 1);
|
||||
}
|
||||
|
||||
public DropItem(Type type, String id, double drop, double unidentification, int min, int max) {
|
||||
public DropItem(int blockId, double drop, int min, int max) {
|
||||
this(null, null, blockId, drop, 0, min, max);
|
||||
}
|
||||
|
||||
public DropItem(Type type, String id, int blockId, double drop, double unidentification, int min, int max) {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
|
||||
this.blockId = 0;
|
||||
this.drop = drop;
|
||||
this.unidentification = unidentification;
|
||||
this.min = min;
|
||||
@ -39,6 +45,7 @@ public class DropItem {
|
||||
public DropItem(Type type, String id, String info) throws Exception {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.blockId = 0;
|
||||
|
||||
String[] argSplit = info.split("\\,");
|
||||
drop = Double.parseDouble(argSplit[0]) / 100;
|
||||
@ -50,6 +57,21 @@ public class DropItem {
|
||||
unidentification = Double.parseDouble(argSplit[2]) / 100;
|
||||
}
|
||||
|
||||
public DropItem(int blockId, String info) throws Exception {
|
||||
this.type = null;
|
||||
this.id = null;
|
||||
this.blockId = blockId;
|
||||
|
||||
String[] argSplit = info.split("\\,");
|
||||
drop = Double.parseDouble(argSplit[0]) / 100;
|
||||
|
||||
String[] amountSplit = argSplit[1].split("\\-");
|
||||
min = Integer.parseInt(amountSplit[0]);
|
||||
max = amountSplit.length > 1 ? Integer.parseInt(amountSplit[1]) : min;
|
||||
|
||||
unidentification = 0;
|
||||
}
|
||||
|
||||
public boolean isDropped() {
|
||||
return random.nextDouble() < drop;
|
||||
}
|
||||
@ -67,7 +89,7 @@ public class DropItem {
|
||||
}
|
||||
|
||||
public ItemStack getItem(int amount) {
|
||||
ItemStack item = MMOItems.plugin.getItems().getItem(type, id);
|
||||
ItemStack item = blockId == 0 ? MMOItems.plugin.getItems().getItem(type, id) : MMOItems.plugin.getCustomBlocks().getBlock(blockId).getItem();
|
||||
if (item == null || item.getType() == Material.AIR)
|
||||
return null;
|
||||
|
||||
|
@ -28,8 +28,8 @@ public class DropTable {
|
||||
MMOItems.plugin.getLogger().warning("Couldn't read sub-table " + key + ": it is missing a sub-table coefficient.");
|
||||
continue;
|
||||
}
|
||||
if (!subtable.contains("items")) {
|
||||
MMOItems.plugin.getLogger().warning("Couldn't read sub-table " + key + ": it is missing sub-table items.");
|
||||
if (!subtable.contains("items") && !subtable.contains("blocks")) {
|
||||
MMOItems.plugin.getLogger().warning("Couldn't read sub-table " + key + ": it is missing sub-table items (or blocks).");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -80,6 +80,7 @@ public class DropTable {
|
||||
private boolean disableSilkTouch;
|
||||
|
||||
public Subtable(ConfigurationSection subtable) {
|
||||
if(subtable.contains("items"))
|
||||
for (String typeFormat : subtable.getConfigurationSection("items").getKeys(false)) {
|
||||
Type type = null;
|
||||
try {
|
||||
@ -96,6 +97,25 @@ public class DropTable {
|
||||
MMOItems.plugin.getLogger().warning("Couldn't read subtable item " + subtable.getName() + "." + type.getId() + "." + id + ": wrong format.");
|
||||
}
|
||||
}
|
||||
if(subtable.contains("blocks"))
|
||||
for (String typeFormat : subtable.getConfigurationSection("blocks").getKeys(false)) {
|
||||
int id = 0;
|
||||
try { id = Integer.parseInt(typeFormat);
|
||||
} catch (Exception e) {
|
||||
MMOItems.plugin.getLogger().warning("Couldn't read subtable " + subtable.getName() + ". " + typeFormat + " is not a valid number.");
|
||||
continue;
|
||||
}
|
||||
if(id > 160 || id < 1 || id == 54) {
|
||||
MMOItems.plugin.getLogger().warning("Couldn't read subtable " + subtable.getName() + ". " + typeFormat + " is not a valid block id.");
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
items.add(new DropItem(id, subtable.getString("blocks." + typeFormat)));
|
||||
} catch (Exception e) {
|
||||
MMOItems.plugin.getLogger().warning("Couldn't read subtable block " + subtable.getName() + "." + id + ": wrong format.");
|
||||
}
|
||||
}
|
||||
|
||||
disableSilkTouch = subtable.getBoolean("disable-silk-touch");
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package net.Indyuce.mmoitems.api.edition;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.edition.process.AnvilGUI;
|
||||
import net.Indyuce.mmoitems.api.edition.process.ChatEdition;
|
||||
import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
import net.Indyuce.mmoitems.gui.edition.BlockEdition.ConfigOptions;
|
||||
|
||||
public class BlockChatEdition implements Edition {
|
||||
|
||||
/*
|
||||
* saves the data about the edited data so the plugin can edit the
|
||||
* corresponding stat. some stats have complex chat formats, so the object
|
||||
* array allow to save more complex edition info
|
||||
*/
|
||||
private final PluginInventory inv;
|
||||
private final ConfigOptions option;
|
||||
private final int blockId;
|
||||
|
||||
public BlockChatEdition(PluginInventory inv, ConfigOptions co, int id) {
|
||||
this.inv = inv;
|
||||
this.option = co;
|
||||
this.blockId = id;
|
||||
}
|
||||
|
||||
public ConfigOptions getConfigOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
public void enable(String... message) {
|
||||
inv.getPlayer().closeInventory();
|
||||
|
||||
inv.getPlayer().sendMessage(ChatColor.YELLOW + "" + ChatColor.STRIKETHROUGH + "-----------------------------------------------------");
|
||||
for (String line : message)
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.translateAlternateColorCodes('&', line));
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
|
||||
|
||||
/*
|
||||
* anvil text input feature. enables players to use an anvil to input
|
||||
* text if they are having conflicts with their chat management plugins.
|
||||
*/
|
||||
if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MMOItems.plugin.getVersion().isBelowOrEqual(1, 13)) {
|
||||
new AnvilGUI(inv, this);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* default chat edition feature
|
||||
*/
|
||||
new ChatEdition(inv, this);
|
||||
MMOItems.plugin.getNMS().sendTitle(inv.getPlayer(), ChatColor.GOLD + "" + ChatColor.BOLD + "Block Edition", "See chat.", 10, 40, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean output(String input) {
|
||||
return input.equals("cancel") || option.whenInput(inv, input, blockId + "." + option.getConfigPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGoBack() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package net.Indyuce.mmoitems.api.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class MushroomState {
|
||||
public Material id;
|
||||
public boolean up, down, west, east, south, north;
|
||||
|
||||
public MushroomState(Material id, boolean up, boolean down, boolean west, boolean east, boolean south, boolean north) {
|
||||
this.id = id;
|
||||
this.up = up; this.down = down; this.west = west;
|
||||
this.east = east; this.south = south; this.north = north;
|
||||
}
|
||||
|
||||
public boolean equals(MushroomState state) {
|
||||
return up == state.up && down == state.down && west == state.west &&
|
||||
east == state.east && south == state.south && north == state.north;
|
||||
}
|
||||
|
||||
public int getUniqueId() {
|
||||
String i;
|
||||
if(id == Material.BROWN_MUSHROOM_BLOCK) i = "0";
|
||||
else if(id == Material.RED_MUSHROOM_BLOCK) i = "1";
|
||||
else i = "2";
|
||||
|
||||
return Integer.parseInt(i + (up ? "1" : "0") + (down ? "1" : "0") + (west ? "1" : "0") +
|
||||
(east ? "1" : "0") + (south ? "1" : "0") + (north ? "1" : "0"));
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package net.Indyuce.mmoitems.api.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class WorldGenTemplate {
|
||||
public double chunkChance;
|
||||
public int minDepth, maxDepth, veinSize, veinCount;
|
||||
|
||||
private List<Material> replaceableMaterials = new ArrayList<>();
|
||||
private List<String> worldWhitelist = new ArrayList<>(), worldBlacklist = new ArrayList<>();
|
||||
private List<String> biomeWhitelist = new ArrayList<>(), biomeBlacklist = new ArrayList<>();
|
||||
private boolean slimeChunk;
|
||||
|
||||
public WorldGenTemplate(ConfigurationSection config) {
|
||||
List<String> matList = config.getStringList("replace");
|
||||
for(String material : matList) {
|
||||
Validate.notNull(Material.valueOf(material), "Could not load material: " + material + " from " + config.getName());
|
||||
replaceableMaterials.add(Material.valueOf(material));
|
||||
}
|
||||
|
||||
List<String> worldList = config.getStringList("worlds");
|
||||
List<String> biomeList = config.getStringList("biomes");
|
||||
|
||||
for(String world : worldList) {
|
||||
if(world.contains("!")) worldBlacklist.add(world.toUpperCase());
|
||||
else worldWhitelist.add(world.toUpperCase());
|
||||
}
|
||||
for(String biome : biomeList) {
|
||||
if(biome.contains("!")) biomeBlacklist.add(biome.toUpperCase());
|
||||
else biomeWhitelist.add(biome.toUpperCase());
|
||||
}
|
||||
|
||||
chunkChance = config.getDouble("chunk-chance");
|
||||
slimeChunk = config.getBoolean("slime-chunk", false);
|
||||
|
||||
String[] depth = config.getString("depth").split("\\=");
|
||||
minDepth = Integer.parseInt(depth[0]);
|
||||
maxDepth = Integer.parseInt(depth[1]);
|
||||
|
||||
veinSize = config.getInt("vein-size");
|
||||
veinCount = config.getInt("vein-count");
|
||||
}
|
||||
|
||||
public boolean canGenerate(Location pos) {
|
||||
if(!worldWhitelist.isEmpty() && !worldWhitelist.contains(pos.getWorld().getName().toUpperCase())) return false;
|
||||
if(!worldBlacklist.isEmpty() && worldBlacklist.contains(pos.getWorld().getName().toUpperCase())) return false;
|
||||
Biome biome = pos.getWorld().getBiome(pos.getBlockX(), pos.getBlockZ());
|
||||
if(!biomeWhitelist.isEmpty() && !biomeWhitelist.contains(biome.name())) return false;
|
||||
if(!biomeBlacklist.isEmpty() && biomeBlacklist.contains(biome.name())) return false;
|
||||
if(slimeChunk && !pos.getChunk().isSlimeChunk()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canReplace(Material type) {
|
||||
return replaceableMaterials.contains(type);
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||
import net.Indyuce.mmoitems.api.util.AmountReader;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.comp.flags.FlagPlugin.CustomFlag;
|
||||
import net.Indyuce.mmoitems.gui.BlockBrowser;
|
||||
import net.Indyuce.mmoitems.gui.CraftingStationView;
|
||||
import net.Indyuce.mmoitems.gui.ItemBrowser;
|
||||
import net.Indyuce.mmoitems.gui.edition.ItemEdition;
|
||||
@ -90,6 +91,10 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
new ItemBrowser((Player) sender).open();
|
||||
return true;
|
||||
}
|
||||
if(args[1].equalsIgnoreCase("blocks")) {
|
||||
new BlockBrowser((Player) sender).open();
|
||||
return true;
|
||||
}
|
||||
if (!Type.isValid(args[1])) {
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Please specify a valid item type.");
|
||||
return true;
|
||||
@ -456,6 +461,7 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
MMOItems.plugin.getTiers().reload();
|
||||
MMOItems.plugin.getSets().reload();
|
||||
MMOItems.plugin.getUpgrades().reload();
|
||||
MMOItems.plugin.getCustomBlocks().reload();
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + MMOItems.plugin.getName() + " " + MMOItems.plugin.getDescription().getVersion() + " reloaded.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getTypes().getAll().size() + ChatColor.GRAY + " Item Types");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getTiers().getAll().size() + ChatColor.GRAY + " Item Tiers");
|
||||
@ -669,7 +675,7 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
|
||||
World world = Bukkit.getWorld(args[3]);
|
||||
if (world == null) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Couldn't find the world called " + args[3] + ".");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Couldn't find the world called " + args[3] + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -679,35 +685,35 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
try {
|
||||
x = Double.parseDouble(args[4]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[4] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[4] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
y = Double.parseDouble(args[5]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[5] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[5] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
z = Double.parseDouble(args[6]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[6] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[6] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
dropChance = Double.parseDouble(args[7]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[7] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[7] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
unidentifiedChance = Double.parseDouble(args[9]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[9] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[9] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -721,21 +727,21 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
try {
|
||||
min = Integer.parseInt(splitAmount[0]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[0] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[0] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
max = Integer.parseInt(splitAmount[1]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[1] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[1] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack item = new DropItem(type, name, dropChance / 100, unidentifiedChance / 100, min, max).getItem();
|
||||
ItemStack item = new DropItem(type, name, 0, dropChance / 100, unidentifiedChance / 100, min, max).getItem();
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -783,13 +789,13 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Usage: /mi edit <type> <item-id>");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Usage: /mi edit <type> <item-id>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Type.isValid(args[1])) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -803,8 +809,8 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
|
||||
ItemStack item = MMOItems.plugin.getItems().getItem(type, id);
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + args[2].toUpperCase() + ".");
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + args[2].toUpperCase() + ".");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -821,7 +827,7 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Usage: /mi ability <ability> (player) (modifier1) (value1) (modifier2) (value2)...");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Usage: /mi ability <ability> (player) (modifier1) (value1) (modifier2) (value2)...");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -881,7 +887,7 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
try {
|
||||
unidentifiedChance = Double.parseDouble(args[4]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[4] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + args[4] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -902,22 +908,22 @@ public class MMOItemsCommand implements CommandExecutor {
|
||||
try {
|
||||
min = Integer.parseInt(splitAmount[0]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[0] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[0] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
max = Integer.parseInt(splitAmount[1]);
|
||||
} catch (Exception e) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[1] + " is not a valid number.");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + splitAmount[1] + " is not a valid number.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack item = new DropItem(type, name, 1, unidentifiedChance / 100, min, max).getItem();
|
||||
ItemStack item = new DropItem(type, name, 0, 1, unidentifiedChance / 100, min, max).getItem();
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
|
||||
((Player) sender).sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
|
||||
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,8 @@ public class MMOItemsCompletion implements TabCompleter {
|
||||
else if (args[0].equalsIgnoreCase("browse") || args[0].equalsIgnoreCase("itemlist") || args[0].equalsIgnoreCase("drop") || args[0].equalsIgnoreCase("create") || args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("edit") || args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("load") || args[0].equalsIgnoreCase("giveall"))
|
||||
for (Type type : MMOItems.plugin.getTypes().getAll())
|
||||
list.add(type.getId());
|
||||
if(args[0].equalsIgnoreCase("browse"))
|
||||
list.add("BLOCKS");
|
||||
|
||||
else if (Type.isValid(args[0]))
|
||||
MMOItems.plugin.getTypes().get(args[0].toUpperCase().replace("-", "_")).getConfigFile().getConfig().getKeys(false).forEach(key -> list.add(key.toUpperCase()));
|
||||
|
168
src/main/java/net/Indyuce/mmoitems/gui/BlockBrowser.java
Normal file
168
src/main/java/net/Indyuce/mmoitems/gui/BlockBrowser.java
Normal file
@ -0,0 +1,168 @@
|
||||
package net.Indyuce.mmoitems.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.api.util.AltChar;
|
||||
import net.Indyuce.mmoitems.gui.edition.BlockEdition;
|
||||
import net.Indyuce.mmoitems.version.VersionMaterial;
|
||||
|
||||
public class BlockBrowser extends PluginInventory {
|
||||
private Map<CustomBlock, ItemStack> cached = new HashMap<>();
|
||||
|
||||
private static final int[] slots = { 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34 };
|
||||
|
||||
public BlockBrowser(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
int min = (page - 1) * slots.length;
|
||||
int max = page * slots.length;
|
||||
int n = 0;
|
||||
|
||||
ItemStack error = VersionMaterial.RED_STAINED_GLASS_PANE.toItem();
|
||||
ItemMeta errorMeta = error.getItemMeta();
|
||||
errorMeta.setDisplayName(ChatColor.RED + "- Error -");
|
||||
List<String> errorLore = new ArrayList<>();
|
||||
errorLore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "An error occured while");
|
||||
errorLore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "trying to generate that block.");
|
||||
errorMeta.setLore(errorLore);
|
||||
error.setItemMeta(errorMeta);
|
||||
|
||||
List<CustomBlock> blocks = new ArrayList<>(MMOItems.plugin.getCustomBlocks().getAll());
|
||||
|
||||
/*
|
||||
* displays every item in a specific type. items are cached inside the
|
||||
* map at the top to reduce performance impact and are directly rendered
|
||||
*/
|
||||
Inventory inv = Bukkit.createInventory(this, 54, ChatColor.UNDERLINE + "Block Explorer");
|
||||
for (int j = min; j < Math.min(max, blocks.size()); j++) {
|
||||
CustomBlock block = blocks.get(j);
|
||||
if (!cached.containsKey(block)) {
|
||||
ItemStack item = block.getItem();
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
cached.put(block, error);
|
||||
inv.setItem(slots[n++], error);
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this block.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this block.");
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
cached.put(block, item);
|
||||
}
|
||||
|
||||
inv.setItem(slots[n++], cached.get(block));
|
||||
}
|
||||
|
||||
ItemStack noItem = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
|
||||
ItemMeta noItemMeta = noItem.getItemMeta();
|
||||
noItemMeta.setDisplayName(ChatColor.RED + "- No Block -");
|
||||
noItem.setItemMeta(noItemMeta);
|
||||
|
||||
ItemStack next = new ItemStack(Material.ARROW);
|
||||
ItemMeta nextMeta = next.getItemMeta();
|
||||
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
|
||||
next.setItemMeta(nextMeta);
|
||||
|
||||
ItemStack previous = new ItemStack(Material.ARROW);
|
||||
ItemMeta previousMeta = previous.getItemMeta();
|
||||
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
|
||||
previous.setItemMeta(previousMeta);
|
||||
|
||||
ItemStack switchBrowse = new ItemStack(Material.IRON_SWORD);
|
||||
ItemMeta switchMeta = switchBrowse.getItemMeta();
|
||||
switchMeta.addItemFlags(ItemFlag.values());
|
||||
switchMeta.setDisplayName(ChatColor.GREEN + "Switch to Item Explorer");
|
||||
switchBrowse.setItemMeta(switchMeta);
|
||||
|
||||
ItemStack downloadPack = new ItemStack(Material.HOPPER);
|
||||
ItemMeta downloadMeta = downloadPack.getItemMeta();
|
||||
downloadMeta.setDisplayName(ChatColor.GREEN + "Download Default Resourcepack");
|
||||
downloadMeta.setLore(Arrays.asList(ChatColor.LIGHT_PURPLE + "Only seeing clay balls?", "", ChatColor.RED + "By downloading the default resourcepack you can", ChatColor.RED + "edit the blocks however you want.", ChatColor.RED + "You will still have to add it to your server!"));
|
||||
downloadPack.setItemMeta(downloadMeta);
|
||||
|
||||
while (n < slots.length)
|
||||
inv.setItem(slots[n++], noItem);
|
||||
inv.setItem(18, page > 1 ? previous : null);
|
||||
inv.setItem(26, max >= blocks.size() ? null : next);
|
||||
|
||||
inv.setItem(45, downloadPack);
|
||||
inv.setItem(53, switchBrowse);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
if (event.getInventory() != event.getClickedInventory())
|
||||
return;
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item == null) return;
|
||||
if (MMOUtils.isPluginItem(item, false)) {
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
|
||||
page++; open(); return;
|
||||
}
|
||||
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Previous Page")) {
|
||||
page--; open(); return;
|
||||
}
|
||||
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Switch to Item Explorer")) {
|
||||
new ItemBrowser(player).open(); return;
|
||||
}
|
||||
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Download Default Resourcepack")) {
|
||||
MMOItems.plugin.getNMS().sendJson(player, "[{\"text\":\"Click to download!\",\"color\":\"green\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://mythiccraft.io/resources/MICustomBlockPack.zip\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"https://mythiccraft.io/resources/MICustomBlockPack.zip\",\"italic\":true,\"color\":\"white\"}]}}]");
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(item.getType() == Material.CLAY_BALL) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL) {
|
||||
player.getInventory().addItem(removeLastLoreLines(item, 3));
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
||||
}
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
||||
new BlockEdition(player, MMOItems.plugin.getCustomBlocks().getBlock(NBTItem.get(item).getInteger("MMOITEMS_BLOCK_ID"))).open();
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack removeLastLoreLines(ItemStack item, int amount) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = meta.getLore();
|
||||
meta.setLore(lore.subList(0, lore.size() - amount));
|
||||
|
||||
ItemStack item1 = item.clone();
|
||||
item1.setItemMeta(meta);
|
||||
return item1;
|
||||
}
|
||||
}
|
@ -89,11 +89,18 @@ public class ItemBrowser extends PluginInventory {
|
||||
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
|
||||
previous.setItemMeta(previousMeta);
|
||||
|
||||
ItemStack switchBrowse = new ItemStack(Material.STONE);
|
||||
ItemMeta switchMeta = switchBrowse.getItemMeta();
|
||||
switchMeta.setDisplayName(ChatColor.GREEN + "Switch to Block Explorer");
|
||||
switchBrowse.setItemMeta(switchMeta);
|
||||
|
||||
while (n < slots.length)
|
||||
inv.setItem(slots[n++], glass);
|
||||
inv.setItem(18, page > 1 ? previous : null);
|
||||
inv.setItem(26, inv.getItem(34).equals(glass) ? null : next);
|
||||
|
||||
inv.setItem(53, switchBrowse);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
@ -210,6 +217,12 @@ public class ItemBrowser extends PluginInventory {
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.rightArrow + " Back"))
|
||||
new ItemBrowser(player).open();
|
||||
|
||||
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Switch to Block Explorer")) {
|
||||
new BlockBrowser(player).open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Cancel Deletion")) {
|
||||
deleteMode = false;
|
||||
open();
|
||||
|
193
src/main/java/net/Indyuce/mmoitems/gui/edition/BlockEdition.java
Normal file
193
src/main/java/net/Indyuce/mmoitems/gui/edition/BlockEdition.java
Normal file
@ -0,0 +1,193 @@
|
||||
package net.Indyuce.mmoitems.gui.edition;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.edition.BlockChatEdition;
|
||||
import net.Indyuce.mmoitems.api.item.plugin.ConfigItem;
|
||||
import net.Indyuce.mmoitems.api.util.AltChar;
|
||||
import net.Indyuce.mmoitems.gui.BlockBrowser;
|
||||
import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
|
||||
public class BlockEdition extends PluginInventory {
|
||||
public static Map<Integer, ConfigOptions> correspondingSlot = new HashMap<>();
|
||||
FileConfiguration config;
|
||||
CustomBlock block;
|
||||
|
||||
public BlockEdition(Player player, CustomBlock block) {
|
||||
super(player);
|
||||
|
||||
this.block = block;
|
||||
config = MMOItems.plugin.getCustomBlocks().getConfig();
|
||||
|
||||
if (correspondingSlot.isEmpty()) {
|
||||
for (ConfigOptions configOptions : ConfigOptions.values()) {
|
||||
correspondingSlot.put(configOptions.getSlot(), configOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, 54, ChatColor.UNDERLINE + "Block Edition: " );
|
||||
for (ConfigOptions configOptions : ConfigOptions.values()) {
|
||||
ItemStack blockItem = new ItemStack(configOptions.getItem());
|
||||
ItemMeta meta = blockItem.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.GREEN + configOptions.name().replace("_", " "));
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
List<String> eventLore = new ArrayList<String>();
|
||||
eventLore.add("");
|
||||
if(configOptions.path.equals("lore")) {
|
||||
eventLore.add(ChatColor.GRAY + "- Current Value:");
|
||||
|
||||
List<String> loreList = config.getStringList(block.getId() + ".lore");
|
||||
if(loreList.isEmpty()) eventLore.add(ChatColor.RED + "No lore.");
|
||||
for(String lore : loreList)
|
||||
eventLore.add(ChatColor.GREEN + ChatColor.translateAlternateColorCodes('&', lore));
|
||||
}
|
||||
else eventLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GREEN + (configOptions.format.equals("int") ? config.contains(block.getId() + "." + configOptions.path) ? ChatColor.GREEN + config.getString(block.getId() + "." + configOptions.path) : ChatColor.RED + "0" : ChatColor.translateAlternateColorCodes('&', config.getString(block.getId() + "." + configOptions.path, ChatColor.RED + "Default"))));
|
||||
|
||||
eventLore.add("");
|
||||
eventLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value.");
|
||||
eventLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove this value.");
|
||||
meta.setLore(eventLore);
|
||||
blockItem.setItemMeta(meta);
|
||||
|
||||
inv.setItem(configOptions.slot, blockItem);
|
||||
}
|
||||
|
||||
ItemStack back = ConfigItem.BACK.getItem();
|
||||
inv.setItem(40, back);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
|
||||
event.setCancelled(true);
|
||||
if (event.getInventory() != event.getClickedInventory() || !MMOUtils.isPluginItem(item, false))
|
||||
return;
|
||||
|
||||
if(event.getSlot() == 40)
|
||||
new BlockBrowser(player).open();
|
||||
|
||||
if (correspondingSlot.containsKey(event.getSlot())) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL) {
|
||||
ConfigOptions co = correspondingSlot.get(event.getSlot());
|
||||
new BlockChatEdition(this, co, block.getId()).enable("Write in the chat the " + co.getChatFormat());
|
||||
}
|
||||
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
String path = correspondingSlot.get(event.getSlot()).getConfigPath();
|
||||
config.set(block.getId() + "." + path, null);
|
||||
try { config.save(new File(MMOItems.plugin.getDataFolder(), "custom-blocks.yml"));
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
MMOItems.plugin.getCustomBlocks().reload();
|
||||
|
||||
new BlockEdition(player, block).open();
|
||||
player.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + MMOUtils.caseOnWords(path.replace("-", " ")) + " Value" + ChatColor.GRAY + " successfully removed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ConfigOptions {
|
||||
DISPLAY_NAME("display-name", Material.WRITABLE_BOOK, 11, "string"),
|
||||
LORE("lore", Material.MAP, 13, "line"),
|
||||
REQUIRED_PICKAXE_POWER("required-power", Material.IRON_PICKAXE, 15, "int"),
|
||||
MIN_XP("min-xp", Material.EXPERIENCE_BOTTLE, 21, "int"),
|
||||
MAX_XP("max-xp", Material.EXPERIENCE_BOTTLE, 23, "int"),
|
||||
WORLD_GEN_TEMPLATE("gen-template", Material.GRASS_BLOCK, 31, "string"),
|
||||
;
|
||||
|
||||
private final String path;
|
||||
private final String format;
|
||||
private final Material item;
|
||||
private final int slot;
|
||||
|
||||
ConfigOptions(String s1, Material m, int i, String s2) {
|
||||
path = s1;
|
||||
item = m;
|
||||
slot = i;
|
||||
format = s2;
|
||||
}
|
||||
|
||||
public String getConfigPath()
|
||||
{ return path; }
|
||||
public String getFormat()
|
||||
{ return format; }
|
||||
public Material getItem()
|
||||
{ return item; }
|
||||
public int getSlot()
|
||||
{ return slot; }
|
||||
|
||||
public String getChatFormat() {
|
||||
switch(format) {
|
||||
case "int":
|
||||
return "desired number for this field.";
|
||||
case "line":
|
||||
return "new line to add.";
|
||||
default:
|
||||
return "new value.";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean whenInput(PluginInventory inv, String message, String path) {
|
||||
switch(format) {
|
||||
case "int":
|
||||
int value = 0;
|
||||
try {
|
||||
value = Integer.parseInt(message);
|
||||
} catch (Exception e1) {
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + message + " is not a valid number.");
|
||||
return false;
|
||||
}
|
||||
setConfigValue(value, path);
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + name().replace("_", " ") + " successfully changed to " + value + ".");
|
||||
break;
|
||||
case "line":
|
||||
FileConfiguration config = MMOItems.plugin.getCustomBlocks().getConfig();
|
||||
List<String> lore = config.contains(path) ? config.getStringList(path) : new ArrayList<>();
|
||||
lore.add(message);
|
||||
setConfigValue(lore, path);
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully added to " + message + " to block lore.");
|
||||
break;
|
||||
default:
|
||||
setConfigValue(message, path);
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully changed value to " + message + ".");
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
public void setConfigValue(Object value, String path) {
|
||||
FileConfiguration config = MMOItems.plugin.getCustomBlocks().getConfig();
|
||||
|
||||
config.set(path, value);
|
||||
try { config.save(new File(MMOItems.plugin.getDataFolder(), "custom-blocks.yml"));
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
MMOItems.plugin.getCustomBlocks().reload();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
|
||||
public class CustomBlockListener implements Listener {
|
||||
Random rnd = new Random();
|
||||
|
||||
public CustomBlockListener() {
|
||||
if(MMOItems.plugin.getLanguage().replaceMushroomDrops)
|
||||
Bukkit.getPluginManager().registerEvents(new MushroomReplacer(), MMOItems.plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(BlockPhysicsEvent event) {
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getChangedType())) {
|
||||
event.setCancelled(true);
|
||||
event.getBlock().getState().update(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void b(BlockBreakEvent event) {
|
||||
Material type = event.getBlock().getType();
|
||||
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(type)) {
|
||||
CustomBlock block = CustomBlock.getFromData(event.getBlock().getBlockData());
|
||||
if(block != null) {
|
||||
event.setDropItems(false);
|
||||
event.setExpToDrop(
|
||||
event.getPlayer().getGameMode() == GameMode.CREATIVE ? 0 :
|
||||
CustomBlockListener.getPickaxePower(event.getPlayer()) >= block.getRequiredPower() ?
|
||||
block.getMaxXPDrop() == 0 && block.getMinXPDrop() == 0 ? 0 :
|
||||
rnd.nextInt((block.getMaxXPDrop() - block.getMinXPDrop()) + 1) + block.getMinXPDrop() : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void c(PlayerInteractEvent event) {
|
||||
if(!event.hasItem()) return;
|
||||
if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if(event.getHand() != EquipmentSlot.HAND) return;
|
||||
if(event.getClickedBlock().getType().isInteractable()) return;
|
||||
if(event.getItem().getType() == Material.CLAY_BALL) {
|
||||
if(NBTItem.get(event.getItem()).getInteger("MMOITEMS_BLOCK_ID") > 160 ||
|
||||
NBTItem.get(event.getItem()).getInteger("MMOITEMS_BLOCK_ID") < 1) return;
|
||||
|
||||
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(NBTItem.get(event.getItem()).getInteger("MMOITEMS_BLOCK_ID"));
|
||||
|
||||
List<Material> mat = Arrays.asList(Material.GRASS, Material.TALL_GRASS, Material.SEAGRASS, Material.TALL_SEAGRASS,
|
||||
Material.FERN, Material.LARGE_FERN, Material.DEAD_BUSH, Material.SNOW);
|
||||
|
||||
Block modify = mat.contains(event.getClickedBlock().getType())
|
||||
? event.getClickedBlock() : event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
|
||||
if(isStandingInside(event.getPlayer().getLocation(), modify.getLocation())) return;
|
||||
|
||||
if(!mat.contains(modify.getType()))
|
||||
switch(modify.getType()) {
|
||||
case AIR:
|
||||
case CAVE_AIR:
|
||||
case STRUCTURE_VOID:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
Block oldState = modify;
|
||||
Material cachedType = modify.getType();
|
||||
BlockData cachedData = modify.getBlockData();
|
||||
modify.setType(block.getType(), false);
|
||||
modify.setBlockData(block.getBlockData(), false);
|
||||
|
||||
MMOItems.plugin.getNMS().playArmAnimation(event.getPlayer());
|
||||
modify.getWorld().playSound(event.getPlayer().getLocation(), MMOItems.plugin.getNMS().getBlockPlaceSound(modify), 0.8f, 1.0f);
|
||||
|
||||
BlockPlaceEvent bpe = new BlockPlaceEvent(modify, oldState.getState(), event.getClickedBlock(), event.getItem(), event.getPlayer(), true, EquipmentSlot.HAND);
|
||||
Bukkit.getServer().getPluginManager().callEvent(bpe);
|
||||
if(bpe.isCancelled()) {
|
||||
modify.setType(cachedType);
|
||||
modify.setBlockData(cachedData);
|
||||
}
|
||||
else if(event.getPlayer().getGameMode() != GameMode.CREATIVE) {
|
||||
ItemStack stack = event.getItem(); stack.setAmount(stack.getAmount() - 1);
|
||||
event.getPlayer().getInventory().setItemInMainHand(stack.getAmount() > 0 ? stack : null);
|
||||
}
|
||||
}
|
||||
/**else if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getItem().getType())) {
|
||||
event.setCancelled(true);
|
||||
Block modify = event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
|
||||
if(isStandingInside(event.getPlayer().getLocation(), modify.getLocation())) return;
|
||||
if(modify.getType() != Material.AIR) return;
|
||||
|
||||
Block oldState = modify;
|
||||
modify.setType(event.getItem().getType(), false);
|
||||
modify.setBlockData(event.getItem().getType().createBlockData(), false);
|
||||
|
||||
BlockPlaceEvent bpe = new BlockPlaceEvent(modify, oldState.getState(), event.getClickedBlock(), event.getItem(), event.getPlayer(), true, EquipmentSlot.HAND);
|
||||
Bukkit.getServer().getPluginManager().callEvent(bpe);
|
||||
if(bpe.isCancelled()) modify.setType(Material.AIR);
|
||||
}*/
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void d(BlockIgniteEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
if(event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD) {
|
||||
BlockFace[] faces = { BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST };
|
||||
for(BlockFace face : faces)
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getBlock().getRelative(face).getType()) &&
|
||||
CustomBlock.getFromData(event.getBlock().getRelative(face).getBlockData()) != null) event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isStandingInside(Location p, Location b) {
|
||||
return (p.getBlockX() == b.getBlockX() &&
|
||||
(p.getBlockY() == b.getBlockY() || p.getBlockY() + 1 == b.getBlockY()) &&
|
||||
p.getBlockZ() == b.getBlockZ());
|
||||
}
|
||||
|
||||
public static int getPickaxePower(Player player) {
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if(item != null && item.getType() != Material.AIR) {
|
||||
NBTItem nbt = NBTItem.get(item);
|
||||
if(nbt.hasType()) {
|
||||
return nbt.getInteger("MMOITEMS_PICKAXE_POWER");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public class MushroomReplacer implements Listener {
|
||||
@EventHandler
|
||||
public void d(BlockBreakEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getBlock().getType()) &&
|
||||
MMOItems.plugin.getDropTables().hasSilkTouchTool(event.getPlayer()))
|
||||
event.setDropItems(false);
|
||||
}
|
||||
}
|
||||
}
|
91
src/main/java/net/Indyuce/mmoitems/manager/BlockManager.java
Normal file
91
src/main/java/net/Indyuce/mmoitems/manager/BlockManager.java
Normal file
@ -0,0 +1,91 @@
|
||||
package net.Indyuce.mmoitems.manager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.util.MushroomState;
|
||||
|
||||
public class BlockManager {
|
||||
final static List<Integer> downIds = Arrays.asList(new Integer[] {23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
|
||||
48,49,50,51,52,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,130,131,132,133,134,135,
|
||||
136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160});
|
||||
final static List<Integer> eastIds = Arrays.asList(new Integer[] {10,11,12,13,14,15,16,17,18,19,20,21,22,39,40,41,42,43,44,45,46,47,48,49,50,
|
||||
51,52,53,59,60,61,62,63,64,65,66,67,68,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,115,116,117,118,119,120,121,122,123,124,125,126,
|
||||
127,128,129,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160});
|
||||
final static List<Integer> northIds = Arrays.asList(new Integer[] {4,5,6,7,8,9,16,17,18,19,20,21,22,31,32,33,34,35,36,37,38,47,48,49,50,51,52,
|
||||
53,55,56,57,58,63,64,65,66,67,68,77,78,79,80,81,82,83,84,93,94,95,96,97,98,99,107,108,109,110,111,112,113,114,123,124,125,126,127,
|
||||
128,129,138,139,140,141,142,143,144,145,154,155,156,157,158,159,160});
|
||||
final static List<Integer> southIds = Arrays.asList(new Integer[] {2,3,6,7,8,9,13,14,15,19,20,21,22,27,28,29,30,35,36,37,38,43,44,45,46,51,52,
|
||||
53,55,56,57,58,61,62,65,66,67,68,73,74,75,76,81,82,83,84,89,90,91,92,97,98,99,103,104,105,106,111,112,113,114,119,120,121,122,127,
|
||||
128,129,134,135,136,137,142,143,144,145,150,151,152,153,158,159,160});
|
||||
final static List<Integer> upIds = Arrays.asList(new Integer[] {8,9,12,15,18,21,22,25,26,29,30,33,34,37,38,41,42,45,46,49,50,53,57,58,60,62,
|
||||
64,67,68,71,72,75,76,79,80,83,84,87,88,91,92,95,96,99,101,102,105,106,109,110,113,114,117,118,121,122,125,126,128,129,132,133,
|
||||
136,137,140,141,144,145,148,149,152,153,156,157,160});
|
||||
final static List<Integer> westIds = Arrays.asList(new Integer[] {1,3,5,7,9,11,12,14,15,17,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,
|
||||
50,52,56,58,59,60,61,62,63,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,
|
||||
124,126,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159});
|
||||
|
||||
FileConfiguration config;
|
||||
private final Map<Integer, CustomBlock> customBlocks = new HashMap<>();
|
||||
private final Map<Integer, Integer> mushroomStateValue = new HashMap<>();
|
||||
|
||||
public BlockManager() {
|
||||
config = new ConfigFile("custom-blocks").getConfig();
|
||||
|
||||
for(int i = 1; i < 161; i++) {
|
||||
if(i != 54) {
|
||||
MushroomState state = new MushroomState(getType(i), upIds.contains(i), downIds.contains(i), westIds.contains(i),
|
||||
eastIds.contains(i), southIds.contains(i), northIds.contains(i));
|
||||
customBlocks.put(i, new CustomBlock(i, state, config.getConfigurationSection("" + i)));
|
||||
mushroomStateValue.put(state.getUniqueId(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Material getType(int id) {
|
||||
if(id < 54) return Material.BROWN_MUSHROOM_BLOCK;
|
||||
else if(id > 99) return Material.MUSHROOM_STEM;
|
||||
else return Material.RED_MUSHROOM_BLOCK;
|
||||
}
|
||||
|
||||
public CustomBlock getBlock(int id) {
|
||||
if(id > 0 && id < 161 && id != 54)
|
||||
return customBlocks.get(id);
|
||||
|
||||
MMOItems.plugin.getLogger().warning("Invalid CustomBlock Id! " + id);
|
||||
return null;
|
||||
}
|
||||
public CustomBlock getBlock(MushroomState state)
|
||||
{ return customBlocks.get(mushroomStateValue.get(state.getUniqueId())); }
|
||||
|
||||
public void reload() {
|
||||
for(CustomBlock block : customBlocks.values())
|
||||
block.reload();
|
||||
}
|
||||
|
||||
public Collection<CustomBlock> getAll()
|
||||
{ return customBlocks.values(); }
|
||||
public Set<Integer> getBlockIds()
|
||||
{ return customBlocks.keySet(); }
|
||||
|
||||
public FileConfiguration getConfig()
|
||||
{ return config; }
|
||||
|
||||
public boolean isVanilla(MushroomState state) {
|
||||
return !mushroomStateValue.containsKey(state.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isMushroomBlock(Material type) {
|
||||
return (type == Material.BROWN_MUSHROOM_BLOCK || type == Material.MUSHROOM_STEM || type == Material.RED_MUSHROOM_BLOCK);
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ public class ConfigManager {
|
||||
private ConfigFile abilities, items, loreFormat, messages, potionEffects, stats, attackEffects, namePlaceholders, durabilityStatesConfig;
|
||||
|
||||
// cached config options
|
||||
public boolean abilityPlayerDamage, dodgeKnockbackEnabled, iterateWholeInventory;
|
||||
public boolean abilityPlayerDamage, dodgeKnockbackEnabled, iterateWholeInventory, replaceMushroomDrops, worldGenEnabled;
|
||||
public String healIndicatorFormat, damageIndicatorFormat, abilitySplitter;
|
||||
public DecimalFormat healIndicatorDecimalFormat, damageIndicatorDecimalFormat;
|
||||
|
||||
@ -189,6 +189,8 @@ public class ConfigManager {
|
||||
* used in runnables, it is thus better to cache them
|
||||
*/
|
||||
iterateWholeInventory = MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory");
|
||||
replaceMushroomDrops = MMOItems.plugin.getConfig().getBoolean("custom-blocks.replace-mushroom-drops");
|
||||
worldGenEnabled = MMOItems.plugin.getConfig().getBoolean("custom-blocks.enable-world-gen");
|
||||
abilityPlayerDamage = MMOItems.plugin.getConfig().getBoolean("ability-player-damage");
|
||||
healIndicatorFormat = ChatColor.translateAlternateColorCodes('&', MMOItems.plugin.getConfig().getString("game-indicators.heal.format"));
|
||||
damageIndicatorFormat = ChatColor.translateAlternateColorCodes('&', MMOItems.plugin.getConfig().getString("game-indicators.damage.format"));
|
||||
@ -275,6 +277,8 @@ public class ConfigManager {
|
||||
// default general config files -> /MMOItems
|
||||
ITEM_TIERS("item-tiers.yml", "", "item-tiers.yml"),
|
||||
ITEM_TYPES("item-types.yml", "", "item-types.yml", true),
|
||||
CUSTOM_BLOCKS("custom-blocks.yml", "", "custom-blocks.yml"),
|
||||
GEN_TEMPLATES("gen-templates.yml", "", "gen-templates.yml"),
|
||||
DROPS("drops.yml", "", "drops.yml"),
|
||||
USE_STATES("use-states.yml", "", "use-states.yml"),
|
||||
ITEM_SETS("item-sets.yml", "", "item-sets.yml"),
|
||||
@ -282,6 +286,7 @@ public class ConfigManager {
|
||||
UPGRADE_TEMPLATES("upgrade-templates.yml", "", "upgrade-templates.yml"),
|
||||
|
||||
// LEGACY_CONFIGS("legacy-configs.zip", "", "legacy-configs.zip", true),
|
||||
// Not included in the jar anymore
|
||||
|
||||
// default language files -> /MMOItems/language
|
||||
LORE_FORMAT("lore-format.yml", "language", "lore-format.yml"),
|
||||
@ -314,7 +319,7 @@ public class ConfigManager {
|
||||
|
||||
/*
|
||||
* allows to use the checkFile() method while not loading it
|
||||
* automatically e.g legacy-configs.zip and item-types.yml
|
||||
* automatically e.g item-types.yml
|
||||
*/
|
||||
private final boolean manual;
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -22,11 +23,14 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.drop.DropTable;
|
||||
import net.Indyuce.mmoitems.listener.CustomBlockListener;
|
||||
|
||||
public class DropTableManager implements Listener {
|
||||
private Map<EntityType, DropTable> monsters = new HashMap<>();
|
||||
private Map<Material, DropTable> blocks = new HashMap<>();
|
||||
private Map<Integer, DropTable> customBlocks = new HashMap<>();
|
||||
|
||||
public DropTableManager() {
|
||||
reload();
|
||||
@ -37,6 +41,7 @@ public class DropTableManager implements Listener {
|
||||
|
||||
monsters.clear();
|
||||
blocks.clear();
|
||||
customBlocks.clear();
|
||||
|
||||
if (config.contains("monsters"))
|
||||
for (String key : config.getConfigurationSection("monsters").getKeys(false))
|
||||
@ -55,6 +60,15 @@ public class DropTableManager implements Listener {
|
||||
} catch (Exception e) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't read the drop table material " + key);
|
||||
}
|
||||
|
||||
if (config.contains("customblocks"))
|
||||
for (String key : config.getConfigurationSection("customblocks").getKeys(false))
|
||||
try {
|
||||
int id = Integer.parseInt(key);
|
||||
customBlocks.put(id, new DropTable(config.getConfigurationSection("customblocks." + key)));
|
||||
} catch (Exception e) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't read the drop table material " + key);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -75,14 +89,29 @@ public class DropTableManager implements Listener {
|
||||
|
||||
Block block = event.getBlock();
|
||||
final Material type = block.getType();
|
||||
CustomBlock custom = CustomBlock.getFromData(block.getBlockData());
|
||||
if(custom != null) {
|
||||
if (customBlocks.containsKey(custom.getId()))
|
||||
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
|
||||
if(CustomBlockListener.getPickaxePower(player) >= custom.getRequiredPower())
|
||||
for (ItemStack drop : customBlocks.get(custom.getId()).read(hasSilkTouchTool(player))) {
|
||||
Item item = block.getWorld().dropItemNaturally(block.getLocation().add(.5, .1, .5), drop);
|
||||
item.setVelocity(item.getVelocity().multiply(0.5f));
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
else {
|
||||
if (blocks.containsKey(type))
|
||||
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
|
||||
for (ItemStack drop : blocks.get(type).read(hasSilkTouchTool(player)))
|
||||
block.getWorld().dropItemNaturally(block.getLocation().add(.5, .3, .5), drop);
|
||||
}, 1);
|
||||
for (ItemStack drop : blocks.get(type).read(hasSilkTouchTool(player))) {
|
||||
Item item = block.getWorld().dropItemNaturally(block.getLocation().add(.5, .1, .5), drop);
|
||||
item.setVelocity(item.getVelocity().multiply(0.5f));
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasSilkTouchTool(Player player) {
|
||||
public boolean hasSilkTouchTool(Player player) {
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
return item != null && item.getType() != Material.AIR && item.hasItemMeta() && item.getItemMeta().hasEnchant(Enchantment.SILK_TOUCH);
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
package net.Indyuce.mmoitems.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.worldgen.WorldGenTemplate;
|
||||
|
||||
public class WorldGenManager implements Listener {
|
||||
Map<String, WorldGenTemplate> templates = new HashMap<String, WorldGenTemplate>();
|
||||
Map<Integer, String> assigned = new HashMap<Integer, String>();
|
||||
BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST, BlockFace.DOWN, BlockFace.UP };
|
||||
Random rnd = new Random();
|
||||
|
||||
public WorldGenManager() {
|
||||
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
|
||||
|
||||
config.getKeys(false).forEach(e -> {
|
||||
MMOItems.plugin.getLogger().info("WorldGenTemplate: " + e);
|
||||
templates.put(e, new WorldGenTemplate(config.getConfigurationSection(e)));
|
||||
});
|
||||
|
||||
if(MMOItems.plugin.getLanguage().worldGenEnabled) Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void a(ChunkLoadEvent event) {
|
||||
if(!event.isNewChunk()) return;
|
||||
|
||||
for(int blocks : assigned.keySet()) {
|
||||
WorldGenTemplate wgt = templates.get(assigned.get(blocks));
|
||||
|
||||
if(rnd.nextDouble() < wgt.chunkChance) {
|
||||
for(int i = 0; i < wgt.veinCount; i++) {
|
||||
int y = rnd.nextInt((wgt.maxDepth - wgt.minDepth) + 1) + wgt.minDepth;
|
||||
Location generatePoint = event.getChunk().getBlock(rnd.nextInt(16), y, rnd.nextInt(16)).getLocation();
|
||||
if(wgt.canGenerate(generatePoint)) {
|
||||
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(blocks);
|
||||
Block modify = event.getWorld().getBlockAt(generatePoint);
|
||||
boolean failedLastCheck = false;
|
||||
|
||||
for(int j = 0; j < wgt.veinSize; j++) {
|
||||
if(wgt.canReplace(modify.getType())) {
|
||||
if(failedLastCheck) continue;
|
||||
failedLastCheck = true; j -= 1; continue;
|
||||
}
|
||||
failedLastCheck = false;
|
||||
modify.setType(block.getType(), false);
|
||||
modify.setBlockData(block.getBlockData(), false);
|
||||
BlockFace nextFace = faces[rnd.nextInt(faces.length)];
|
||||
modify = modify.getRelative(nextFace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void register(CustomBlock block) {
|
||||
assigned.put(block.getId(), block.getTemplateName());
|
||||
}
|
||||
}
|
24
src/main/java/net/Indyuce/mmoitems/stat/Pickaxe_Power.java
Normal file
24
src/main/java/net/Indyuce/mmoitems/stat/Pickaxe_Power.java
Normal file
@ -0,0 +1,24 @@
|
||||
package net.Indyuce.mmoitems.stat;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.DoubleStat;
|
||||
import net.Indyuce.mmoitems.version.nms.ItemTag;
|
||||
|
||||
public class Pickaxe_Power extends DoubleStat {
|
||||
public Pickaxe_Power() {
|
||||
super(new ItemStack(Material.IRON_PICKAXE), "Pickaxe Power", new String[] { "The breaking strength of the", "item when mining custom blocks." }, "pickaxe-power", new String[] { "tool" });
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean whenApplied(MMOItemBuilder item, StatData data) {
|
||||
int pickPower = (int) ((DoubleData) data).generateNewValue();
|
||||
|
||||
item.addItemTag(new ItemTag("MMOITEMS_PICKAXE_POWER", pickPower));
|
||||
item.getLore().insert("pickaxe-power", format(pickPower, "#", "" + pickPower));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -54,6 +54,7 @@ import net.Indyuce.mmoitems.stat.Max_Health;
|
||||
import net.Indyuce.mmoitems.stat.Movement_Speed;
|
||||
import net.Indyuce.mmoitems.stat.Perm_Effects;
|
||||
import net.Indyuce.mmoitems.stat.Permission;
|
||||
import net.Indyuce.mmoitems.stat.Pickaxe_Power;
|
||||
import net.Indyuce.mmoitems.stat.Potion_Color;
|
||||
import net.Indyuce.mmoitems.stat.Required_Class;
|
||||
import net.Indyuce.mmoitems.stat.Required_Level;
|
||||
@ -141,6 +142,7 @@ public abstract class ItemStat {
|
||||
public static final ItemStat CRAFTING_RECIPE = new Crafting_Recipe(), FURNACE_RECIPE = new Furnace_Recipe(), SHAPELESS_RECIPE = new Shapeless_Recipe(), ADVANCED_CRAFTING_RECIPE = new Advanced_Crafting_Recipe(), ADVANCED_CRAFTING_RECIPE_PERMISSION = new Advanced_Crafting_Recipe_Permission();
|
||||
public static final ItemStat AUTOSMELT = new BooleanStat(new ItemStack(Material.COAL), "Autosmelt", new String[] { "If set to true, your tool will", "automaticaly smelt mined ores." }, "autosmelt", new String[] { "tool" });
|
||||
public static final ItemStat BOUNCING_CRACK = new BooleanStat(new ItemStack(VersionMaterial.COBBLESTONE_WALL.toMaterial()), "Bouncing Crack", new String[] { "If set to true, your tool will", "also break nearby blocks." }, "bouncing-crack", new String[] { "tool" });
|
||||
public static final ItemStat PICKAXE_POWER = new Pickaxe_Power();
|
||||
public static final ItemStat CUSTOM_SOUNDS = new CustomSounds();
|
||||
public static final ItemStat ELEMENTS = new Elements();
|
||||
public static final ItemStat COMMANDS = new Commands(), STAFF_SPIRIT = new Staff_Spirit(), LUTE_ATTACK_SOUND = new Lute_Attack_Sound(), LUTE_ATTACK_EFFECT = new Lute_Attack_Effect();
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.Indyuce.mmoitems.version.nms;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -33,8 +35,12 @@ public interface NMSHandler {
|
||||
|
||||
void addActiveContainerSlotListener(Object container, Player player);
|
||||
|
||||
void playArmAnimation(Player player);
|
||||
|
||||
Inventory toBukkitInventory(Object container);
|
||||
|
||||
Sound getBlockPlaceSound(Block block);
|
||||
|
||||
Object newContainerAnvil(Player player);
|
||||
|
||||
boolean isInBoundingBox(Entity entity, Location loc);
|
||||
|
@ -1,9 +1,12 @@
|
||||
package net.Indyuce.mmoitems.version.nms;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory;
|
||||
@ -14,6 +17,7 @@ import org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_12_R1.Block;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.Blocks;
|
||||
import net.minecraft.server.v1_12_R1.ChatMessage;
|
||||
@ -21,14 +25,23 @@ import net.minecraft.server.v1_12_R1.ChatMessageType;
|
||||
import net.minecraft.server.v1_12_R1.Container;
|
||||
import net.minecraft.server.v1_12_R1.ContainerAnvil;
|
||||
import net.minecraft.server.v1_12_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_12_R1.EnumHand;
|
||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_12_R1.ItemStack;
|
||||
import net.minecraft.server.v1_12_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayInArmAnimation;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutChat;
|
||||
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.PlayerConnection;
|
||||
import net.minecraft.server.v1_12_R1.SoundEffect;
|
||||
import net.minecraft.server.v1_12_R1.SoundEffectType;
|
||||
import net.minecraft.server.v1_12_R1.World;
|
||||
|
||||
public class NMSHandler_1_12_R1 implements NMSHandler {
|
||||
@Override
|
||||
@ -195,4 +208,36 @@ public class NMSHandler_1_12_R1 implements NMSHandler {
|
||||
|
||||
return dx * dx + dx * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playArmAnimation(Player player) {
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
PlayerConnection connection = p.playerConnection;
|
||||
PacketPlayOutAnimation armSwing = new PacketPlayOutAnimation(p, 0);
|
||||
connection.sendPacket(armSwing);
|
||||
connection.a(new PacketPlayInArmAnimation(EnumHand.MAIN_HAND));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getBlockPlaceSound(org.bukkit.block.Block block) {
|
||||
try {
|
||||
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
|
||||
|
||||
Block nmsBlock = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())).getBlock();
|
||||
SoundEffectType soundEffectType = nmsBlock.getStepSound();
|
||||
|
||||
Field breakSound = SoundEffectType.class.getDeclaredField("y");
|
||||
breakSound.setAccessible(true);
|
||||
SoundEffect nmsSound = (SoundEffect) breakSound.get(soundEffectType);
|
||||
|
||||
Field keyField = SoundEffect.class.getDeclaredField("a");
|
||||
keyField.setAccessible(true);
|
||||
MinecraftKey nmsString = (MinecraftKey) keyField.get(nmsSound);
|
||||
|
||||
return Sound.valueOf(nmsString.getKey().replace(".", "_").toUpperCase());
|
||||
} catch (IllegalAccessException | NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package net.Indyuce.mmoitems.version.nms;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
|
||||
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;
|
||||
@ -13,6 +16,7 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_13_R1.Block;
|
||||
import net.minecraft.server.v1_13_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R1.Blocks;
|
||||
import net.minecraft.server.v1_13_R1.ChatMessage;
|
||||
@ -20,14 +24,23 @@ import net.minecraft.server.v1_13_R1.ChatMessageType;
|
||||
import net.minecraft.server.v1_13_R1.Container;
|
||||
import net.minecraft.server.v1_13_R1.ContainerAnvil;
|
||||
import net.minecraft.server.v1_13_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R1.EnumHand;
|
||||
import net.minecraft.server.v1_13_R1.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_13_R1.ItemStack;
|
||||
import net.minecraft.server.v1_13_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayInArmAnimation;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_13_R1.PacketPlayOutChat;
|
||||
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.PlayerConnection;
|
||||
import net.minecraft.server.v1_13_R1.SoundEffect;
|
||||
import net.minecraft.server.v1_13_R1.SoundEffectType;
|
||||
import net.minecraft.server.v1_13_R1.World;
|
||||
|
||||
public class NMSHandler_1_13_R1 implements NMSHandler {
|
||||
@Override
|
||||
@ -193,4 +206,36 @@ public class NMSHandler_1_13_R1 implements NMSHandler {
|
||||
|
||||
return dx * dx + dx * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playArmAnimation(Player player) {
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
PlayerConnection connection = p.playerConnection;
|
||||
PacketPlayOutAnimation armSwing = new PacketPlayOutAnimation(p, 0);
|
||||
connection.sendPacket(armSwing);
|
||||
connection.a(new PacketPlayInArmAnimation(EnumHand.MAIN_HAND));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getBlockPlaceSound(org.bukkit.block.Block block) {
|
||||
try {
|
||||
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
|
||||
|
||||
Block nmsBlock = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())).getBlock();
|
||||
SoundEffectType soundEffectType = nmsBlock.getStepSound();
|
||||
|
||||
Field breakSound = SoundEffectType.class.getDeclaredField("y");
|
||||
breakSound.setAccessible(true);
|
||||
SoundEffect nmsSound = (SoundEffect) breakSound.get(soundEffectType);
|
||||
|
||||
Field keyField = SoundEffect.class.getDeclaredField("a");
|
||||
keyField.setAccessible(true);
|
||||
MinecraftKey nmsString = (MinecraftKey) keyField.get(nmsSound);
|
||||
|
||||
return Sound.valueOf(nmsString.getKey().replace(".", "_").toUpperCase());
|
||||
} catch (IllegalAccessException | NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package net.Indyuce.mmoitems.version.nms;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
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;
|
||||
@ -13,6 +16,7 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_13_R2.Block;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.Blocks;
|
||||
import net.minecraft.server.v1_13_R2.ChatMessage;
|
||||
@ -20,14 +24,23 @@ import net.minecraft.server.v1_13_R2.ChatMessageType;
|
||||
import net.minecraft.server.v1_13_R2.Container;
|
||||
import net.minecraft.server.v1_13_R2.ContainerAnvil;
|
||||
import net.minecraft.server.v1_13_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R2.EnumHand;
|
||||
import net.minecraft.server.v1_13_R2.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_13_R2.ItemStack;
|
||||
import net.minecraft.server.v1_13_R2.MinecraftKey;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayInArmAnimation;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutChat;
|
||||
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.PlayerConnection;
|
||||
import net.minecraft.server.v1_13_R2.SoundEffect;
|
||||
import net.minecraft.server.v1_13_R2.SoundEffectType;
|
||||
import net.minecraft.server.v1_13_R2.World;
|
||||
|
||||
public class NMSHandler_1_13_R2 implements NMSHandler {
|
||||
@Override
|
||||
@ -194,4 +207,36 @@ public class NMSHandler_1_13_R2 implements NMSHandler {
|
||||
|
||||
return dx * dx + dx * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playArmAnimation(Player player) {
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
PlayerConnection connection = p.playerConnection;
|
||||
PacketPlayOutAnimation armSwing = new PacketPlayOutAnimation(p, 0);
|
||||
connection.sendPacket(armSwing);
|
||||
connection.a(new PacketPlayInArmAnimation(EnumHand.MAIN_HAND));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getBlockPlaceSound(org.bukkit.block.Block block) {
|
||||
try {
|
||||
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
|
||||
|
||||
Block nmsBlock = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())).getBlock();
|
||||
SoundEffectType soundEffectType = nmsBlock.getStepSound();
|
||||
|
||||
Field breakSound = SoundEffectType.class.getDeclaredField("y");
|
||||
breakSound.setAccessible(true);
|
||||
SoundEffect nmsSound = (SoundEffect) breakSound.get(soundEffectType);
|
||||
|
||||
Field keyField = SoundEffect.class.getDeclaredField("a");
|
||||
keyField.setAccessible(true);
|
||||
MinecraftKey nmsString = (MinecraftKey) keyField.get(nmsSound);
|
||||
|
||||
return Sound.valueOf(nmsString.getKey().replace(".", "_").toUpperCase());
|
||||
} catch (IllegalAccessException | NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
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;
|
||||
@ -16,6 +17,7 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
import net.minecraft.server.v1_14_R1.Block;
|
||||
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_14_R1.ChatMessage;
|
||||
import net.minecraft.server.v1_14_R1.ChatMessageType;
|
||||
@ -24,14 +26,22 @@ import net.minecraft.server.v1_14_R1.ContainerAccess;
|
||||
import net.minecraft.server.v1_14_R1.ContainerAnvil;
|
||||
import net.minecraft.server.v1_14_R1.Containers;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.EnumHand;
|
||||
import net.minecraft.server.v1_14_R1.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_14_R1.ItemStack;
|
||||
import net.minecraft.server.v1_14_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayInArmAnimation;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutAnimation;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutChat;
|
||||
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.PlayerConnection;
|
||||
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||
import net.minecraft.server.v1_14_R1.SoundEffectType;
|
||||
import net.minecraft.server.v1_14_R1.World;
|
||||
|
||||
public class NMSHandler_1_14_R1 implements NMSHandler {
|
||||
@Override
|
||||
@ -217,4 +227,36 @@ public class NMSHandler_1_14_R1 implements NMSHandler {
|
||||
|
||||
return dx * dx + dx * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playArmAnimation(Player player) {
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
PlayerConnection connection = p.playerConnection;
|
||||
PacketPlayOutAnimation armSwing = new PacketPlayOutAnimation(p, 0);
|
||||
connection.sendPacket(armSwing);
|
||||
connection.a(new PacketPlayInArmAnimation(EnumHand.MAIN_HAND));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sound getBlockPlaceSound(org.bukkit.block.Block block) {
|
||||
try {
|
||||
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
|
||||
|
||||
Block nmsBlock = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())).getBlock();
|
||||
SoundEffectType soundEffectType = nmsBlock.getStepSound(nmsBlock.getBlockData());
|
||||
|
||||
Field breakSound = SoundEffectType.class.getDeclaredField("y");
|
||||
breakSound.setAccessible(true);
|
||||
SoundEffect nmsSound = (SoundEffect) breakSound.get(soundEffectType);
|
||||
|
||||
Field keyField = SoundEffect.class.getDeclaredField("a");
|
||||
keyField.setAccessible(true);
|
||||
MinecraftKey nmsString = (MinecraftKey) keyField.get(nmsSound);
|
||||
|
||||
return Sound.valueOf(nmsString.getKey().replace(".", "_").toUpperCase());
|
||||
} catch (IllegalAccessException | NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +124,18 @@ gem-sockets:
|
||||
# uncolored gem socket i.e a socket for any type of gem.
|
||||
uncolored: 'Uncolored'
|
||||
|
||||
custom-blocks:
|
||||
# Whether or not custom blocks should
|
||||
# generate in the world according to
|
||||
# their generation template.
|
||||
enable-world-gen: false
|
||||
# Whether or not to remove mushroom block drops
|
||||
# from the droplist when mining a mushroom block
|
||||
# with silk-touch.
|
||||
# HIGHLY Recommended for servers that use
|
||||
# custom blocks, as the mushroom blocks can BREAK everything.
|
||||
replace-mushroom-drops: false
|
||||
|
||||
advanced-workbench:
|
||||
# Define on what actions the adv workbench will open.
|
||||
open-when:
|
||||
|
15
src/main/resources/default/custom-blocks.yml
Normal file
15
src/main/resources/default/custom-blocks.yml
Normal file
@ -0,0 +1,15 @@
|
||||
1:
|
||||
display-name: "&aMy First Custom Block"
|
||||
lore:
|
||||
- "&7Wow... It's possible!"
|
||||
- "&7That's awesome!"
|
||||
required-power: 2
|
||||
min-xp: 10
|
||||
max-xp: 20
|
||||
gen-template: basic-template
|
||||
2:
|
||||
display-name: "&bMy Second Custom Block"
|
||||
3:
|
||||
lore:
|
||||
- "I have no display name."
|
||||
- "I only have a lore!"
|
@ -30,7 +30,16 @@ blocks:
|
||||
MATERIAL:
|
||||
RARE_DIAMOND: 100,2-3,0
|
||||
|
||||
|
||||
# Custom Blocks Drop Tables
|
||||
# Read when a custom block is mined/broken by a player.
|
||||
customblocks:
|
||||
1:
|
||||
more-rare-diamond:
|
||||
coef: 1
|
||||
disable-silk-touch: true
|
||||
items:
|
||||
MATERIAL:
|
||||
RARE_DIAMOND: 100,2-3,0
|
||||
|
||||
# Monsters Drop Tables
|
||||
# Read when any monster dies.
|
||||
|
22
src/main/resources/default/gen-templates.yml
Normal file
22
src/main/resources/default/gen-templates.yml
Normal file
@ -0,0 +1,22 @@
|
||||
basic-template:
|
||||
# A list of materials this template can replace.
|
||||
replace: [STONE]
|
||||
# The chance for a chunk to be chosen for world gen.
|
||||
# (0.7 = 70% chance)
|
||||
chunk-chance: 0.7
|
||||
# The depth range of the generation.
|
||||
# This example allows the blocks to generate between
|
||||
# y coord 10 and y coord 24
|
||||
depth: 10=24
|
||||
# How many blocks to generate in each vein.
|
||||
# (Note this is a maximum value and smaller veins can appear)
|
||||
vein-size: 5
|
||||
# The amount of veins to generate per chunk.
|
||||
vein-count: 2
|
||||
slime-chunks-only:
|
||||
replace: [STONE]
|
||||
chunk-chance: 0.6
|
||||
slime-chunk: true
|
||||
depth: 0=100
|
||||
vein-size: 1
|
||||
vein-count: 4
|
@ -70,6 +70,7 @@ lore-format:
|
||||
- '#two-handed#'
|
||||
- '#autosmelt#'
|
||||
- '#bouncing-crack#'
|
||||
- '#pickaxe-power#'
|
||||
- '#restore-health#'
|
||||
- '#restore-food#'
|
||||
- '#restore-saturation#'
|
||||
|
@ -89,6 +89,7 @@ soulbound-level: '&7■ Level &e# &7Soulbound'
|
||||
# Tool Enchants
|
||||
autosmelt: '&7■ &fAutosmelt'
|
||||
bouncing-crack: '&7■ &fBouncing Crack'
|
||||
pickaxe-power: '&7■ &fPickaxe Power: &a#'
|
||||
|
||||
# General
|
||||
item-type: '&c#'
|
||||
|
Loading…
Reference in New Issue
Block a user