diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7eca3b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.gradle/ +target/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6bb8a29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..628a9f5 --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +mvn package \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..780f0ab --- /dev/null +++ b/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + pw.kaboom + Weapons + 1.0.0 + + + 7 + 7 + + + + + com.destroystokyo.paper + paper-api + 1.12.2-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot + 1.12.2-R0.1-SNAPSHOT + + + + + + destroystokyo-repo + https://repo.destroystokyo.com/repository/maven-public/ + + + + + ${project.artifactId} + + + src/main/resources + true + + + + + diff --git a/src/main/java/pw/kaboom/weapons/Main.java b/src/main/java/pw/kaboom/weapons/Main.java new file mode 100644 index 0000000..b89087b --- /dev/null +++ b/src/main/java/pw/kaboom/weapons/Main.java @@ -0,0 +1,133 @@ +package pw.kaboom.weapons; + +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import org.bukkit.material.MaterialData; + +import org.bukkit.plugin.java.JavaPlugin; + +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Main extends JavaPlugin implements Listener { + public void onEnable() { + this.getCommand("weapons").setExecutor(new CommandWeapons()); + this.getServer().getPluginManager().registerEvents(this, this); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + Player player = (Player) event.getWhoClicked(); + ItemStack clickedItem = event.getCurrentItem(); + String name = clickedItem.getItemMeta().getDisplayName().toLowerCase(); + + if (event.getInventory().getName() == "Weapons") { + if (clickedItem != null) { + player.getInventory().addItem(clickedItem); + player.closeInventory(); + player.sendMessage("You have received the " + name + "!"); + } + } + } + + @EventHandler + void onPlayerInteract(PlayerInteractEvent event) { + Action action = event.getAction(); + Player player = event.getPlayer(); + boolean hasName = event.getItem().getItemMeta().hasDisplayName(); + Material item = event.getMaterial(); + String name = event.getItem().getItemMeta().getDisplayName(); + Location lookPos = player.getTargetBlock((Set) null, 100).getLocation(); + Location playerPos = player.getLocation(); + World world = player.getLocation().getWorld(); + + if (hasName == true) { + if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) { + if (item == Material.ANVIL && name == "Anvil Dropper") { + for (int x = -2; x <= 2; x += 1) { + for (int z = -2; z <= 2; z += 1) { + Location blockPos = new Location(world, playerPos.getX() - x, playerPos.getY(), playerPos.getZ() - z); + MaterialData blockMaterial = new MaterialData(Material.ANVIL); + world.spawnFallingBlock(blockPos, blockMaterial); + } + } + event.setCancelled(true); + } else if (item == Material.STICK && name == "Lightning Stick") { + world.strikeLightning(lookPos); + event.setCancelled(true); + } else if (item == Material.BLAZE_ROD && name == "Nuker") { + Projectile projectile = (Projectile) world.spawnEntity(playerPos, EntityType.FIREBALL); + projectile.setShooter(player); + projectile.setVelocity(playerPos.getDirection().multiply(6)); + world.createExplosion(lookPos, 6); + world.playSound(playerPos, Sound.ENTITY_GHAST_SHOOT, 0.9F, 1.5F); + world.playSound(playerPos, Sound.ENTITY_BAT_TAKEOFF, 0.8F, 2.0F); + event.setCancelled(true); + } else if (item == Material.IRON_BARDING && name == "Sniper") { + Location projectilePos = new Location(world, playerPos.getX(), playerPos.getY() + 1.5, playerPos.getZ()); + Projectile projectile = (Projectile) world.spawnEntity(projectilePos, EntityType.SNOWBALL); + projectile.setShooter(player); + projectile.setVelocity(playerPos.getDirection().multiply(6)); + world.playSound(playerPos, Sound.BLOCK_PISTON_CONTRACT, 1.0F, 63.0F); + event.setCancelled(true); + } + } else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { + if (item == Material.IRON_BARDING && name == "Sniper") { + if (player.hasPotionEffect(PotionEffectType.SLOW)) { + player.removePotionEffect(PotionEffectType.SLOW); + } else { + PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 90000, 7); + player.addPotionEffect(effect); + } + event.setCancelled(true); + } + } + } + } +} + +class CommandWeapons implements CommandExecutor { + private void addWeapon(Inventory inventory, Material material, String name) { + ItemStack item = new ItemStack​(material, 1); + ItemMeta itemMeta = item.getItemMeta(); + itemMeta.setDisplayName(name); + item.setItemMeta(itemMeta); + inventory.addItem(item); + } + + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player)sender; + Inventory inventory = Bukkit.createInventory(null, 9, "Weapons"); + addWeapon(inventory, Material.ANVIL, "Anvil Dropper"); + addWeapon(inventory, Material.STICK, "Lightning Stick"); + addWeapon(inventory, Material.BLAZE_ROD, "Nuker"); + addWeapon(inventory, Material.IRON_BARDING, "Sniper"); + player.openInventory(inventory); + return true; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..2e8508c --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: Weapons +main: pw.kaboom.weapons.Main +description: Plugin that adds weapons. +version: ${project.version} + +commands: + weapons: + aliases: weapon + description: Gives you a weapon + usage: /weapons + permission: weapons.command