From 9139dd49cb8a133103cd3f3ddcff1070d2298d4e Mon Sep 17 00:00:00 2001 From: xoy Date: Fri, 21 Jun 2024 17:39:50 +0200 Subject: [PATCH] First commit --- .gitignore | 3 + ideas/custom_items.txt | 1 + ideas/magic.txt | 2 + pom.xml | 71 +++++++++++++++++++ .../java/dev/xoy/xoyshowoff/XoyShowOff.java | 31 ++++++++ .../commands/GiveSandArrowCommand.java | 26 +++++++ .../commands/GiveSandGunCommand.java | 22 ++++++ .../java/dev/xoy/xoyshowoff/items/Keys.java | 9 +++ .../dev/xoy/xoyshowoff/items/SandArrow.java | 18 +++++ .../dev/xoy/xoyshowoff/items/SandGun.java | 22 ++++++ .../xoy/xoyshowoff/items/SandGunListener.java | 54 ++++++++++++++ src/main/resources/plugin.yml | 11 +++ xoyShowOff.iml | 14 ++++ 13 files changed, 284 insertions(+) create mode 100644 .gitignore create mode 100644 ideas/custom_items.txt create mode 100644 ideas/magic.txt create mode 100644 pom.xml create mode 100644 src/main/java/dev/xoy/xoyshowoff/XoyShowOff.java create mode 100644 src/main/java/dev/xoy/xoyshowoff/commands/GiveSandArrowCommand.java create mode 100644 src/main/java/dev/xoy/xoyshowoff/commands/GiveSandGunCommand.java create mode 100644 src/main/java/dev/xoy/xoyshowoff/items/Keys.java create mode 100644 src/main/java/dev/xoy/xoyshowoff/items/SandArrow.java create mode 100644 src/main/java/dev/xoy/xoyshowoff/items/SandGun.java create mode 100644 src/main/java/dev/xoy/xoyshowoff/items/SandGunListener.java create mode 100644 src/main/resources/plugin.yml create mode 100644 xoyShowOff.iml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7e04b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target +out +.idea diff --git a/ideas/custom_items.txt b/ideas/custom_items.txt new file mode 100644 index 0000000..41990db --- /dev/null +++ b/ideas/custom_items.txt @@ -0,0 +1 @@ +Sand gun - Gun shooting sand \ No newline at end of file diff --git a/ideas/magic.txt b/ideas/magic.txt new file mode 100644 index 0000000..28351b0 --- /dev/null +++ b/ideas/magic.txt @@ -0,0 +1,2 @@ +damage shield - sphere particles as a damage shield +particle tail - particle tail following the player \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5033a42 --- /dev/null +++ b/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + dev.xoy + xoyShowOff + 1.0-SNAPSHOT + jar + + xoy Show Off + + + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + + + src/main/resources + true + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + io.papermc.paper + paper-api + 1.20.6-R0.1-SNAPSHOT + provided + + + diff --git a/src/main/java/dev/xoy/xoyshowoff/XoyShowOff.java b/src/main/java/dev/xoy/xoyshowoff/XoyShowOff.java new file mode 100644 index 0000000..9c72ddf --- /dev/null +++ b/src/main/java/dev/xoy/xoyshowoff/XoyShowOff.java @@ -0,0 +1,31 @@ +package dev.xoy.xoyshowoff; + +import dev.xoy.xoyshowoff.commands.GiveSandArrowCommand; +import dev.xoy.xoyshowoff.commands.GiveSandGunCommand; +import dev.xoy.xoyshowoff.items.SandGunListener; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.Objects; +import java.util.logging.Logger; + +public final class XoyShowOff extends JavaPlugin { + + public static final Logger LOGGER = Logger.getLogger("xoyShowOff"); + + @Override + public void onEnable() { + LOGGER.info("xoyShowOff is now enabled!"); + getServer().getPluginManager().registerEvents(new SandGunListener(), this); + getCommand("givesandgun").setExecutor(new GiveSandGunCommand()); + getCommand("givesandarrow").setExecutor(new GiveSandArrowCommand()); + } + + @Override + public void onDisable() { + LOGGER.info("xoyShowOff is now disabled!"); + } + + public static XoyShowOff getInstance() { + return getPlugin(XoyShowOff.class); + } +} diff --git a/src/main/java/dev/xoy/xoyshowoff/commands/GiveSandArrowCommand.java b/src/main/java/dev/xoy/xoyshowoff/commands/GiveSandArrowCommand.java new file mode 100644 index 0000000..6a0acbc --- /dev/null +++ b/src/main/java/dev/xoy/xoyshowoff/commands/GiveSandArrowCommand.java @@ -0,0 +1,26 @@ +package dev.xoy.xoyshowoff.commands; + +import dev.xoy.xoyshowoff.items.SandArrow; +import dev.xoy.xoyshowoff.items.SandGun; +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 org.jetbrains.annotations.NotNull; + +public class GiveSandArrowCommand implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + ItemStack stack = new SandArrow(); + stack.setAmount(16); + player.getInventory().addItem(stack); + return true; + } else { + sender.sendMessage("This command can only be used by a player."); + return false; + } + } +} diff --git a/src/main/java/dev/xoy/xoyshowoff/commands/GiveSandGunCommand.java b/src/main/java/dev/xoy/xoyshowoff/commands/GiveSandGunCommand.java new file mode 100644 index 0000000..d94abb7 --- /dev/null +++ b/src/main/java/dev/xoy/xoyshowoff/commands/GiveSandGunCommand.java @@ -0,0 +1,22 @@ +package dev.xoy.xoyshowoff.commands; + +import dev.xoy.xoyshowoff.items.SandGun; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class GiveSandGunCommand implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + player.getInventory().addItem(new SandGun()); + return true; + } else { + sender.sendMessage("This command can only be used by a player."); + return false; + } + } +} diff --git a/src/main/java/dev/xoy/xoyshowoff/items/Keys.java b/src/main/java/dev/xoy/xoyshowoff/items/Keys.java new file mode 100644 index 0000000..54ef965 --- /dev/null +++ b/src/main/java/dev/xoy/xoyshowoff/items/Keys.java @@ -0,0 +1,9 @@ +package dev.xoy.xoyshowoff.items; + +import dev.xoy.xoyshowoff.XoyShowOff; +import org.bukkit.NamespacedKey; + +public class Keys { + public static final NamespacedKey SANDGUN = new NamespacedKey(XoyShowOff.getInstance(), "SandGun"); + public static final NamespacedKey SANDARROW = new NamespacedKey(XoyShowOff.getInstance(), "SandArrow"); +} diff --git a/src/main/java/dev/xoy/xoyshowoff/items/SandArrow.java b/src/main/java/dev/xoy/xoyshowoff/items/SandArrow.java new file mode 100644 index 0000000..d7f89e9 --- /dev/null +++ b/src/main/java/dev/xoy/xoyshowoff/items/SandArrow.java @@ -0,0 +1,18 @@ +package dev.xoy.xoyshowoff.items; + +import net.kyori.adventure.text.Component; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; + +public class SandArrow extends ItemStack { + public SandArrow() { + super(Material.ARROW); + ItemMeta meta = getItemMeta(); + meta.displayName(Component.text("Sand Arrow")); + meta.setMaxStackSize(16); + meta.getPersistentDataContainer().set(Keys.SANDARROW, PersistentDataType.BOOLEAN, true); + setItemMeta(meta); + } +} diff --git a/src/main/java/dev/xoy/xoyshowoff/items/SandGun.java b/src/main/java/dev/xoy/xoyshowoff/items/SandGun.java new file mode 100644 index 0000000..40c71dd --- /dev/null +++ b/src/main/java/dev/xoy/xoyshowoff/items/SandGun.java @@ -0,0 +1,22 @@ +package dev.xoy.xoyshowoff.items; + +import net.kyori.adventure.text.Component; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.util.Vector; + +public class SandGun extends ItemStack{ + + public SandGun() { + super(Material.BOW); + ItemMeta meta = getItemMeta(); + meta.displayName(Component.text("Sand Gun")); + meta.getPersistentDataContainer().set(Keys.SANDGUN, PersistentDataType.BOOLEAN, true); + setItemMeta(meta); + } +} diff --git a/src/main/java/dev/xoy/xoyshowoff/items/SandGunListener.java b/src/main/java/dev/xoy/xoyshowoff/items/SandGunListener.java new file mode 100644 index 0000000..b62e0bf --- /dev/null +++ b/src/main/java/dev/xoy/xoyshowoff/items/SandGunListener.java @@ -0,0 +1,54 @@ +package dev.xoy.xoyshowoff.items; + +import dev.xoy.xoyshowoff.XoyShowOff; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.util.Vector; + +public class SandGunListener implements Listener { + private ItemStack inventoryContainsItemStackWithKey(Player player, NamespacedKey key) { + PlayerInventory inventory = player.getInventory(); + for(ItemStack stack : inventory.getContents()) { + if(stack != null && stack.getItemMeta() != null && + stack.getItemMeta().getPersistentDataContainer().has(key)) return stack; + } + return null; + } + + public FallingBlock spawnSandEntityWithVelocity(Location location, Vector velocity) { + FallingBlock sand = (FallingBlock) location.getWorld().spawnEntity(location, EntityType.FALLING_BLOCK); + sand.setBlockData(Material.SAND.createBlockData()); + sand.setVelocity(velocity); + + return sand; + } + + @EventHandler + public void onEntityShootBow(EntityShootBowEvent event) { + XoyShowOff.LOGGER.info("onEntityShootBow"); + if(event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + ItemStack bow = event.getBow(); + if(bow != null && bow.getItemMeta() != null && bow.getItemMeta().getPersistentDataContainer().has(Keys.SANDGUN)) { + XoyShowOff.LOGGER.info("isSandGun"); + ItemStack ammo = inventoryContainsItemStackWithKey(player, Keys.SANDARROW); + if(ammo != null) { + //ammo.setAmount(ammo.getAmount() - 1); + Vector velocity = player.getEyeLocation().getDirection(); + FallingBlock sand = spawnSandEntityWithVelocity(player.getEyeLocation(), velocity); + XoyShowOff.LOGGER.info("Spawned: " + sand.getName()); + } + event.setCancelled(true); + } + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..94b2f0c --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: xoyShowOff +version: '${project.version}' +main: dev.xoy.xoyshowoff.XoyShowOff +api-version: '1.20' +commands: + givesandgun: + description: Gives the player a Sand Gun. + usage: /givesandgun + givesandarrow: + description: Gives the player a stack Sand Arrows. + usage: /givesandarrow \ No newline at end of file diff --git a/xoyShowOff.iml b/xoyShowOff.iml new file mode 100644 index 0000000..bbeeb3e --- /dev/null +++ b/xoyShowOff.iml @@ -0,0 +1,14 @@ + + + + + + + PAPER + ADVENTURE + + 1 + + + + \ No newline at end of file