Compare commits
No commits in common. "4c6180e8f11b7b92f3bafd9c1ebd9b81a87787d6" and "b617a39b40993243daaa8371b823acf6c7303f67" have entirely different histories.
4c6180e8f1
...
b617a39b40
42
pom.xml
42
pom.xml
@ -4,14 +4,7 @@
|
||||
|
||||
<groupId>net.hexa</groupId>
|
||||
<artifactId>MythicItems</artifactId>
|
||||
<version>1.0-SNAPSHOT-1.21.11</version>
|
||||
|
||||
<properties>
|
||||
<minecraft.version>1.21.11</minecraft.version>
|
||||
<spigot.version>${minecraft.version}-R0.1-SNAPSHOT</spigot.version>
|
||||
<java.version>14</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
@ -19,43 +12,16 @@
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<source>14</source>
|
||||
<target>14</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<outputDirectory>${user.home}/Documents/vanilla+/plugins/</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@ -63,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>${spigot.version}</version>
|
||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
package net.hexa.MythicItems;
|
||||
|
||||
import net.hexa.MythicItems.mythics.MythicItem;
|
||||
import net.hexa.MythicItems.Mythics.MythicItem;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CommandListMythics implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
@ -16,8 +14,7 @@ public class CommandListMythics implements CommandExecutor {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
ItemStack item = null;
|
||||
item = MythicItem.getMythicById(0).item;
|
||||
ItemStack item = MythicItem.getMythicById(0).item;
|
||||
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
package net.hexa.MythicItems;
|
||||
|
||||
import net.hexa.MythicItems.mythics.MythicItem;
|
||||
import net.hexa.MythicItems.Mythics.MythicEssence;
|
||||
import net.hexa.MythicItems.Mythics.MythicItem;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CommandMythicEssence implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
@ -16,8 +15,7 @@ public class CommandMythicEssence implements CommandExecutor {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
ItemStack item = null;
|
||||
item = MythicItem.getMythicById(0).item;
|
||||
ItemStack item = MythicItem.getMythicById(0).item;
|
||||
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
|
||||
@ -1,21 +1,11 @@
|
||||
package net.hexa.MythicItems;
|
||||
|
||||
import net.hexa.MythicItems.mythics.MythicItem;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MythicItems extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("onEnable is called!");
|
||||
MythicItem.init(this);
|
||||
|
||||
startupLog();
|
||||
|
||||
this.getCommand("essence").setExecutor(new CommandMythicEssence());
|
||||
getServer().getPluginManager().registerEvents(new MythicListener(), this);
|
||||
}
|
||||
@ -24,24 +14,4 @@ public class MythicItems extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
getLogger().info("onDisable is called!");
|
||||
}
|
||||
|
||||
// Helpers
|
||||
private void startupLog() {
|
||||
// Log which directory we are scanning for mythic JSON files
|
||||
File mythicDir = new File(getDataFolder(), "mythic-items/");
|
||||
getLogger().info("Scanning for mythics in: " + mythicDir.getPath());
|
||||
|
||||
List<MythicItem> mythics = MythicItem.getMythics();
|
||||
getLogger().info("Found " + mythics.size() + " mythic item(s).");
|
||||
|
||||
for (MythicItem mythic : mythics) {
|
||||
ItemStack item = mythic.item;
|
||||
String typeName = item.getType().name();
|
||||
String displayName = item.getItemMeta() != null && item.getItemMeta().hasDisplayName()
|
||||
? item.getItemMeta().getDisplayName()
|
||||
: "<no custom name>";
|
||||
getLogger().info(" - Mythic: material=" + typeName + ", name=" + displayName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
package net.hexa.MythicItems;
|
||||
|
||||
import net.hexa.MythicItems.mythics.MythicEssence;
|
||||
import net.hexa.MythicItems.mythics.MythicItem;
|
||||
import net.hexa.MythicItems.Mythics.MythicEssence;
|
||||
import net.hexa.MythicItems.Mythics.MythicItem;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package net.hexa.MythicItems.mythics;
|
||||
package net.hexa.MythicItems.Mythics;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@ -1,5 +1,6 @@
|
||||
package net.hexa.MythicItems.mythics;
|
||||
package net.hexa.MythicItems.Mythics;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
@ -11,7 +12,7 @@ public class MythicEssence {
|
||||
private static final List<MythicItem> mythics = MythicItem.getMythics();
|
||||
|
||||
public static ItemStack rollMythic() {
|
||||
int mythic_id = random.nextInt(mythics.size());
|
||||
int mythic_id = random.nextInt(mythics.size() + 1);
|
||||
return mythics.get(mythic_id).item;
|
||||
}
|
||||
}
|
||||
188
src/main/java/net/hexa/MythicItems/Mythics/MythicItem.java
Normal file
188
src/main/java/net/hexa/MythicItems/Mythics/MythicItem.java
Normal file
@ -0,0 +1,188 @@
|
||||
package net.hexa.MythicItems.Mythics;
|
||||
|
||||
import org.json.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MythicItem {
|
||||
private static final String MYTHIC_DIR = "resources/mythic-items";
|
||||
|
||||
|
||||
public ItemStack item;
|
||||
private static final Logger logger = Bukkit.getServer().getPluginManager().getPlugin("MythicItems").getLogger();
|
||||
|
||||
public MythicItem() {}
|
||||
|
||||
// Parse a mythic item from a json file
|
||||
public MythicItem(JSONObject json) {
|
||||
if (json == null) {
|
||||
item = new ItemStack(Material.GRAVEL);
|
||||
logger.warning("Constructor was passed a NULL JSONObject.");
|
||||
return;
|
||||
}
|
||||
|
||||
String item_id = json.getString("item_id");
|
||||
|
||||
this.item = new ItemStack(Material.getMaterial(item_id));
|
||||
|
||||
ItemMeta item_metadata = item.getItemMeta();
|
||||
|
||||
if (json.has("Unbreakable"))
|
||||
item_metadata.setUnbreakable(json.getBoolean("Unbreakable"));
|
||||
|
||||
if (json.has("Name"))
|
||||
item_metadata.setItemName(json.getString("Name"));
|
||||
|
||||
if (json.has("Lore")) {
|
||||
List<Object> lines = json.getJSONArray("Lore").toList();
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
for (Object line : lines) {
|
||||
lore.add(line.toString());
|
||||
}
|
||||
|
||||
item_metadata.setLore(lore);
|
||||
}
|
||||
|
||||
// Add all enchantments
|
||||
JSONObject enchantments = json.getJSONObject("Enchantments");
|
||||
for (String enchantment_key : enchantments.keySet()) {
|
||||
|
||||
int enchantment_level = enchantments.getInt(enchantment_key);
|
||||
|
||||
switch (enchantment_key.toUpperCase()) {
|
||||
case "UNBREAKING" -> this.item.addUnsafeEnchantment(Enchantment.UNBREAKING, enchantment_level);
|
||||
case "EFFICIENCY" -> this.item.addUnsafeEnchantment(Enchantment.EFFICIENCY, enchantment_level);
|
||||
case "PROTECTION" -> this.item.addUnsafeEnchantment(Enchantment.PROTECTION, enchantment_level);
|
||||
case "FIRE_PROTECTION" -> this.item.addUnsafeEnchantment(Enchantment.FIRE_PROTECTION, enchantment_level);
|
||||
case "FEATHER_FALLING" -> this.item.addUnsafeEnchantment(Enchantment.FEATHER_FALLING, enchantment_level);
|
||||
case "BLAST_PROTECTION" -> this.item.addUnsafeEnchantment(Enchantment.BLAST_PROTECTION, enchantment_level);
|
||||
case "PROJECTILE_PROTECTION" -> this.item.addUnsafeEnchantment(Enchantment.PROJECTILE_PROTECTION, enchantment_level);
|
||||
case "RESPIRATION" -> this.item.addUnsafeEnchantment(Enchantment.RESPIRATION, enchantment_level);
|
||||
case "AQUA_AFFINITY" -> this.item.addUnsafeEnchantment(Enchantment.AQUA_AFFINITY, enchantment_level);
|
||||
case "THORNS" -> this.item.addUnsafeEnchantment(Enchantment.THORNS, enchantment_level);
|
||||
case "DEPTH_STRIDER" -> this.item.addUnsafeEnchantment(Enchantment.DEPTH_STRIDER, enchantment_level);
|
||||
case "FROST_WALKER" -> this.item.addUnsafeEnchantment(Enchantment.FROST_WALKER, enchantment_level);
|
||||
case "BINDING_CURSE" -> this.item.addUnsafeEnchantment(Enchantment.BINDING_CURSE, enchantment_level); // if you want it for some reason
|
||||
case "SHARPNESS" -> this.item.addUnsafeEnchantment(Enchantment.SHARPNESS, enchantment_level);
|
||||
case "SMITE" -> this.item.addUnsafeEnchantment(Enchantment.SMITE, enchantment_level);
|
||||
case "BANE_OF_ARTHROPODS" -> this.item.addUnsafeEnchantment(Enchantment.BANE_OF_ARTHROPODS, enchantment_level);
|
||||
case "KNOCKBACK" -> this.item.addUnsafeEnchantment(Enchantment.KNOCKBACK, enchantment_level);
|
||||
case "FIRE_ASPECT" -> this.item.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, enchantment_level);
|
||||
case "LOOTING" -> this.item.addUnsafeEnchantment(Enchantment.LOOTING, enchantment_level);
|
||||
case "SWEEPING_EDGE" -> this.item.addUnsafeEnchantment(Enchantment.SWEEPING_EDGE, enchantment_level);
|
||||
case "SILK_TOUCH" -> this.item.addUnsafeEnchantment(Enchantment.SILK_TOUCH, enchantment_level);
|
||||
case "FORTUNE" -> this.item.addUnsafeEnchantment(Enchantment.FORTUNE, enchantment_level);
|
||||
case "POWER" -> this.item.addUnsafeEnchantment(Enchantment.POWER, enchantment_level);
|
||||
case "PUNCH" -> this.item.addUnsafeEnchantment(Enchantment.PUNCH, enchantment_level);
|
||||
case "FLAME" -> this.item.addUnsafeEnchantment(Enchantment.FLAME, enchantment_level);
|
||||
case "INFINITY" -> this.item.addUnsafeEnchantment(Enchantment.INFINITY, enchantment_level);
|
||||
case "LUCK_OF_THE_SEA" -> this.item.addUnsafeEnchantment(Enchantment.LOOTING, enchantment_level);
|
||||
case "LURE" -> this.item.addUnsafeEnchantment(Enchantment.LURE, enchantment_level);
|
||||
case "LOYALTY" -> this.item.addUnsafeEnchantment(Enchantment.LOYALTY, enchantment_level);
|
||||
case "IMPALING" -> this.item.addUnsafeEnchantment(Enchantment.IMPALING, enchantment_level);
|
||||
case "RIPTIDE" -> this.item.addUnsafeEnchantment(Enchantment.RIPTIDE, enchantment_level);
|
||||
case "CHANNELING" -> this.item.addUnsafeEnchantment(Enchantment.CHANNELING, enchantment_level);
|
||||
case "MULTISHOT" -> this.item.addUnsafeEnchantment(Enchantment.MULTISHOT, enchantment_level);
|
||||
case "QUICK_CHARGE" -> this.item.addUnsafeEnchantment(Enchantment.QUICK_CHARGE, enchantment_level);
|
||||
case "PIERCING" -> this.item.addUnsafeEnchantment(Enchantment.PIERCING, enchantment_level);
|
||||
case "DENSITY" -> this.item.addUnsafeEnchantment(Enchantment.DENSITY, enchantment_level);
|
||||
case "WIND_BURST" -> this.item.addUnsafeEnchantment(Enchantment.WIND_BURST, enchantment_level);
|
||||
case "MENDING" -> this.item.addUnsafeEnchantment(Enchantment.MENDING, enchantment_level);
|
||||
case "VANISHING_CURSE" -> this.item.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, enchantment_level);
|
||||
case "SOUL_SPEED" -> this.item.addUnsafeEnchantment(Enchantment.SOUL_SPEED, enchantment_level);
|
||||
case "SWIFT_SNEAK" -> this.item.addUnsafeEnchantment(Enchantment.SWIFT_SNEAK, enchantment_level);
|
||||
default -> logger.warning("Enchantment " + enchantment_key + "does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
// Save the metadata
|
||||
item.setItemMeta(item_metadata);
|
||||
|
||||
// Write the mythic id to the PDC
|
||||
if (json.has("mythic_id")) {
|
||||
setMythicId(json.getInt("mythic_id"));
|
||||
} else {
|
||||
logger.warning("No Mythic ID was included!");
|
||||
}
|
||||
}
|
||||
|
||||
// Parse all mythic items in the resources/mythics-items/ directory
|
||||
public static List<MythicItem> getMythics() {
|
||||
ArrayList<MythicItem> mythic_items = new ArrayList<>();
|
||||
|
||||
File mythic_directory = new File(MYTHIC_DIR);
|
||||
File[] mythic_jsons = mythic_directory.listFiles();
|
||||
|
||||
if (mythic_jsons != null) {
|
||||
for (File mythic_json : mythic_jsons) {
|
||||
String json_content = null;
|
||||
try {
|
||||
json_content = new Scanner(mythic_json).useDelimiter("\\Z").next();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
mythic_items.add(new MythicItem(new JSONObject(json_content)));
|
||||
}
|
||||
}
|
||||
|
||||
return mythic_items;
|
||||
}
|
||||
|
||||
public static MythicItem getMythicById(int id) {
|
||||
File mythic_directory = new File(MYTHIC_DIR);
|
||||
File[] mythic_jsons = mythic_directory.listFiles();
|
||||
|
||||
if (mythic_jsons != null) {
|
||||
for (File mythic_json : mythic_jsons) {
|
||||
String json_content = null;
|
||||
try {
|
||||
json_content = new Scanner(mythic_json).useDelimiter("\\Z").next();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject(json_content);
|
||||
|
||||
if (json.has("mythic_id")) {
|
||||
if (json.getInt("mythic_id") == id) {
|
||||
return new MythicItem(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new MythicItem();
|
||||
}
|
||||
|
||||
public static int getMythicId(ItemStack item) {
|
||||
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
||||
|
||||
return itemData.get(Constants.mythic_key, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
public static boolean isMythic(ItemStack item) {
|
||||
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
||||
|
||||
return itemData.has(Constants.mythic_key);
|
||||
}
|
||||
|
||||
protected void setMythicId(int id) {
|
||||
ItemMeta itemData = item.getItemMeta();
|
||||
itemData.getPersistentDataContainer().set(Constants.mythic_key, PersistentDataType.INTEGER, id);
|
||||
this.item.setItemMeta(itemData);
|
||||
}
|
||||
}
|
||||
@ -1,228 +0,0 @@
|
||||
package net.hexa.MythicItems.mythics;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MythicItem {
|
||||
private static final String MYTHIC_DIR = "mythic-items/";
|
||||
|
||||
private static JavaPlugin plugin;
|
||||
|
||||
public ItemStack item;
|
||||
private static final Logger logger = Bukkit.getServer().getPluginManager().getPlugin("MythicItems").getLogger();
|
||||
|
||||
public static void init(JavaPlugin pl) {
|
||||
plugin = pl;
|
||||
}
|
||||
|
||||
public MythicItem() {}
|
||||
|
||||
// Parse a mythic item from a json file
|
||||
public MythicItem(JSONObject json) {
|
||||
logger.info("Json: " + json.toString());
|
||||
if (json == null) {
|
||||
item = new ItemStack(Material.GRAVEL);
|
||||
logger.warning("Constructor was passed a NULL JSONObject.");
|
||||
return;
|
||||
}
|
||||
|
||||
String item_id = json.getString("item_id");
|
||||
|
||||
Material m = Material.matchMaterial(item_id);
|
||||
if (m == null) {
|
||||
m = Material.DIRT;
|
||||
}
|
||||
|
||||
this.item = new ItemStack(m);
|
||||
|
||||
ItemMeta item_metadata = item.getItemMeta();
|
||||
|
||||
if (json.has("Unbreakable"))
|
||||
item_metadata.setUnbreakable(json.getBoolean("Unbreakable"));
|
||||
|
||||
if (json.has("Name"))
|
||||
item_metadata.setItemName(json.getString("Name"));
|
||||
|
||||
if (json.has("Lore")) {
|
||||
List<Object> lines = json.getJSONArray("Lore").toList();
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
for (Object line : lines) {
|
||||
lore.add(line.toString());
|
||||
}
|
||||
|
||||
item_metadata.setLore(lore);
|
||||
}
|
||||
|
||||
// Add all enchantments onto the ItemMeta so they are not overwritten
|
||||
if (json.has("Enchantments")) {
|
||||
JSONObject enchantments = json.getJSONObject("Enchantments");
|
||||
for (String enchantment_key : enchantments.keySet()) {
|
||||
|
||||
int enchantment_level = enchantments.getInt(enchantment_key);
|
||||
|
||||
switch (enchantment_key.toUpperCase()) {
|
||||
case "UNBREAKING" -> item_metadata.addEnchant(Enchantment.UNBREAKING, enchantment_level, true);
|
||||
case "EFFICIENCY" -> item_metadata.addEnchant(Enchantment.EFFICIENCY, enchantment_level, true);
|
||||
case "PROTECTION" -> item_metadata.addEnchant(Enchantment.PROTECTION, enchantment_level, true);
|
||||
case "FIRE_PROTECTION" -> item_metadata.addEnchant(Enchantment.FIRE_PROTECTION, enchantment_level, true);
|
||||
case "FEATHER_FALLING" -> item_metadata.addEnchant(Enchantment.FEATHER_FALLING, enchantment_level, true);
|
||||
case "BLAST_PROTECTION" -> item_metadata.addEnchant(Enchantment.BLAST_PROTECTION, enchantment_level, true);
|
||||
case "PROJECTILE_PROTECTION" -> item_metadata.addEnchant(Enchantment.PROJECTILE_PROTECTION, enchantment_level, true);
|
||||
case "RESPIRATION" -> item_metadata.addEnchant(Enchantment.RESPIRATION, enchantment_level, true);
|
||||
case "AQUA_AFFINITY" -> item_metadata.addEnchant(Enchantment.AQUA_AFFINITY, enchantment_level, true);
|
||||
case "THORNS" -> item_metadata.addEnchant(Enchantment.THORNS, enchantment_level, true);
|
||||
case "DEPTH_STRIDER" -> item_metadata.addEnchant(Enchantment.DEPTH_STRIDER, enchantment_level, true);
|
||||
case "FROST_WALKER" -> item_metadata.addEnchant(Enchantment.FROST_WALKER, enchantment_level, true);
|
||||
case "BINDING_CURSE" -> item_metadata.addEnchant(Enchantment.BINDING_CURSE, enchantment_level, true); // if you want it for some reason
|
||||
case "SHARPNESS" -> item_metadata.addEnchant(Enchantment.SHARPNESS, enchantment_level, true);
|
||||
case "SMITE" -> item_metadata.addEnchant(Enchantment.SMITE, enchantment_level, true);
|
||||
case "BANE_OF_ARTHROPODS" -> item_metadata.addEnchant(Enchantment.BANE_OF_ARTHROPODS, enchantment_level, true);
|
||||
case "KNOCKBACK" -> item_metadata.addEnchant(Enchantment.KNOCKBACK, enchantment_level, true);
|
||||
case "FIRE_ASPECT" -> item_metadata.addEnchant(Enchantment.FIRE_ASPECT, enchantment_level, true);
|
||||
case "LOOTING" -> item_metadata.addEnchant(Enchantment.LOOTING, enchantment_level, true);
|
||||
case "SWEEPING_EDGE" -> item_metadata.addEnchant(Enchantment.SWEEPING_EDGE, enchantment_level, true);
|
||||
case "SILK_TOUCH" -> item_metadata.addEnchant(Enchantment.SILK_TOUCH, enchantment_level, true);
|
||||
case "FORTUNE" -> item_metadata.addEnchant(Enchantment.FORTUNE, enchantment_level, true);
|
||||
case "POWER" -> item_metadata.addEnchant(Enchantment.POWER, enchantment_level, true);
|
||||
case "PUNCH" -> item_metadata.addEnchant(Enchantment.PUNCH, enchantment_level, true);
|
||||
case "FLAME" -> item_metadata.addEnchant(Enchantment.FLAME, enchantment_level, true);
|
||||
case "INFINITY" -> item_metadata.addEnchant(Enchantment.INFINITY, enchantment_level, true);
|
||||
case "LUCK_OF_THE_SEA" -> item_metadata.addEnchant(Enchantment.LUCK_OF_THE_SEA, enchantment_level, true);
|
||||
case "LURE" -> item_metadata.addEnchant(Enchantment.LURE, enchantment_level, true);
|
||||
case "LOYALTY" -> item_metadata.addEnchant(Enchantment.LOYALTY, enchantment_level, true);
|
||||
case "IMPALING" -> item_metadata.addEnchant(Enchantment.IMPALING, enchantment_level, true);
|
||||
case "RIPTIDE" -> item_metadata.addEnchant(Enchantment.RIPTIDE, enchantment_level, true);
|
||||
case "CHANNELING" -> item_metadata.addEnchant(Enchantment.CHANNELING, enchantment_level, true);
|
||||
case "MULTISHOT" -> item_metadata.addEnchant(Enchantment.MULTISHOT, enchantment_level, true);
|
||||
case "QUICK_CHARGE" -> item_metadata.addEnchant(Enchantment.QUICK_CHARGE, enchantment_level, true);
|
||||
case "PIERCING" -> item_metadata.addEnchant(Enchantment.PIERCING, enchantment_level, true);
|
||||
case "DENSITY" -> item_metadata.addEnchant(Enchantment.DENSITY, enchantment_level, true);
|
||||
case "WIND_BURST" -> item_metadata.addEnchant(Enchantment.WIND_BURST, enchantment_level, true);
|
||||
case "MENDING" -> item_metadata.addEnchant(Enchantment.MENDING, enchantment_level, true);
|
||||
case "VANISHING_CURSE" -> item_metadata.addEnchant(Enchantment.VANISHING_CURSE, enchantment_level, true);
|
||||
case "SOUL_SPEED" -> item_metadata.addEnchant(Enchantment.SOUL_SPEED, enchantment_level, true);
|
||||
case "SWIFT_SNEAK" -> item_metadata.addEnchant(Enchantment.SWIFT_SNEAK, enchantment_level, true);
|
||||
default -> logger.warning("Enchantment " + enchantment_key + " does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the metadata
|
||||
item.setItemMeta(item_metadata);
|
||||
|
||||
// Write the mythic id to the PDC
|
||||
if (json.has("mythic_id")) {
|
||||
setMythicId(json.getInt("mythic_id"));
|
||||
} else {
|
||||
logger.warning("No Mythic ID was included!");
|
||||
}
|
||||
}
|
||||
|
||||
// Parse all mythic items from the plugin's data folder mythic-items/ directory
|
||||
public static List<MythicItem> getMythics() {
|
||||
ArrayList<MythicItem> mythicItems = new ArrayList<>();
|
||||
|
||||
if (plugin == null) {
|
||||
logger.warning("MythicItem plugin reference is null; cannot load mythics.");
|
||||
return mythicItems;
|
||||
}
|
||||
|
||||
File mythicDirectory = new File(plugin.getDataFolder(), MYTHIC_DIR);
|
||||
if (!mythicDirectory.exists() || !mythicDirectory.isDirectory()) {
|
||||
logger.warning("Mythic directory does not exist: " + mythicDirectory.getPath());
|
||||
return mythicItems;
|
||||
}
|
||||
|
||||
File[] mythicJsons = mythicDirectory.listFiles((dir, name) -> name.toLowerCase().endsWith(".json"));
|
||||
if (mythicJsons == null) {
|
||||
return mythicItems;
|
||||
}
|
||||
|
||||
for (File mythicJson : mythicJsons) {
|
||||
String jsonContent;
|
||||
try {
|
||||
jsonContent = new Scanner(mythicJson).useDelimiter("\\Z").next();
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.warning("Failed to read mythic file " + mythicJson.getName() + ": " + e.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
mythicItems.add(new MythicItem(new JSONObject(jsonContent)));
|
||||
}
|
||||
|
||||
return mythicItems;
|
||||
}
|
||||
|
||||
public static MythicItem getMythicById(int id) {
|
||||
if (plugin == null) {
|
||||
logger.warning("MythicItem plugin reference is null; cannot load mythics by id.");
|
||||
return new MythicItem();
|
||||
}
|
||||
|
||||
File mythicDirectory = new File(plugin.getDataFolder(), MYTHIC_DIR);
|
||||
if (!mythicDirectory.exists() || !mythicDirectory.isDirectory()) {
|
||||
logger.warning("Mythic directory does not exist: " + mythicDirectory.getPath());
|
||||
return new MythicItem();
|
||||
}
|
||||
|
||||
File[] mythicJsons = mythicDirectory.listFiles((dir, name) -> name.toLowerCase().endsWith(".json"));
|
||||
if (mythicJsons == null) {
|
||||
return new MythicItem();
|
||||
}
|
||||
|
||||
for (File mythicJson : mythicJsons) {
|
||||
String jsonContent;
|
||||
try {
|
||||
jsonContent = new Scanner(mythicJson).useDelimiter("\\Z").next();
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.warning("Failed to read mythic file " + mythicJson.getName() + ": " + e.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject(jsonContent);
|
||||
if (json.has("mythic_id") && json.getInt("mythic_id") == id) {
|
||||
return new MythicItem(json);
|
||||
}
|
||||
}
|
||||
|
||||
logger.warning("No mythic found with id " + id + "; returning default MythicItem.");
|
||||
return new MythicItem();
|
||||
}
|
||||
|
||||
public static int getMythicId(ItemStack item) {
|
||||
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
||||
|
||||
return itemData.get(Constants.mythic_key, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
public static boolean isMythic(ItemStack item) {
|
||||
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
||||
|
||||
return itemData.has(Constants.mythic_key);
|
||||
}
|
||||
|
||||
protected void setMythicId(int id) {
|
||||
ItemMeta itemData = item.getItemMeta();
|
||||
itemData.getPersistentDataContainer().set(Constants.mythic_key, PersistentDataType.INTEGER, id);
|
||||
this.item.setItemMeta(itemData);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user