From c4fbbf9a3494a792d4f3596f6dca2bc1c33c1f69 Mon Sep 17 00:00:00 2001 From: k3y0708 Date: Mon, 31 Mar 2025 01:49:33 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Add=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/example/firstplugin/BootLocker.java | 39 +++++++++++++++ .../java/org/example/firstplugin/Main.java | 48 ++++++++++++++++--- .../org/example/firstplugin/items/Test.java | 4 ++ .../items/{ => boots}/AbstractBoots.java | 4 +- .../items/{ => boots}/MagmaBoots.java | 2 +- .../items/{ => boots}/SpongeBoots.java | 5 +- .../items/{ => boots}/WaterBoots.java | 3 +- .../items/{ => boots}/WetSpongeBoots.java | 4 +- src/main/resources/plugin.yml | 7 +++ 9 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/example/firstplugin/BootLocker.java create mode 100644 src/main/java/org/example/firstplugin/items/Test.java rename src/main/java/org/example/firstplugin/items/{ => boots}/AbstractBoots.java (96%) rename src/main/java/org/example/firstplugin/items/{ => boots}/MagmaBoots.java (96%) rename src/main/java/org/example/firstplugin/items/{ => boots}/SpongeBoots.java (93%) rename src/main/java/org/example/firstplugin/items/{ => boots}/WaterBoots.java (91%) rename src/main/java/org/example/firstplugin/items/{ => boots}/WetSpongeBoots.java (90%) diff --git a/src/main/java/org/example/firstplugin/BootLocker.java b/src/main/java/org/example/firstplugin/BootLocker.java new file mode 100644 index 0000000..b06636f --- /dev/null +++ b/src/main/java/org/example/firstplugin/BootLocker.java @@ -0,0 +1,39 @@ +package org.example.firstplugin; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.NotNull; + +public class BootLocker implements CommandExecutor { + + public void onPlayerInteractEntity(PlayerInteractEntityEvent e) { + Player p = e.getPlayer(); + if(e.getRightClicked() instanceof Villager v) { + if(v.getCustomName().equalsIgnoreCase("Boot Locker")) { + //Do something + //For example open an Inventory + Inventory inv = Bukkit.createInventory(null, 27, "Boot Locker"); + + Main.getBoots().forEach(boot -> inv.addItem(boot.getBoots())); + + p.openInventory(inv); + } + } + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + // Spawn a villager + Player player = (Player) sender; + Villager villager = player.getWorld().spawn(player.getLocation(), Villager.class); + villager.setCustomName("Boot Locker"); + villager.setCustomNameVisible(true); + return true; + } +} diff --git a/src/main/java/org/example/firstplugin/Main.java b/src/main/java/org/example/firstplugin/Main.java index 43a1fca..676eb92 100644 --- a/src/main/java/org/example/firstplugin/Main.java +++ b/src/main/java/org/example/firstplugin/Main.java @@ -2,16 +2,25 @@ package org.example.firstplugin; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MerchantRecipe; import org.bukkit.plugin.java.JavaPlugin; -import org.example.firstplugin.items.AbstractBoots; -import org.example.firstplugin.items.MagmaBoots; -import org.example.firstplugin.items.SpongeBoots; -import org.example.firstplugin.items.WaterBoots; -import org.example.firstplugin.items.WetSpongeBoots; +import org.example.firstplugin.items.boots.AbstractBoots; +import org.example.firstplugin.items.boots.MagmaBoots; +import org.example.firstplugin.items.boots.SpongeBoots; +import org.example.firstplugin.items.boots.WaterBoots; +import org.example.firstplugin.items.boots.WetSpongeBoots; import java.util.ArrayList; import java.util.List; @@ -27,6 +36,9 @@ public class Main extends JavaPlugin implements Listener { Objects.requireNonNull(this.getCommand(boot.getCommandName())).setExecutor(boot); Bukkit.addRecipe(boot.getRecipe()); } + + BootLocker bootLocker = new BootLocker(); + Objects.requireNonNull(this.getCommand("bootlocker")).setExecutor(bootLocker); } @EventHandler @@ -42,7 +54,13 @@ public class Main extends JavaPlugin implements Listener { } } - private List getBoots() { + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + BootLocker bootLocker = new BootLocker(); + //bootLocker.onPlayerInteractEntity(event); + } + + public static List getBoots() { List boots = new ArrayList<>(); boots.add(new WaterBoots()); boots.add(new MagmaBoots()); @@ -50,4 +68,22 @@ public class Main extends JavaPlugin implements Listener { boots.add(new WetSpongeBoots()); return boots; } + + @EventHandler + public void onArmorStand(PlayerArmorStandManipulateEvent event) { + ArmorStand armorstand = event.getRightClicked(); + Villager villager = armorstand.getWorld().spawn(armorstand.getLocation(), Villager.class); + villager.setCustomName("Boot Locker"); + villager.setCustomNameVisible(true); + + // Add trades + List trades = new ArrayList<>(); + MerchantRecipe recipe = new MerchantRecipe(new MagmaBoots().getBoots(), Integer.MAX_VALUE); + recipe.addIngredient(new ItemStack(Material.MAGMA_BLOCK, 4)); + recipe.addIngredient(new ItemStack(Material.EMERALD, 3)); + trades.add(recipe); + villager.setRecipes(trades); + + armorstand.remove(); + } } diff --git a/src/main/java/org/example/firstplugin/items/Test.java b/src/main/java/org/example/firstplugin/items/Test.java new file mode 100644 index 0000000..85c2cf6 --- /dev/null +++ b/src/main/java/org/example/firstplugin/items/Test.java @@ -0,0 +1,4 @@ +package org.example.firstplugin.items; + +public class Test { +} diff --git a/src/main/java/org/example/firstplugin/items/AbstractBoots.java b/src/main/java/org/example/firstplugin/items/boots/AbstractBoots.java similarity index 96% rename from src/main/java/org/example/firstplugin/items/AbstractBoots.java rename to src/main/java/org/example/firstplugin/items/boots/AbstractBoots.java index c5605d9..968c15a 100644 --- a/src/main/java/org/example/firstplugin/items/AbstractBoots.java +++ b/src/main/java/org/example/firstplugin/items/boots/AbstractBoots.java @@ -1,4 +1,4 @@ -package org.example.firstplugin.items; +package org.example.firstplugin.items.boots; import org.bukkit.GameMode; import org.bukkit.Location; @@ -19,7 +19,7 @@ import javax.annotation.Nonnull; import java.util.Collections; import java.util.Map; -public abstract class AbstractBoots implements CommandExecutor { + public abstract class AbstractBoots implements CommandExecutor { public abstract ItemStack getBoots(); public abstract String getCommandName(); public abstract Recipe getRecipe(); diff --git a/src/main/java/org/example/firstplugin/items/MagmaBoots.java b/src/main/java/org/example/firstplugin/items/boots/MagmaBoots.java similarity index 96% rename from src/main/java/org/example/firstplugin/items/MagmaBoots.java rename to src/main/java/org/example/firstplugin/items/boots/MagmaBoots.java index 3281641..3b26c8b 100644 --- a/src/main/java/org/example/firstplugin/items/MagmaBoots.java +++ b/src/main/java/org/example/firstplugin/items/boots/MagmaBoots.java @@ -1,4 +1,4 @@ -package org.example.firstplugin.items; +package org.example.firstplugin.items.boots; import net.kyori.adventure.text.Component; import org.bukkit.Color; diff --git a/src/main/java/org/example/firstplugin/items/SpongeBoots.java b/src/main/java/org/example/firstplugin/items/boots/SpongeBoots.java similarity index 93% rename from src/main/java/org/example/firstplugin/items/SpongeBoots.java rename to src/main/java/org/example/firstplugin/items/boots/SpongeBoots.java index 984ed82..2639dcd 100644 --- a/src/main/java/org/example/firstplugin/items/SpongeBoots.java +++ b/src/main/java/org/example/firstplugin/items/boots/SpongeBoots.java @@ -1,4 +1,4 @@ -package org.example.firstplugin.items; +package org.example.firstplugin.items.boots; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; @@ -47,6 +47,9 @@ public class SpongeBoots extends AbstractBoots { @Override protected void onReplaceUnderPlayer(Player player, Material oldBlockUnderPlayer, Material newBlockUnderPlayer) { + // Make a sponge absorb water when the player is wearing sponge boots + + ItemMeta meta = player.getInventory().getBoots().getItemMeta(); meta.displayName(WET_SPONGEBOOTS_NAME); player.getInventory().getBoots().setItemMeta(meta); diff --git a/src/main/java/org/example/firstplugin/items/WaterBoots.java b/src/main/java/org/example/firstplugin/items/boots/WaterBoots.java similarity index 91% rename from src/main/java/org/example/firstplugin/items/WaterBoots.java rename to src/main/java/org/example/firstplugin/items/boots/WaterBoots.java index 69b59c5..acee1a8 100644 --- a/src/main/java/org/example/firstplugin/items/WaterBoots.java +++ b/src/main/java/org/example/firstplugin/items/boots/WaterBoots.java @@ -1,4 +1,4 @@ -package org.example.firstplugin.items; +package org.example.firstplugin.items.boots; import net.kyori.adventure.text.Component; import org.bukkit.Color; @@ -6,6 +6,7 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.example.firstplugin.items.boots.AbstractBoots; import java.util.Map; import java.util.TreeMap; diff --git a/src/main/java/org/example/firstplugin/items/WetSpongeBoots.java b/src/main/java/org/example/firstplugin/items/boots/WetSpongeBoots.java similarity index 90% rename from src/main/java/org/example/firstplugin/items/WetSpongeBoots.java rename to src/main/java/org/example/firstplugin/items/boots/WetSpongeBoots.java index a59fb5b..98cd4ac 100644 --- a/src/main/java/org/example/firstplugin/items/WetSpongeBoots.java +++ b/src/main/java/org/example/firstplugin/items/boots/WetSpongeBoots.java @@ -1,4 +1,4 @@ -package org.example.firstplugin.items; +package org.example.firstplugin.items.boots; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -6,6 +6,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.example.firstplugin.items.boots.AbstractBoots; +import org.example.firstplugin.items.boots.SpongeBoots; import java.util.Map; import java.util.TreeMap; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4c4aa79..fa47ce3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,6 +25,10 @@ commands: description: Gives you wet sponge boots usage: / permission: firstplugin.wetspongeboots + bootlocker: + description: Spwans a boot locker employee + usage: / + permission: firstplugin.bootlocker permissions: firstplugin.waterboots: @@ -39,3 +43,6 @@ permissions: firstplugin.wetspongeboots: description: Allows you to use the wetspongeboots command default: op + firstplugin.bootlocker: + description: Allows you to use the bootlocker command + default: op