use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class DeathListener method playerDamageCheck.
@EventHandler
public void playerDamageCheck(EntityDamageEvent e) {
if (!(e.getEntity() instanceof Player))
return;
Player player = (Player) e.getEntity();
Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
if (!player.getType().equals(EntityType.PLAYER))
return;
if (!KnockbackFFA.getInstance().BungeeMode() && !knocker.isInGame())
return;
if (e.getCause() == EntityDamageEvent.DamageCause.VOID)
e.setDamage(KnockbackFFA.getInstance().getConfig().getInt("default-void-damage"));
else
e.setDamage(0);
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class GameEventsListener method onPressureButton.
@EventHandler
public void onPressureButton(PlayerInteractEvent e) {
Player player = e.getPlayer();
Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
if (knocker.isInGame()) {
if (e.getAction() != Action.PHYSICAL)
return;
if (Material.LIGHT_WEIGHTED_PRESSURE_PLATE.equals(e.getClickedBlock().getType())) {
Block block = e.getClickedBlock();
block.getDrops().clear();
player.setVelocity(player.getLocation().getDirection().setY(KnockbackFFA.getInstance().getItems().getConfig.getInt("SpecialItems.JumpPlate.jumpLevel")));
player.playSound(player.getLocation(), Sounds.JUMP_PLATE.toSound(), 1, 1);
}
}
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (e.getClickedBlock().getState() instanceof Sign || e.getClickedBlock().getState() instanceof WallSign) {
Sign sign = (Sign) e.getClickedBlock().getState();
if (!(ChatColor.YELLOW + "[A]KnockbackFFA").equalsIgnoreCase(sign.getLine(0)))
return;
if (!(ChatColor.GREEN + "Join").equalsIgnoreCase(sign.getLine(1)))
return;
if (knocker.isInGame())
player.sendMessage(Message.ALREADY_INGAME.toString());
else
player.chat("/join");
}
}
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class GameEventsListener method onBlockPlace.
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
if (!knocker.isInGame())
return;
if (e.getBlockPlaced().getType() == Material.WHITE_WOOL) {
Block block = e.getBlockPlaced();
DataBlock db = KnockbackFFA.getInstance().getBlockDataManager().getBlockData(block);
db.setBlockType("BuildingBlock");
String arenaName = KnockbackFFA.getInstance().getArenaManager().getEnabledArena().getName();
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
if (KnockbackFFA.getInstance().getArenaManager().getEnabledArena().getName().equalsIgnoreCase(arenaName)) {
switch(block.getType()) {
case WHITE_WOOL:
block.setType(Material.YELLOW_WOOL);
break;
case YELLOW_WOOL:
block.setType(Material.ORANGE_WOOL);
break;
case ORANGE_WOOL:
block.setType(Material.RED_WOOL);
break;
case RED_WOOL:
block.setType(Material.AIR);
cancel();
break;
}
} else {
block.setType(Material.AIR);
db.setBlockType("");
}
}
};
runnable.runTaskTimer(KnockbackFFA.getInstance(), 10L, 20L);
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncDelayedTask(KnockbackFFA.getInstance(), () -> player.getInventory().addItem(Items.BUILDING_BLOCK.getItem()), 1);
}
if (e.getBlockPlaced().getType() == Material.LIGHT_WEIGHTED_PRESSURE_PLATE) {
Block block = e.getBlockPlaced();
block.getDrops().clear();
BukkitScheduler blockTimer = Bukkit.getServer().getScheduler();
blockTimer.scheduleSyncDelayedTask(KnockbackFFA.getInstance(), () -> e.getBlock().setType(Material.AIR), 100);
}
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class GuiStuff method onPlayerItemInteract.
@EventHandler
public void onPlayerItemInteract(PlayerInteractEvent e) {
ItemStack item = e.getItem();
if (item == null || item.getItemMeta() == null)
return;
ItemMeta itemMeta = item.getItemMeta();
Player player = e.getPlayer();
if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
assert itemMeta != null;
assert Items.COSMETIC_ITEM.getItem() != null;
if (Items.COSMETIC_ITEM.getItem().equals(item)) {
e.setCancelled(true);
GUI cosmeticMenu = new GUI("Cosmetic Menu", (short) 5);
List<String> cList = knocker.getConfig().getStringList("owned-cosmetics");
cList.forEach(cosmetic -> {
if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".name") != null) {
String displayName = ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".name"));
String icon = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".icon");
List<String> lore = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getStringList(cosmetic + ".lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList());
assert icon != null;
Button cosmeticItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(icon), 1, displayName, Collections.singletonList("")).create(), event -> {
List<String> ownedCosmetics = knocker.getConfig().getStringList("owned-cosmetics");
String selC = ownedCosmetics.get(event.getSlot());
assert event.getCurrentItem() != null;
assert event.getCurrentItem().getItemMeta() != null;
if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(selC + ".type").equals("KILL_PARTICLE"))
knocker.getConfig().set("selected-trails", event.getCurrentItem().getItemMeta().hasEnchant(Enchantment.DURABILITY) ? selC : "");
else if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(selC + ".type").equals("TRAIL"))
knocker.getConfig().set("selected-trails", event.getCurrentItem().getItemMeta().hasEnchant(Enchantment.DURABILITY) ? selC : "");
knocker.saveConfig();
player.closeInventory();
});
ItemMeta meta = cosmeticItem.getItem().getItemMeta();
if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".type").equals("KILL_PARTICLE")) {
if (knocker.getConfig().getString("selected-cosmetic") == null)
knocker.getConfig().set("selected-cosmetic", cosmetic);
cosmeticItem.setSelected(knocker.getConfig().getString("selected-cosmetic").equals(cosmetic));
} else if (KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".type").equals("TRAIL"))
if (knocker.getConfig().getString("selected-trails") == null)
knocker.getConfig().set("selected-trails", cosmetic);
cosmeticItem.setSelected(knocker.getConfig().getString("selected-trails").equals(cosmetic));
meta.setLore(lore);
cosmeticItem.getItem().setItemMeta(meta);
cosmeticMenu.add(cosmeticItem, cList.indexOf(cosmetic));
} else {
cList.remove(cosmetic);
knocker.getConfig().set("owned-cosmetics", cList);
knocker.saveConfig();
}
});
cosmeticMenu.setOpenEventConsumer(event -> {
Player player1 = (Player) event.getPlayer();
player1.playSound(player1.getLocation(), Sounds.GUI_OPEN.toSound(), 1, 1);
});
cosmeticMenu.setCloseEventConsumer(inventoryCloseEvent -> {
Player player1 = (Player) inventoryCloseEvent.getPlayer();
player1.playSound(player1.getLocation(), Sounds.GUI_CLOSE.toSound(), 1, 1);
});
cosmeticMenu.open(player);
}
if (Items.SHOP_ITEM.getItem().equals(item)) {
e.setCancelled(true);
GUI shopMenu = new GUI("Shop Menu", (short) 5);
String cIcon = KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.cosmetic.material");
String cName = ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.cosmetic.name"));
GUI cosmeticShop = new GUI("Cosmetic Shop", (short) 5);
Button cosmeticItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(cIcon), 1, cName, Arrays.asList("")).create(), event -> {
List<String> cosmetics = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getList("registered-cosmetics").stream().map(s -> s.toString()).collect(Collectors.toList());
List<String> cList = knocker.getConfig().getStringList("owned-cosmetics");
for (String cosmetic : cosmetics) {
Button cosmeticsItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".icon")), 1, ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getString(cosmetic + ".name")), Collections.singletonList("")).create(), event1 -> {
float playerBal = knocker.getBalance();
if (playerBal >= KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getInt(cosmetics.get(event1.getSlot()) + ".price")) {
List<String> ownedCosmetics = knocker.getConfig().getStringList("owned-cosmetics");
if (!ownedCosmetics.contains(cosmetics.get(event1.getSlot()))) {
knocker.removeBalance(KnockbackFFA.getInstance().getItems().getConfig.getInt(cosmetics.get(event1.getSlot()) + ".price"));
ownedCosmetics.add(cosmetics.get(event1.getSlot()));
knocker.getConfig().set("owned-cosmetics", ownedCosmetics);
knocker.saveConfig();
player.sendMessage(Message.COSMETIC_PURCHASE_SUCCESS.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
} else
player.sendMessage(Message.COSMETIC_ALREADY_OWNED.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
} else
player.sendMessage(Message.COSMETIC_NO_ENOUGH_MONEY.toString().replace("&", "§"));
player.closeInventory();
});
ItemMeta cosmeticMeta = cosmeticsItem.getItem().getItemMeta();
List<String> lore = KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getStringList(cosmetic + ".lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList());
lore.add("§7Cost: §a" + KnockbackFFA.getInstance().getCosmeticConfiguration().getConfig.getInt(cosmetic + ".price"));
cosmeticMeta.setLore(lore);
cosmeticsItem.setSelected(cList.contains(cosmetic), "§8(§aOwned§8)");
cosmeticsItem.getItem().setItemMeta(cosmeticMeta);
cosmeticShop.add(cosmeticsItem, cosmetics.indexOf(cosmetic));
}
knocker.openGUI(cosmeticShop);
});
ItemMeta cosmeticMeta = cosmeticItem.getItem().getItemMeta();
cosmeticMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.cosmetic.name")));
cosmeticMeta.setLore(KnockbackFFA.getInstance().getItems().getConfig.getStringList("ShopMenu.cosmetic.lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList()));
cosmeticItem.getItem().setItemMeta(cosmeticMeta);
shopMenu.add(cosmeticItem, KnockbackFFA.getInstance().getItems().getConfig.getInt("ShopMenu.cosmetic.slot"));
String kIcon = KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.kit.material");
String kName = ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.kit.name"));
Button kitItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(Material.getMaterial(kIcon), 1, kName, Arrays.asList("")).create(), event -> {
GUI kitShop = new GUI("Kit Shop", (short) 5);
List<String> cosmetics = Arrays.asList(KnockbackFFA.getInstance().getKitManager().getFolder().list()).stream().map(s -> s.replace(".yml", "")).collect(Collectors.toList());
List<String> cList = knocker.getConfig().getStringList("owned-kits");
for (String cosmetic : cosmetics) {
if (cosmetic == null)
return;
Kit kit = KnockbackFFA.getInstance().getKitManager().load(cosmetic);
Button kitsItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(kit.getIcon(), 1, kit.getKitName(), Collections.singletonList("")).create(), event1 -> {
float playerBal = knocker.getBalance();
if (playerBal >= kit.getPrice()) {
List<String> ownedKits = knocker.getConfig().getStringList("owned-kits");
if (!ownedKits.contains(cosmetics.get(event1.getSlot()))) {
knocker.removeBalance(kit.getPrice());
ownedKits.add(cosmetics.get(event1.getSlot()));
knocker.getConfig().set("owned-kits", ownedKits);
knocker.saveConfig();
player.closeInventory();
player.sendMessage(Message.COSMETIC_PURCHASE_SUCCESS.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
} else
player.sendMessage(Message.COSMETIC_ALREADY_OWNED.toString().replace("&", "§").replace("%cosmetic%", cosmetics.get(event1.getSlot())));
} else
player.sendMessage(Message.COSMETIC_NO_ENOUGH_MONEY.toString().replace("&", "§"));
player.closeInventory();
});
if (kitsItem.getItem().getType() == Material.AIR)
kitsItem.getItem().setType(Material.BARRIER);
ItemMeta kitsMeta = kitsItem.getItem().getItemMeta();
List<String> lore = kit.getConfig().getStringList("KitDescription").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList());
lore.add("§7Cost: §a" + kit.getPrice());
kitsMeta.setLore(lore);
if (cList.contains(cosmetic)) {
kitsMeta.addEnchant(Enchantment.DURABILITY, 1, true);
kitsMeta.setDisplayName(kitsMeta.getDisplayName().replace("&", "§") + " §8(§aOwned§8)");
} else {
kitsMeta.removeEnchant(Enchantment.DURABILITY);
kitsMeta.setDisplayName(kitsMeta.getDisplayName().replace("&", "§").replace(" §8(§aOwned§8)", ""));
}
kitsItem.getItem().setItemMeta(kitsMeta);
kitShop.add(kitsItem, cosmetics.indexOf(cosmetic));
}
knocker.openGUI(kitShop);
});
ItemMeta kitMeta = kitItem.getItem().getItemMeta();
kitMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', KnockbackFFA.getInstance().getItems().getConfig.getString("ShopMenu.kit.name")));
kitMeta.setLore(KnockbackFFA.getInstance().getItems().getConfig.getStringList("ShopMenu.kit.lore").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList()));
kitItem.getItem().setItemMeta(kitMeta);
shopMenu.add(kitItem, KnockbackFFA.getInstance().getItems().getConfig.getInt("ShopMenu.kit.slot"));
knocker.openGUI(shopMenu);
}
assert Items.KIT_ITEM.getItem() != null;
if (Items.KIT_ITEM.getItem().equals(item)) {
e.setCancelled(true);
GUI kitsMenu = new GUI("Kits Menu", (short) 5);
kitsMenu.setOpenEventConsumer(event -> {
Player player1 = (Player) event.getPlayer();
player1.playSound(player1.getLocation(), Sounds.GUI_OPEN.toSound(), 1, 1);
});
kitsMenu.setCloseEventConsumer(inventoryCloseEvent -> {
Player player1 = (Player) inventoryCloseEvent.getPlayer();
player1.playSound(player1.getLocation(), Sounds.GUI_CLOSE.toSound(), 1, 1);
});
if (knocker.getConfig().getList("owned-kits") != null && knocker.getConfig().getList("owned-kits").size() > 0) {
if (knocker.getConfig().getList("owned-kits") == null)
knocker.getConfig().set("owned-kits", Collections.singletonList("Default"));
List<String> kitsList = knocker.getConfig().getList("owned-kits").stream().map(Object::toString).collect(Collectors.toList());
for (String kit : kitsList) {
if (kit == null)
return;
Kit kitItems = KnockbackFFA.getInstance().getKitManager().load(kit);
if (kitItems.getIcon() == null)
return;
Button kitItem = KnockbackFFA.getInstance().getButtonManager().create(new ItemBuilder(kitItems.getIcon(), 1, kitItems.getKitName(), Collections.singletonList("")).create(), event -> {
String selC = kitsList.get(event.getSlot());
assert event.getCurrentItem() != null;
assert event.getCurrentItem().getItemMeta() != null;
if (!event.getCurrentItem().getItemMeta().hasEnchant(Enchantment.DURABILITY)) {
knocker.getConfig().set("selected-kit", selC);
player.sendMessage(Message.SUCCESSFULLY_SELECTED_COSMETIC.toString().replace("%cosmetic%", selC));
} else {
knocker.getConfig().set("selected-kit", "");
player.sendMessage(Message.SUCCESSFULLY_DESELECTED_COSMETIC.toString().replace("%cosmetic%", selC));
}
knocker.saveConfig();
player.closeInventory();
});
kitItem.setSelected(knocker.getConfig().getString("selected-kit").equalsIgnoreCase(kit));
ItemMeta kitMeta = kitItem.getItem().getItemMeta();
if (kitItem.getItem().getType() == Material.AIR)
kitItem.getItem().setType(Material.BARRIER);
assert kitMeta != null;
kitMeta.setLore(kitItems.getConfig().getStringList("KitDescription").stream().map(s -> s.replace("&", "§")).collect(Collectors.toList()));
kitItem.getItem().setItemMeta(kitMeta);
kitsMenu.add(kitItem, kitsList.indexOf(kit));
}
knocker.saveConfig();
kitsMenu.setOpenEventConsumer(event -> {
Player player1 = (Player) event.getPlayer();
player1.playSound(player1.getLocation(), Sounds.GUI_OPEN.toSound(), 1, 1);
});
kitsMenu.setCloseEventConsumer(inventoryCloseEvent -> {
Player player1 = (Player) inventoryCloseEvent.getPlayer();
player1.playSound(player1.getLocation(), Sounds.GUI_CLOSE.toSound(), 1, 1);
});
}
knocker.openGUI(kitsMenu);
}
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class JoinLeaveListeners method playerJoin.
@EventHandler
public void playerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
if (knocker.getConfig().getString("deaths") != null)
return;
knocker.getConfig().set("deaths", 0);
knocker.getConfig().set("kills", 0);
knocker.getConfig().set("owned-kits", knocker.getConfig().getStringList("owned-kits").add("Default"));
knocker.getConfig().set("selected-kit", "Default");
knocker.saveConfig();
if (KnockbackFFA.getInstance().getConfig().getBoolean("join-sound"))
player.playSound(player.getLocation(), Sounds.PLAYER_JOIN.toSound(), 1, 1);
if (KnockbackFFA.getInstance().getArenaManager().getEnabledArena() == null)
knocker.setInGame(false);
else {
if (KnockbackFFA.getInstance().BungeeMode()) {
KnockbackFFA.getInstance().getArenaManager().teleportPlayerToArena(player);
player.getInventory().clear();
knocker.giveLobbyItems();
} else {
if (!knocker.isInGame()) {
KnockbackFFA.getInstance().getArenaManager().teleportToMainLobby(player);
}
}
}
}
Aggregations