mirror of
https://github.com/SimplexDevelopment/StrikePlugin.git
synced 2024-12-23 01:17:36 +00:00
Release 1.0
This commit is contained in:
parent
39f8c25db1
commit
c8e83cae42
@ -3,9 +3,12 @@ package io.github.simplexdev.strike;
|
||||
import io.github.simplexdev.strike.api.ConfigUser;
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager;
|
||||
import io.github.simplexdev.strike.listeners.InventoryEditGUI;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
@ -27,9 +30,19 @@ public class StrikeCommand implements CommandExecutor {
|
||||
if (args[0].isEmpty() || args.length > 1) {
|
||||
return true;
|
||||
}
|
||||
if ("reload".equals(args[0].toLowerCase())) {
|
||||
if ("reload".equalsIgnoreCase(args[0])) {
|
||||
this.plugin.reloadConfig();
|
||||
Arrays.<ConfigUser>stream(configUsers).forEach(configUser -> configUser.refresh());
|
||||
Arrays.stream(configUsers).forEach(configUser -> configUser.refresh());
|
||||
}
|
||||
|
||||
else if ("edit".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
new InventoryEditGUI(plugin).openInventory((Player) sender);
|
||||
}
|
||||
|
||||
else if ("get".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
player.getInventory().setContents(new InventoryEditConfigManager(plugin).getInventory(player));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,14 +1,21 @@
|
||||
package io.github.simplexdev.strike;
|
||||
|
||||
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.listeners.*;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public final class StrikePlugin extends JavaPlugin {
|
||||
//TODO
|
||||
// Full Ammo after dead
|
||||
// Fall Damage Disable
|
||||
// Health Pack head not working
|
||||
// Bullet through Grass
|
||||
// Ammo CHat Remove
|
||||
// NPC Edit
|
||||
// SetSpawn
|
||||
// LaunchPad
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -19,17 +26,19 @@ public final class StrikePlugin extends JavaPlugin {
|
||||
Jumper jumper = new Jumper(this);
|
||||
SpawnController spawnController = new SpawnController(this);
|
||||
HealthPackage healthPackage = new HealthPackage(this);
|
||||
Grenade grenade = new Grenade(this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(gun, this);
|
||||
getServer().getPluginManager().registerEvents(jumper, this);
|
||||
getServer().getPluginManager().registerEvents(spawnController, this);
|
||||
getServer().getPluginManager().registerEvents(healthPackage, this);
|
||||
getServer().getPluginManager().registerEvents(grenade, this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(new Grenade(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryEditGUI(this), this);
|
||||
|
||||
getCommand("strike").setExecutor(new StrikeCommand(this));
|
||||
|
||||
StrikeCommand.loadInstances(gun, jumper, spawnController);
|
||||
StrikeCommand.loadInstances(gun, jumper, spawnController, grenade);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,4 +1,7 @@
|
||||
package io.github.simplexdev.strike.api.utils;
|
||||
|
||||
public class InventoryEdit {
|
||||
public class InstanceStorage {
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package io.github.simplexdev.strike.api.utils;
|
||||
|
||||
import io.github.simplexdev.strike.listeners.Grenade;
|
||||
import io.github.simplexdev.strike.listeners.Gun;
|
||||
import io.github.simplexdev.strike.listeners.HealthPackage;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class InventoryEditConfigManager {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final FileConfiguration dataConfig;
|
||||
private final File dataFile;
|
||||
|
||||
public InventoryEditConfigManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
dataFile = new File("plugins\\Strike\\inventories.yml");
|
||||
|
||||
if (!dataFile.isFile()) {
|
||||
try {
|
||||
dataFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
dataConfig = new YamlConfiguration();
|
||||
try {
|
||||
dataConfig.load(dataFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setInventory(Player player, ItemStack[] items) throws IOException {
|
||||
|
||||
if (items.length != 9)
|
||||
throw new IllegalArgumentException("The length of the items can be only 9");
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
dataConfig.set(player.getUniqueId().toString() + "." + i, items[i]);
|
||||
dataConfig.save(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ItemStack[] getInventory(Player player) {
|
||||
ItemStack[] items = new ItemStack[9];
|
||||
String uuid = player.getUniqueId().toString();
|
||||
|
||||
if (dataConfig.get(uuid) == null) {
|
||||
ItemStack[] defaultItems = new ItemStack[9];
|
||||
|
||||
defaultItems[0] = new ItemStack(Material.WOODEN_SWORD);
|
||||
defaultItems[1] = new Gun(plugin).createItem();
|
||||
defaultItems[2] = new Grenade(plugin).createItem();
|
||||
defaultItems[8] = new HealthPackage(plugin).createItem();
|
||||
|
||||
try {
|
||||
setInventory(player, defaultItems);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return defaultItems;
|
||||
}
|
||||
|
||||
Set<String> setString = dataConfig.getKeys(true);
|
||||
|
||||
for (String string : setString) {
|
||||
if (string.startsWith(uuid) && !string.equalsIgnoreCase(uuid)) {
|
||||
|
||||
Integer integer = Integer.parseInt(string.replace(uuid + ".", "").trim());
|
||||
|
||||
items[integer] = dataConfig.getItemStack(uuid + "." + integer);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return items;
|
||||
|
||||
}
|
||||
|
||||
public int getItemSlot(ItemStack itemStack, Player player) {
|
||||
|
||||
ItemStack[] itemStacks = getInventory(player);
|
||||
|
||||
for (int i = 0; i < itemStacks.length; i++)
|
||||
if (itemStacks[i].isSimilar(itemStack))
|
||||
return i;
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
}
|
@ -45,7 +45,7 @@ public class Grenade implements ConfigUser {
|
||||
|
||||
this.plugin.getServer().getOnlinePlayers().forEach(player -> player.getInventory().addItem(new ItemStack[]{stack}));
|
||||
|
||||
return stack;
|
||||
return stack.clone();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,185 +1,155 @@
|
||||
/* */ package io.github.simplexdev.strike.listeners;
|
||||
/* */ import io.github.simplexdev.strike.api.ConfigUser;
|
||||
package io.github.simplexdev.strike.listeners;
|
||||
|
||||
import io.github.simplexdev.strike.api.ConfigUser;
|
||||
import io.github.simplexdev.strike.api.Spawn;
|
||||
/* */ import java.util.Collection;
|
||||
/* */ import java.util.HashMap;
|
||||
/* */ import io.github.simplexdev.strike.events.GunKillEvent;
|
||||
import io.github.simplexdev.strike.events.GunKillEvent;
|
||||
import org.bukkit.*;
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ import org.bukkit.entity.Entity;
|
||||
/* */ import org.bukkit.entity.LivingEntity;
|
||||
/* */ import org.bukkit.entity.Player;
|
||||
/* */ import org.bukkit.event.Event;
|
||||
/* */ import org.bukkit.event.EventHandler;
|
||||
/* */ import org.bukkit.event.block.Action;
|
||||
/* */ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
/* */ import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
/* */ import org.bukkit.inventory.ItemStack;
|
||||
/* */ import org.bukkit.inventory.meta.ItemMeta;
|
||||
/* */ import org.bukkit.plugin.Plugin;
|
||||
/* */ import org.bukkit.plugin.java.JavaPlugin;
|
||||
/* */ import org.bukkit.scheduler.BukkitRunnable;
|
||||
/* */
|
||||
/* */ public class Gun implements ConfigUser {
|
||||
/* 24 */ private static final HashMap<ItemStack, Integer> ammoMap = new HashMap<>();
|
||||
/* */
|
||||
/* */ private final ItemStack gunItemStack;
|
||||
/* */
|
||||
/* */ private final JavaPlugin plugin;
|
||||
/* */
|
||||
/* */ private int maxAmmo;
|
||||
/* */
|
||||
/* */ private int maxDistance;
|
||||
/* */
|
||||
/* */
|
||||
/* */ public Gun(JavaPlugin plugin) {
|
||||
/* 36 */ this.plugin = plugin;
|
||||
/* 37 */ this.gunItemStack = createItem();
|
||||
/* 38 */ this.maxAmmo = plugin.getConfig().getInt("gun.ammo");
|
||||
/* 39 */ this.maxDistance = plugin.getConfig().getInt("gun.range");
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ public ItemStack createItem() {
|
||||
/* 43 */ ItemStack stack = new ItemStack(Material.IRON_HORSE_ARMOR, 1);
|
||||
/* 44 */ ItemMeta meta = this.plugin.getServer().getItemFactory().getItemMeta(Material.IRON_HORSE_ARMOR);
|
||||
/* */
|
||||
/* 46 */ meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("gun.name")));
|
||||
/* */
|
||||
/* 48 */ stack.setItemMeta(meta);
|
||||
/* */
|
||||
/* 50 */ this.plugin.getServer().getOnlinePlayers().forEach(player -> player.getInventory().addItem(new ItemStack[] { stack }));
|
||||
/* */
|
||||
/* 52 */ return stack;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ @EventHandler
|
||||
/* */ private void activeActionBar(PlayerItemHeldEvent e) {
|
||||
/* 75 */ final Player player = e.getPlayer();
|
||||
/* */
|
||||
/* 77 */ if (!player.getWorld().equals(Spawn.getWorld()) || player.getInventory().getItem(e.getNewSlot()) == null || !player.getInventory().getItem(e.getNewSlot()).equals(this.gunItemStack)) {
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 80 */ (new BukkitRunnable()
|
||||
/* */ {
|
||||
/* */ public void run() {
|
||||
/* 83 */ ItemStack mainHandItem = player.getInventory().getItemInMainHand();
|
||||
/* 84 */ if (!mainHandItem.isSimilar(Gun.this.gunItemStack)) {
|
||||
/* 85 */ cancel();
|
||||
/* */
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 89 */ String ammoText = (Gun.ammoMap.containsKey(mainHandItem) ? ((Integer)Gun.ammoMap.get(mainHandItem)).intValue() : Gun.this.maxAmmo) + " | " + Gun.this.maxAmmo;
|
||||
/* */
|
||||
/* 91 */ player.sendActionBar(ammoText);
|
||||
/* */ }
|
||||
/* 94 */ }).runTaskTimer((Plugin)this.plugin, 0L, 7L);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ @EventHandler
|
||||
/* */ private void onRightClick(PlayerInteractEvent e) {
|
||||
/* 101 */ final ItemStack itemStack = e.getItem();
|
||||
/* 102 */ Player player = e.getPlayer();
|
||||
/* 103 */ Action action = e.getAction();
|
||||
/* */
|
||||
/* 105 */ if (!player.getWorld().equals(Spawn.getWorld()) || itemStack == null || !itemStack.equals(this.gunItemStack) || !action.toString().startsWith("RIGHT_CLICK")) {
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 108 */ int ammo = this.maxAmmo;
|
||||
/* */
|
||||
/* 110 */ if (!ammoMap.containsKey(itemStack)) {
|
||||
/* 111 */ ammoMap.put(itemStack, Integer.valueOf(this.maxAmmo - 1));
|
||||
/* */ } else {
|
||||
/* */
|
||||
/* 114 */ ammo = ((Integer)ammoMap.get(itemStack)).intValue();
|
||||
/* */
|
||||
/* 116 */ if (ammo == 1)
|
||||
/* */ {
|
||||
/* 118 */ (new BukkitRunnable()
|
||||
/* */ {
|
||||
/* */ public void run() {
|
||||
/* 121 */ Gun.ammoMap.replace(itemStack, Integer.valueOf(Gun.this.maxAmmo));
|
||||
/* */ }
|
||||
/* 123 */ }).runTaskLater((Plugin)this.plugin, 20L * this.plugin.getConfig().getInt("gun.reload-time"));
|
||||
/* */ }
|
||||
/* */
|
||||
/* 126 */ if (((Integer)ammoMap.get(itemStack)).intValue() != 0) {
|
||||
/* 127 */ ammoMap.replace(itemStack, Integer.valueOf(ammo - 1));
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* 130 */ if (ammo <= 0) {
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 133 */ player.sendMessage(String.valueOf(ammo));
|
||||
/* */
|
||||
/* 135 */ spawnParticle(player, player.getEyeLocation().clone(), 0.0D);
|
||||
/* 136 */ Entity entity = player.getTargetEntity(this.maxDistance);
|
||||
/* */
|
||||
/* 138 */ if (!(entity instanceof LivingEntity)) {
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 141 */ LivingEntity livingEntity = (LivingEntity)entity;
|
||||
/* 142 */ double currentHealth = livingEntity.getHealth();
|
||||
/* 143 */ double damageHealth = this.plugin.getConfig().getInt("gun.damage");
|
||||
/* */
|
||||
/* 145 */ if (currentHealth <= damageHealth) {
|
||||
/* 146 */ Bukkit.getServer().getPluginManager().callEvent((Event)new GunKillEvent(player, livingEntity));
|
||||
/* */ }
|
||||
/* 148 */ livingEntity.damage(damageHealth);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void spawnParticle(Player player, Location location, double distance) {
|
||||
/* 154 */ World world = location.getWorld();
|
||||
/* */
|
||||
/* 156 */ location.add(location.getDirection().multiply(0.1D));
|
||||
/* 157 */ world.spawnParticle(Particle.CRIT, location, 1, 0.0D, 0.0D, 0.0D, 0.001D);
|
||||
/* */
|
||||
/* 159 */ distance += 0.1D;
|
||||
/* */
|
||||
/* 161 */ if (location.getBlock().getType() != Material.AIR || distance > this.maxDistance) {
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 164 */ Collection<LivingEntity> entities = location.getNearbyLivingEntities(0.1D);
|
||||
/* */
|
||||
/* 166 */ if (!entities.isEmpty() && entities.size() == 1 && !entities.contains(player)) {
|
||||
/* */ return;
|
||||
/* */ }
|
||||
/* 169 */ spawnParticle(player, location, distance);
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void refresh() {
|
||||
/* 175 */ this.maxAmmo = this.plugin.getConfig().getInt("gun.ammo");
|
||||
/* 176 */ this.maxDistance = this.plugin.getConfig().getInt("gun.range");
|
||||
/* */ }
|
||||
/* */ }
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Gun implements ConfigUser {
|
||||
private static final HashMap<ItemStack, Integer> ammoMap = new HashMap<>();
|
||||
|
||||
private final ItemStack gunItemStack;
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
private int maxAmmo;
|
||||
|
||||
private int maxDistance;
|
||||
|
||||
|
||||
/* Location: E:\Rishi\Codes\Java Projects\Minecraft Plugins\PaperMC\1.16.4\Server Testing\plugins\strike-1.0-SNAPSHOT.jar!\io\github\simplexdev\simplexcore\strike\listeners\Gun.class
|
||||
* Java compiler version: 8 (52.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
public Gun(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.gunItemStack = createItem();
|
||||
this.maxAmmo = plugin.getConfig().getInt("gun.ammo");
|
||||
this.maxDistance = plugin.getConfig().getInt("gun.range");
|
||||
}
|
||||
|
||||
public ItemStack createItem() {
|
||||
ItemStack stack = new ItemStack(Material.IRON_HORSE_ARMOR, 1);
|
||||
ItemMeta meta = this.plugin.getServer().getItemFactory().getItemMeta(Material.IRON_HORSE_ARMOR);
|
||||
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("gun.name")));
|
||||
|
||||
stack.setItemMeta(meta);
|
||||
|
||||
this.plugin.getServer().getOnlinePlayers().forEach(player -> player.getInventory().addItem(new ItemStack[]{stack}));
|
||||
|
||||
return stack.clone();
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
private void activeActionBar(PlayerItemHeldEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
|
||||
if (!player.getWorld().equals(Spawn.getWorld()) || player.getInventory().getItem(e.getNewSlot()) == null || !player.getInventory().getItem(e.getNewSlot()).equals(this.gunItemStack)) {
|
||||
return;
|
||||
}
|
||||
(new BukkitRunnable() {
|
||||
public void run() {
|
||||
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
|
||||
if (!mainHandItem.isSimilar(Gun.this.gunItemStack)) {
|
||||
cancel();
|
||||
|
||||
return;
|
||||
}
|
||||
String ammoText = (Gun.ammoMap.containsKey(mainHandItem) ? ((Integer) Gun.ammoMap.get(mainHandItem)).intValue() : Gun.this.maxAmmo) + " | " + Gun.this.maxAmmo;
|
||||
|
||||
player.sendActionBar(ammoText);
|
||||
}
|
||||
}).runTaskTimer((Plugin) this.plugin, 0L, 7L);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
private void onRightClick(PlayerInteractEvent e) {
|
||||
final ItemStack itemStack = e.getItem();
|
||||
Player player = e.getPlayer();
|
||||
Action action = e.getAction();
|
||||
|
||||
if (!player.getWorld().equals(Spawn.getWorld()) || itemStack == null || !itemStack.equals(this.gunItemStack) || !action.toString().startsWith("RIGHT_CLICK")) {
|
||||
return;
|
||||
}
|
||||
int ammo = this.maxAmmo;
|
||||
|
||||
if (!ammoMap.containsKey(itemStack)) {
|
||||
ammoMap.put(itemStack, Integer.valueOf(this.maxAmmo - 1));
|
||||
} else {
|
||||
|
||||
ammo = ((Integer) ammoMap.get(itemStack)).intValue();
|
||||
|
||||
if (ammo == 1) {
|
||||
(new BukkitRunnable() {
|
||||
public void run() {
|
||||
Gun.ammoMap.replace(itemStack, Integer.valueOf(Gun.this.maxAmmo));
|
||||
}
|
||||
}).runTaskLater((Plugin) this.plugin, 20L * this.plugin.getConfig().getInt("gun.reload-time"));
|
||||
}
|
||||
|
||||
if (((Integer) ammoMap.get(itemStack)).intValue() != 0) {
|
||||
ammoMap.replace(itemStack, Integer.valueOf(ammo - 1));
|
||||
}
|
||||
}
|
||||
if (ammo <= 0) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(String.valueOf(ammo));
|
||||
|
||||
spawnParticle(player, player.getEyeLocation().clone(), 0.0D);
|
||||
Entity entity = player.getTargetEntity(this.maxDistance);
|
||||
|
||||
if (!(entity instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
double currentHealth = livingEntity.getHealth();
|
||||
double damageHealth = this.plugin.getConfig().getInt("gun.damage");
|
||||
|
||||
if (currentHealth <= damageHealth) {
|
||||
Bukkit.getServer().getPluginManager().callEvent((Event) new GunKillEvent(player, livingEntity));
|
||||
}
|
||||
livingEntity.damage(damageHealth);
|
||||
}
|
||||
|
||||
|
||||
private void spawnParticle(Player player, Location location, double distance) {
|
||||
World world = location.getWorld();
|
||||
|
||||
location.add(location.getDirection().multiply(0.1D));
|
||||
world.spawnParticle(Particle.CRIT, location, 1, 0.0D, 0.0D, 0.0D, 0.001D);
|
||||
|
||||
distance += 0.1D;
|
||||
|
||||
if (location.getBlock().getType() != Material.AIR || distance > this.maxDistance) {
|
||||
return;
|
||||
}
|
||||
Collection<LivingEntity> entities = location.getNearbyLivingEntities(0.1D);
|
||||
|
||||
if (!entities.isEmpty() && entities.size() == 1 && !entities.contains(player)) {
|
||||
return;
|
||||
}
|
||||
spawnParticle(player, location, distance);
|
||||
}
|
||||
|
||||
|
||||
public void refresh() {
|
||||
this.maxAmmo = this.plugin.getConfig().getInt("gun.ammo");
|
||||
this.maxDistance = this.plugin.getConfig().getInt("gun.range");
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack createHealthPackage() {
|
||||
public ItemStack createItem() {
|
||||
String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGExNTU4YTgzZjQwMjZkYjIzMmY4MGJjOTYxNWNjM2JhNDE1ZGM0MDk0MGE1YTEzYWUyYThjOTBiMTVjM2MzZSJ9fX0=";
|
||||
|
||||
ItemStack healthPackage = SkullCreator.itemFromBase64(base64);
|
||||
@ -63,7 +63,7 @@
|
||||
|
||||
healthPackage.setItemMeta(meta);
|
||||
|
||||
return healthPackage;
|
||||
return healthPackage.clone();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -93,6 +93,6 @@
|
||||
public void refresh() {
|
||||
this.usedMessage = plugin.getConfig().getString("health-package.restore-health-message", "You have restored your health");
|
||||
this.regainHealth = plugin.getConfig().getInt("health-package.restore-health");
|
||||
this.healthPackage = createHealthPackage();
|
||||
this.healthPackage = createItem();
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package io.github.simplexdev.strike.listeners;
|
||||
|
||||
import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InventoryEditGUI implements Listener {
|
||||
|
||||
private static List<Inventory> inventories = new ArrayList<>();
|
||||
private final InventoryEditConfigManager configManager;
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public InventoryEditGUI(JavaPlugin plugin) {
|
||||
configManager = new InventoryEditConfigManager(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public void openInventory(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 9);
|
||||
inventories.add(inventory);
|
||||
|
||||
inventory.setContents(configManager.getInventory(player));
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
private void onCloseInventory(InventoryCloseEvent e) {
|
||||
if (!inventories.contains(e.getInventory()))
|
||||
return;
|
||||
|
||||
try {
|
||||
configManager.setInventory((Player) e.getPlayer(), e.getInventory().getContents());
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onClick(InventoryClickEvent e) {
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
Inventory openedInventory = player.getOpenInventory().getTopInventory();
|
||||
|
||||
if (inventories.contains(openedInventory) && !e.getClickedInventory().equals(openedInventory))
|
||||
e.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +1,41 @@
|
||||
/* */ package io.github.simplexdev.strike.listeners;
|
||||
/* */
|
||||
/* */ import io.github.simplexdev.strike.api.ConfigUser;
|
||||
/* */ import io.github.simplexdev.strike.api.Spawn;
|
||||
/* */
|
||||
import org.bukkit.Material;
|
||||
/* */ import org.bukkit.entity.Player;
|
||||
/* */ import org.bukkit.event.EventHandler;
|
||||
/* */ import org.bukkit.event.EventPriority;
|
||||
/* */ import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
/* */ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
/* */ import org.bukkit.inventory.ItemStack;
|
||||
/* */ import org.bukkit.plugin.java.JavaPlugin;
|
||||
/* */
|
||||
/* */
|
||||
/* */ public class SpawnController
|
||||
/* */ implements ConfigUser
|
||||
/* */ {
|
||||
/* */ private final JavaPlugin plugin;
|
||||
/* */
|
||||
/* */ public SpawnController(JavaPlugin plugin) {
|
||||
/* 21 */ this.plugin = plugin;
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ @EventHandler
|
||||
/* */ private void onDeath(PlayerDeathEvent e) {
|
||||
/* 26 */ Player player = e.getEntity();
|
||||
/* */
|
||||
/* 28 */ if (player.getWorld().equals(Spawn.getWorld()))
|
||||
/* 29 */ player.getInventory().clear();
|
||||
/* */ }
|
||||
/* */
|
||||
/* */ @EventHandler(priority = EventPriority.HIGH)
|
||||
/* */ private void onRespawn(PlayerRespawnEvent e) {
|
||||
/* 34 */ if (e.getPlayer().getWorld().equals(Spawn.getWorld())) {
|
||||
/* 35 */ e.setRespawnLocation(Spawn.getSpawn());
|
||||
/* 36 */ giveItems(e.getPlayer());
|
||||
/* */ }
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */ private void giveItems(Player player) {
|
||||
/* 42 */ player.getInventory().addItem(new ItemStack[] { (new Gun(this.plugin)).createItem() });
|
||||
/* 43 */ player.getInventory().addItem(new ItemStack[] { (new Grenade(this.plugin)).createItem() });
|
||||
/* 44 */ player.getInventory().addItem(new ItemStack[] { new ItemStack(Material.WOODEN_SWORD) });
|
||||
/* */ }
|
||||
/* */
|
||||
/* */
|
||||
/* */ public void refresh() {
|
||||
/* 49 */ Spawn.loadConfig(this.plugin);
|
||||
/* */ }
|
||||
/* */ }
|
||||
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 org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
/* Location: E:\Rishi\Codes\Java Projects\Minecraft Plugins\PaperMC\1.16.4\Server Testing\plugins\strike-1.0-SNAPSHOT.jar!\io\github\simplexdev\simplexcore\strike\listeners\SpawnController.class
|
||||
* Java compiler version: 8 (52.0)
|
||||
* JD-Core Version: 1.1.3
|
||||
*/
|
||||
public class SpawnController
|
||||
implements ConfigUser {
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public SpawnController(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onDeath(PlayerDeathEvent e) {
|
||||
Player player = e.getEntity();
|
||||
|
||||
if (player.getWorld().equals(Spawn.getWorld()))
|
||||
player.getInventory().clear();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
private void onRespawn(PlayerRespawnEvent e) {
|
||||
if (e.getPlayer().getWorld().equals(Spawn.getWorld())) {
|
||||
e.setRespawnLocation(Spawn.getSpawn());
|
||||
e.getPlayer().getInventory().setContents(new InventoryEditConfigManager(plugin).getInventory(e.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
Spawn.loadConfig(this.plugin);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user