use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class GameRules method onBowUse.
@EventHandler
public void onBowUse(ProjectileLaunchEvent e) {
if (!(e.getEntity().getShooter() instanceof Player))
return;
Player player = (Player) e.getEntity().getShooter();
Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
if (!KnockbackFFA.getInstance().BungeeMode() || !knocker.isInGame())
return;
if (!Items.BOW.getItem().equals(player.getInventory().getItemInMainHand()))
return;
new BukkitRunnable() {
int timer = 10;
@Override
public void run() {
timer--;
if (timer == 10 || timer == 9 || timer == 8 || timer == 7 || timer == 6 || timer == 5 || timer == 4 || timer == 3 || timer == 2 || timer == 1) {
if (player.getInventory().contains(Material.ARROW) || !player.getInventory().contains(Material.BOW)) {
cancel();
timer = 10;
} else
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(Message.BOW_COOLDOWN.toString().replace("%timer%", String.valueOf(timer)).replace("%player%", player.getName()).replace("&", "ยง")));
if (timer == 0) {
if (!player.getInventory().contains(Material.ARROW) && player.getInventory().contains(Material.BOW))
player.getInventory().addItem(Items.ARROW.getItem());
cancel();
timer = 10;
}
}
}
}.runTaskTimer(KnockbackFFA.getInstance(), 0, 20);
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class KnockbackFFA method getKnocker.
@NotNull
public Knocker getKnocker(@NotNull Player player) {
if (knockerHandler.containsKey(player.getUniqueId()))
return knockerHandler.get(player.getUniqueId());
Knocker knocker = new Knocker(player.getUniqueId());
knockerHandler.put(player.getUniqueId(), knocker);
return knocker;
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class KnockbackFFA method onEnable.
@SneakyThrows
@Override
public void onEnable() {
long time = System.currentTimeMillis();
instance = this;
getLogger().info("Loading config files...");
if (!getDataFolder().exists())
getDataFolder().mkdir();
loadConfig();
loadMessages();
loadSounds();
getLogger().info("Connecting to the database...");
databaseManager = new DatabaseManager("SQLITE");
arenaManager = new ArenaManager();
kitManager = new KitManager();
blockDataManager = new BlockDataManager();
botManager = new BotManager();
scoreboardManager = new BoardManager();
buttonManager = new ButtonManager();
Field f = getServer().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
commandMap = (CommandMap) f.get(getServer());
getLogger().info("Loading Commands");
commandManager = new CommandManager();
getLogger().info("Loading Listeners");
loadListeners();
getLogger().info("Loading Tasks");
loadTasks();
long takenTime = (System.currentTimeMillis() - time);
getLogger().info("Plugin loaded successfully in " + takenTime + "ms");
registerPlaceholders();
if (!Bukkit.getOnlinePlayers().isEmpty()) {
for (Player player : Bukkit.getOnlinePlayers()) {
Knocker knocker = getKnocker(player);
knocker.setInGame(BungeeMode());
}
}
for (Knocker p : getInGamePlayers()) {
if (p.getPlayer().getInventory().contains(Material.BOW) && !p.getPlayer().getInventory().contains(Material.ARROW))
p.getInventory().addItem(Items.ARROW.getItem());
}
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class KnockbackFFA method loadTasks.
private void loadTasks() {
if (arenaManager.getFolder().listFiles() == null || arenaManager.getFolder().listFiles().length == 0)
return;
List<Arena> arenaList = arenaManager.getArenaList();
arenaManager.setEnabledArena(arenaList.get(0));
timer = getConfig().getInt("arena-switch-timer");
new BukkitRunnable() {
@Override
public void run() {
if (arenaList.size() > 0) {
String arenaName = arenaList.get(0).getName();
arenaManager.setEnabledArena(arenaName);
zoneConfiguration.save();
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
Knocker knocker = getKnocker(p);
if (!knocker.isInGame())
return;
arenaManager.changeArena(arenaManager.load(arenaName.replace(".yml", "")));
cancel();
}
if (arenaList.size() > 1)
arenaID++;
}
}
}.runTaskTimer(this, 0, 1);
new BukkitRunnable() {
@Override
public void run() {
timer--;
if (timer == 0) {
// what should happen when timer is up
timer = getConfig().getInt("arena-switch-timer");
if (!arenaList.isEmpty()) {
// checking if arenaList even has arenas
arenaID++;
if (!(arenaID <= arenaList.size()))
arenaID = 1;
arenaManager.changeArena(arenaList.get(arenaID - 1));
}
}
}
}.runTaskTimer(this, 0, 20);
new BukkitRunnable() {
@Override
public void run() {
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
Knocker knocker = getKnocker(p);
if (!knocker.isInGame())
return;
World world = p.getWorld();
List<Entity> entList = world.getEntities();
for (Entity current : entList) if (current instanceof Item)
if (((Item) current).getItemStack().getType() == Material.LIGHT_WEIGHTED_PRESSURE_PLATE)
current.remove();
}
}
}.runTaskTimer(this, 0, 5);
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
if (!getConfig().getBoolean("wipe-items.enabled"))
return;
scheduler.scheduleSyncRepeatingTask(this, () -> {
Bukkit.broadcastMessage(Message.ITEM_CLEAR.toString());
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
Knocker knocker = getKnocker(p);
if (!knocker.isInGame())
return;
World world = p.getWorld();
List<Entity> entList = world.getEntities();
for (Entity current : entList) {
if (!(current instanceof Item))
return;
current.remove();
p.playSound(p.getLocation(), Sounds.ITEM_REMOVED.toSound(), 1, 1);
}
}
}, 10L, getConfig().getInt("wipe-items.period") * 20L);
}
use of me.gameisntover.kbffa.api.Knocker in project KnockbackFFA by GaMeIsNtOvEr.
the class GameRules method onPlayerItemPickup.
@EventHandler
public void onPlayerItemPickup(EntityPickupItemEvent e) {
if (!(e.getEntity() instanceof Player))
return;
Player player = (Player) e.getEntity();
Knocker knocker = KnockbackFFA.getInstance().getKnocker(player);
if (knocker.isInGame() || KnockbackFFA.getInstance().BungeeMode())
e.setCancelled(true);
}
Aggregations