some refactors + better id setting
This commit is contained in:
1 parent
1f5a062416
commit
d897688ab4
9 files changed
+72
-29
No files matched your search
+2
-2
@@ -1,4 +1,4 @@
|
||||
package net.hexa.Plugin;
|
||||
package net.hexa.MythicItems;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.hexa.Plugin.Mythics.RockCracker;
|
||||
import net.hexa.MythicItems.Mythics.RockCracker;
|
||||
|
||||
public class CommandMythicEssence implements CommandExecutor {
|
||||
|
||||
+3
-2
@@ -1,12 +1,13 @@
|
||||
package net.hexa.Plugin;
|
||||
package net.hexa.MythicItems;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public class Plugin extends JavaPlugin {
|
||||
public class MythicItems extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("onEnable is called!");
|
||||
this.getCommand("essence").setExecutor(new CommandMythicEssence());
|
||||
getServer().getPluginManager().registerEvents(new MythicListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
+5
-7
@@ -1,13 +1,12 @@
|
||||
package net.hexa.Plugin;
|
||||
package net.hexa.MythicItems;
|
||||
|
||||
import net.hexa.MythicItems.Mythics.MythicItem;
|
||||
|
||||
import net.hexa.Plugin.Mythics.Constants;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class MythicListener implements Listener {
|
||||
|
||||
@@ -16,12 +15,11 @@ public class MythicListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
||||
|
||||
boolean isMythic = itemData.has(Constants.mythic_key);
|
||||
boolean isMythic = MythicItem.isMythic(item);
|
||||
|
||||
if (isMythic) {
|
||||
int mythic_id = itemData.get(Constants.mythic_key, PersistentDataType.INTEGER);
|
||||
int mythic_id = MythicItem.getMythicId(item);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package net.hexa.Plugin.Mythics;
|
||||
package net.hexa.MythicItems.Mythics;
|
||||
|
||||
import net.hexa.Plugin.Plugin;
|
||||
import net.hexa.MythicItems.MythicItems;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
public class Constants {
|
||||
public static NamespacedKey mythic_key = new NamespacedKey(new Plugin(), "mythic-id");
|
||||
public static NamespacedKey mythic_key = new NamespacedKey(new MythicItems(), "mythic-id");
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.hexa.MythicItems.Mythics;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public abstract class MythicItem {
|
||||
public ItemStack item;
|
||||
|
||||
public 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) {
|
||||
PersistentDataContainer itemData = item.getItemMeta().getPersistentDataContainer();
|
||||
itemData.set(Constants.mythic_key, PersistentDataType.INTEGER, id);
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,8 +1,6 @@
|
||||
package net.hexa.Plugin.Mythics;
|
||||
package net.hexa.MythicItems.Mythics;
|
||||
|
||||
import net.hexa.Plugin.Plugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
@@ -21,6 +19,6 @@ public class RockCracker extends MythicItem {
|
||||
item.getItemMeta().setLore(Arrays.asList("and the land thrashes in furious pain..."));
|
||||
item.getItemMeta().setEnchantable(0);
|
||||
|
||||
item.getItemMeta().getPersistentDataContainer().set(Constants.mythic_key, PersistentDataType.INTEGER, 1);
|
||||
setMythicId(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.hexa.MythicItems.Mythics;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Terra extends MythicItem {
|
||||
public Terra() {
|
||||
item = new ItemStack(Material.NETHERITE_SHOVEL);
|
||||
|
||||
item.addUnsafeEnchantment(Enchantment.EFFICIENCY, 8);
|
||||
item.addUnsafeEnchantment(Enchantment.UNBREAKING, 10);
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setUnbreakable(true);
|
||||
meta.setDisplayName("Terra");
|
||||
meta.setLore(Arrays.asList("All will eventually return to Terra."));
|
||||
meta.setEnchantable(0);
|
||||
|
||||
item.setItemMeta(meta);
|
||||
setMythicId(2);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package net.hexa.Plugin.Mythics;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class MythicItem {
|
||||
public ItemStack item;
|
||||
|
||||
public MythicItem() {}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
name: EconPlugin
|
||||
name: MythicItems
|
||||
version: 1.0
|
||||
main: net.hexa.Plugin.Plugin
|
||||
main: net.hexa.MythicItems.MythicItems
|
||||
api-version: '1.21.4'
|
||||
|
||||
commands:
|
||||
|
||||
Reference in new issue
Block a user