Initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>WildernessPvP</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<artifactId>Factions</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.cosmicpvp.cosmicwildpvp;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.commands.WildPvPCommand;
|
||||
import com.cosmicpvp.cosmicwildpvp.listeners.MenuListener;
|
||||
import com.cosmicpvp.cosmicwildpvp.listeners.QueueListener;
|
||||
import com.cosmicpvp.cosmicwildpvp.queue.QueueManager;
|
||||
import com.cosmicpvp.cosmicwildpvp.settings.CagesSetting;
|
||||
import com.cosmicpvp.cosmicwildpvp.settings.MatchSetting;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WildPvPPlugin extends JavaPlugin
|
||||
{
|
||||
private static WildPvPPlugin instance;
|
||||
private QueueManager queueManager;
|
||||
private List<MatchSetting> settingList;
|
||||
|
||||
public void onEnable() {
|
||||
WildPvPPlugin.instance = this;
|
||||
this.queueManager = new QueueManager(this);
|
||||
(this.settingList = Lists.newArrayList()).add(new CagesSetting());
|
||||
Bukkit.getPluginManager().registerEvents((Listener)new QueueListener(this), (Plugin)this);
|
||||
Bukkit.getPluginManager().registerEvents((Listener)new MenuListener(), (Plugin)this);
|
||||
this.getCommand("wildpvp").setExecutor((CommandExecutor)new WildPvPCommand(this));
|
||||
System.out.println("[AstroWildPvP] Loaded...");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
if (Bukkit.getWorld("world") != null) {
|
||||
return Bukkit.getWorld("world").getSpawnLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void tpNow(final Player player, final Location loc) {
|
||||
player.teleport(loc, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
}
|
||||
|
||||
public QueueManager getQueueManager() {
|
||||
return this.queueManager;
|
||||
}
|
||||
|
||||
public List<MatchSetting> getSettingList() {
|
||||
return this.settingList;
|
||||
}
|
||||
|
||||
|
||||
public static WildPvPPlugin getInstance() {
|
||||
return WildPvPPlugin.instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.commands;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import com.cosmicpvp.cosmicwildpvp.queue.SingleWildQueue;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.BryUtil;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WildPvPCommand implements CommandExecutor, Listener
|
||||
{
|
||||
private WildPvPPlugin plugin;
|
||||
|
||||
public WildPvPCommand(final WildPvPPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getPluginManager().registerEvents((Listener)this, (Plugin)plugin);
|
||||
}
|
||||
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
BryUtil.sendMessage(sender, "&c&l(!)&c You must be a &lPlayer&c.");
|
||||
return true;
|
||||
}
|
||||
final Player player = (Player)sender;
|
||||
if (args.length == 0) {
|
||||
this.plugin.getQueueManager().openQueueInventory(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("top")) {
|
||||
((Player)sender).chat("/pvptop");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!args[0].equalsIgnoreCase("leave")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
final SingleWildQueue queue = this.plugin.getQueueManager().getQueueByHost(player);
|
||||
if (queue == null) {
|
||||
BryUtil.sendMessage((CommandSender)player, "&c&l(!)&c You are not in the &lWild PvP Queue&c.");
|
||||
return true;
|
||||
}
|
||||
this.plugin.getQueueManager().removeExisitingQueue(queue);
|
||||
BryUtil.sendMessage((CommandSender)player, "&c&l(!)&c You have left the &lWild PvP Queue&c.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.event;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.queue.SingleWildQueue;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class QueueCreateEvent extends Event implements Cancellable
|
||||
{
|
||||
private static final HandlerList handlers;
|
||||
private Player host;
|
||||
private SingleWildQueue queue;
|
||||
private boolean cancelled;
|
||||
|
||||
public QueueCreateEvent(final Player host, final SingleWildQueue queue) {
|
||||
this.host = host;
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return QueueCreateEvent.handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return QueueCreateEvent.handlers;
|
||||
}
|
||||
|
||||
public Player getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public SingleWildQueue getQueue() {
|
||||
return this.queue;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
public void setHost(final Player host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setQueue(final SingleWildQueue queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
static {
|
||||
handlers = new HandlerList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.event;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.queue.SingleWildQueue;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class QueueRemoveEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers;
|
||||
private SingleWildQueue queue;
|
||||
@Deprecated
|
||||
private Player host;
|
||||
|
||||
public QueueRemoveEvent(final SingleWildQueue queue) {
|
||||
this.host = queue.getHost();
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return QueueRemoveEvent.handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return QueueRemoveEvent.handlers;
|
||||
}
|
||||
|
||||
public SingleWildQueue getQueue() {
|
||||
return this.queue;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Player getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public void setQueue(final SingleWildQueue queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHost(final Player host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
static {
|
||||
handlers = new HandlerList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.listeners;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.util.Menu;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class MenuListener implements Listener
|
||||
{
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void onClick(final InventoryClickEvent event) {
|
||||
final InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (!(holder instanceof Menu)) {
|
||||
return;
|
||||
}
|
||||
((Menu)holder).onClick((Player)event.getWhoClicked(), event.getSlot(), event.getClick(), event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import com.cosmicpvp.cosmicwildpvp.event.QueueCreateEvent;
|
||||
import com.cosmicpvp.cosmicwildpvp.event.QueueRemoveEvent;
|
||||
import com.cosmicpvp.cosmicwildpvp.menus.MatchSettingsMenu;
|
||||
import com.cosmicpvp.cosmicwildpvp.queue.QueueState;
|
||||
import com.cosmicpvp.cosmicwildpvp.queue.SingleWildQueue;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.BryUtil;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.PlayerInventoryDisplay;
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.event.LandClaimEvent;
|
||||
import net.crankedpvp.crankedutils.utils.FactionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class QueueListener implements Listener
|
||||
{
|
||||
private WildPvPPlugin plugin;
|
||||
|
||||
public QueueListener(final WildPvPPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(final PlayerMoveEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Chunk fromChunk = event.getFrom().getChunk();
|
||||
final Chunk toChunk = event.getTo().getChunk();
|
||||
final SingleWildQueue queue = this.plugin.getQueueManager().getQueueContainingPlayer(player);
|
||||
if (fromChunk == toChunk || queue == null) {
|
||||
return;
|
||||
}
|
||||
final Chunk queueChunk = queue.getCreationLocation().getChunk();
|
||||
if (toChunk != queueChunk) {
|
||||
if (player == queue.getOpponent()) {
|
||||
queue.removeOpponentAndRequeue();
|
||||
}
|
||||
else if (player == queue.getHost()) {
|
||||
queue.cancelQueue(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final String cmd = event.getMessage().toLowerCase();
|
||||
final SingleWildQueue queue = this.plugin.getQueueManager().getQueueContainingPlayer(player);
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
if (cmd.contains("spawn") || cmd.contains("pvp leave")) {
|
||||
queue.cancelQueue(player);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
BryUtil.sendMessage((CommandSender)player, "&c&l(!) Command Not Permitted (!)");
|
||||
BryUtil.sendMessage((CommandSender)player, "&7You must use &c/spawn&7 or &c/pvp leave&7 to exit.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onLandClaim(final LandClaimEvent event) {
|
||||
final FPlayer fPlayer = event.getfPlayer();
|
||||
final Chunk chunk = event.getLocation().getChunk();
|
||||
if (this.plugin.getQueueManager().getQueueByChunk(chunk) != null) {
|
||||
BryUtil.sendMessage((CommandSender)fPlayer.getPlayer(), "&c&l(!)&c You cannot claim this land during a &lPvP Queue.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(final EntityDamageEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
final Player player = (Player)event.getEntity();
|
||||
final SingleWildQueue queue = this.plugin.getQueueManager().getQueueContainingPlayer(player);
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
if (queue.getState() == QueueState.INVINCIBILITY) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQueueRemove(final QueueRemoveEvent event) {
|
||||
final SingleWildQueue queue = event.getQueue();
|
||||
if (queue.getState() == QueueState.INVINCIBILITY) {
|
||||
queue.removeInvincibility();
|
||||
}
|
||||
if (!queue.isCageMatch() || queue.getState() == QueueState.CANCELLED) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final SingleWildQueue queue = this.plugin.getQueueManager().getQueueContainingPlayer(player);
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
queue.cancelQueue(player);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onQueueCreate(final QueueCreateEvent event) {
|
||||
final Player player = event.getHost();
|
||||
final FPlayer fPlayer = (FPlayer)FPlayers.getInstance().getByPlayer(player);
|
||||
if (this.plugin.getQueueManager().getQueueByHost(player) != null) {
|
||||
BryUtil.sendMessage((CommandSender)player, "&c&l(!)&c You are already in the Wild PvP Queue.");
|
||||
BryUtil.sendMessage((CommandSender)player, "&7You may use &c/pvp leave&7 to exit the queue.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!Board.getInstance().getFactionAt(fPlayer.getLastStoodAt()).isNone()) {
|
||||
BryUtil.sendMessage((CommandSender)player, "&c&l(!)&c You must be in &2Wilderness&c to create a queue.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!fPlayer.getFaction().isWilderness()) {
|
||||
Bukkit.broadcastMessage(BryUtil.color("&a&lWildPvP &8➥ &f" + player.getName() + "&7 (&a&n" + FactionUtils.getFaction(player).getOnlinePlayers().size() + "&f Online&7) has created a &n/pvp match&7. &cDefeat them!"));
|
||||
}
|
||||
else {
|
||||
Bukkit.broadcastMessage(BryUtil.color("&a&lWildPvP &8➥ &f" + player.getName() + " &7has created a &n/pvp match&7. &cDefeat them!"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQueueInventoryClick(final InventoryClickEvent event) {
|
||||
final Player player = (Player)event.getWhoClicked();
|
||||
final FPlayer fPlayer = (FPlayer)FPlayers.getInstance().getByPlayer(player);
|
||||
final Inventory inventory = event.getInventory();
|
||||
final ItemStack item = event.getCurrentItem();
|
||||
if (!inventory.getTitle().endsWith(ChatColor.DARK_GRAY + "Wild PvP Queue")) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
if (item != null && item.hasItemMeta() && item.getItemMeta().getDisplayName() != null && item.getItemMeta().getDisplayName().equalsIgnoreCase(CC.translate("&a&lEnter Wild PvP Queue"))) {
|
||||
player.openInventory(new MatchSettingsMenu(player, this.plugin).getInventory());
|
||||
return;
|
||||
}
|
||||
|
||||
if (item != null && item.hasItemMeta() && item.getItemMeta().getDisplayName() != null && item.getItemMeta().getDisplayName().equalsIgnoreCase(CC.translate("&6&l1v1 Cage Match"))) {
|
||||
player.closeInventory();
|
||||
player.chat("/1v1");
|
||||
return;
|
||||
}
|
||||
final SingleWildQueue queue = this.plugin.getQueueManager().getQueueByItem(item);
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
if (event.isRightClick()) {
|
||||
new PlayerInventoryDisplay(queue.getHost()).show(player);
|
||||
return;
|
||||
}
|
||||
if (this.plugin.getQueueManager().getQueueContainingPlayer(player) != null) {
|
||||
BryUtil.sendMessage((CommandSender)player, "&c&l(!)&c You are already in a pvp queue.");
|
||||
return;
|
||||
}
|
||||
if (!queue.getState().isJoinable()) {
|
||||
BryUtil.sendMessage((CommandSender)player, "&c&l(!)&c This queue currently cannot be joined.");
|
||||
return;
|
||||
}
|
||||
queue.addOpponentToQueue(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPreviewInventoryClick(final InventoryClickEvent event) {
|
||||
final Player player = (Player)event.getWhoClicked();
|
||||
final Inventory inventory = event.getInventory();
|
||||
if (inventory.getTitle().endsWith(ChatColor.GREEN + "'s Inventory")) {
|
||||
event.setCancelled(true);
|
||||
if (event.getRawSlot() == 45) {
|
||||
this.plugin.getQueueManager().openQueueInventory(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.menus;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import com.cosmicpvp.cosmicwildpvp.settings.CagesSetting;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.Menu;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MatchSettingsMenu implements Menu
|
||||
{
|
||||
private Inventory inventory;
|
||||
private WildPvPPlugin plugin;
|
||||
boolean cagesEnabled;
|
||||
boolean doublesEnabled;
|
||||
|
||||
public MatchSettingsMenu(final Player player, final WildPvPPlugin plugin) {
|
||||
this.inventory = Bukkit.createInventory((InventoryHolder)this, 9, "Match Settings");
|
||||
this.cagesEnabled = false;
|
||||
this.doublesEnabled = false;
|
||||
this.plugin = plugin;
|
||||
this.inventory.setItem(4, this.getConfirmQueue());
|
||||
}
|
||||
|
||||
public void update(final Player player) {
|
||||
this.inventory.setItem(22, this.getConfirmQueue());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final Player player, final int slot, final ClickType type, final InventoryClickEvent event) {
|
||||
if (slot == 4) {
|
||||
event.setCancelled(true);
|
||||
this.plugin.getQueueManager().createNewQueue(player, this.cagesEnabled);
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getCagesClickable() {
|
||||
return new CagesSetting().getMatchItem(this.cagesEnabled);
|
||||
}
|
||||
|
||||
private ItemStack getConfirmQueue() {
|
||||
final ItemStack item = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(CC.translate("&a&lConfirm Queue"));
|
||||
final List<String> lore = Lists.newArrayList();
|
||||
lore.add(CC.translate("&7Click here to accept and confirm the queue."));
|
||||
meta.setLore((List)lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.queue;
|
||||
|
||||
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import com.cosmicpvp.cosmicwildpvp.event.QueueCreateEvent;
|
||||
import com.cosmicpvp.cosmicwildpvp.event.QueueRemoveEvent;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.BryUtil;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.InventoryUpdateTask;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.FactionUtils;
|
||||
import net.crankedpvp.crankedutils.utils.WorldGuardUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class QueueManager
|
||||
{
|
||||
private List<SingleWildQueue> queues;
|
||||
private WildPvPPlugin plugin;
|
||||
|
||||
public QueueManager(final WildPvPPlugin plugin) {
|
||||
this.queues = Lists.newArrayList();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void openQueueInventory(final Player player) {
|
||||
new InventoryUpdateTask(player, this.plugin.getQueueManager().getQueueInventory(player)) {
|
||||
@Override
|
||||
public ItemStack[] getUpdatedContents() {
|
||||
return QueueManager.this.plugin.getQueueManager().getQueueInventory(player).getContents();
|
||||
}
|
||||
};
|
||||
BryUtil.playSound(player, Sound.NOTE_PLING);
|
||||
}
|
||||
|
||||
public Inventory getQueueInventory(final Player viewer) {
|
||||
final int inventorySize = (this.queues.size() % 9 == 0) ? (this.queues.size() + 9) : (9 - this.queues.size() % 9 + this.queues.size());
|
||||
final Inventory queueInventory = Bukkit.createInventory((InventoryHolder)null, inventorySize, ChatColor.DARK_GRAY + "Wild PvP Queue");
|
||||
queueInventory.setItem(8, BryUtil.createItem(Material.STAINED_GLASS_PANE, "&a&lEnter Wild PvP Queue", 1, 5, "", "&7Click to create a &nWild PvP", "&7match at your current location.", "", "&a&lWhat is Wild PvP?", "&7Wild PvP is when a player or", "&7players fight inside Wilderness", "&7chunks (unclaimed land) to", "&7ensure the most fair fight.", "", "&7Once an opponent accepts your Wild PvP", "&7match they will be teleported to your", "&7location and you will each receive", "&77 seconds of immunity - then, you fight!"));
|
||||
queueInventory.setItem(7, BryUtil.createItem(Material.IRON_FENCE, "&6&l1v1 Cage Match", 1, 5, Arrays.asList("", "&7Click to create a &n1v1 Cage PvP Match", "&7match at your current location.", "", "&6&lWhat is a 1v1 Cage Match?", "&71v1 Cage PvP is where", "&72 players fight in the wilderness", "&7in a chunk until a player", "&7defeats the other one.", "", "&7Once an opponent accepts your 1v1 Cage PvP", "&7match they will be teleported to your", "&7location and you will each receive", "&77 seconds of immunity - then, you fight!")));
|
||||
|
||||
this.queues.stream().filter(queue -> queue.getHost() != viewer).forEach(queue -> queueInventory.addItem(new ItemStack[] { queue.getQueueDisplayItem(viewer) }));
|
||||
return queueInventory;
|
||||
}
|
||||
|
||||
public SingleWildQueue getQueueByItem(final ItemStack itemStack) {
|
||||
if (itemStack == null || !itemStack.hasItemMeta() || !itemStack.getItemMeta().hasDisplayName()) {
|
||||
return null;
|
||||
}
|
||||
final Player player = Bukkit.getPlayer(ChatColor.stripColor(itemStack.getItemMeta().getDisplayName()));
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
return this.getQueueByHost(player);
|
||||
}
|
||||
|
||||
public SingleWildQueue getQueueByChunk(final Chunk chunk) {
|
||||
return this.queues.stream().filter(queue -> queue.getCreationLocation().getChunk().equals(chunk)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public SingleWildQueue getQueueByHost(final Player player) {
|
||||
return this.queues.stream().filter(queue -> queue.getHost().equals(player)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public SingleWildQueue getQueueContainingPlayer(final Player player) {
|
||||
return this.queues.stream().filter(queue -> queue.containsPlayer(player)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public void createNewQueue(final Player host, final boolean cages) {
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (host.getLocation().getChunk() == p.getLocation().getChunk() && !p.getPlayer().getName().equals(host.getName())) {
|
||||
host.sendMessage(CC.translate("&c&l(!)&c You cannot create a pvp match when there is someone else standing in the same chunk as you."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!FactionUtils.getFactionAt(host.getLocation()).isWilderness()) {
|
||||
host.sendMessage(CC.translate("&c&l(!)&c You cannot create a pvp match here."));
|
||||
return;
|
||||
}
|
||||
final SingleWildQueue queue = new SingleWildQueue(host);
|
||||
queue.setTimeInitiated(System.currentTimeMillis());
|
||||
queue.setCageMatch(cages);
|
||||
final QueueCreateEvent event = new QueueCreateEvent(host, queue);
|
||||
Bukkit.getPluginManager().callEvent((Event)event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
final List<String> messages = Lists.newArrayList("&a&l(!)&a You have entered into the Wild PvP queue!", "&7Please wait for an opponent to join.", "");
|
||||
if (cages) {
|
||||
messages.add("&5&lCage Match &7- &dThe chunk you are standing in has been enclosed with a inescapable cage, this cage will not be removed until 120s after the match begins.");
|
||||
}
|
||||
else {
|
||||
messages.add("&c&lGlass Border &7- &cThe glass border displays the outside of the current chunk you are standing in, this chunk will not be claimable until after player invincibility is removed.");
|
||||
}
|
||||
BryUtil.sendMessage((CommandSender)host, messages);
|
||||
queue.showChunkBorder();
|
||||
this.queues.add(queue);
|
||||
}
|
||||
|
||||
public void removeExisitingQueue(final SingleWildQueue queue) {
|
||||
final QueueRemoveEvent event = new QueueRemoveEvent(queue);
|
||||
Bukkit.getPluginManager().callEvent((Event)event);
|
||||
queue.hideChunkBorder();
|
||||
queue.setHost(null);
|
||||
queue.setCreationLocation(null);
|
||||
queue.setOpponent(null);
|
||||
queue.setState(null);
|
||||
queue.setPreviousLocationMap(null);
|
||||
this.queues.remove(queue);
|
||||
}
|
||||
|
||||
public List<SingleWildQueue> getQueues() {
|
||||
return this.queues;
|
||||
}
|
||||
|
||||
public WildPvPPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.queue;
|
||||
|
||||
public enum QueueState
|
||||
{
|
||||
IDLE(true, false),
|
||||
INVINCIBILITY(false, true),
|
||||
CANCELLED(false, false),
|
||||
END(false, true);
|
||||
|
||||
private boolean joinable;
|
||||
private boolean teleported;
|
||||
|
||||
private QueueState(final boolean joinable, final boolean teleported) {
|
||||
this.joinable = joinable;
|
||||
this.teleported = teleported;
|
||||
}
|
||||
|
||||
public boolean isJoinable() {
|
||||
return this.joinable;
|
||||
}
|
||||
|
||||
public boolean isTeleported() {
|
||||
return this.teleported;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.queue;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.BryUtil;
|
||||
import com.cosmicpvp.cosmicwildpvp.util.InvincibilityTimer;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.iface.RelationParticipator;
|
||||
import net.crankedpvp.crankedutils.utils.TimeUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SingleWildQueue
|
||||
{
|
||||
protected Map<UUID, Location> previousLocationMap;
|
||||
protected Location creationLocation;
|
||||
protected InvincibilityTimer invincibilityTimer;
|
||||
protected Player host;
|
||||
protected Player opponent;
|
||||
protected QueueState state;
|
||||
protected long timeInitiated;
|
||||
protected boolean hidden;
|
||||
protected boolean cageMatch;
|
||||
protected Map<String, Boolean> settingKeyMap;
|
||||
|
||||
public SingleWildQueue(final Player host) {
|
||||
this.previousLocationMap = Maps.newHashMap();
|
||||
this.host = host;
|
||||
this.creationLocation = host.getLocation();
|
||||
this.timeInitiated = System.currentTimeMillis();
|
||||
this.settingKeyMap = Maps.newHashMap();
|
||||
this.state = QueueState.IDLE;
|
||||
}
|
||||
|
||||
public ItemStack getQueueDisplayItem(final Player viewer) {
|
||||
final FPlayer fviewer = (FPlayer)FPlayers.getInstance().getByPlayer(viewer);
|
||||
final FPlayer fhost = (FPlayer)FPlayers.getInstance().getByPlayer(this.host);
|
||||
final ChatColor relationColor = fviewer.getColorTo((RelationParticipator)fhost);
|
||||
final List<String> lore = Lists.newArrayList();
|
||||
lore.add("&7" + TimeUtils.formatSeconds((long)this.getUptime()));
|
||||
lore.add("");
|
||||
lore.add("&a&lPlayer HP&a: &a&n" + new Double(this.host.getHealth()).intValue());
|
||||
lore.add("");
|
||||
lore.add("&a&lFaction");
|
||||
lore.add(" &f" + fhost.getFaction().getTag(fviewer) + " &7(&a" + fhost.getFaction().getOnlinePlayers().size() + "&7 online)");
|
||||
lore.add("");
|
||||
lore.add("&a&lNearby");
|
||||
lore.add(" &f" + BryUtil.getNearbyPlayers(this.host, 64).size() + " Player(s)");
|
||||
lore.add("");
|
||||
lore.add("&7Left-Click to accept their request.");
|
||||
lore.add("&7Right-Click to view their inventory.");
|
||||
if (!this.cageMatch) {
|
||||
return BryUtil.createPlayerSkull(this.host.getName(), relationColor.toString() + ChatColor.BOLD + this.host.getName(), lore);
|
||||
}
|
||||
lore.add(1, "&e&lCAGE MATCH ENABLED");
|
||||
return BryUtil.createItem(Material.IRON_FENCE, relationColor.toString() + ChatColor.BOLD + this.host.getName(), lore);
|
||||
}
|
||||
|
||||
public void addOpponentToQueue(final Player opponent) {
|
||||
this.opponent = opponent;
|
||||
this.state = QueueState.INVINCIBILITY;
|
||||
this.invincibilityTimer = new InvincibilityTimer(this, 7);
|
||||
this.previousLocationMap.put(opponent.getUniqueId(), opponent.getLocation());
|
||||
WildPvPPlugin.tpNow(opponent, this.creationLocation);
|
||||
opponent.sendMessage("");
|
||||
BryUtil.sendMessage((CommandSender)opponent, "&a&l(!)&a You have joined " + this.host.getName() + "'s Wild PvP Queue.");
|
||||
opponent.sendMessage("");
|
||||
this.host.sendMessage("");
|
||||
BryUtil.sendMessage((CommandSender)this.host, "&a&l(!) &f&l" + opponent.getName() + " &ahas joined &nYOUR&a Wild PvP Queue.\n");
|
||||
this.host.sendMessage("");
|
||||
}
|
||||
|
||||
public void sendOpponentToPreviousLocation() {
|
||||
WildPvPPlugin.tpNow(this.opponent, this.previousLocationMap.get(this.opponent.getUniqueId()));
|
||||
this.previousLocationMap.remove(this.opponent.getUniqueId());
|
||||
}
|
||||
|
||||
public void removeOpponentAndRequeue() {
|
||||
BryUtil.sendMessage((CommandSender)this.host, "&c&l(!)&c&l " + this.opponent.getName() + "&c has left the &lWild PvP Queue&c.");
|
||||
BryUtil.sendMessage((CommandSender)this.host, " &7&o(( You've been added back to the queue ))");
|
||||
this.opponent = null;
|
||||
this.state = QueueState.IDLE;
|
||||
}
|
||||
|
||||
public boolean containsPlayer(final Player player) {
|
||||
return this.host == player || this.opponent == player;
|
||||
}
|
||||
|
||||
public List<Player> getBoth() {
|
||||
return Lists.newArrayList(this.host, this.opponent);
|
||||
}
|
||||
|
||||
public void cancelQueue(final Player whoCancelled) {
|
||||
this.removeInvincibility();
|
||||
this.getBoth().stream().filter(player -> player != null).forEach(player -> BryUtil.sendMessage(player, "&c&l(!) &c" + whoCancelled.getName() + " has left the pvp queue."));
|
||||
if (this.opponent != null) {
|
||||
this.sendOpponentToPreviousLocation();
|
||||
if (this.opponent == whoCancelled) {
|
||||
this.removeOpponentAndRequeue();
|
||||
}
|
||||
}
|
||||
if (this.host == whoCancelled) {
|
||||
this.state = QueueState.CANCELLED;
|
||||
WildPvPPlugin.getInstance().getQueueManager().removeExisitingQueue(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeInvincibility() {
|
||||
if (this.invincibilityTimer != null) {
|
||||
this.invincibilityTimer.remove();
|
||||
this.invincibilityTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void hideChunkBorder() {
|
||||
BryUtil.getChunkBorderLocations(this.creationLocation, 3).forEach(loc -> loc.getBlock().getState().update());
|
||||
}
|
||||
|
||||
public void showChunkBorder() {
|
||||
|
||||
BryUtil.getChunkBorderLocations(this.creationLocation, 3).forEach(loc -> this.host.sendBlockChange(loc, Material.STAINED_GLASS, (byte)14));
|
||||
|
||||
}
|
||||
|
||||
public int getUptime() {
|
||||
return (int)(System.currentTimeMillis() - this.timeInitiated) / 1000;
|
||||
}
|
||||
|
||||
public void endSuccesfully() {
|
||||
this.state = QueueState.END;
|
||||
WildPvPPlugin.getInstance().getQueueManager().removeExisitingQueue(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Map<UUID, Location> getPreviousLocationMap() {
|
||||
return this.previousLocationMap;
|
||||
}
|
||||
|
||||
public Location getCreationLocation() {
|
||||
return this.creationLocation;
|
||||
}
|
||||
|
||||
public InvincibilityTimer getInvincibilityTimer() {
|
||||
return this.invincibilityTimer;
|
||||
}
|
||||
|
||||
public Player getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public Player getOpponent() {
|
||||
return this.opponent;
|
||||
}
|
||||
|
||||
public QueueState getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public long getTimeInitiated() {
|
||||
return this.timeInitiated;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public boolean isCageMatch() {
|
||||
return this.cageMatch;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getSettingKeyMap() {
|
||||
return this.settingKeyMap;
|
||||
}
|
||||
|
||||
public void setPreviousLocationMap(final Map<UUID, Location> previousLocationMap) {
|
||||
this.previousLocationMap = previousLocationMap;
|
||||
}
|
||||
|
||||
public void setCreationLocation(final Location creationLocation) {
|
||||
this.creationLocation = creationLocation;
|
||||
}
|
||||
|
||||
public void setInvincibilityTimer(final InvincibilityTimer invincibilityTimer) {
|
||||
this.invincibilityTimer = invincibilityTimer;
|
||||
}
|
||||
|
||||
public void setHost(final Player host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setOpponent(final Player opponent) {
|
||||
this.opponent = opponent;
|
||||
}
|
||||
|
||||
public void setState(final QueueState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void setTimeInitiated(final long timeInitiated) {
|
||||
this.timeInitiated = timeInitiated;
|
||||
}
|
||||
|
||||
public void setHidden(final boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public void setCageMatch(final boolean cageMatch) {
|
||||
this.cageMatch = cageMatch;
|
||||
}
|
||||
|
||||
public void setSettingKeyMap(final Map<String, Boolean> settingKeyMap) {
|
||||
this.settingKeyMap = settingKeyMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.settings;
|
||||
|
||||
|
||||
import net.crankedpvp.crankedutils.utils.CC;
|
||||
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CagesSetting extends MatchSetting
|
||||
{
|
||||
public CagesSetting() {
|
||||
super("cages");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getMatchItem(final boolean enabled) {
|
||||
final String status = enabled ? CC.translate("&a&lENABLED") : CC.translate("&c&lDISABLED");
|
||||
return new ItemBuilder(Material.IRON_FENCE, CC.translate("&e&lCAGE MATCH"), status, "", CC.translate("&7If this setting is enabled all players"), CC.translate("&7will be sent into an inescapable cage."), "", CC.translate("&7The cage will despawn &n60 seconds&7 after"), CC.translate("&7the pvp match begins."), "", CC.translate("&7Click here to &ntoggle&7 this setting")).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.settings;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class MatchSetting
|
||||
{
|
||||
private String key;
|
||||
|
||||
public MatchSetting(final String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public abstract ItemStack getMatchItem(final boolean p0);
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BryUtil
|
||||
{
|
||||
private static final char COLOR_CHAR = '&';
|
||||
private static final String LOGGER_PREFIX;
|
||||
|
||||
public static ItemStack createItem(final Material material, final String name, final int amount, final int data, final String... lore) {
|
||||
final ItemStack item = new ItemStack(material, amount, (short)data);
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(color(name));
|
||||
meta.setLore((List)color(Arrays.asList(lore)));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createItem(final Material material, final String name, final String... lore) {
|
||||
return createItem(material, name, 1, 0, lore);
|
||||
}
|
||||
|
||||
public static ItemStack createItem(final Material material, final String name, final int amount, final String... lore) {
|
||||
return createItem(material, name, amount, 1, lore);
|
||||
}
|
||||
|
||||
public static ItemStack createItem(final Material material, final String name, final int amount, final int data, final List<String> lore) {
|
||||
return createItem(material, name, amount, data, (String[])lore.toArray(new String[lore.size()]));
|
||||
}
|
||||
|
||||
public static ItemStack createItem(final Material material, final String name, final List<String> lore) {
|
||||
return createItem(material, name, (String[])lore.toArray(new String[lore.size()]));
|
||||
}
|
||||
|
||||
public static ItemStack createPlayerSkull(final String owner, final String name, final String... lore) {
|
||||
final ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
|
||||
final SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
meta.setOwner(owner);
|
||||
meta.setDisplayName(color(name));
|
||||
meta.setLore((List)color(Arrays.asList(lore)));
|
||||
item.setItemMeta((ItemMeta)meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createPlayerSkull(final String owner, final String name, final List<String> lore) {
|
||||
return createPlayerSkull(owner, name, (String[])lore.toArray(new String[lore.size()]));
|
||||
}
|
||||
|
||||
public static ItemStack createEntitySkull(final EntityType entityType, final String name, final String... lore) {
|
||||
return createPlayerSkull("MHF_" + entityType.name(), name, lore);
|
||||
}
|
||||
|
||||
public static List<ItemStack> removeNulls(final List<ItemStack> itemStacks) {
|
||||
final List<ItemStack> list = new ArrayList<ItemStack>();
|
||||
for (final ItemStack item : itemStacks) {
|
||||
if (item != null) {
|
||||
if (item.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<ItemStack> removeMaterial(final List<ItemStack> itemStacks, final Material material) {
|
||||
final List<ItemStack> list = new ArrayList<ItemStack>();
|
||||
for (final ItemStack item : itemStacks) {
|
||||
if (item != null) {
|
||||
if (item.getType() == material) {
|
||||
continue;
|
||||
}
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
return removeNulls(list);
|
||||
}
|
||||
|
||||
public static List<ItemStack> removeMaterials(final List<ItemStack> itemStacks, final Material... materials) {
|
||||
List<ItemStack> list = itemStacks;
|
||||
for (final Material mat : materials) {
|
||||
list = removeMaterial(list, mat);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static int roundInventorySize(final int count) {
|
||||
return (count + 8) / 9 * 9;
|
||||
}
|
||||
|
||||
public static String oridinate(final String string) {
|
||||
return colorAndStrip(string.toLowerCase().replaceAll(" ", "").replace("_", ""));
|
||||
}
|
||||
|
||||
public static String colorAndStrip(final String message) {
|
||||
return ChatColor.stripColor(color(message));
|
||||
}
|
||||
|
||||
public static String color(final String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
public static List<String> color(final List<String> messages) {
|
||||
return messages.stream().map(BryUtil::color).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void playSound(final Player player, final Sound sound) {
|
||||
player.playSound(player.getLocation(), sound, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
public static void sendMessage(final CommandSender sender, final String message) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage(color(message));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(final CommandSender sender, final List<String> messages) {
|
||||
sender.sendMessage((String[])color(messages).toArray(new String[messages.size()]));
|
||||
}
|
||||
|
||||
public static void fillInventory(final Inventory inventory, final ItemStack item) {
|
||||
for (int i = 0; i < inventory.getSize(); ++i) {
|
||||
if (inventory.getItem(i) == null) {
|
||||
inventory.setItem(i, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void fillInventory(final Inventory inventory) {
|
||||
fillInventory(inventory, createItem(Material.STAINED_GLASS_PANE, "&7", 1, 15, "&7"));
|
||||
}
|
||||
|
||||
public static boolean hasArmorOn(final Player player) {
|
||||
for (final ItemStack item : player.getInventory().getArmorContents()) {
|
||||
if (item != null && item != null && item.getType() != Material.AIR) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void log(final String message, final LogLevel level) {
|
||||
Bukkit.getConsoleSender().sendMessage(color(level.getColor() + BryUtil.LOGGER_PREFIX.replace("%level%", level.name()) + " " + message));
|
||||
}
|
||||
|
||||
public static String formatBoolean(final boolean enabled) {
|
||||
return color(enabled ? "&a&lENABLED" : "&c&lDISABLED");
|
||||
}
|
||||
|
||||
public static List<ItemStack> getAllContents(final Player player) {
|
||||
final List<ItemStack> contents = Lists.newArrayList(player.getInventory().getArmorContents());
|
||||
contents.addAll(Lists.newArrayList(player.getInventory().getContents()));
|
||||
return removeNulls(contents);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List getNearbyPlayers(Player player, int radius) {
|
||||
return player.getNearbyEntities((double)radius, (double)radius, (double)radius).stream().filter((entity) -> entity instanceof Player).map((entity) -> (Player)entity).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Location> getChunkBorderLocations(final Chunk c, final int y, final int height) {
|
||||
final List<Location> blocks = Lists.newArrayList();
|
||||
final int maxX = 15;
|
||||
final int maxY = y + height;
|
||||
final int maxZ = 15;
|
||||
final int minX = -16;
|
||||
final int minY = y;
|
||||
final int minZ = -16;
|
||||
for (int locX = -16; locX <= 15; ++locX) {
|
||||
for (int locZ = -16; locZ <= 15; ++locZ) {
|
||||
for (int locY = minY; locY <= maxY; ++locY) {
|
||||
final Block block = c.getBlock(locX, locY, locZ);
|
||||
if (locX == -16 || locX == 15 || locZ == -16 || locZ == 15) {
|
||||
blocks.add(block.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public static List<Location> getChunkBorderLocations(final Location loc, final int height) {
|
||||
final List<Location> blocks = Lists.newArrayList();
|
||||
final Chunk c = loc.getChunk();
|
||||
final int maxX = 15;
|
||||
final int maxY = loc.getBlockY() + height;
|
||||
final int maxZ = 15;
|
||||
final int minX = -16;
|
||||
final int minY = loc.getBlockY() - height;
|
||||
final int minZ = -16;
|
||||
for (int locX = -16; locX <= 15; ++locX) {
|
||||
for (int locZ = -16; locZ <= 15; ++locZ) {
|
||||
for (int locY = minY; locY <= maxY; ++locY) {
|
||||
final Block block = c.getBlock(locX, locY, locZ);
|
||||
if (locX == -16 || locX == 15 || locZ == -16 || locZ == 15) {
|
||||
blocks.add(block.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
static {
|
||||
LOGGER_PREFIX = color("[AdvancedDuels] %level%:");
|
||||
}
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
INFO(ChatColor.WHITE),
|
||||
ERROR(ChatColor.RED),
|
||||
SUCCESS(ChatColor.GREEN);
|
||||
|
||||
private ChatColor color;
|
||||
|
||||
private LogLevel(final ChatColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public ChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.util;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public abstract class InventoryUpdateTask extends BukkitRunnable
|
||||
{
|
||||
private Player player;
|
||||
private Inventory inventory;
|
||||
|
||||
public InventoryUpdateTask(final Player player, final Inventory inventory) {
|
||||
this.player = player;
|
||||
this.inventory = inventory;
|
||||
this.player.openInventory(inventory);
|
||||
this.runTaskTimer((Plugin) WildPvPPlugin.getInstance(), 60L, 60L);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (!this.player.isOnline()) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (this.player.getOpenInventory() == null) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!this.player.getOpenInventory().getTopInventory().getTitle().equals(this.inventory.getTitle())) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
this.inventory.setContents(this.getUpdatedContents());
|
||||
}
|
||||
|
||||
public abstract ItemStack[] getUpdatedContents();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.util;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import com.cosmicpvp.cosmicwildpvp.queue.SingleWildQueue;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class InvincibilityTimer extends BukkitRunnable
|
||||
{
|
||||
private SingleWildQueue queue;
|
||||
private int timeRemaining;
|
||||
|
||||
public InvincibilityTimer(final SingleWildQueue queue, final int duration) {
|
||||
this.queue = queue;
|
||||
this.timeRemaining = duration;
|
||||
queue.getBoth().forEach(player -> player.setMetadata("wildpvp_timer", (MetadataValue)new FixedMetadataValue((Plugin) WildPvPPlugin.getInstance(), (Object)true)));
|
||||
this.runTaskTimer((Plugin)WildPvPPlugin.getInstance(), 20L, 20L);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (this.timeRemaining == 0) {
|
||||
try {
|
||||
this.queue.getBoth().forEach(player -> {
|
||||
BryUtil.sendMessage((CommandSender)player, "&aInvincibility - &lEXPIRED");
|
||||
BryUtil.playSound(player, Sound.NOTE_BASS);
|
||||
player.removeMetadata("wildpvp_timer", (Plugin)WildPvPPlugin.getInstance());
|
||||
return;
|
||||
});
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
this.cancel();
|
||||
this.queue.endSuccesfully();
|
||||
this.remove();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.queue.getBoth().forEach(player -> {
|
||||
BryUtil.sendMessage((CommandSender)player, "&aInvincibility - &lExpiring in " + this.timeRemaining + "s... &7(&C/spawn&7 to exit)");
|
||||
BryUtil.playSound(player, Sound.ORB_PICKUP);
|
||||
return;
|
||||
});
|
||||
}
|
||||
catch (Exception ex2) {}
|
||||
--this.timeRemaining;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
try {
|
||||
this.queue.getBoth().forEach(player -> player.removeMetadata("wildpvp_timer", (Plugin)WildPvPPlugin.getInstance()));
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
this.queue = null;
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public interface Menu extends InventoryHolder
|
||||
{
|
||||
default void onClick(final Player player, final int slot, final ClickType type, final InventoryClickEvent event) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.util;
|
||||
|
||||
import com.cosmicpvp.cosmicwildpvp.WildPvPPlugin;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class NoCleanTimer extends BukkitRunnable
|
||||
{
|
||||
private Player player;
|
||||
private int timeRemaining;
|
||||
|
||||
public NoCleanTimer(final Player player, final int duration) {
|
||||
this.player = player;
|
||||
this.timeRemaining = duration;
|
||||
this.runTaskTimer((Plugin) WildPvPPlugin.getInstance(), 20L, 20L);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (this.timeRemaining == 0) {
|
||||
try {
|
||||
BryUtil.sendMessage((CommandSender)this.player, "&cNo Clean Protection - &lEXPIRED");
|
||||
BryUtil.playSound(this.player, Sound.NOTE_BASS);
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
BryUtil.sendMessage((CommandSender)this.player, "&cNo Clean Protection - &lExpiring in " + this.timeRemaining + "s... &7(&C/spawn&7 to exit)");
|
||||
BryUtil.playSound(this.player, Sound.ORB_PICKUP);
|
||||
}
|
||||
catch (Exception ex2) {}
|
||||
--this.timeRemaining;
|
||||
}
|
||||
|
||||
public synchronized void cancel() throws IllegalStateException {
|
||||
this.player = null;
|
||||
super.cancel();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class PlayerInventoryDisplay
|
||||
{
|
||||
private Inventory inventory;
|
||||
|
||||
public PlayerInventoryDisplay(final Player player) {
|
||||
(this.inventory = Bukkit.createInventory((InventoryHolder)null, 54, ChatColor.GREEN + player.getName() + ChatColor.GREEN + "'s Inventory")).setContents(player.getInventory().getContents());
|
||||
this.inventory.setItem(45, BryUtil.createItem(Material.ARROW, "&a&lReturn to Queue", "", "&7Click here to return to the", "&7Wild PvP queue menu."));
|
||||
final ListIterator<Integer> slotIter = Lists.newArrayList(51, 50, 48, 47).listIterator();
|
||||
while (slotIter.hasNext()) {
|
||||
this.inventory.setItem((int)slotIter.next(), player.getInventory().getArmorContents()[slotIter.nextIndex() - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public void show(final Player viewer) {
|
||||
viewer.closeInventory();
|
||||
viewer.openInventory(this.inventory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.cosmicpvp.cosmicwildpvp.util;
|
||||
|
||||
public class TimeUtil
|
||||
{
|
||||
public static String getRemaining(final int seconds, final TimeFormat type) {
|
||||
if (seconds < 60) {
|
||||
switch (type) {
|
||||
case DAYS: {
|
||||
return "0";
|
||||
}
|
||||
case HOURS: {
|
||||
return "0";
|
||||
}
|
||||
case MINUTES: {
|
||||
return "0";
|
||||
}
|
||||
case SECONDS: {
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
default: {
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
final int minutes = seconds / 60;
|
||||
final int s = 60 * minutes;
|
||||
final int secondsLeft = seconds - s;
|
||||
if (minutes < 60) {
|
||||
switch (type) {
|
||||
case DAYS: {
|
||||
return "0";
|
||||
}
|
||||
case HOURS: {
|
||||
return "0";
|
||||
}
|
||||
case MINUTES: {
|
||||
return String.valueOf(minutes);
|
||||
}
|
||||
case SECONDS: {
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
default: {
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (minutes < 1440) {
|
||||
final int i = minutes / 60;
|
||||
final int j = 60 * i;
|
||||
final int k = minutes - j;
|
||||
switch (type) {
|
||||
case DAYS: {
|
||||
return "0";
|
||||
}
|
||||
case HOURS: {
|
||||
return String.valueOf(i);
|
||||
}
|
||||
case MINUTES: {
|
||||
return String.valueOf(k);
|
||||
}
|
||||
case SECONDS: {
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
default: {
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
final int days = minutes / 1440;
|
||||
final int inMins = 1440 * days;
|
||||
final int leftOver = minutes - inMins;
|
||||
if (leftOver < 60) {
|
||||
switch (type) {
|
||||
case DAYS: {
|
||||
return String.valueOf(days);
|
||||
}
|
||||
case HOURS: {
|
||||
return String.valueOf(0);
|
||||
}
|
||||
case MINUTES: {
|
||||
return String.valueOf(leftOver);
|
||||
}
|
||||
case SECONDS: {
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
default: {
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
final int hours = leftOver / 60;
|
||||
final int hoursInMins = 60 * hours;
|
||||
final int minsLeft = leftOver - hoursInMins;
|
||||
switch (type) {
|
||||
case DAYS: {
|
||||
return String.valueOf(days);
|
||||
}
|
||||
case HOURS: {
|
||||
return String.valueOf(hours);
|
||||
}
|
||||
case MINUTES: {
|
||||
return String.valueOf(minsLeft);
|
||||
}
|
||||
case SECONDS: {
|
||||
return String.valueOf(secondsLeft);
|
||||
}
|
||||
default: {
|
||||
return String.valueOf(seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTime(final int seconds) {
|
||||
if (seconds < 60) {
|
||||
return seconds + "s";
|
||||
}
|
||||
final int minutes = seconds / 60;
|
||||
final int s = 60 * minutes;
|
||||
final int secondsLeft = seconds - s;
|
||||
if (minutes < 60) {
|
||||
return (secondsLeft > 0) ? String.valueOf(minutes + "m " + secondsLeft + "s") : String.valueOf(minutes + "m");
|
||||
}
|
||||
if (minutes < 1440) {
|
||||
final int i = minutes / 60;
|
||||
String str = i + "h";
|
||||
final int j = 60 * i;
|
||||
final int k = minutes - j;
|
||||
if (k >= 1) {
|
||||
str = str + " " + k + "m";
|
||||
}
|
||||
if (secondsLeft > 0) {
|
||||
str = str + " " + secondsLeft + "s";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
final int days = minutes / 1440;
|
||||
String time = days + "d";
|
||||
final int inMins = 1440 * days;
|
||||
final int leftOver = minutes - inMins;
|
||||
if (leftOver >= 1) {
|
||||
if (leftOver < 60) {
|
||||
time = time + " " + leftOver + "m";
|
||||
}
|
||||
else {
|
||||
final int hours = leftOver / 60;
|
||||
time = time + " " + hours + "h";
|
||||
final int hoursInMins = 60 * hours;
|
||||
final int minsLeft = leftOver - hoursInMins;
|
||||
time = time + " " + minsLeft + "m";
|
||||
}
|
||||
}
|
||||
if (secondsLeft > 0) {
|
||||
time = time + " " + secondsLeft + "s";
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
public enum TimeFormat
|
||||
{
|
||||
DAYS,
|
||||
HOURS,
|
||||
MINUTES,
|
||||
SECONDS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
name: CrankedWildPvP
|
||||
main: com.cosmicpvp.cosmicwildpvp.WildPvPPlugin
|
||||
version: 1.0-DEV
|
||||
commands:
|
||||
wildpvp:
|
||||
usage: /<command>
|
||||
description: WildPvP command.
|
||||
aliases: [pvp]
|
||||
Reference in New Issue
Block a user