mirror of
https://github.com/SimplexDevelopment/StrikePlugin.git
synced 2025-01-08 16:07:37 +00:00
Fix 2.0
This commit is contained in:
parent
ee971706d3
commit
1bc6d53739
@ -3,7 +3,6 @@ package io.github.simplexdev.strike;
|
|||||||
import io.github.simplexdev.strike.api.ConfigUser;
|
import io.github.simplexdev.strike.api.ConfigUser;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import io.github.simplexdev.strike.api.Spawn;
|
|
||||||
import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager;
|
import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager;
|
||||||
import io.github.simplexdev.strike.listeners.InventoryEditGUI;
|
import io.github.simplexdev.strike.listeners.InventoryEditGUI;
|
||||||
import io.github.simplexdev.strike.listeners.SpawnController;
|
import io.github.simplexdev.strike.listeners.SpawnController;
|
||||||
@ -44,7 +43,7 @@ public class StrikeCommand implements CommandExecutor {
|
|||||||
else if ("get".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
else if ("get".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
player.getInventory().setContents(new InventoryEditConfigManager(plugin).getInventory(player));
|
player.getInventory().setContents(new InventoryEditConfigManager(plugin).getInventoryItems(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ("set-spawn".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
else if ("set-spawn".equalsIgnoreCase(args[0]) && sender instanceof Player) {
|
||||||
|
@ -7,8 +7,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public final class StrikePlugin extends JavaPlugin {
|
public final class StrikePlugin extends JavaPlugin {
|
||||||
//TODO
|
//TODO
|
||||||
// Fall Damage Disable
|
|
||||||
// Bullet through Grass, Glass, Fence, Gates, Bars
|
|
||||||
// NPC Edit
|
// NPC Edit
|
||||||
// LaunchPad
|
// LaunchPad
|
||||||
|
|
||||||
|
@ -5,9 +5,6 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class Spawn {
|
public class Spawn {
|
||||||
private static World world = null;
|
private static World world = null;
|
||||||
private static Location spawn = null;
|
private static Location spawn = null;
|
||||||
@ -24,22 +21,17 @@ public class Spawn {
|
|||||||
config.set("spawn.coords.x", spawn.getX());
|
config.set("spawn.coords.x", spawn.getX());
|
||||||
config.set("spawn.coords.y", spawn.getY());
|
config.set("spawn.coords.y", spawn.getY());
|
||||||
config.set("spawn.coords.z", spawn.getZ());
|
config.set("spawn.coords.z", spawn.getZ());
|
||||||
try {
|
|
||||||
config.save(new File(config.getCurrentPath()));
|
plugin.saveConfig();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
Spawn.spawn = spawn;
|
Spawn.spawn = spawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setWorld(World world, JavaPlugin plugin) {
|
public static void setWorld(World world, JavaPlugin plugin) {
|
||||||
plugin.getConfig().set("spawn.world", world.getName());
|
plugin.getConfig().set("spawn.world", world.getName());
|
||||||
try {
|
|
||||||
plugin.getConfig().save(new File(plugin.getConfig().getCurrentPath()));
|
plugin.saveConfig();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Spawn.world = world;
|
Spawn.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,43 +3,41 @@ package io.github.simplexdev.strike.api.utils;
|
|||||||
import io.github.simplexdev.strike.listeners.Grenade;
|
import io.github.simplexdev.strike.listeners.Grenade;
|
||||||
import io.github.simplexdev.strike.listeners.Gun;
|
import io.github.simplexdev.strike.listeners.Gun;
|
||||||
import io.github.simplexdev.strike.listeners.HealthPackage;
|
import io.github.simplexdev.strike.listeners.HealthPackage;
|
||||||
|
import io.github.simplexdev.strike.listeners.ItemManager;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class InventoryEditConfigManager {
|
public class InventoryEditConfigManager {
|
||||||
|
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
private final FileConfiguration dataConfig;
|
|
||||||
private final File dataFile;
|
private final File dataFile;
|
||||||
|
private FileConfiguration dataConfig;
|
||||||
|
|
||||||
public InventoryEditConfigManager(JavaPlugin plugin) {
|
public InventoryEditConfigManager(JavaPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
dataFile = new File("plugins\\Strike\\inventories.yml");
|
dataFile = new File("plugins\\Strike\\inventories.yml");
|
||||||
|
|
||||||
if (!dataFile.isFile()) {
|
|
||||||
try {
|
|
||||||
dataFile.createNewFile();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dataConfig = new YamlConfiguration();
|
|
||||||
try {
|
try {
|
||||||
|
if (!dataFile.isFile()) {
|
||||||
|
|
||||||
|
dataFile.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
dataConfig = new YamlConfiguration();
|
||||||
dataConfig.load(dataFile);
|
dataConfig.load(dataFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvalidConfigurationException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,17 +55,23 @@ public class InventoryEditConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ItemStack[] getInventory(Player player) {
|
public ItemStack[] getInventoryItems(Player player) {
|
||||||
ItemStack[] items = new ItemStack[9];
|
ItemStack[] items = new ItemStack[9];
|
||||||
|
ItemStack[] defaultItems = new ItemStack[9];
|
||||||
|
ItemMeta meta;
|
||||||
|
|
||||||
|
defaultItems[0] = new ItemStack(Material.WOODEN_SWORD);
|
||||||
|
meta = defaultItems[0].getItemMeta();
|
||||||
|
meta.setUnbreakable(true);
|
||||||
|
|
||||||
|
defaultItems[0].setItemMeta(meta);
|
||||||
|
|
||||||
|
defaultItems[1] = new Gun(plugin).createItem();
|
||||||
|
defaultItems[2] = new Grenade(plugin).createItem();
|
||||||
|
defaultItems[8] = new HealthPackage(plugin).createItem();
|
||||||
String uuid = player.getUniqueId().toString();
|
String uuid = player.getUniqueId().toString();
|
||||||
|
|
||||||
if (dataConfig.get(uuid) == null) {
|
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 {
|
try {
|
||||||
setInventory(player, defaultItems);
|
setInventory(player, defaultItems);
|
||||||
@ -83,13 +87,23 @@ public class InventoryEditConfigManager {
|
|||||||
for (String string : setString) {
|
for (String string : setString) {
|
||||||
if (string.startsWith(uuid) && !string.equalsIgnoreCase(uuid)) {
|
if (string.startsWith(uuid) && !string.equalsIgnoreCase(uuid)) {
|
||||||
|
|
||||||
Integer integer = Integer.parseInt(string.replace(uuid + ".", "").trim());
|
int integer = Integer.parseInt(string.replace(uuid + ".", "").trim());
|
||||||
|
|
||||||
items[integer] = dataConfig.getItemStack(uuid + "." + integer);
|
items[integer] = dataConfig.getItemStack(uuid + "." + integer);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Arrays.asList(defaultItems).containsAll(Arrays.asList(items))) {
|
||||||
|
try {
|
||||||
|
setInventory(player, defaultItems);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
|
||||||
@ -97,15 +111,13 @@ public class InventoryEditConfigManager {
|
|||||||
|
|
||||||
public int getItemSlot(ItemStack itemStack, Player player) {
|
public int getItemSlot(ItemStack itemStack, Player player) {
|
||||||
|
|
||||||
ItemStack[] itemStacks = getInventory(player);
|
ItemStack[] itemStacks = getInventoryItems(player);
|
||||||
|
|
||||||
for (int i = 0; i < itemStacks.length; i++)
|
for (int i = 0; i < itemStacks.length; i++)
|
||||||
if (itemStacks[i].isSimilar(itemStack))
|
if (itemStacks[i] != null && itemStacks[i].isSimilar(itemStack))
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,10 @@ public class Grenade implements ConfigUser {
|
|||||||
ItemStack stack = new ItemStack(Material.MAGMA_CREAM, 1);
|
ItemStack stack = new ItemStack(Material.MAGMA_CREAM, 1);
|
||||||
ItemMeta meta = this.plugin.getServer().getItemFactory().getItemMeta(Material.MAGMA_CREAM);
|
ItemMeta meta = this.plugin.getServer().getItemFactory().getItemMeta(Material.MAGMA_CREAM);
|
||||||
|
|
||||||
meta.setDisplayName(ChatColor.RED + "Grenade");
|
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("grenade.name")));
|
||||||
|
|
||||||
stack.setItemMeta(meta);
|
stack.setItemMeta(meta);
|
||||||
|
|
||||||
this.plugin.getServer().getOnlinePlayers().forEach(player -> player.getInventory().addItem(new ItemStack[]{stack}));
|
|
||||||
|
|
||||||
return stack.clone();
|
return stack.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,12 +71,12 @@ public class Grenade implements ConfigUser {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.getLocation().createExplosion(4.0F, false, false);
|
item.getLocation().createExplosion(4.0F, false, false);
|
||||||
Collection<LivingEntity> entities = item.getLocation().getNearbyLivingEntities(4.0D);
|
Collection<LivingEntity> entities = item.getLocation().getNearbyLivingEntities(10.0D);
|
||||||
|
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = new ArrayList<>();
|
||||||
|
|
||||||
entities.forEach(livingEntity -> {
|
entities.forEach(livingEntity -> {
|
||||||
if (livingEntity instanceof Player) {
|
if (livingEntity instanceof Player && !player.equals(livingEntity)) {
|
||||||
players.add((Player) livingEntity);
|
players.add((Player) livingEntity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -96,10 +94,11 @@ public class Grenade implements ConfigUser {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onPlayerDamage(EntityDamageEvent e) {
|
private void onPlayerDamage(EntityDamageEvent e) {
|
||||||
if (!e.getEntity().getWorld().equals(Spawn.getWorld()) || !(e.getEntity() instanceof Player))
|
if (e.getCause() != EntityDamageEvent.DamageCause.BLOCK_EXPLOSION || !e.getEntity().getWorld().equals(Spawn.getWorld()) || !(e.getEntity() instanceof Player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) e.getEntity();
|
Player player = (Player) e.getEntity();;
|
||||||
|
|
||||||
Player killer = null;
|
Player killer = null;
|
||||||
|
|
||||||
for (Map.Entry<Player, List<Player>> entry : map.entrySet()) {
|
for (Map.Entry<Player, List<Player>> entry : map.entrySet()) {
|
||||||
|
@ -65,6 +65,12 @@ public class Gun implements ConfigUser {
|
|||||||
blocks.add(Material.WATER);
|
blocks.add(Material.WATER);
|
||||||
blocks.add(Material.LAVA);
|
blocks.add(Material.LAVA);
|
||||||
blocks.add(Material.AIR);
|
blocks.add(Material.AIR);
|
||||||
|
blocks.add(Material.COBWEB);
|
||||||
|
blocks.add(Material.ACACIA_LEAVES);
|
||||||
|
blocks.add(Material.BIRCH_LEAVES);
|
||||||
|
blocks.add(Material.OAK_LEAVES);
|
||||||
|
blocks.add(Material.DARK_OAK_LEAVES);
|
||||||
|
blocks.add(Material.SPRUCE_LEAVES);
|
||||||
|
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
@ -85,8 +91,6 @@ public class Gun implements ConfigUser {
|
|||||||
|
|
||||||
stack.setItemMeta(meta);
|
stack.setItemMeta(meta);
|
||||||
|
|
||||||
this.plugin.getServer().getOnlinePlayers().forEach(player -> player.getInventory().addItem(new ItemStack[]{stack}));
|
|
||||||
|
|
||||||
return stack.clone();
|
return stack.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,8 +159,6 @@ public class Gun implements ConfigUser {
|
|||||||
|
|
||||||
Entity entity = getEntity(player, player.getEyeLocation().clone(), 0.0D);
|
Entity entity = getEntity(player, player.getEyeLocation().clone(), 0.0D);
|
||||||
|
|
||||||
System.out.println(entity);
|
|
||||||
|
|
||||||
if (!(entity instanceof LivingEntity)) {
|
if (!(entity instanceof LivingEntity)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,73 +1,74 @@
|
|||||||
package io.github.simplexdev.strike.listeners;
|
package io.github.simplexdev.strike.listeners;
|
||||||
|
|
||||||
import io.github.simplexdev.strike.api.ConfigUser;
|
import io.github.simplexdev.strike.api.ConfigUser;
|
||||||
import io.github.simplexdev.strike.api.Spawn;
|
import io.github.simplexdev.strike.api.Spawn;
|
||||||
import io.github.simplexdev.strike.events.GrenadeKillEvent;
|
import io.github.simplexdev.strike.api.utils.SkullCreator;
|
||||||
import io.github.simplexdev.strike.events.GunKillEvent;
|
import org.bukkit.ChatColor;
|
||||||
import io.github.simplexdev.strike.api.utils.SkullCreator;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.block.Skull;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class HealthPackage implements ConfigUser {
|
import java.util.Locale;
|
||||||
private final JavaPlugin plugin;
|
|
||||||
private ItemStack healthPackage;
|
|
||||||
private String usedMessage;
|
|
||||||
private int regainHealth;
|
|
||||||
|
|
||||||
public HealthPackage(JavaPlugin plugin) {
|
public class HealthPackage implements ConfigUser {
|
||||||
this.plugin = plugin;
|
private final JavaPlugin plugin;
|
||||||
refresh();
|
private ItemStack healthPackage;
|
||||||
}
|
private String usedMessage;
|
||||||
|
private int regainHealth;
|
||||||
|
|
||||||
@EventHandler
|
public HealthPackage(JavaPlugin plugin) {
|
||||||
public void onInteract(PlayerInteractEvent e) {
|
this.plugin = plugin;
|
||||||
Player player = e.getPlayer();
|
refresh();
|
||||||
ItemStack item = player.getInventory().getItemInMainHand();
|
}
|
||||||
|
|
||||||
if (!player.getWorld().equals(Spawn.getWorld())) {
|
@EventHandler
|
||||||
return;
|
public void onInteract(PlayerInteractEvent e) {
|
||||||
}
|
Player player = e.getPlayer();
|
||||||
if (player.getInventory().getItemInMainHand().isSimilar(this.healthPackage)) {
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK) || e.getAction().equals(Action.LEFT_CLICK_AIR)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.setHealth(this.regainHealth);
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', usedMessage));
|
|
||||||
|
|
||||||
if (item.getAmount() == 1) {
|
if (!player.getWorld().equals(Spawn.getWorld())) {
|
||||||
player.getInventory().setItemInMainHand(null);
|
return;
|
||||||
} else {
|
}
|
||||||
|
if (player.getInventory().getItemInMainHand().isSimilar(this.healthPackage)) {
|
||||||
|
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK) || e.getAction().equals(Action.LEFT_CLICK_AIR)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.setHealth(this.regainHealth);
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', usedMessage));
|
||||||
|
|
||||||
item.setAmount(item.getAmount() - 1);
|
if (item.getAmount() == 1) {
|
||||||
}
|
player.getInventory().setItemInMainHand(null);
|
||||||
e.setCancelled(true);
|
} else {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack createItem() {
|
item.setAmount(item.getAmount() - 1);
|
||||||
String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGExNTU4YTgzZjQwMjZkYjIzMmY4MGJjOTYxNWNjM2JhNDE1ZGM0MDk0MGE1YTEzYWUyYThjOTBiMTVjM2MzZSJ9fX0=";
|
}
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack healthPackage = SkullCreator.itemWithUrl(SkullCreator.createSkull(), base64);
|
public ItemStack createItem() {
|
||||||
ItemMeta meta = plugin.getServer().getItemFactory().getItemMeta(Material.PLAYER_HEAD);
|
String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGExNTU4YTgzZjQwMjZkYjIzMmY4MGJjOTYxNWNjM2JhNDE1ZGM0MDk0MGE1YTEzYWUyYThjOTBiMTVjM2MzZSJ9fX0=";
|
||||||
|
|
||||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("health-package.name")));
|
ItemStack healthPackage = SkullCreator.createSkull();
|
||||||
|
ItemMeta meta = healthPackage.getItemMeta();
|
||||||
|
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("health-package.name")));
|
||||||
|
|
||||||
healthPackage.setItemMeta(meta);
|
healthPackage.setItemMeta(meta);
|
||||||
|
|
||||||
return healthPackage.clone();
|
healthPackage = SkullCreator.itemWithBase64(healthPackage, base64);
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh() {
|
return healthPackage.clone();
|
||||||
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 = createItem();
|
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 = createItem();
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,7 @@ public class InventoryEditGUI implements Listener {
|
|||||||
Inventory inventory = Bukkit.createInventory(null, 9);
|
Inventory inventory = Bukkit.createInventory(null, 9);
|
||||||
inventories.add(inventory);
|
inventories.add(inventory);
|
||||||
|
|
||||||
inventory.setContents(configManager.getInventory(player));
|
inventory.setContents(configManager.getInventoryItems(player));
|
||||||
player.openInventory(inventory);
|
player.openInventory(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public class InventoryEditGUI implements Listener {
|
|||||||
Player player = (Player) e.getWhoClicked();
|
Player player = (Player) e.getWhoClicked();
|
||||||
Inventory openedInventory = player.getOpenInventory().getTopInventory();
|
Inventory openedInventory = player.getOpenInventory().getTopInventory();
|
||||||
|
|
||||||
if (inventories.contains(openedInventory) && !e.getClickedInventory().equals(openedInventory))
|
if (inventories.contains(openedInventory) && (e.getClickedInventory() == null || e.isShiftClick() || !e.getClickedInventory().equals(openedInventory)))
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class ItemManager implements ConfigUser {
|
public class ItemManager implements ConfigUser {
|
||||||
@ -22,15 +23,14 @@ public class ItemManager implements ConfigUser {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDeath(PlayerDeathEvent e) {
|
private void onDeath(PlayerDeathEvent e) {
|
||||||
Player player = e.getEntity();
|
Player player = e.getEntity();
|
||||||
|
|
||||||
if (player.getWorld().equals(Spawn.getWorld())) {
|
if (player.getWorld().equals(Spawn.getWorld())) {
|
||||||
|
if (player.getKiller() != null)
|
||||||
addItem(player);
|
addItem(player.getKiller());
|
||||||
|
|
||||||
if (player.getKiller() != null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,22 +45,35 @@ public class ItemManager implements ConfigUser {
|
|||||||
addItem(e.getKiller());
|
addItem(e.getKiller());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addItem(Player player) {
|
public void addItem(Player player) {
|
||||||
InventoryEditConfigManager configManager = new InventoryEditConfigManager(plugin);
|
InventoryEditConfigManager configManager = new InventoryEditConfigManager(plugin);
|
||||||
|
|
||||||
if (!hasItem(player.getInventory(), grenade))
|
setItem(player, grenade, configManager);
|
||||||
player.getInventory().setItem(configManager.getItemSlot(grenade, player), grenade);
|
setItem(player, healthPackage, configManager);
|
||||||
|
|
||||||
if (!hasItem(player.getInventory(), healthPackage))
|
player.updateInventory();
|
||||||
player.getInventory().setItem(configManager.getItemSlot(healthPackage, player), healthPackage);
|
}
|
||||||
|
|
||||||
|
private void setItem(Player player, ItemStack itemStack, InventoryEditConfigManager configManager) {
|
||||||
|
PlayerInventory playerInventory = player.getInventory();
|
||||||
|
|
||||||
|
if (!hasItem(playerInventory, itemStack)) {
|
||||||
|
int slot = configManager.getItemSlot(itemStack, player);
|
||||||
|
|
||||||
|
if (playerInventory.getItem(slot) != null)
|
||||||
|
playerInventory.addItem(itemStack);
|
||||||
|
else
|
||||||
|
playerInventory.setItem(slot, itemStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasItem(Inventory inventory, ItemStack itemStack) {
|
private boolean hasItem(Inventory inventory, ItemStack itemStack) {
|
||||||
for (int i = 0; i < inventory.getSize(); i++)
|
for (int i = 0; i < inventory.getSize(); i++) {
|
||||||
if (inventory.getItem(0).isSimilar(itemStack))
|
|
||||||
|
if (inventory.getItem(i) != null && inventory.getItem(i).isSimilar(itemStack))
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,13 @@ package io.github.simplexdev.strike.listeners;
|
|||||||
|
|
||||||
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
||||||
import io.github.simplexdev.strike.api.ConfigUser;
|
import io.github.simplexdev.strike.api.ConfigUser;
|
||||||
|
import io.github.simplexdev.strike.api.Spawn;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -26,22 +29,30 @@ public class Jumper implements ConfigUser {
|
|||||||
this.coolDownTime = Integer.valueOf(plugin.getConfig().getInt("double-jump.cooldown"));
|
this.coolDownTime = Integer.valueOf(plugin.getConfig().getInt("double-jump.cooldown"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onDamage(EntityDamageEvent e) {
|
||||||
|
if (!(e.getEntity() instanceof Player))
|
||||||
|
return;
|
||||||
|
Player player = (Player) e.getEntity();
|
||||||
|
if (!player.getWorld().equals(Spawn.getWorld()) || e.getCause() != EntityDamageEvent.DamageCause.FALL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onPlayerMove(PlayerMoveEvent e) {
|
private void onPlayerJump(PlayerJumpEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
GameMode mode = player.getGameMode();
|
GameMode mode = player.getGameMode();
|
||||||
|
|
||||||
if (mode == GameMode.CREATIVE || mode == GameMode.SPECTATOR) {
|
if (!player.getWorld().equals(Spawn.getWorld()) || mode == GameMode.CREATIVE || mode == GameMode.SPECTATOR)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (playersOnCoolDown.containsKey(player.getUniqueId()))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
player.setAllowFlight(true);
|
player.setAllowFlight(true);
|
||||||
|
|
||||||
if (playersOnCoolDown.containsKey(player.getUniqueId())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +61,7 @@ public class Jumper implements ConfigUser {
|
|||||||
final Player player = e.getPlayer();
|
final Player player = e.getPlayer();
|
||||||
GameMode mode = player.getGameMode();
|
GameMode mode = player.getGameMode();
|
||||||
|
|
||||||
if (mode == GameMode.CREATIVE || mode == GameMode.SPECTATOR) {
|
if (!player.getWorld().equals(Spawn.getWorld()) || mode == GameMode.CREATIVE || mode == GameMode.SPECTATOR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.setAllowFlight(false);
|
player.setAllowFlight(false);
|
||||||
@ -63,7 +74,9 @@ public class Jumper implements ConfigUser {
|
|||||||
(new BukkitRunnable() {
|
(new BukkitRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Jumper.playersOnCoolDown.remove(player.getPlayer().getUniqueId());
|
Jumper.playersOnCoolDown.remove(player.getPlayer().getUniqueId());
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', Jumper.this.plugin.getConfig().getString("double-jump.cooldown-finish-message")));
|
if (plugin.getConfig().getBoolean("double-jump.message-enabled"))
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', Jumper.this.plugin.getConfig().getString("double-jump.cooldown-finish-message")));
|
||||||
|
|
||||||
}
|
}
|
||||||
}).runTaskLater((Plugin) this.plugin, 20L * this.coolDownTime.intValue());
|
}).runTaskLater((Plugin) this.plugin, 20L * this.coolDownTime.intValue());
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,15 @@ package io.github.simplexdev.strike.listeners;
|
|||||||
import io.github.simplexdev.strike.api.ConfigUser;
|
import io.github.simplexdev.strike.api.ConfigUser;
|
||||||
import io.github.simplexdev.strike.api.Spawn;
|
import io.github.simplexdev.strike.api.Spawn;
|
||||||
import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager;
|
import io.github.simplexdev.strike.api.utils.InventoryEditConfigManager;
|
||||||
import io.github.simplexdev.strike.events.GrenadeKillEvent;
|
import org.bukkit.ChatColor;
|
||||||
import io.github.simplexdev.strike.events.GunKillEvent;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
|
||||||
@ -24,6 +24,19 @@ public class SpawnController implements ConfigUser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onPlayerWorldChange(PlayerChangedWorldEvent e) {
|
||||||
|
if (e.getPlayer().getWorld().equals(Spawn.getWorld()))
|
||||||
|
new ItemManager(plugin).addItem(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private void onMove(PlayerMoveEvent e) {
|
||||||
|
Player player = e.getPlayer();
|
||||||
|
if (player.getWorld().equals(Spawn.getWorld()) && player.getFoodLevel() < 20)
|
||||||
|
player.setFoodLevel(20);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onDeath(PlayerDeathEvent e) {
|
private void onDeath(PlayerDeathEvent e) {
|
||||||
Player player = e.getEntity();
|
Player player = e.getEntity();
|
||||||
@ -34,9 +47,11 @@ public class SpawnController implements ConfigUser {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
private void onRespawn(PlayerRespawnEvent e) {
|
private void onRespawn(PlayerRespawnEvent e) {
|
||||||
if (e.getPlayer().getWorld().equals(Spawn.getWorld())) {
|
Player player = e.getPlayer();
|
||||||
|
if (player.getWorld().equals(Spawn.getWorld())) {
|
||||||
e.setRespawnLocation(Spawn.getSpawn());
|
e.setRespawnLocation(Spawn.getSpawn());
|
||||||
e.getPlayer().getInventory().setContents(new InventoryEditConfigManager(plugin).getInventory(e.getPlayer()));
|
player.getInventory().setContents(new InventoryEditConfigManager(plugin).getInventoryItems(e.getPlayer()));
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("spawn.respawn-message")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
double-jump:
|
double-jump:
|
||||||
cooldown: 10 #Time in Seconds
|
cooldown: 10 #Time in Seconds
|
||||||
cooldown-finish-message: "Done"
|
cooldown-finish-message: "Done"
|
||||||
|
message-enabled: true
|
||||||
|
|
||||||
gun:
|
gun:
|
||||||
ammo: 30
|
ammo: 30
|
||||||
|
Loading…
Reference in New Issue
Block a user