diff --git a/src/main/java/io/github/simplexdev/strike/StrikeCommand.java b/src/main/java/io/github/simplexdev/strike/StrikeCommand.java index 07262bb..7af0062 100644 --- a/src/main/java/io/github/simplexdev/strike/StrikeCommand.java +++ b/src/main/java/io/github/simplexdev/strike/StrikeCommand.java @@ -4,10 +4,13 @@ import com.github.juliarn.npc.NPC; import com.github.juliarn.npc.NPCPool; import com.github.juliarn.npc.profile.Profile; import io.github.simplexdev.strike.api.ConfigUser; -import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager; +import io.github.simplexdev.strike.api.utils.yml.manager.LaunchPad; +import io.github.simplexdev.strike.api.utils.yml.manager.InventoryEdit; import io.github.simplexdev.strike.listeners.InventoryEditGUI; +import io.github.simplexdev.strike.listeners.LaunchPadListener; import io.github.simplexdev.strike.listeners.SpawnController; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -20,6 +23,7 @@ import java.util.*; public class StrikeCommand implements CommandExecutor { private static Map npcMap = new HashMap<>(); + private static Location launchPad; private static ConfigUser[] configUsers; private final JavaPlugin plugin; @@ -37,8 +41,12 @@ public class StrikeCommand implements CommandExecutor { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args[0].isEmpty() || args.length > 1) { + helpCommand(sender); return true; } + if ("help".equalsIgnoreCase(args[0])) { + helpCommand(sender); + } if ("reload".equalsIgnoreCase(args[0])) { this.plugin.reloadConfig(); Arrays.stream(configUsers).forEach(configUser -> configUser.refresh()); @@ -48,7 +56,7 @@ public class StrikeCommand implements CommandExecutor { } else if ("get".equalsIgnoreCase(args[0]) && sender instanceof Player) { Player player = (Player) sender; - player.getInventory().setContents(new InventoryEditConfigManager(plugin).getInventoryItems(player)); + player.getInventory().setContents(new InventoryEdit(plugin).getInventoryItems(player)); } else if ("set-spawn".equalsIgnoreCase(args[0]) && sender instanceof Player) { Player player = ((Player) sender); new SpawnController(plugin).setSpawn(player.getLocation()); @@ -66,6 +74,7 @@ public class StrikeCommand implements CommandExecutor { } while (npcMap.containsKey(random)); + sender.sendMessage(ChatColor.GREEN + "NPC id: " + random + " was successfully created"); npcMap.put(random, npc); } @@ -86,10 +95,29 @@ public class StrikeCommand implements CommandExecutor { npcPool.removeNPC(npcMap.get(integer).getEntityId()); } + else if ("pad-create".equalsIgnoreCase(args[0]) && sender instanceof Player) { + Player player = (Player) sender; + + LaunchPadListener.locationMap.put(player.getLocation().getBlock().getLocation(), 1); + LaunchPad.addLocation(player.getLocation().getBlock().getLocation(), 1); + } return true; } + + private void helpCommand(CommandSender sender) { + sender.sendMessage( + ChatColor.GREEN + "/strike reload - " + ChatColor.YELLOW + "To load the config to the plugin\n" + + ChatColor.GREEN + "/strike edit - " + ChatColor.YELLOW + "To edit the player's spawn inventory\n" + + ChatColor.GREEN + "/strike get - " + ChatColor.YELLOW + "To get the items\n" + + ChatColor.GREEN + "/strike set-spawn - " + ChatColor.YELLOW + "To set the world and the location where the player spawns\n" + + ChatColor.GREEN + "/strike spawn-npc - " + ChatColor.YELLOW + "To spawn the npc that allows you to config your inventory\n" + + ChatColor.GREEN + "/strike remove-npc - " + ChatColor.YELLOW + "To remove the npc that allows you to config your inventory\n" + + ChatColor.GREEN + "/strike pad-create - " + ChatColor.YELLOW + "To add a launch pad on the block in on which you are standing on\n" + ); + } + public static Map getNpcMap() { return npcMap; } diff --git a/src/main/java/io/github/simplexdev/strike/StrikeCommandCompleter.java b/src/main/java/io/github/simplexdev/strike/StrikeCommandCompleter.java new file mode 100644 index 0000000..70dbfe1 --- /dev/null +++ b/src/main/java/io/github/simplexdev/strike/StrikeCommandCompleter.java @@ -0,0 +1,27 @@ +package io.github.simplexdev.strike; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import java.util.ArrayList; +import java.util.List; + +public class StrikeCommandCompleter implements TabCompleter { + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + + List strings = new ArrayList<>(); + + strings.add("get"); + strings.add("reload"); + strings.add("help"); + strings.add("edit"); + strings.add("set-spawn"); + strings.add("pad-create"); + strings.add("remove-npc"); + strings.add("spawn-npc"); + + return strings; + } +} diff --git a/src/main/java/io/github/simplexdev/strike/StrikePlugin.java b/src/main/java/io/github/simplexdev/strike/StrikePlugin.java index 72738c4..542e9d2 100644 --- a/src/main/java/io/github/simplexdev/strike/StrikePlugin.java +++ b/src/main/java/io/github/simplexdev/strike/StrikePlugin.java @@ -2,14 +2,11 @@ package io.github.simplexdev.strike; import io.github.simplexdev.strike.api.Spawn; import io.github.simplexdev.strike.listeners.*; +import org.bukkit.command.PluginCommand; import org.bukkit.plugin.java.JavaPlugin; public final class StrikePlugin extends JavaPlugin { - //TODO - // Custom Explosion - // NPC Edit - // LaunchPad @Override public void onEnable() { @@ -22,6 +19,7 @@ public final class StrikePlugin extends JavaPlugin { HealthPackage healthPackage = new HealthPackage(this); Grenade grenade = new Grenade(this); ItemManager itemManager = new ItemManager(this); + LaunchPadListener launchPad = new LaunchPadListener(this); getServer().getPluginManager().registerEvents(gun, this); getServer().getPluginManager().registerEvents(jumper, this); @@ -29,10 +27,13 @@ public final class StrikePlugin extends JavaPlugin { getServer().getPluginManager().registerEvents(healthPackage, this); getServer().getPluginManager().registerEvents(grenade, this); getServer().getPluginManager().registerEvents(itemManager, this); + getServer().getPluginManager().registerEvents(launchPad, this); getServer().getPluginManager().registerEvents(new InventoryEditGUI(this), this); - getCommand("strike").setExecutor(new StrikeCommand(this)); + PluginCommand command = getCommand("strike"); + command.setExecutor(new StrikeCommand(this)); + command.setTabCompleter(new StrikeCommandCompleter()); StrikeCommand.loadInstances(gun, jumper, spawnController, grenade, itemManager); } diff --git a/src/main/java/io/github/simplexdev/strike/api/utils/InventoryEditConfigManager.java b/src/main/java/io/github/simplexdev/strike/api/utils/yml/manager/InventoryEdit.java similarity index 95% rename from src/main/java/io/github/simplexdev/strike/api/utils/InventoryEditConfigManager.java rename to src/main/java/io/github/simplexdev/strike/api/utils/yml/manager/InventoryEdit.java index ac2005a..02abecf 100644 --- a/src/main/java/io/github/simplexdev/strike/api/utils/InventoryEditConfigManager.java +++ b/src/main/java/io/github/simplexdev/strike/api/utils/yml/manager/InventoryEdit.java @@ -1,4 +1,4 @@ -package io.github.simplexdev.strike.api.utils; +package io.github.simplexdev.strike.api.utils.yml.manager; import io.github.simplexdev.strike.listeners.Grenade; import io.github.simplexdev.strike.listeners.Gun; @@ -17,13 +17,13 @@ import java.io.IOException; import java.util.Arrays; import java.util.Set; -public class InventoryEditConfigManager { +public class InventoryEdit { private final JavaPlugin plugin; private final File dataFile; private FileConfiguration dataConfig; - public InventoryEditConfigManager(JavaPlugin plugin) { + public InventoryEdit(JavaPlugin plugin) { this.plugin = plugin; dataFile = new File("plugins\\Strike\\inventories.yml"); diff --git a/src/main/java/io/github/simplexdev/strike/api/utils/yml/manager/LaunchPad.java b/src/main/java/io/github/simplexdev/strike/api/utils/yml/manager/LaunchPad.java new file mode 100644 index 0000000..8196cac --- /dev/null +++ b/src/main/java/io/github/simplexdev/strike/api/utils/yml/manager/LaunchPad.java @@ -0,0 +1,84 @@ +package io.github.simplexdev.strike.api.utils.yml.manager; + +import io.github.simplexdev.strike.listeners.LaunchPadListener; +import org.bukkit.Location; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +public class LaunchPad { + + private static File ymlFile; + private static FileConfiguration ymlConfig; + + + public static void init(JavaPlugin plugin) { + + try { + + ymlFile = new File(plugin.getDataFolder().toString() + "\\launchPads.yml"); + + if (!ymlFile.exists()) { + ymlFile.getParentFile().mkdirs(); + ymlFile.createNewFile(); + } + + + ymlConfig = new YamlConfiguration(); + + ymlConfig.load(ymlFile); + + + } catch (IOException | InvalidConfigurationException e) { + e.printStackTrace(); + } + } + + public static int getID(Location location) { + for (Map.Entry entry : ymlConfig.getValues(false).entrySet()) { + if (!(entry.getValue() instanceof Location)) + continue; + + if (entry.getValue().equals(location)) + return Integer.parseInt(entry.getKey()); + } + + return 0; + } + + public static Map getMap() { + HashMap map = new HashMap<>(); + + for (Map.Entry entry : ymlConfig.getValues(false).entrySet()) { + if (entry.getValue() instanceof Location) + map.put((Location) entry.getValue(), Integer.parseInt(entry.getKey())); + } + + return map; + } + + public static void addLocation(Location location, int id) { + do { + id = new Random().nextInt(200000); + } + while (id == 0 || LaunchPadListener.locationMap.containsKey(id)); + + ymlConfig.set(String.valueOf(id), location); + try { + ymlConfig.save(ymlFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static Location getLocation(int id) { + return ymlConfig.getLocation(String.valueOf(id)); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/simplexdev/strike/listeners/Grenade.java b/src/main/java/io/github/simplexdev/strike/listeners/Grenade.java index 8067b2e..e1e579b 100644 --- a/src/main/java/io/github/simplexdev/strike/listeners/Grenade.java +++ b/src/main/java/io/github/simplexdev/strike/listeners/Grenade.java @@ -91,16 +91,19 @@ public class Grenade implements ConfigUser { items.add(item); } - @EventHandler private void onPlayerDamage(EntityDamageEvent e) { if (e.getCause() != EntityDamageEvent.DamageCause.BLOCK_EXPLOSION || !e.getEntity().getWorld().equals(Spawn.getWorld()) || !(e.getEntity() instanceof Player)) return; - Player player = (Player) e.getEntity();; + Player player = (Player) e.getEntity(); Player killer = null; + + int damageMultiplier = Math.round((long) (3 * (1/e.getDamage()))); + e.setDamage(e.getDamage() * (damageMultiplier == 0 ? 1 : damageMultiplier)); + for (Map.Entry> entry : map.entrySet()) { if (entry.getValue().contains(player)) { diff --git a/src/main/java/io/github/simplexdev/strike/listeners/Gun.java b/src/main/java/io/github/simplexdev/strike/listeners/Gun.java index bb4c0bf..d62e234 100644 --- a/src/main/java/io/github/simplexdev/strike/listeners/Gun.java +++ b/src/main/java/io/github/simplexdev/strike/listeners/Gun.java @@ -155,7 +155,7 @@ public class Gun implements ConfigUser { public void run() { delay.remove(player); } - }.runTaskLater(plugin, 2); + }.runTaskLater(plugin, 5); Entity entity = getEntity(player, player.getEyeLocation().clone(), 0.0D); @@ -169,6 +169,7 @@ public class Gun implements ConfigUser { if (currentHealth <= damageHealth) { Bukkit.getServer().getPluginManager().callEvent((Event) new GunKillEvent(player, livingEntity)); } + livingEntity.damage(damageHealth); } diff --git a/src/main/java/io/github/simplexdev/strike/listeners/InventoryEditGUI.java b/src/main/java/io/github/simplexdev/strike/listeners/InventoryEditGUI.java index 3d84509..9400bdb 100644 --- a/src/main/java/io/github/simplexdev/strike/listeners/InventoryEditGUI.java +++ b/src/main/java/io/github/simplexdev/strike/listeners/InventoryEditGUI.java @@ -2,7 +2,7 @@ package io.github.simplexdev.strike.listeners; import com.github.juliarn.npc.event.PlayerNPCInteractEvent; import io.github.simplexdev.strike.StrikeCommand; -import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager; +import io.github.simplexdev.strike.api.utils.yml.manager.InventoryEdit; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -19,11 +19,11 @@ import java.util.List; public class InventoryEditGUI implements Listener { private static List inventories = new ArrayList<>(); - private final InventoryEditConfigManager configManager; + private final InventoryEdit configManager; private final JavaPlugin plugin; public InventoryEditGUI(JavaPlugin plugin) { - configManager = new InventoryEditConfigManager(plugin); + configManager = new InventoryEdit(plugin); this.plugin = plugin; } diff --git a/src/main/java/io/github/simplexdev/strike/listeners/ItemManager.java b/src/main/java/io/github/simplexdev/strike/listeners/ItemManager.java index 5b25ca5..a9f5496 100644 --- a/src/main/java/io/github/simplexdev/strike/listeners/ItemManager.java +++ b/src/main/java/io/github/simplexdev/strike/listeners/ItemManager.java @@ -4,7 +4,7 @@ import io.github.simplexdev.strike.api.ConfigUser; import io.github.simplexdev.strike.api.Spawn; import io.github.simplexdev.strike.api.events.GrenadeKillEvent; import io.github.simplexdev.strike.api.events.GunKillEvent; -import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager; +import io.github.simplexdev.strike.api.utils.yml.manager.InventoryEdit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; @@ -46,7 +46,7 @@ public class ItemManager implements ConfigUser { } public void addItem(Player player) { - InventoryEditConfigManager configManager = new InventoryEditConfigManager(plugin); + InventoryEdit configManager = new InventoryEdit(plugin); setItem(player, grenade, configManager); setItem(player, healthPackage, configManager); @@ -54,17 +54,15 @@ public class ItemManager implements ConfigUser { player.updateInventory(); } - private void setItem(Player player, ItemStack itemStack, InventoryEditConfigManager configManager) { + private void setItem(Player player, ItemStack itemStack, InventoryEdit configManager) { PlayerInventory playerInventory = player.getInventory(); - if (!hasItem(playerInventory, itemStack)) { - int slot = configManager.getItemSlot(itemStack, player); + int slot = configManager.getItemSlot(itemStack, player); - if (playerInventory.getItem(slot) != null) - playerInventory.addItem(itemStack); - else - playerInventory.setItem(slot, itemStack); - } + if (playerInventory.getItem(slot) != null) + playerInventory.addItem(itemStack); + else + playerInventory.setItem(slot, itemStack); } private boolean hasItem(Inventory inventory, ItemStack itemStack) { diff --git a/src/main/java/io/github/simplexdev/strike/listeners/LaunchPadListener.java b/src/main/java/io/github/simplexdev/strike/listeners/LaunchPadListener.java new file mode 100644 index 0000000..95baeb1 --- /dev/null +++ b/src/main/java/io/github/simplexdev/strike/listeners/LaunchPadListener.java @@ -0,0 +1,64 @@ +package io.github.simplexdev.strike.listeners; + +import io.github.simplexdev.strike.api.ConfigUser; +import io.github.simplexdev.strike.api.utils.yml.manager.LaunchPad; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; + +import java.util.Map; +import java.util.Scanner; +import java.util.function.Consumer; + +public class LaunchPadListener implements ConfigUser { + + public static Map locationMap; + private final JavaPlugin plugin; + + public LaunchPadListener(JavaPlugin plugin) { + this.plugin = plugin; + LaunchPad.init(plugin); + locationMap = LaunchPad.getMap(); + } + + @EventHandler + private void onMove(PlayerMoveEvent e) { + Location location = e.getPlayer().getLocation().getBlock().getLocation()/*.clone().subtract(0, -1, 0)*/; + + if (!locationMap.containsKey(location)) + return; + + Player player = e.getPlayer(); + + ArmorStand armorStand = (ArmorStand) player.getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND); + + armorStand.setVisible(false); + armorStand.addPassenger(player); + armorStand.setVelocity(player.getEyeLocation().getDirection().multiply(4)); + + Consumer consumer = bukkitTask -> killDriver(armorStand, bukkitTask); + + Bukkit.getScheduler().runTaskTimer(plugin, consumer, 5, 5); + + } + + + private void killDriver(ArmorStand armorStand, BukkitTask task) { + if (!armorStand.isOnGround()) + return; + + armorStand.remove(); + task.cancel(); + } + + @Override + public void refresh() { + + } +} diff --git a/src/main/java/io/github/simplexdev/strike/listeners/SpawnController.java b/src/main/java/io/github/simplexdev/strike/listeners/SpawnController.java index 613ca26..9655f0e 100644 --- a/src/main/java/io/github/simplexdev/strike/listeners/SpawnController.java +++ b/src/main/java/io/github/simplexdev/strike/listeners/SpawnController.java @@ -2,7 +2,7 @@ package io.github.simplexdev.strike.listeners; import io.github.simplexdev.strike.api.ConfigUser; import io.github.simplexdev.strike.api.Spawn; -import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager; +import io.github.simplexdev.strike.api.utils.yml.manager.InventoryEdit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -59,7 +59,7 @@ public class SpawnController implements ConfigUser { Player player = e.getPlayer(); if (player.getWorld().equals(Spawn.getWorld())) { e.setRespawnLocation(Spawn.getSpawn()); - player.getInventory().setContents(new InventoryEditConfigManager(plugin).getInventoryItems(e.getPlayer())); + player.getInventory().setContents(new InventoryEdit(plugin).getInventoryItems(e.getPlayer())); player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("spawn.respawn-message"))); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 55060fd..5825b54 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,6 +2,8 @@ name: Strike version: @version@ main: io.github.simplexdev.strike.StrikePlugin api-version: 1.16 +depend: + - ProtocolLib commands: strike: usage: