Working on upgrade item
This commit is contained in:
@@ -4,6 +4,7 @@ import io.github.itzispyder.pdk.PDK;
|
|||||||
import io.github.itzispyder.pdk.utils.SchedulerUtils;
|
import io.github.itzispyder.pdk.utils.SchedulerUtils;
|
||||||
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
|
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
|
||||||
import io.github.thetrouper.sssbliss.cmds.*;
|
import io.github.thetrouper.sssbliss.cmds.*;
|
||||||
|
import io.github.thetrouper.sssbliss.server.crafting.UpgradeItem;
|
||||||
import io.github.thetrouper.sssbliss.data.config.*;
|
import io.github.thetrouper.sssbliss.data.config.*;
|
||||||
import io.github.thetrouper.sssbliss.events.*;
|
import io.github.thetrouper.sssbliss.events.*;
|
||||||
import io.github.thetrouper.sssbliss.server.functions.GemPassiveEffects;
|
import io.github.thetrouper.sssbliss.server.functions.GemPassiveEffects;
|
||||||
@@ -51,7 +52,8 @@ public final class SSSBliss extends JavaPlugin {
|
|||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
log.info("Starting Up! (" + getDescription().getVersion() + ")...");
|
log.info("Starting Up! (" + getDescription().getVersion() + ")...");
|
||||||
|
|
||||||
// Enable Functions
|
// Recipes
|
||||||
|
UpgradeItem.addUpgradeRecipe();
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
new SSSBlissCommand().register();
|
new SSSBlissCommand().register();
|
||||||
@@ -63,7 +65,6 @@ public final class SSSBliss extends JavaPlugin {
|
|||||||
new DeathListener().register();
|
new DeathListener().register();
|
||||||
//new GemMoveListener().register();
|
//new GemMoveListener().register();
|
||||||
|
|
||||||
|
|
||||||
// Scheduled timers
|
// Scheduled timers
|
||||||
SchedulerUtils.repeat(100, GemPassiveEffects::applyPassiveEffects);
|
SchedulerUtils.repeat(100, GemPassiveEffects::applyPassiveEffects);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package io.github.thetrouper.sssbliss.events;
|
||||||
|
|
||||||
|
import io.github.itzispyder.pdk.events.CustomListener;
|
||||||
|
import io.github.thetrouper.sssbliss.server.crafting.UpgradeItem;
|
||||||
|
import io.github.thetrouper.sssbliss.server.util.GemUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public class UpgradeListener implements CustomListener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onUpgrade(PlayerInteractEvent e) {
|
||||||
|
if (!e.getAction().isRightClick() || !e.getItem().isSimilar(UpgradeItem.UPGRADE_ITEM)) return;
|
||||||
|
if (GemUtils.hasGem(e.getPlayer()).upgrade() == null) return;
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
p.getInventory().removeItem(UpgradeItem.UPGRADE_ITEM);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.thetrouper.sssbliss.server.crafting;
|
||||||
|
|
||||||
|
import io.github.itzispyder.pdk.Global;
|
||||||
|
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
|
||||||
|
import io.github.thetrouper.sssbliss.SSSBliss;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
|
|
||||||
|
public class UpgradeItem {
|
||||||
|
|
||||||
|
public static final ItemStack UPGRADE_ITEM = ItemBuilder.create()
|
||||||
|
.material(Material.HEART_OF_THE_SEA)
|
||||||
|
.name(Global.instance.color("&bGem Upgrade"))
|
||||||
|
.lore(Global.instance.color("&7Right click to upgrade your gem!"))
|
||||||
|
.enchant(Enchantment.LURE,1)
|
||||||
|
.flag(ItemFlag.HIDE_ENCHANTS)
|
||||||
|
.build();
|
||||||
|
public static void addUpgradeRecipe() {
|
||||||
|
// Create a NamespacedKey for your recipe (replace "your_plugin_name" with your actual plugin name)
|
||||||
|
NamespacedKey key = new NamespacedKey(SSSBliss.getInstance(), "custom_crafting_recipe");
|
||||||
|
|
||||||
|
// Create the recipe
|
||||||
|
ShapedRecipe recipe = new ShapedRecipe(key, UPGRADE_ITEM);
|
||||||
|
recipe.shape("ABC", "DEF", "GHI"); // Define the crafting grid
|
||||||
|
|
||||||
|
// Define the ingredients
|
||||||
|
recipe.setIngredient('A', Material.NETHERITE_INGOT);
|
||||||
|
recipe.setIngredient('B', Material.DIAMOND_BLOCK);
|
||||||
|
recipe.setIngredient('C', Material.NETHERITE_INGOT);
|
||||||
|
|
||||||
|
recipe.setIngredient('D', Material.DIAMOND_BLOCK);
|
||||||
|
recipe.setIngredient('E', Material.TRIDENT);
|
||||||
|
recipe.setIngredient('F', Material.DIAMOND_BLOCK);
|
||||||
|
|
||||||
|
recipe.setIngredient('G', Material.NETHERITE_INGOT);
|
||||||
|
recipe.setIngredient('H', Material.DIAMOND_BLOCK);
|
||||||
|
recipe.setIngredient('I', Material.NETHERITE_INGOT);
|
||||||
|
// Repeat for other letters in the grid
|
||||||
|
|
||||||
|
// Add the recipe to the server
|
||||||
|
SSSBliss.getInstance().getServer().addRecipe(recipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package io.github.thetrouper.sssbliss.server.util;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class PlayerUtils {
|
||||||
|
/**
|
||||||
|
* Removes a specified amount of a specific ItemStack from a player's inventory.
|
||||||
|
*
|
||||||
|
* @param player The player from whose inventory items will be removed.
|
||||||
|
* @param item The ItemStack to be removed.
|
||||||
|
* @param amount The amount of items to remove.
|
||||||
|
* @return {@code true} if the specified amount of items was successfully removed,
|
||||||
|
* {@code false} if the player does not have enough items.
|
||||||
|
*/
|
||||||
|
public static boolean removeItems(Player player, ItemStack item, int amount) {
|
||||||
|
Inventory inventory = player.getInventory();
|
||||||
|
|
||||||
|
int totalAmountToRemove = amount;
|
||||||
|
|
||||||
|
for (ItemStack stack : inventory.getContents()) {
|
||||||
|
if (stack != null && stack.isSimilar(item)) {
|
||||||
|
int stackAmount = stack.getAmount();
|
||||||
|
|
||||||
|
if (stackAmount <= totalAmountToRemove) {
|
||||||
|
totalAmountToRemove -= stackAmount;
|
||||||
|
inventory.removeItem(stack);
|
||||||
|
} else {
|
||||||
|
stack.setAmount(stackAmount - totalAmountToRemove);
|
||||||
|
totalAmountToRemove = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalAmountToRemove == 0) {
|
||||||
|
return true; // Successfully removed the items
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // Player didn't have enough items
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user