mirror of
https://github.com/SimplexDevelopment/StrikePlugin.git
synced 2024-12-22 08:57:37 +00:00
Explosion Fix
This commit is contained in:
parent
b43bf0f8a1
commit
e0ff352821
@ -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<Integer, NPC> 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 <npc-id> - " + 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<Integer, NPC> getNpcMap() {
|
||||
return npcMap;
|
||||
}
|
||||
|
@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
@ -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<String, Object> 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<Location, Integer> getMap() {
|
||||
HashMap<Location, Integer> map = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, Object> 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));
|
||||
}
|
||||
}
|
@ -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<Player, List<Player>> entry : map.entrySet()) {
|
||||
|
||||
if (entry.getValue().contains(player)) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<Inventory> 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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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<Location, Integer> 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<BukkitTask> 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() {
|
||||
|
||||
}
|
||||
}
|
@ -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")));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ name: Strike
|
||||
version: @version@
|
||||
main: io.github.simplexdev.strike.StrikePlugin
|
||||
api-version: 1.16
|
||||
depend:
|
||||
- ProtocolLib
|
||||
commands:
|
||||
strike:
|
||||
usage: <command>
|
||||
|
Loading…
Reference in New Issue
Block a user