Initial commit
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
package net.crankedpvp.wildpvp;
|
||||
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import net.crankedpvp.wildpvp.combattag.CombatTagManager;
|
||||
import net.crankedpvp.wildpvp.commands.CageMatchCommand;
|
||||
import net.crankedpvp.wildpvp.factions.FactionsManager;
|
||||
import net.crankedpvp.wildpvp.immune.ImmuneManager;
|
||||
import net.crankedpvp.wildpvp.listeners.*;
|
||||
import net.crankedpvp.wildpvp.playerdata.PlayerDataManager;
|
||||
import net.crankedpvp.wildpvp.tasks.MatchesTask;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import net.crankedpvp.wildpvp.worldguard.WorldGuardManager;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CagePvPPlugin extends JavaPlugin {
|
||||
private static CagePvPPlugin instance;
|
||||
|
||||
private FileConfiguration configLoad;
|
||||
|
||||
private CageMatchManager cageMatchManager;
|
||||
|
||||
private PlayerDataManager playerDataManager;
|
||||
|
||||
private WorldGuardManager worldGuardManager;
|
||||
|
||||
private FactionsManager factionsManager;
|
||||
|
||||
private ImmuneManager immuneManager;
|
||||
|
||||
private CombatTagManager combatTagManager;
|
||||
|
||||
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
saveDefaultConfig();
|
||||
this.configLoad = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
|
||||
this.cageMatchManager = new CageMatchManager(this);
|
||||
this.playerDataManager = new PlayerDataManager();
|
||||
this.factionsManager = new FactionsManager();
|
||||
this.immuneManager = new ImmuneManager(this);
|
||||
this.combatTagManager = new CombatTagManager();
|
||||
this.worldGuardManager = new WorldGuardManager();
|
||||
(new MatchesTask(this)).runTaskTimerAsynchronously(this, 0L, 20L);
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new JoinListener(this), this);
|
||||
pluginManager.registerEvents(new QuitListener(this), this);
|
||||
pluginManager.registerEvents(new MoveListener(this), this);
|
||||
pluginManager.registerEvents(new ItemListener(this), this);
|
||||
pluginManager.registerEvents(new DeathListener(this), this);
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new PotionListener(this), this);
|
||||
pluginManager.registerEvents(new EntityListener(this), this);
|
||||
pluginManager.registerEvents(new VehicleListener(this), this);
|
||||
pluginManager.registerEvents(new FactionListener(this), this);
|
||||
pluginManager.registerEvents(new CommandListener(this), this);
|
||||
pluginManager.registerEvents(new InteractListener(this), this);
|
||||
pluginManager.registerEvents(new TeleportListener(this), this);
|
||||
CommandManager commandManager = new CommandManager(this);
|
||||
commandManager.register(new CageMatchCommand(this));
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
if (this.cageMatchManager != null)
|
||||
this.cageMatchManager.onDisable();
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return this.configLoad;
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
this.configLoad = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
|
||||
}
|
||||
|
||||
public CageMatchManager getWildPvPManager() {
|
||||
return this.cageMatchManager;
|
||||
}
|
||||
|
||||
public PlayerDataManager getPlayerDataManager() {
|
||||
return this.playerDataManager;
|
||||
}
|
||||
|
||||
public WorldGuardManager getWorldGuardManager() {
|
||||
return this.worldGuardManager;
|
||||
}
|
||||
|
||||
public FactionsManager getFactionsManager() {
|
||||
return this.factionsManager;
|
||||
}
|
||||
|
||||
|
||||
public ImmuneManager getImmuneManager() {
|
||||
return this.immuneManager;
|
||||
}
|
||||
|
||||
public static CagePvPPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public CombatTagManager getCombatTagManager() {
|
||||
return this.combatTagManager;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.crankedpvp.wildpvp.combattag;
|
||||
|
||||
|
||||
import net.crankedpvp.combatlog.CombatTagAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CombatTagManager {
|
||||
public boolean isTagged(Player player) {
|
||||
return CombatTagAPI.isInCombat(player);
|
||||
}
|
||||
|
||||
public void removeTag(Player player) {
|
||||
CombatTagAPI.removePlayerFromCombat(player);
|
||||
}
|
||||
|
||||
public void giveTag(Player player) {
|
||||
CombatTagAPI.putPlayerInCombat(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package net.crankedpvp.wildpvp.commands;
|
||||
|
||||
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
import me.mattstudios.mf.annotations.SubCommand;
|
||||
import me.mattstudios.mf.base.CommandBase;
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.combattag.CombatTagManager;
|
||||
import net.crankedpvp.wildpvp.menus.Matches;
|
||||
import net.crankedpvp.wildpvp.utils.TitleManager;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatch;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Command("1v1")
|
||||
public class CageMatchCommand extends CommandBase {
|
||||
|
||||
private final CagePvPPlugin plugin;
|
||||
private final CombatTagManager combatTagManager;
|
||||
private final CageMatchManager cageMatchManager;
|
||||
private final FileConfiguration configLoad;
|
||||
|
||||
public CageMatchCommand(CagePvPPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.combatTagManager = this.plugin.getCombatTagManager();
|
||||
this.cageMatchManager = this.plugin.getWildPvPManager();
|
||||
this.configLoad = this.plugin.getConfig();
|
||||
}
|
||||
|
||||
@Default
|
||||
public void defaultCommand(Player player) {
|
||||
this.plugin.getPlayerDataManager().getPlayerData(player).setPage(1);
|
||||
Matches.getInstance().open(player);
|
||||
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
@SubCommand("leave")
|
||||
public void leaveCommand(Player player) {
|
||||
if (!cageMatchManager.hasWildPvP(player)) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
} else {
|
||||
if (combatTagManager.isTagged(player) && cageMatchManager.getWildPvP(player).hasStarted()) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.CombatTag.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
} else {
|
||||
CageMatch cageMatch = cageMatchManager.getWildPvP(player);
|
||||
cageMatch.setEnded(true);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
|
||||
if (cageMatch.hasJoined()) {
|
||||
Player creator;
|
||||
if (cageMatch.isJoined(player)) {
|
||||
creator = cageMatch.getCreator();
|
||||
|
||||
|
||||
cageMatch.teleportToJoinLocation(player);
|
||||
|
||||
cageMatch.hideBorder(player);
|
||||
cageMatch.hideBorder(creator);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Player.Participant.Message").replace("%player", creator.getName())));
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Teleported.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
|
||||
creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Participant.Message").replace("%player", player.getName())));
|
||||
creator.playSound(creator.getLocation(), Sound.IRONGOLEM_HIT, 1.0F, 1.0F);
|
||||
} else {
|
||||
creator = cageMatch.getJoined();
|
||||
cageMatch.teleportToJoinLocation(creator);
|
||||
cageMatch.hideBorder(player);
|
||||
cageMatch.hideBorder(creator);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Player.Participant.Message").replace("%player", creator.getName())));
|
||||
player.playSound(player.getLocation(), Sound.IRONGOLEM_HIT, 1.0F, 1.0F);
|
||||
creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Participant.Message").replace("%player", player.getName())));
|
||||
|
||||
creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Teleported.Message")));
|
||||
|
||||
creator.playSound(creator.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
|
||||
}
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(creator, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
} else {
|
||||
cageMatch.hideBorder(player);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Player.Alone.Message")));
|
||||
player.playSound(player.getLocation(), Sound.IRONGOLEM_HIT, 1.0F, 1.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Commands.WildPvP.Leave.Left.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
}
|
||||
|
||||
if (combatTagManager.isTagged(cageMatch.getCreator())) {
|
||||
combatTagManager.removeTag(cageMatch.getCreator());
|
||||
}
|
||||
|
||||
if (cageMatch.hasJoined() && combatTagManager.isTagged(cageMatch.getJoined())) {
|
||||
combatTagManager.removeTag(cageMatch.getJoined());
|
||||
}
|
||||
|
||||
cageMatchManager.removeWildPvP(cageMatch);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.crankedpvp.wildpvp.factions;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.perms.Relation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public class FactionsManager {
|
||||
private boolean factionsPlugin;
|
||||
|
||||
public FactionsManager() {
|
||||
this.registerFactions();
|
||||
}
|
||||
|
||||
public String getFactionName(Player player) {
|
||||
return FPlayers.getInstance().getByPlayer(player).getFaction().getTag();
|
||||
}
|
||||
|
||||
public boolean isFactionMember(Player player1, Player player2) {
|
||||
FPlayers fPlayers = FPlayers.getInstance();
|
||||
return fPlayers.getByPlayer(player1).getFaction().getRelationTo(fPlayers.getByPlayer(player2).getFaction()) == Relation.MEMBER;
|
||||
}
|
||||
|
||||
public boolean isFactionAlly(Player player1, Player player2) {
|
||||
FPlayers fPlayers = FPlayers.getInstance();
|
||||
return fPlayers.getByPlayer(player1).getFaction().getRelationTo(fPlayers.getByPlayer(player2).getFaction()) == Relation.ALLY;
|
||||
}
|
||||
|
||||
public boolean isWilderness(Location location) {
|
||||
Faction factionAtLocation = Board.getInstance().getFactionAt(new FLocation(location));
|
||||
return factionAtLocation == null || factionAtLocation.isWilderness();
|
||||
}
|
||||
|
||||
public void registerFactions() {
|
||||
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
|
||||
if (pluginManager.getPlugin("Factions") != null) {
|
||||
this.factionsPlugin = pluginManager.getPlugin("Factions") != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean hasFactions() {
|
||||
if (!this.factionsPlugin) {
|
||||
this.registerFactions();
|
||||
}
|
||||
|
||||
return this.factionsPlugin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.crankedpvp.wildpvp.immune;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.utils.TitleManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class Immune {
|
||||
private final CagePvPPlugin instance;
|
||||
private final Player player;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public Immune(CagePvPPlugin instance, Player player) {
|
||||
this.instance = instance;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
final ImmuneManager immuneManager = this.instance.getImmuneManager();
|
||||
final FileConfiguration configLoad = this.instance.getConfig();
|
||||
this.player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Started.Message")));
|
||||
(new BukkitRunnable() {
|
||||
int countdown = 20;
|
||||
|
||||
public void run() {
|
||||
if (!Immune.this.cancelled && Immune.this.player.isOnline() && this.countdown >= 0) {
|
||||
if (this.countdown == 15 || this.countdown == 10 || this.countdown > 0 && this.countdown <= 5) {
|
||||
Immune.this.player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ending.Message").replace("%countdown", String.valueOf(this.countdown))));
|
||||
TitleManager.sendTitle(Immune.this.player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ending.Title.Title").replace("%countdown", String.valueOf(this.countdown))), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ending.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown))), 0, 30, 0);
|
||||
Immune.this.player.playSound(Immune.this.player.getLocation(), Sound.NOTE_STICKS, 1.0F, 1.0F);
|
||||
} else if (this.countdown == 0) {
|
||||
Immune.this.cancelled = true;
|
||||
this.cancel();
|
||||
immuneManager.removeImmune(Immune.this.player);
|
||||
Immune.this.player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ended.Message").replace("%countdown", String.valueOf(this.countdown))));
|
||||
TitleManager.sendTitle(Immune.this.player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ended.Title.Title").replace("%countdown", String.valueOf(this.countdown))), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Immune.Countdown.Ended.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown))), 0, 30, 10);
|
||||
Immune.this.player.playSound(Immune.this.player.getLocation(), Sound.FIZZ, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
--this.countdown;
|
||||
} else {
|
||||
immuneManager.removeImmune(Immune.this.player);
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskTimerAsynchronously(this.instance, 0L, 20L);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.crankedpvp.wildpvp.immune;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ImmuneManager {
|
||||
private final CagePvPPlugin instance;
|
||||
private final List<Immune> immunes = new ArrayList();
|
||||
|
||||
public ImmuneManager(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public Immune createImmune(Player player) {
|
||||
Immune immune = new Immune(this.instance, player);
|
||||
this.immunes.add(immune);
|
||||
return immune;
|
||||
}
|
||||
|
||||
public void removeImmune(Immune immune) {
|
||||
this.immunes.remove(immune);
|
||||
}
|
||||
|
||||
public void removeImmune(Player player) {
|
||||
Iterator<Immune> immuneIterator = this.immunes.iterator();
|
||||
|
||||
while(immuneIterator.hasNext()) {
|
||||
Immune immune = immuneIterator.next();
|
||||
if (immune.getPlayer().getUniqueId().equals(player.getUniqueId())) {
|
||||
immuneIterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Immune getImmune(Player player) {
|
||||
Iterator<Immune> var2 = this.immunes.iterator();
|
||||
|
||||
Immune immune;
|
||||
do {
|
||||
if (!var2.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
immune = var2.next();
|
||||
} while(!immune.getPlayer().getUniqueId().equals(player.getUniqueId()));
|
||||
|
||||
return immune;
|
||||
}
|
||||
|
||||
public boolean hasImmune(Player player) {
|
||||
return this.getImmune(player) != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
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.EntityExplodeEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class BlockListeners implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public BlockListeners(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Block.Place.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
} else if (cageMatchManager.hasWildPvP(event.getBlock().getChunk())) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Block.Place.Chunk.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
if(event.getBlock().getType() == Material.DOUBLE_PLANT) return;
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Block.Break.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
} else if (cageMatchManager.hasWildPvP(event.getBlock().getChunk())) {
|
||||
if(event.getBlock().getType() == Material.DOUBLE_PLANT) return;
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Block.Break.Chunk.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
if (!this.instance.getConfig().getBoolean("WildPvP.EntityExplosion.Enable")) {
|
||||
Iterator blockListIterator = event.blockList().iterator();
|
||||
|
||||
while(blockListIterator.hasNext()) {
|
||||
org.bukkit.block.Block block = (org.bukkit.block.Block)blockListIterator.next();
|
||||
if (cageMatchManager.hasWildPvP(block.getChunk())) {
|
||||
blockListIterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class CommandListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public CommandListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (!event.getMessage().toLowerCase().startsWith("/wildpvp") && !event.getMessage().toLowerCase().startsWith("/1v1")) {
|
||||
if(event.getPlayer().hasPermission("cranked.admin")) return;
|
||||
Player player = event.getPlayer();
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
Iterator var4 = configLoad.getStringList("Listeners.Command.AllowedCommands").iterator();
|
||||
|
||||
String allowedCommand;
|
||||
do {
|
||||
if (!var4.hasNext()) {
|
||||
if (!this.instance.getWildPvPManager().hasWildPvP(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Command.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
allowedCommand = (String)var4.next();
|
||||
} while(!event.getMessage().split(" ")[0].toLowerCase().equalsIgnoreCase("/" + allowedCommand.toLowerCase()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.combattag.CombatTagManager;
|
||||
import net.crankedpvp.wildpvp.immune.Immune;
|
||||
import net.crankedpvp.wildpvp.immune.ImmuneManager;
|
||||
import net.crankedpvp.wildpvp.utils.TitleManager;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatch;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class DeathListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public DeathListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
CombatTagManager combatTagManager = this.instance.getCombatTagManager();
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
ImmuneManager immuneManager = this.instance.getImmuneManager();
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
CageMatch cageMatch = cageMatchManager.getWildPvP(player);
|
||||
if (cageMatch.hasJoined()) {
|
||||
cageMatch.setEnded(true);
|
||||
Player creator;
|
||||
Immune immune;
|
||||
Iterator var10;
|
||||
Player all;
|
||||
if (cageMatch.isJoined(player)) {
|
||||
creator = cageMatch.getCreator();
|
||||
cageMatch.hideBorder(player);
|
||||
cageMatch.hideBorder(creator);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Lost.Message").replace("%player", creator.getName())));
|
||||
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.0F, 5.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Lost.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Lost.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
|
||||
creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Won.Message").replace("%player", player.getName())));
|
||||
creator.playSound(creator.getLocation(), Sound.ENDERDRAGON_GROWL, 1.0F, 5.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(creator, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Won.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Won.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
|
||||
immune = immuneManager.createImmune(creator);
|
||||
immune.start();
|
||||
var10 = Bukkit.getOnlinePlayers().iterator();
|
||||
|
||||
while(var10.hasNext()) {
|
||||
all = (Player)var10.next();
|
||||
if (!all.getUniqueId().equals(player.getUniqueId()) && !all.getUniqueId().equals(creator.getUniqueId())) {
|
||||
all.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Broadcast.Message").replace("%winner", creator.getName()).replace("%loser", player.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
if (combatTagManager.isTagged(creator)) {
|
||||
combatTagManager.removeTag(creator);
|
||||
}
|
||||
} else {
|
||||
creator = cageMatch.getJoined();
|
||||
cageMatch.hideBorder(player);
|
||||
cageMatch.hideBorder(creator);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Lost.Message").replace("%player", creator.getName())));
|
||||
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.0F, 5.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Lost.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Lost.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
|
||||
creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Won.Message").replace("%player", player.getName())));
|
||||
creator.playSound(creator.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 5.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(creator, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Won.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Won.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
|
||||
immune = immuneManager.createImmune(creator);
|
||||
immune.start();
|
||||
var10 = Bukkit.getOnlinePlayers().iterator();
|
||||
|
||||
while(var10.hasNext()) {
|
||||
all = (Player)var10.next();
|
||||
if (!all.getUniqueId().equals(player.getUniqueId()) && !all.getUniqueId().equals(creator.getUniqueId())) {
|
||||
all.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Death.Broadcast.Message").replace("%winner", creator.getName()).replace("%loser", player.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
if (combatTagManager.isTagged(creator)) {
|
||||
combatTagManager.removeTag(creator);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(configLoad.getString("Listeners.Death.Alone.Message"));
|
||||
player.playSound(player.getLocation(), Sound.IRONGOLEM_HIT, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
cageMatchManager.removeWildPvP(cageMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.immune.ImmuneManager;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatch;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class EntityListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public EntityListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
Player damaged;
|
||||
Player damager;
|
||||
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
|
||||
damaged = (Player)event.getEntity();
|
||||
damager = (Player)event.getDamager();
|
||||
} else {
|
||||
label64: {
|
||||
if (event.getEntity() instanceof Player && event.getDamager() instanceof Projectile) {
|
||||
Projectile projectile = (Projectile)event.getDamager();
|
||||
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
|
||||
damaged = (Player)event.getEntity();
|
||||
damager = (Player)projectile.getShooter();
|
||||
if (damaged.getUniqueId().equals(damager.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
break label64;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
ImmuneManager immuneManager = this.instance.getImmuneManager();
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
if (immuneManager.hasImmune(damager)) {
|
||||
event.setCancelled(true);
|
||||
damager.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Damage.Immune.Immune.Message")));
|
||||
damager.playSound(damager.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
} else if (immuneManager.hasImmune(damaged)) {
|
||||
event.setCancelled(true);
|
||||
damager.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Damage.Immune.Player.Message")));
|
||||
damager.playSound(damager.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
} else if (cageMatchManager.hasWildPvP(damager)) {
|
||||
CageMatch cageMatch = cageMatchManager.getWildPvP(damager);
|
||||
if (cageMatch.isParticipant(damaged)) {
|
||||
if (cageMatch.isGrace()) {
|
||||
event.setCancelled(true);
|
||||
damager.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Damage.Grace.Message")));
|
||||
damager.playSound(damager.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
damager.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Damage.Match.Participant.Message")));
|
||||
damager.playSound(damager.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
} else if (cageMatchManager.hasWildPvP(damaged)) {
|
||||
event.setCancelled(true);
|
||||
damager.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Damage.Match.Player.Message")));
|
||||
damager.playSound(damager.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import com.massivecraft.factions.event.LandClaimEvent;
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class FactionListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public FactionListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLandClaim(LandClaimEvent event) {
|
||||
if (event.getLocation() != null) {
|
||||
if (this.instance.getWildPvPManager().hasWildPvP(event.getLocation().getChunk())) {
|
||||
if (event.getfPlayer() != null && event.getfPlayer().getPlayer() != null) {
|
||||
event.setCancelled(true);
|
||||
Player player = event.getfPlayer().getPlayer();
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.instance.getConfig().getString("Listeners.Claim.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public class InteractListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public InteractListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player player = event.getPlayer();
|
||||
if (this.instance.getWildPvPManager().hasWildPvP(player)) {
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
|
||||
for (String block : configLoad.getStringList("WildPvP.Match.BlockInteractBlacklist")) {
|
||||
if (event.getClickedBlock().getType().name().equalsIgnoreCase(block)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Interact.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPearl(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (this.instance.getWildPvPManager().hasWildPvP(player)) {
|
||||
if (player.getItemInHand() != null) {
|
||||
if (player.getItemInHand().getType() == Material.ENDER_PEARL) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.instance.getConfig().getString("Listeners.Teleport.Match.Participant.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
|
||||
public class ItemListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public ItemListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
Player player = event.getPlayer();
|
||||
if (this.instance.getWildPvPManager().hasWildPvP(player)) {
|
||||
|
||||
//for(String item : this.instance.getConfig().getStringList("WildPvP.Match.ItemPickupBlacklist")) {
|
||||
//if(event.getItem().getItemStack().getType().name().equalsIgnoreCase(item)) {
|
||||
event.setCancelled(true);
|
||||
//break;
|
||||
//}
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public JoinListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
this.instance.getPlayerDataManager().createPlayerData(player);
|
||||
if (this.instance.getWildPvPManager().hasWildPvP(player.getLocation().getChunk())) {
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
|
||||
for(String command : configLoad.getStringList("WildPvP.Join.Commands")) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%player", player.getName()));
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Join.Teleported.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatch;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class MoveListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public MoveListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMoveOutsideChunk(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Location fromLocation = event.getFrom();
|
||||
Location toLocation = event.getTo();
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
if (player.hasPermission("cranked.admin")) return;
|
||||
CageMatch cageMatch = cageMatchManager.getWildPvP(player);
|
||||
if (fromLocation.getChunk().getX() == cageMatch.getChunk().getX() && fromLocation.getChunk().getZ() == cageMatch.getChunk().getZ() && (toLocation.getChunk().getX() != cageMatch.getChunk().getX() || toLocation.getChunk().getZ() != cageMatch.getChunk().getZ())) {
|
||||
Location location = player.getLocation().clone().add(fromLocation.toVector().subtract(toLocation.toVector()).normalize().multiply(2.0D));
|
||||
if (location.getBlock().getType().isSolid()) {
|
||||
location.setY(location.getWorld().getHighestBlockYAt(location));
|
||||
}
|
||||
|
||||
player.teleport(location, TeleportCause.UNKNOWN);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.instance.getConfig().getString("Listeners.Move.Chunk.Participant.Message")));
|
||||
player.playSound(player.getLocation(), Sound.FIREWORK_LAUNCH, 1.0F, 5.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMoveInsideChunk(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() != GameMode.SPECTATOR) {
|
||||
Location fromLocation = event.getFrom();
|
||||
Location toLocation = event.getTo();
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
if (cageMatchManager.hasWildPvP(toLocation.getChunk())) {
|
||||
if (player.hasPermission("cranked.admin")) return;
|
||||
if (player.hasPermission("essentials.tp.others")) return;
|
||||
|
||||
CageMatch cageMatch = cageMatchManager.getWildPvP(toLocation.getChunk());
|
||||
if (!cageMatch.isParticipant(player)) {
|
||||
Location location = player.getLocation().clone().add(fromLocation.toVector().subtract(toLocation.toVector()).normalize().multiply(2.0D));
|
||||
if (location.getBlock().getType().isSolid()) {
|
||||
location.setY(location.getWorld().getHighestBlockYAt(location));
|
||||
}
|
||||
|
||||
player.teleport(location, TeleportCause.UNKNOWN);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.instance.getConfig().getString("Listeners.Move.Chunk.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.FIREWORK_LAUNCH, 1.0F, 5.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.immune.ImmuneManager;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatch;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class PotionListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public PotionListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
if (event.getAffectedEntities().size() != 0) {
|
||||
ThrownPotion thrownPotion = event.getPotion();
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
ImmuneManager immuneManager = this.instance.getImmuneManager();
|
||||
Iterator<LivingEntity> affectedEntitiesIterator = event.getAffectedEntities().iterator();
|
||||
if (thrownPotion.getShooter() != null && thrownPotion.getShooter() instanceof Player) {
|
||||
Player shooter = (Player)thrownPotion.getShooter();
|
||||
if (cageMatchManager.hasWildPvP(shooter)) {
|
||||
CageMatch cageMatch = cageMatchManager.getWildPvP(shooter);
|
||||
|
||||
while(affectedEntitiesIterator.hasNext()) {
|
||||
LivingEntity livingEntity = (LivingEntity)affectedEntitiesIterator.next();
|
||||
if (livingEntity instanceof Player) {
|
||||
Player player = (Player)livingEntity;
|
||||
if (!player.getUniqueId().equals(shooter.getUniqueId()) && !cageMatch.isParticipant(player)) {
|
||||
affectedEntitiesIterator.remove();
|
||||
event.setIntensity(livingEntity, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LivingEntity livingEntity;
|
||||
Player player;
|
||||
if (immuneManager.hasImmune(shooter)) {
|
||||
while(affectedEntitiesIterator.hasNext()) {
|
||||
livingEntity = (LivingEntity)affectedEntitiesIterator.next();
|
||||
if (livingEntity instanceof Player) {
|
||||
player = (Player)livingEntity;
|
||||
if (!player.getUniqueId().equals(shooter.getUniqueId())) {
|
||||
affectedEntitiesIterator.remove();
|
||||
event.setIntensity(livingEntity, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while(true) {
|
||||
do {
|
||||
do {
|
||||
do {
|
||||
if (!affectedEntitiesIterator.hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
livingEntity = (LivingEntity)affectedEntitiesIterator.next();
|
||||
} while(!(livingEntity instanceof Player));
|
||||
|
||||
player = (Player)livingEntity;
|
||||
} while(player.getUniqueId().equals(shooter.getUniqueId()));
|
||||
} while(!cageMatchManager.hasWildPvP(player) && !immuneManager.hasImmune(player));
|
||||
|
||||
affectedEntitiesIterator.remove();
|
||||
event.setIntensity(livingEntity, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while(true) {
|
||||
LivingEntity livingEntity;
|
||||
Player player;
|
||||
do {
|
||||
do {
|
||||
if (!affectedEntitiesIterator.hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
livingEntity = (LivingEntity)affectedEntitiesIterator.next();
|
||||
} while(!(livingEntity instanceof Player));
|
||||
|
||||
player = (Player)livingEntity;
|
||||
} while(!cageMatchManager.hasWildPvP(player) && !immuneManager.hasImmune(player));
|
||||
|
||||
affectedEntitiesIterator.remove();
|
||||
event.setIntensity(livingEntity, 0.0D);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.combattag.CombatTagManager;
|
||||
import net.crankedpvp.wildpvp.immune.Immune;
|
||||
import net.crankedpvp.wildpvp.immune.ImmuneManager;
|
||||
import net.crankedpvp.wildpvp.utils.TitleManager;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatch;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class QuitListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public QuitListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.LOWEST
|
||||
)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
this.instance.getPlayerDataManager().removePlayerData(player);
|
||||
CombatTagManager combatTagManager = this.instance.getCombatTagManager();
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
ImmuneManager immuneManager = this.instance.getImmuneManager();
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
if (immuneManager.hasImmune(player)) {
|
||||
Immune immune = immuneManager.getImmune(player);
|
||||
immune.setCancelled(true);
|
||||
immuneManager.removeImmune(immune);
|
||||
}
|
||||
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
CageMatch cageMatch = cageMatchManager.getWildPvP(player);
|
||||
cageMatch.setEnded(true);
|
||||
if (cageMatch.hasJoined()) {
|
||||
Player joined;
|
||||
if (!combatTagManager.isTagged(player)) {
|
||||
if (cageMatch.isJoined(player)) {
|
||||
joined = cageMatch.getCreator();
|
||||
cageMatch.teleportToJoinLocation(player);
|
||||
cageMatch.hideBorder(joined);
|
||||
joined.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Left.Message").replace("%player", player.getName())));
|
||||
joined.playSound(joined.getLocation(), Sound.IRONGOLEM_HIT, 1.0F, 1.0F);
|
||||
|
||||
} else {
|
||||
joined = cageMatch.getJoined();
|
||||
cageMatch.teleportToJoinLocation(joined);
|
||||
cageMatch.hideBorder(joined);
|
||||
joined.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Left.Message").replace("%player", player.getName())));
|
||||
joined.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Teleported.Message").replace("%player", player.getName())));
|
||||
joined.playSound(joined.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
|
||||
|
||||
}
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(joined, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Left.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Left.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
} else {
|
||||
Immune immune;
|
||||
Iterator var10;
|
||||
Player all;
|
||||
if (cageMatch.isJoined(player)) {
|
||||
joined = cageMatch.getCreator();
|
||||
|
||||
} else {
|
||||
joined = cageMatch.getJoined();
|
||||
|
||||
}
|
||||
cageMatch.hideBorder(joined);
|
||||
joined.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Won.Message").replace("%player", player.getName())));
|
||||
joined.playSound(joined.getLocation(), Sound.ENDERDRAGON_GROWL, 1.0F, 5.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(joined, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Won.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Won.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
combatTagManager.removeTag(joined);
|
||||
immune = immuneManager.createImmune(joined);
|
||||
immune.start();
|
||||
var10 = Bukkit.getOnlinePlayers().iterator();
|
||||
while(var10.hasNext()) {
|
||||
all = (Player)var10.next();
|
||||
if (!all.getUniqueId().equals(joined.getUniqueId())) {
|
||||
all.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Quit.Broadcast.Message").replace("%winner", joined.getName()).replace("%loser", player.getName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (combatTagManager.isTagged(joined)) {
|
||||
combatTagManager.removeTag(joined);
|
||||
}
|
||||
}
|
||||
|
||||
cageMatchManager.removeWildPvP(cageMatch);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class TeleportListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public TeleportListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleportParticipant(PlayerTeleportEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
if (event.getCause() != TeleportCause.UNKNOWN) {
|
||||
Player player = event.getPlayer();
|
||||
if (this.instance.getWildPvPManager().hasWildPvP(player)) {
|
||||
if(event.getPlayer().hasPermission("cranked.admin")) return;
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.instance.getConfig().getString("Listeners.Teleport.Match.Participant.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleportMatch(PlayerTeleportEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
if (event.getCause() == TeleportCause.UNKNOWN || event.getCause() == TeleportCause.ENDER_PEARL) return;
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() != GameMode.SPECTATOR) {
|
||||
|
||||
CageMatchManager cageMatchManager = this.instance.getWildPvPManager();
|
||||
if (cageMatchManager.hasWildPvP(event.getTo().getChunk())) {
|
||||
if(event.getPlayer().hasPermission("cranked.admin")) return;
|
||||
if (!cageMatchManager.getWildPvP(event.getTo().getChunk()).isParticipant(player)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.instance.getConfig().getString("Listeners.Teleport.Match.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package net.crankedpvp.wildpvp.listeners;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
|
||||
public class VehicleListener implements Listener {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public VehicleListener(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
if (event.getEntered() instanceof Player) {
|
||||
Player player = (Player)event.getEntered();
|
||||
if (this.instance.getWildPvPManager().hasWildPvP(player)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', this.instance.getConfig().getString("Listeners.Vehicle.Match.Message")));
|
||||
player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
package net.crankedpvp.wildpvp.menus;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.combattag.CombatTagManager;
|
||||
import net.crankedpvp.wildpvp.factions.FactionsManager;
|
||||
import net.crankedpvp.wildpvp.immune.ImmuneManager;
|
||||
import net.crankedpvp.wildpvp.playerdata.PlayerData;
|
||||
import net.crankedpvp.wildpvp.utils.*;
|
||||
import net.crankedpvp.wildpvp.utils.inventory.Placeholder;
|
||||
import net.crankedpvp.wildpvp.utils.inventory.nInventoryUtil;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatch;
|
||||
import net.crankedpvp.wildpvp.wildpvp.CageMatchManager;
|
||||
import net.crankedpvp.wildpvp.worldguard.WorldGuardManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Matches {
|
||||
private static Matches instance;
|
||||
|
||||
public static Matches getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Matches();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void open(final Player player) {
|
||||
final CagePvPPlugin instance = CagePvPPlugin.getInstance();
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(instance, new Runnable() {
|
||||
public void run() {
|
||||
final WorldGuardManager worldGuardManager = instance.getWorldGuardManager();
|
||||
final CombatTagManager combatTagManager = instance.getCombatTagManager();
|
||||
final FactionsManager factionsManager = instance.getFactionsManager();
|
||||
final CageMatchManager cageMatchManager = instance.getWildPvPManager();
|
||||
final ImmuneManager immuneManager = instance.getImmuneManager();
|
||||
final FileConfiguration configLoad = instance.getConfig();
|
||||
final PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
|
||||
final nInventoryUtil inv = new nInventoryUtil(player, event -> {
|
||||
ItemStack is = event.getItem();
|
||||
if (is.getType() == Material.FENCE_GATE) {
|
||||
player.playSound(player.getLocation(), Sound.CHEST_CLOSE, 1.0F, 1.0F);
|
||||
} else if (is.getType() == Material.ARROW && (is.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Next.Unavailable.Displayname"))) || is.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Previous.Unavailable.Displayname"))))) {
|
||||
event.setWillClose(false);
|
||||
event.setWillDestroy(false);
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
} else if (is.getType() == Material.ARROW) {
|
||||
event.setWillClose(false);
|
||||
event.setWillDestroy(false);
|
||||
if (is.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Next.Available.Displayname")))) {
|
||||
playerData.setPage(playerData.getPage() + 1);
|
||||
} else if (is.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Previous.Available.Displayname")))) {
|
||||
playerData.setPage(playerData.getPage() - 1);
|
||||
}
|
||||
|
||||
Matches.this.open(player);
|
||||
player.playSound(player.getLocation(), Sound.ARROW_HIT, 1.0F, 1.0F);
|
||||
} else if (is.getType() == Material.BOOK) {
|
||||
event.setWillClose(false);
|
||||
event.setWillDestroy(false);
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
Bukkit.getServer().dispatchCommand(player, "1v1 leave");
|
||||
Matches.this.open(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (immuneManager.hasImmune(player)) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Immune.Create.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (combatTagManager.isTagged(player)) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.CombatTag.Create.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldGuardManager.hasWorldGuard() && worldGuardManager.isRegionAtLocation(player.getLocation())) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Region.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (factionsManager.hasFactions() && !factionsManager.isWilderness(player.getLocation())) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Wilderness.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cageMatchManager.hasWildPvP(player.getLocation().getChunk())) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Chunk.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (EntityUtil.getPlayersInChunk(player.getLocation().getChunk()).size() - 1 != 0) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Players.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
CageMatch wildPvPx = cageMatchManager.createWildPvP(player, true);
|
||||
wildPvPx.showBorder(player);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Queued.Player.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1.0F, 1.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(player, ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Queued.Player.Title.Title")), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Queued.Player.Title.SubTitle")), 0, 30, 10);
|
||||
}
|
||||
|
||||
player.closeInventory();
|
||||
if (configLoad.getBoolean("WildPvP.Match.Broadcast")) {
|
||||
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
if (!all.getUniqueId().equals(player.getUniqueId())) {
|
||||
all.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Queued.Broadcast.Message").replace("%player", player.getName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (is.getType() == Material.STAINED_GLASS_PANE) {
|
||||
event.setWillClose(false);
|
||||
event.setWillDestroy(false);
|
||||
player.playSound(player.getLocation(), Sound.GLASS, 1.0F, 1.0F);
|
||||
} else if (is.getType() == Material.SKULL_ITEM) {
|
||||
event.setWillClose(false);
|
||||
event.setWillDestroy(false);
|
||||
UUID uuid = UUID.fromString(Objects.requireNonNull(NBTUtil.getTag(is, "Match")));
|
||||
Player creator = Bukkit.getServer().getPlayer(uuid);
|
||||
if (cageMatchManager.hasWildPvP(creator)) {
|
||||
final CageMatch cageMatch = cageMatchManager.getWildPvP(creator);
|
||||
if (cageMatch.isParticipant(player)) {
|
||||
Bukkit.getServer().dispatchCommand(player, "1v1 leave");
|
||||
Matches.this.open(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getClick() == ClickType.LEFT) {
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Already.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cageMatch.hasJoined()) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Started.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (immuneManager.hasImmune(player)) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Immune.Join.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
if (combatTagManager.isTagged(player)) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.CombatTag.Join.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
return;
|
||||
}
|
||||
|
||||
cageMatch.setJoinLocation(player.getLocation().clone());
|
||||
cageMatch.teleport(player);
|
||||
cageMatch.setJoined(player);
|
||||
cageMatch.startMatch();
|
||||
Bukkit.getServer().getScheduler().runTaskLater(instance, new Runnable() {
|
||||
public void run() {
|
||||
cageMatch.showBorder(player);
|
||||
}
|
||||
}, 30L);
|
||||
} else if (event.getClick() == ClickType.RIGHT) {
|
||||
player.performCommand("invsee " + creator.getName());
|
||||
//Invsee.getInstance().open(player, creator);
|
||||
player.playSound(player.getLocation(), Sound.WOOD_CLICK, 1.0F, 1.0F);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Listeners.Inventory.Matches.Available.Message")));
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
inv.setTitle(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Title")));
|
||||
inv.setRows(3);
|
||||
if (cageMatchManager.hasWildPvP(player)) {
|
||||
inv.addItem(inv.createItem(new ItemStack(Material.BOOK), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Information.Displayname")), configLoad.getStringList("Menus.Matches.Items.Information.Leave.Lore"), new Placeholder[]{new Placeholder("%active", NumberUtil.formatNumberByCommas(cageMatchManager.getActiveWildPvPs().size())), new Placeholder("%queued", NumberUtil.formatNumberByCommas(cageMatchManager.getPendingWildPvPs().size()))}, null, null), 22);
|
||||
} else {
|
||||
inv.addItem(inv.createItem(new ItemStack(Material.BOOK), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Information.Displayname")), configLoad.getStringList("Menus.Matches.Items.Information.Create.Lore"), new Placeholder[]{new Placeholder("%active", NumberUtil.formatNumberByCommas(cageMatchManager.getActiveWildPvPs().size())), new Placeholder("%queued", NumberUtil.formatNumberByCommas(cageMatchManager.getPendingWildPvPs().size()))}, null, null), 22);
|
||||
}
|
||||
|
||||
int index = playerData.getPage() * 36 - 36;
|
||||
int endIndex = index >= cageMatchManager.getPendingWildPvPs().size() ? cageMatchManager.getPendingWildPvPs().size() - 1 : index + 36;
|
||||
int invSlot = -1;
|
||||
int nextEndIndex = 0;
|
||||
for(; index < endIndex; ++index) {
|
||||
if (cageMatchManager.getPendingWildPvPs().size() > index) {
|
||||
++invSlot;
|
||||
CageMatch cageMatch = cageMatchManager.getPendingWildPvPs().get(index);
|
||||
Placeholder[] placeholder;
|
||||
if (factionsManager.hasFactions()) {
|
||||
placeholder = new Placeholder[]{new Placeholder("%playersnearby", String.valueOf(EntityUtil.getPlayersNearby(cageMatch.getLocation(), configLoad.getInt("WildPvP.Queued.PlayersNearby.Radius")).size() - 1)), new Placeholder("%player", cageMatch.getCreator().getName()), new Placeholder("%health", String.valueOf((int) cageMatch.getCreator().getHealth())), new Placeholder("%faction", factionsManager.getFactionName(cageMatch.getCreator()))};
|
||||
} else {
|
||||
placeholder = new Placeholder[]{new Placeholder("%playersnearby", String.valueOf(EntityUtil.getPlayersNearby(cageMatch.getLocation(), configLoad.getInt("WildPvP.Queued.PlayersNearby.Radius")).size() - 1)), new Placeholder("%player", cageMatch.getCreator().getName()), new Placeholder("%health", String.valueOf((int) cageMatch.getCreator().getHealth())), new Placeholder("%faction", "")};
|
||||
}
|
||||
|
||||
if (cageMatch.isCreator(player)) {
|
||||
inv.addItem(inv.createItem(SkullUtil.getPlayerSkull(cageMatch.getCreator()), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Match.Displayname").replace("%player", cageMatch.getCreator().getName())), configLoad.getStringList("Menus.Matches.Items.Match.Leave.Lore"), placeholder, null, null), invSlot);
|
||||
} else {
|
||||
inv.addItem(inv.createItem(SkullUtil.getPlayerSkull(cageMatch.getCreator()), ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Items.Match.Displayname").replace("%player", cageMatch.getCreator().getName())), configLoad.getStringList("Menus.Matches.Items.Match.Enter.Lore"), placeholder, null, null), invSlot);
|
||||
}
|
||||
|
||||
inv.createInventory();
|
||||
inv.addItemStack(NBTUtil.addTag(inv.getInventory().getItem(invSlot), "Match", cageMatch.getCreator().getUniqueId().toString()), invSlot);
|
||||
}
|
||||
|
||||
|
||||
nextEndIndex = cageMatchManager.getPendingWildPvPs().size() - playerData.getPage() * 36;
|
||||
}
|
||||
|
||||
if (playerData.getPage() == 1) {
|
||||
inv.addItem(inv.createItem(new ItemStack(Material.ARROW), configLoad.getString("Menus.Matches.Items.Previous.Unavailable.Displayname"), null, null, null, null), 18);
|
||||
} else {
|
||||
inv.addItem(inv.createItem(new ItemStack(Material.ARROW), configLoad.getString("Menus.Matches.Items.Previous.Available.Displayname"), null, null, null, null), 18);
|
||||
}
|
||||
|
||||
if (nextEndIndex != 0 && nextEndIndex >= 0) {
|
||||
inv.addItem(inv.createItem(new ItemStack(Material.ARROW), configLoad.getString("Menus.Matches.Items.Next.Available.Displayname"), null, null, null, null), 26);
|
||||
} else {
|
||||
inv.addItem(inv.createItem(new ItemStack(Material.ARROW), configLoad.getString("Menus.Matches.Items.Next.Unavailable.Displayname"), null, null, null, null), 26);
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().runTask(instance, inv::open);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.crankedpvp.wildpvp.playerdata;
|
||||
|
||||
public class PlayerData {
|
||||
private int page = 1;
|
||||
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return this.page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.crankedpvp.wildpvp.playerdata;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerDataManager {
|
||||
private Map<UUID, PlayerData> playerDataStorage = new HashMap();
|
||||
|
||||
public PlayerDataManager() {
|
||||
|
||||
for(Player all : Bukkit.getOnlinePlayers()) {
|
||||
this.createPlayerData(all);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void createPlayerData(Player player) {
|
||||
this.playerDataStorage.put(player.getUniqueId(), new PlayerData());
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(UUID uuid) {
|
||||
return (PlayerData)this.playerDataStorage.get(uuid);
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(Player player) {
|
||||
return (PlayerData)this.playerDataStorage.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayerData(UUID uuid) {
|
||||
this.playerDataStorage.remove(uuid);
|
||||
}
|
||||
|
||||
public void removePlayerData(Player player) {
|
||||
this.playerDataStorage.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean hasPlayerData(UUID uuid) {
|
||||
return this.playerDataStorage.containsKey(uuid);
|
||||
}
|
||||
|
||||
public boolean hasPlayerData(Player player) {
|
||||
return this.playerDataStorage.containsKey(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.wildpvp.tasks;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.menus.Matches;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class MatchesTask extends BukkitRunnable {
|
||||
private final CagePvPPlugin instance;
|
||||
|
||||
public MatchesTask(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
FileConfiguration configLoad = this.instance.getConfig();
|
||||
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
InventoryView inv = all.getOpenInventory();
|
||||
if (inv != null && inv.getTitle().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', configLoad.getString("Menus.Matches.Title")))) {
|
||||
Matches.getInstance().open(all);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.crankedpvp.wildpvp.utils;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityUtil {
|
||||
public static List<Player> getPlayersNearby(Location location, int radius) {
|
||||
List<Player> players = new ArrayList<>();
|
||||
for (Entity entity : location.getWorld().getNearbyEntities(location, radius, 255.0D, radius)) {
|
||||
if (!(entity instanceof Player))
|
||||
continue;
|
||||
players.add((Player)entity);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
public static List<Player> getPlayersInChunk(Chunk chunk) {
|
||||
List<Player> players = new ArrayList<>();
|
||||
byte b;
|
||||
int i;
|
||||
Entity[] arrayOfEntity;
|
||||
for (i = (arrayOfEntity = chunk.getEntities()).length, b = 0; b < i; ) {
|
||||
Entity entity = arrayOfEntity[b];
|
||||
if (entity instanceof Player)
|
||||
players.add((Player)entity);
|
||||
b = (byte)(b + 1);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package net.crankedpvp.wildpvp.utils;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class NBTUtil {
|
||||
private static final Class<?> CraftItemStackClass = NMSUtil.getCraftClass("inventory.CraftItemStack");
|
||||
private static final Class<?> NBTTagCompoundClass = NMSUtil.getNMSClass("NBTTagCompound");
|
||||
private static final Class<?> NBTTagStringClass = NMSUtil.getNMSClass("NBTTagString");
|
||||
private static final Class<?> NBTBaseClass = NMSUtil.getNMSClass("NBTBase");
|
||||
|
||||
public static ItemStack addTag(ItemStack item, String tag, String data) {
|
||||
try {
|
||||
Object NMSItemStack = CraftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke((Object)null, item);
|
||||
Field tagField = NMSItemStack.getClass().getDeclaredField("tag");
|
||||
tagField.setAccessible(true);
|
||||
Object NBTTagCompound = tagField.get(NMSItemStack);
|
||||
if (NBTTagCompound == null) {
|
||||
NBTTagCompound = NBTTagCompoundClass.newInstance();
|
||||
}
|
||||
|
||||
Object NBTTagString = NBTTagStringClass.getConstructor(String.class).newInstance(data);
|
||||
Method setMethod = NBTTagCompoundClass.getMethod("set", String.class, NBTBaseClass);
|
||||
setMethod.setAccessible(true);
|
||||
setMethod.invoke(NBTTagCompound, tag, NBTTagString);
|
||||
tagField.set(NMSItemStack, NBTTagCompound);
|
||||
Object object1 = CraftItemStackClass.getMethod("asBukkitCopy", NMSItemStack.getClass()).invoke((Object)null, NMSItemStack);
|
||||
return (ItemStack)object1;
|
||||
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | NoSuchFieldException | InstantiationException | IllegalAccessException var9) {
|
||||
var9.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTag(ItemStack item, String tag) {
|
||||
try {
|
||||
Object NMSItemStack = CraftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke((Object)null, item);
|
||||
Field tagField = NMSItemStack.getClass().getDeclaredField("tag");
|
||||
tagField.setAccessible(true);
|
||||
Object NBTTagCompound = tagField.get(NMSItemStack);
|
||||
if (NBTTagCompound == null) {
|
||||
return null;
|
||||
} else {
|
||||
Method getStringMethod = NBTTagCompound.getClass().getMethod("getString", String.class);
|
||||
getStringMethod.setAccessible(true);
|
||||
return (String)getStringMethod.invoke(NBTTagCompound, tag);
|
||||
}
|
||||
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | NoSuchFieldException | IllegalAccessException var6) {
|
||||
var6.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasTag(ItemStack item, String tag) {
|
||||
String data = getTag(item, tag);
|
||||
return data != null && data != "";
|
||||
}
|
||||
|
||||
public static boolean hasTag(ItemStack item, String tag, String searchData) {
|
||||
String data = getTag(item, tag);
|
||||
return data != null && data.equals(searchData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package net.crankedpvp.wildpvp.utils;
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSUtil {
|
||||
public static String getVersion(){
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
public static int getVersionNumber(){
|
||||
String name = getVersion().substring(3);
|
||||
return Integer.parseInt(name.substring(0, name.length() - 4));
|
||||
}
|
||||
|
||||
public static int getVersionReleaseNumber(){
|
||||
String NMSVersion = getVersion();
|
||||
return Integer.parseInt(NMSVersion.substring(NMSVersion.length() - 2).replace(".", ""));
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String className){
|
||||
try {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getCraftClass(String className){
|
||||
try {
|
||||
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(Class<?> clazz, String name, boolean declared){
|
||||
try {
|
||||
Field field;
|
||||
if(declared) {
|
||||
field = clazz.getDeclaredField(name);
|
||||
} else{
|
||||
field = clazz.getField(name);
|
||||
}
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getFieldObject(Object object, Field field){
|
||||
try {
|
||||
return field.get(object);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Object object, String fieldName, Object fieldValue, boolean declared){
|
||||
try {
|
||||
Field field;
|
||||
if(declared) {
|
||||
field = object.getClass().getDeclaredField(fieldName);
|
||||
} else{
|
||||
field = object.getClass().getField(fieldName);
|
||||
}
|
||||
field.setAccessible(true);
|
||||
field.set(object, fieldValue);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Object packet){
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", new Class[]{getNMSClass("Packet")}).invoke(playerConnection, packet);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.crankedpvp.wildpvp.utils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class NumberUtil {
|
||||
private static final DecimalFormat decimalFormat = new DecimalFormat("##.#");
|
||||
|
||||
public static String formatNumberByCommas(int number){
|
||||
return String.format("%,d", number);
|
||||
}
|
||||
|
||||
public static String formatNumberByCommas(String number){
|
||||
String numberValue = "", numberDecimalValue = "";
|
||||
if(number.contains(".")) {
|
||||
numberDecimalValue = "." + number.split("\\.")[1];
|
||||
numberValue = number.replace(numberDecimalValue, "");
|
||||
} else{
|
||||
return String.format("%,d", new BigInteger(number));
|
||||
}
|
||||
if(numberDecimalValue.equals(".0")) numberDecimalValue = "";
|
||||
return String.format("%,d", new BigInteger(numberValue)) + numberDecimalValue;
|
||||
}
|
||||
|
||||
public static String formatNumberByDecimal(float number){
|
||||
return decimalFormat.format(number);
|
||||
}
|
||||
|
||||
public static String formatNumberBySuffix(double number){
|
||||
if(number < 1000.0D) return String.valueOf(number);
|
||||
int exp = (int) (Math.log(number) / Math.log(1000.0D));
|
||||
return String.format("%.1f%c", number / Math.pow(1000.0D, exp), "kMBTPE".charAt(exp - 1));
|
||||
}
|
||||
|
||||
public static int formatNumberByText(String text) {
|
||||
return Integer.parseInt(text.replace("k", "000").replace("m", "000000").replace("b", "000000000"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.crankedpvp.wildpvp.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class SkullUtil {
|
||||
public static ItemStack getPlayerSkull(Player player) {
|
||||
ItemStack is = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
|
||||
SkullMeta sm = (SkullMeta)is.getItemMeta();
|
||||
|
||||
try {
|
||||
Object EntityPlayer = player.getClass().getMethod("getHandle").invoke(player);
|
||||
NMSUtil.setField(sm, "profile", NMSUtil.getFieldObject(EntityPlayer, NMSUtil.getField(EntityPlayer.getClass().getSuperclass(), "bH", true)), true);
|
||||
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | IllegalAccessException var4) {
|
||||
var4.printStackTrace();
|
||||
}
|
||||
|
||||
is.setItemMeta(sm);
|
||||
return is;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.crankedpvp.wildpvp.utils;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class TitleManager {
|
||||
private static final Class<?> PacketPlayOutTitle = NMSUtil.getNMSClass("PacketPlayOutTitle");
|
||||
private static final Class<?> IChatBaseComponent = NMSUtil.getNMSClass("IChatBaseComponent");
|
||||
|
||||
public static void sendTitle(Player player, String titleText, String subtitleText, int fadeIn, int stay, int fadeOut) {
|
||||
try {
|
||||
assert PacketPlayOutTitle != null;
|
||||
Object enumTitle = PacketPlayOutTitle.getDeclaredClasses()[0].getField("TITLE").get((Object)null);
|
||||
assert IChatBaseComponent != null;
|
||||
Object titleChat = IChatBaseComponent.getDeclaredClasses()[0].getMethod("a", String.class).invoke((Object)null, "{\"text\":\"" + titleText + "\"}");
|
||||
Object enumSubtitle = PacketPlayOutTitle.getDeclaredClasses()[0].getField("SUBTITLE").get((Object)null);
|
||||
Object subtitleChat = IChatBaseComponent.getDeclaredClasses()[0].getMethod("a", String.class).invoke((Object)null, "{\"text\":\"" + subtitleText + "\"}");
|
||||
Object enumTimes = PacketPlayOutTitle.getDeclaredClasses()[0].getField("TIMES").get((Object)null);
|
||||
Constructor<?> titleConstructor = PacketPlayOutTitle.getConstructor(PacketPlayOutTitle.getDeclaredClasses()[0], IChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
Object titlePacket = titleConstructor.newInstance(enumTitle, titleChat, 0, 0, 0);
|
||||
Object subtitlePacket = titleConstructor.newInstance(enumSubtitle, subtitleChat, 0, 0, 0);
|
||||
Object timesPacket = titleConstructor.newInstance(enumTimes, null, fadeIn, stay, fadeOut);
|
||||
NMSUtil.sendPacket(player, titlePacket);
|
||||
NMSUtil.sendPacket(player, subtitlePacket);
|
||||
NMSUtil.sendPacket(player, timesPacket);
|
||||
} catch (Exception var15) {
|
||||
var15.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.crankedpvp.wildpvp.utils.inventory;
|
||||
|
||||
public class Placeholder {
|
||||
private final String placeholder;
|
||||
|
||||
private final String result;
|
||||
|
||||
public Placeholder(String placeholder, String result){
|
||||
this.placeholder = placeholder;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getPlaceholder(){
|
||||
return this.placeholder;
|
||||
}
|
||||
|
||||
public String getResult(){
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
package net.crankedpvp.wildpvp.utils.inventory;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class nInventoryUtil {
|
||||
private final Player player;
|
||||
|
||||
private Listener listener;
|
||||
|
||||
private Inventory inv;
|
||||
|
||||
private String title;
|
||||
|
||||
private int size = 9;
|
||||
|
||||
private InventoryType type;
|
||||
|
||||
private final Map<Integer, ItemStack> items = new HashMap<>();
|
||||
|
||||
public nInventoryUtil(final Player player, final ClickEventHandler handler){
|
||||
this.player = player;
|
||||
if(handler != null) {
|
||||
this.listener = new Listener() {
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event){
|
||||
if(! (event.getWhoClicked() instanceof Player)) return;
|
||||
if(nInventoryUtil.this.inv != null && event.getInventory().equals(nInventoryUtil.this.inv)) {
|
||||
event.setCancelled(true);
|
||||
if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || event.getRawSlot() > nInventoryUtil.this.size)
|
||||
return;
|
||||
ClickEvent clickEvent = new ClickEvent(event.getClick(), event.getSlot(), event.getCurrentItem());
|
||||
handler.onClick(clickEvent);
|
||||
if(! clickEvent.getCancelled()) event.setCancelled(false);
|
||||
if(clickEvent.getWillClose()) event.getWhoClicked().closeInventory();
|
||||
if(clickEvent.getWillDestroy()) nInventoryUtil.this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event){
|
||||
if(! (event.getPlayer() instanceof Player)) return;
|
||||
Inventory inv = event.getInventory();
|
||||
if(inv.equals(nInventoryUtil.this.inv)) {
|
||||
inv.clear();
|
||||
nInventoryUtil.this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event){
|
||||
if(event.getPlayer().getUniqueId().equals(player.getUniqueId())) nInventoryUtil.this.destroy();
|
||||
}
|
||||
};
|
||||
Bukkit.getPluginManager().registerEvents(this.listener, CagePvPPlugin.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(Item item, int... slots){
|
||||
byte b;
|
||||
int i;
|
||||
int[] arrayOfInt;
|
||||
for(i = (arrayOfInt = slots).length, b = 0; b < i; ) {
|
||||
int slotList = arrayOfInt[b];
|
||||
this.items.put(slotList, item.prepareItem());
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
public void addItemStack(ItemStack is, int... slots){
|
||||
byte b;
|
||||
int i;
|
||||
int[] arrayOfInt;
|
||||
for(i = (arrayOfInt = slots).length, b = 0; b < i; ) {
|
||||
int slotList = arrayOfInt[b];
|
||||
this.items.put(slotList, is);
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, ItemStack> getItems(){
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public Item createItem(ItemStack is, String itemDisplayname, List<String> itemLore, Placeholder[] placeholders, Enchantment[] itemEnchantments, ItemFlag[] itemFlags){
|
||||
return new Item(is, itemDisplayname, itemLore, placeholders, itemEnchantments, itemFlags);
|
||||
}
|
||||
|
||||
public void open(){
|
||||
createInventory();
|
||||
this.player.openInventory(this.inv);
|
||||
}
|
||||
|
||||
public void setTitle(String title){
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setType(InventoryType type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setRows(int rows){
|
||||
if(rows > 6 || rows < 0) {
|
||||
this.size = 9;
|
||||
return;
|
||||
}
|
||||
this.size = rows * 9;
|
||||
}
|
||||
|
||||
public void setSize(int size){
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void createInventory(){
|
||||
if(this.type == null) {
|
||||
if(this.title == null) {
|
||||
this.inv = Bukkit.createInventory(null, this.size);
|
||||
} else{
|
||||
this.inv = Bukkit.createInventory(null, this.size, this.title);
|
||||
}
|
||||
} else if(this.title == null) {
|
||||
this.inv = Bukkit.createInventory(null, this.type);
|
||||
} else{
|
||||
this.inv = Bukkit.createInventory(null, this.type, this.title);
|
||||
}
|
||||
for(int i = 0; i < this.items.size(); i++) {
|
||||
int slot = (Integer) this.items.keySet().toArray()[i];
|
||||
this.inv.setItem(slot, this.items.get(slot));
|
||||
}
|
||||
}
|
||||
|
||||
public Inventory getInventory(){
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
public void setInventory(Inventory inv){
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
if(this.listener != null) HandlerList.unregisterAll(this.listener);
|
||||
this.title = null;
|
||||
this.type = null;
|
||||
this.inv = null;
|
||||
this.items.clear();
|
||||
this.listener = null;
|
||||
}
|
||||
|
||||
public interface ClickEventHandler {
|
||||
void onClick(ClickEvent param1ClickEvent);
|
||||
}
|
||||
|
||||
public class Item {
|
||||
private final ItemStack is;
|
||||
|
||||
private final String itemDisplayname;
|
||||
|
||||
private List<String> itemLore;
|
||||
|
||||
private final Placeholder[] placeholders;
|
||||
|
||||
private final Enchantment[] itemEnchantments;
|
||||
|
||||
private final ItemFlag[] itemFlags;
|
||||
|
||||
public Item(ItemStack is, String itemDisplayname, List<String> itemLore, Placeholder[] placeholders, Enchantment[] itemEnchantments, ItemFlag[] itemFlags){
|
||||
this.is = is;
|
||||
this.itemDisplayname = ChatColor.translateAlternateColorCodes('&', itemDisplayname);
|
||||
this.itemLore = itemLore;
|
||||
this.placeholders = placeholders;
|
||||
this.itemEnchantments = itemEnchantments;
|
||||
this.itemFlags = itemFlags;
|
||||
}
|
||||
|
||||
public void setLore(){
|
||||
if(this.itemLore != null) {
|
||||
ArrayList<String> formattedItemLore = new ArrayList<>();
|
||||
for(String itemLoreList : this.itemLore) {
|
||||
if(this.placeholders != null) {
|
||||
byte b;
|
||||
int i;
|
||||
Placeholder[] arrayOfPlaceholder;
|
||||
for(i = (arrayOfPlaceholder = this.placeholders).length, b = 0; b < i; ) {
|
||||
Placeholder placeholderList = arrayOfPlaceholder[b];
|
||||
if(itemLoreList.contains(placeholderList.getPlaceholder()))
|
||||
itemLoreList = ChatColor.translateAlternateColorCodes('&', itemLoreList.replace(placeholderList.getPlaceholder(), placeholderList.getResult()));
|
||||
b++;
|
||||
}
|
||||
}
|
||||
formattedItemLore.add(ChatColor.translateAlternateColorCodes('&', itemLoreList));
|
||||
}
|
||||
this.itemLore.clear();
|
||||
this.itemLore = formattedItemLore;
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemMeta(){
|
||||
ItemMeta im = this.is.hasItemMeta() ? this.is.getItemMeta() : Bukkit.getItemFactory().getItemMeta(this.is.getType());
|
||||
im.setDisplayName(this.itemDisplayname);
|
||||
im.setLore(this.itemLore);
|
||||
if(this.itemFlags != null) im.addItemFlags(this.itemFlags);
|
||||
if(this.itemEnchantments != null) {
|
||||
byte b;
|
||||
int i;
|
||||
Enchantment[] arrayOfEnchantment;
|
||||
for(i = (arrayOfEnchantment = this.itemEnchantments).length, b = 0; b < i; ) {
|
||||
Enchantment itemEnchantmentList = arrayOfEnchantment[b];
|
||||
im.addEnchant(itemEnchantmentList, 1, true);
|
||||
b++;
|
||||
}
|
||||
}
|
||||
this.is.setItemMeta(im);
|
||||
}
|
||||
|
||||
public ItemStack prepareItem(){
|
||||
setLore();
|
||||
setItemMeta();
|
||||
return this.is;
|
||||
}
|
||||
}
|
||||
|
||||
public class ClickEvent {
|
||||
private final ClickType click;
|
||||
|
||||
private final int slot;
|
||||
|
||||
private final ItemStack is;
|
||||
|
||||
private boolean close = true;
|
||||
|
||||
private boolean destroy = true;
|
||||
|
||||
private boolean cancelled = true;
|
||||
|
||||
public ClickEvent(ClickType click, int slot, ItemStack is){
|
||||
this.click = click;
|
||||
this.slot = slot;
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
public ClickType getClick(){
|
||||
return this.click;
|
||||
}
|
||||
|
||||
public int getSlot(){
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public ItemStack getItem(){
|
||||
return this.is;
|
||||
}
|
||||
|
||||
public boolean getWillClose(){
|
||||
return this.close;
|
||||
}
|
||||
|
||||
public void setWillClose(boolean close){
|
||||
this.close = close;
|
||||
}
|
||||
|
||||
public boolean getWillDestroy(){
|
||||
return this.destroy;
|
||||
}
|
||||
|
||||
public void setWillDestroy(boolean destroy){
|
||||
this.destroy = destroy;
|
||||
}
|
||||
|
||||
public boolean getCancelled(){
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled){
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
package net.crankedpvp.wildpvp.wildpvp;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import net.crankedpvp.wildpvp.utils.TitleManager;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class CageMatch {
|
||||
private final CagePvPPlugin instance;
|
||||
private final Player creator;
|
||||
private Player joined;
|
||||
private final Location location;
|
||||
private Location joinLocation;
|
||||
private boolean grace = true;
|
||||
private boolean ended = false;
|
||||
|
||||
public CageMatch(CagePvPPlugin instance, Player creator, Location location) {
|
||||
this.instance = instance;
|
||||
this.creator = creator;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Player getCreator() {
|
||||
return this.creator;
|
||||
}
|
||||
|
||||
public boolean isCreator(Player player) {
|
||||
return this.creator.getUniqueId().equals(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void setJoined(Player joined) {
|
||||
this.joined = joined;
|
||||
}
|
||||
|
||||
public Player getJoined() {
|
||||
return this.joined;
|
||||
}
|
||||
|
||||
public boolean isJoined(Player player) {
|
||||
return this.joined != null && this.joined.getUniqueId().equals(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean hasJoined() {
|
||||
return this.joined != null;
|
||||
}
|
||||
|
||||
public boolean isParticipant(Player player) {
|
||||
return this.creator.getUniqueId().equals(player.getUniqueId()) || this.joined != null && this.joined.getUniqueId().equals(player.getUniqueId());
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public void setJoinLocation(Location joinLocation) {
|
||||
this.joinLocation = joinLocation;
|
||||
}
|
||||
|
||||
public Location getJoinLocation() {
|
||||
return this.joinLocation;
|
||||
}
|
||||
|
||||
public void teleportToJoinLocation(Player player) {
|
||||
Location location = this.joinLocation.clone();
|
||||
if (location.getBlock().getType().isSolid() || location.clone().add(0.0D, 1.0D, 0.0D).getBlock().getType().isSolid()) {
|
||||
location.setY(location.getWorld().getHighestBlockYAt(location));
|
||||
}
|
||||
|
||||
player.teleport(location, TeleportCause.UNKNOWN);
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
return this.location.getChunk();
|
||||
}
|
||||
|
||||
public boolean isGrace() {
|
||||
return this.grace;
|
||||
}
|
||||
|
||||
public void setEnded(boolean ended) {
|
||||
this.ended = ended;
|
||||
}
|
||||
|
||||
public boolean hasEnded() {
|
||||
return this.ended;
|
||||
}
|
||||
|
||||
public boolean hasStarted() {
|
||||
return this.creator != null && this.joined != null;
|
||||
}
|
||||
|
||||
public void showBorder(Player player) {
|
||||
Chunk chunk = this.getChunk();
|
||||
Location corner1 = chunk.getBlock(0, 0, 0).getLocation();
|
||||
Location corner2 = chunk.getBlock(15, 0, 0).getLocation();
|
||||
Location corner3 = chunk.getBlock(0, 0, 15).getLocation();
|
||||
Location corner4 = chunk.getBlock(15, 0, 15).getLocation();
|
||||
|
||||
for(int y = 0; y < 130; ++y) {
|
||||
for(int xz = 0; xz < 15; ++xz) {
|
||||
corner1 = chunk.getBlock(xz, y, 0).getLocation();
|
||||
corner2 = chunk.getBlock(15, y, xz).getLocation();
|
||||
corner3 = chunk.getBlock(15 - xz, y, 15).getLocation();
|
||||
corner4 = chunk.getBlock(0, y, 15 - xz).getLocation();
|
||||
if (corner1.getBlock().getType() == Material.AIR) {
|
||||
//player.sendBlockChange(corner1, Material.STAINED_GLASS, (byte)14);
|
||||
player.sendBlockChange(corner1, Material.IRON_FENCE, (byte)0);
|
||||
|
||||
}
|
||||
|
||||
if (corner2.getBlock().getType() == Material.AIR) {
|
||||
//player.sendBlockChange(corner2, Material.STAINED_GLASS, (byte)14);
|
||||
player.sendBlockChange(corner2, Material.IRON_FENCE, (byte)0);
|
||||
|
||||
}
|
||||
|
||||
if (corner3.getBlock().getType() == Material.AIR) {
|
||||
//player.sendBlockChange(corner3, Material.STAINED_GLASS, (byte)14);
|
||||
player.sendBlockChange(corner3, Material.IRON_FENCE, (byte)0);
|
||||
|
||||
}
|
||||
|
||||
if (corner4.getBlock().getType() == Material.AIR) {
|
||||
//player.sendBlockChange(corner4, Material.STAINED_GLASS, (byte)14);
|
||||
player.sendBlockChange(corner4, Material.IRON_FENCE, (byte)0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void hideBorder(Player player) {
|
||||
Chunk chunk = this.getChunk();
|
||||
Location corner1 = chunk.getBlock(0, 0, 0).getLocation();
|
||||
Location corner2 = chunk.getBlock(15, 0, 0).getLocation();
|
||||
Location corner3 = chunk.getBlock(0, 0, 15).getLocation();
|
||||
Location corner4 = chunk.getBlock(15, 0, 15).getLocation();
|
||||
|
||||
for(int y = 0; y < 130; ++y) {
|
||||
for(int xz = 0; xz < 15; ++xz) {
|
||||
corner1 = chunk.getBlock(xz, y, 0).getLocation();
|
||||
corner2 = chunk.getBlock(15, y, xz).getLocation();
|
||||
corner3 = chunk.getBlock(15 - xz, y, 15).getLocation();
|
||||
corner4 = chunk.getBlock(0, y, 15 - xz).getLocation();
|
||||
if (corner1.getBlock().getType() == Material.AIR) {
|
||||
player.sendBlockChange(corner1, Material.AIR, (byte)0);
|
||||
}
|
||||
|
||||
if (corner2.getBlock().getType() == Material.AIR) {
|
||||
player.sendBlockChange(corner2, Material.AIR, (byte)0);
|
||||
}
|
||||
|
||||
if (corner3.getBlock().getType() == Material.AIR) {
|
||||
player.sendBlockChange(corner3, Material.AIR, (byte)0);
|
||||
}
|
||||
|
||||
if (corner4.getBlock().getType() == Material.AIR) {
|
||||
player.sendBlockChange(corner4, Material.AIR, (byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void teleport(Player player) {
|
||||
Random random = new Random();
|
||||
Location location = this.getChunk().getBlock(random.nextInt(14) + 1, 0, random.nextInt(14) + 1).getLocation().clone();
|
||||
location.setY(location.getWorld().getHighestBlockYAt(location));
|
||||
player.teleport(location, TeleportCause.UNKNOWN);
|
||||
}
|
||||
|
||||
public void startMatch() {
|
||||
if (this.joined != null) {
|
||||
final FileConfiguration configLoad = this.instance.getConfig();
|
||||
this.creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Joined.Creator.Message").replace("%player", this.joined.getName())));
|
||||
this.creator.playSound(this.creator.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 5.0F);
|
||||
if (configLoad.getBoolean("WildPvP.Match.Title")) {
|
||||
TitleManager.sendTitle(this.creator, ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Joined.Creator.Title.Title").replace("%player", this.joined.getName())), ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Joined.Creator.Title.SubTitle").replace("%player", this.joined.getName())), 0, 30, 10);
|
||||
}
|
||||
|
||||
this.joined.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Joined.Joiner.Message").replace("%player", this.creator.getName())));
|
||||
this.joined.playSound(this.joined.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 5.0F);
|
||||
(new BukkitRunnable() {
|
||||
int countdown = 10;
|
||||
|
||||
public void run() {
|
||||
if (!CageMatch.this.ended && this.countdown >= 0) {
|
||||
if (this.countdown == 8) {
|
||||
TitleManager.sendTitle(CageMatch.this.creator, ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Versus.Title.Title").replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName())), ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Versus.Title.SubTitle").replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName())), 10, 30, 10);
|
||||
TitleManager.sendTitle(CageMatch.this.joined, ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Versus.Title.Title").replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName())), ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Versus.Title.SubTitle").replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName())), 10, 30, 10);
|
||||
CageMatch.this.creator.playSound(CageMatch.this.creator.getLocation(), Sound.VILLAGER_YES, 0.5F, 1.0F);
|
||||
CageMatch.this.joined.playSound(CageMatch.this.joined.getLocation(), Sound.VILLAGER_YES, 0.5F, 1.0F);
|
||||
} else if (this.countdown > 0 && this.countdown <= 5) {
|
||||
CageMatch.this.creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ending.Message").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.joined.getName())));
|
||||
CageMatch.this.joined.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ending.Message").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.creator.getName())));
|
||||
TitleManager.sendTitle(CageMatch.this.creator, ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ending.Title.Title").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.joined.getName())), ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ending.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.joined.getName())), 0, 30, 0);
|
||||
TitleManager.sendTitle(CageMatch.this.joined, ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ending.Title.Title").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.creator.getName())), ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ending.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.creator.getName())), 0, 30, 0);
|
||||
CageMatch.this.creator.playSound(CageMatch.this.creator.getLocation(), Sound.NOTE_STICKS, 1.0F, 1.0F);
|
||||
CageMatch.this.joined.playSound(CageMatch.this.joined.getLocation(), Sound.NOTE_STICKS, 1.0F, 1.0F);
|
||||
} else if (this.countdown == 0) {
|
||||
CageMatch.this.grace = false;
|
||||
this.cancel();
|
||||
CageMatch.this.creator.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ended.Message").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.joined.getName())));
|
||||
CageMatch.this.joined.sendMessage(ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ended.Message").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.creator.getName())));
|
||||
TitleManager.sendTitle(CageMatch.this.creator, ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ended.Title.Title").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.joined.getName())), ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ended.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.joined.getName())), 0, 30, 10);
|
||||
TitleManager.sendTitle(CageMatch.this.joined, ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ended.Title.Title").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.creator.getName())), ChatColor.translateAlternateColorCodes('&', configLoad.getString("WildPvP.Countdown.Grace.Ended.Title.SubTitle").replace("%countdown", String.valueOf(this.countdown)).replace("%creator", CageMatch.this.creator.getName()).replace("%joined", CageMatch.this.joined.getName()).replace("%versus", CageMatch.this.creator.getName())), 0, 30, 10);
|
||||
CageMatch.this.creator.playSound(CageMatch.this.creator.getLocation(), Sound.WITHER_SHOOT, 1.0F, 10.0F);
|
||||
CageMatch.this.joined.playSound(CageMatch.this.joined.getLocation(), Sound.WITHER_SHOOT, 1.0F, 10.0F);
|
||||
instance.getCombatTagManager().giveTag(CageMatch.this.creator);
|
||||
instance.getCombatTagManager().giveTag(CageMatch.this.joined);
|
||||
|
||||
}
|
||||
|
||||
--this.countdown;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskTimerAsynchronously(this.instance, 0L, 20L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package net.crankedpvp.wildpvp.wildpvp;
|
||||
|
||||
import net.crankedpvp.wildpvp.CagePvPPlugin;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class CageMatchManager {
|
||||
private final CagePvPPlugin instance;
|
||||
private List<CageMatch> cageMatches = new ArrayList();
|
||||
|
||||
public CageMatchManager(CagePvPPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
for(CageMatch cageMatch : this.cageMatches) {
|
||||
cageMatch.hideBorder(cageMatch.getCreator());
|
||||
if(cageMatch.hasJoined()) {
|
||||
cageMatch.teleportToJoinLocation(cageMatch.getJoined());
|
||||
cageMatch.hideBorder(cageMatch.getJoined());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CageMatch createWildPvP(Player player, boolean teleport) {
|
||||
CageMatch cageMatch = new CageMatch(this.instance, player, player.getLocation().clone());
|
||||
if (teleport) {
|
||||
cageMatch.teleport(player);
|
||||
}
|
||||
|
||||
this.cageMatches.add(cageMatch);
|
||||
return cageMatch;
|
||||
}
|
||||
|
||||
public void removeWildPvP(CageMatch cageMatch) {
|
||||
this.cageMatches.remove(cageMatch);
|
||||
}
|
||||
|
||||
public CageMatch getWildPvP(Player player) {
|
||||
Iterator var2 = this.cageMatches.iterator();
|
||||
|
||||
CageMatch cageMatch;
|
||||
do {
|
||||
if (!var2.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
cageMatch = (CageMatch)var2.next();
|
||||
} while(!cageMatch.isCreator(player) && !cageMatch.isJoined(player));
|
||||
|
||||
return cageMatch;
|
||||
}
|
||||
|
||||
public boolean hasWildPvP(Player player) {
|
||||
return this.getWildPvP(player) != null;
|
||||
}
|
||||
|
||||
public CageMatch getWildPvP(Chunk chunk) {
|
||||
Iterator var2 = this.cageMatches.iterator();
|
||||
|
||||
CageMatch cageMatch;
|
||||
do {
|
||||
if (!var2.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
cageMatch = (CageMatch)var2.next();
|
||||
} while(cageMatch.getChunk().getX() != chunk.getX() || cageMatch.getChunk().getZ() != chunk.getZ());
|
||||
|
||||
return cageMatch;
|
||||
}
|
||||
|
||||
public boolean hasWildPvP(Chunk chunk) {
|
||||
return this.getWildPvP(chunk) != null;
|
||||
}
|
||||
|
||||
public List<CageMatch> getActiveWildPvPs() {
|
||||
List<CageMatch> activeCageMatches = new ArrayList();
|
||||
|
||||
for(CageMatch cageMatch : this.cageMatches) {
|
||||
if(cageMatch.hasJoined()) {
|
||||
activeCageMatches.add(cageMatch);
|
||||
}
|
||||
}
|
||||
|
||||
return activeCageMatches;
|
||||
}
|
||||
|
||||
public List<CageMatch> getPendingWildPvPs() {
|
||||
List<CageMatch> pendingCageMatches = new ArrayList();
|
||||
|
||||
for(CageMatch cageMatch : this.cageMatches) {
|
||||
if(!cageMatch.hasJoined()) {
|
||||
pendingCageMatches.add(cageMatch);
|
||||
}
|
||||
}
|
||||
|
||||
return pendingCageMatches;
|
||||
}
|
||||
|
||||
public List<CageMatch> getWildPvPs() {
|
||||
return this.cageMatches;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.crankedpvp.wildpvp.worldguard;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public class WorldGuardManager {
|
||||
private WorldGuardPlugin worldGuard;
|
||||
|
||||
public WorldGuardManager() {
|
||||
registerWorldGuard();
|
||||
}
|
||||
|
||||
public void registerWorldGuard() {
|
||||
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
|
||||
if (pluginManager.getPlugin("WorldGuard") != null) {
|
||||
System.out.println("Hooked into Worldguard!");
|
||||
this.worldGuard = (WorldGuardPlugin) pluginManager.getPlugin("WorldGuard");
|
||||
} else {
|
||||
System.out.println("Could not find worldguard :(");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRegionAtLocation(Location location) {
|
||||
RegionManager regionManager = this.worldGuard.getRegionManager(location.getWorld());
|
||||
ApplicableRegionSet regionsAtLocation = regionManager.getApplicableRegions(location);
|
||||
return regionsAtLocation.size() != 0;
|
||||
}
|
||||
|
||||
public WorldGuardPlugin getWorldGuard() {
|
||||
if (this.worldGuard == null)
|
||||
registerWorldGuard();
|
||||
return this.worldGuard;
|
||||
}
|
||||
|
||||
public boolean hasWorldGuard() {
|
||||
return (getWorldGuard() != null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user