diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..575a882 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/.project b/.project new file mode 100644 index 0000000..7fe2b54 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + IranPvP-1.7 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..9d7a7c9 --- /dev/null +++ b/config.yml @@ -0,0 +1,140 @@ +SET_SPAWN: '&aSet practice spawn' +SET_EDITOR_SPAWN: '&aSet editor spawn' +IN_DUEL_ERROR: '&4Cant do this while in a duel' +IN_QUEUE_ERROR: '&4Cant do this while in queue' +TARGET_IN_QUEUE: 'cant duel %target% because they are in queue' +IN_FFA_ERROR: '&4Cant do this while in the FFA' +IN_SPECTATOR_ERROR: '&4Cant do this while in Spectator mode' +IN_SPECTATOR_TARGET: '%player% is in spectator mode and cant get invites' +ARENA_REMOVE_SUCCESS: '&cThe arena by the name of &6%arena% &chas been deleted' +ARENA_REMOVE_FAIL: '&cError while trying to delete arena &6%arena%' +ARENA_CREATE_SUCCESS: 'arena %arena% created successfully' +ARENA_CREATE_FAIL: 'could not create arena %arena% as it already exists' +ARENA_TELEPORT: 'Teleported to arena %arena% created by %creator%' +ARENA_SET_TEAM1: 'set team1 loc for %arena%' +ARENA_SET_TEAM2: 'set team2 loc for %arena%' +ARENA_SET_LOC1: 'Set %arena%s loc 1' +ARENA_SET_LOC2: 'Set %arena%s loc 2' +ARENA_SET_TIME: 'set arena %arena%s time to %time%' +ARENA_SET_TEAM_TRUE: 'set arena %arena% to a team arena' +ARENA_SET_TEAM_FALSE: 'set arena %arena% to a 1v1 arena' +TARGET_NULL: '%target% could not be found' +TARGET_IS_PLAYER: 'Cant duel yourself' +ALREADY_DUELED_TARGET: 'You have already dueled %target%' +TARGET_BUSY: '%target% is busy right now' +PLAYER_IN_DUEL: 'cant do this while in a duel' +IN_TEAM_ERROR: 'cant do this while in a team' +TARGET_IN_TEAM: '%target% is in a team and cant recieve duels' +SPECTATE_TEAM_MESSAGE: 'spectating team %team%' +SPECTATE_PLAYER_MESSAGE: 'spectating %player1% vs %player2%' +SPECTATE_PLAYER_MESSAGE_RANKED: '&3spectating match &a%player1%&b(%player1elo%) &cvs &a%player2%&b(%player2elo%)' +ENDERPEARL_COOLDOWN_MESSAGE: '&b&lCooldown for &c&l%timer%' +KIT_EDITOR: '&4Kit Editor' +TOGGLEPLAYERS_ON: '&aYou have hidden everyone' +TOGGLEPLAYERS_OFF: '&cEveryone is visible now' +RANKED_SWORD: '&a&lRanked Queue' +UNRANKED_SWORD: '&b&lUnranked Queue' +CREATE_TEAM: '&6&lCreate Team' +TEAM_INFO: '&a&lTeam Info' +DISBAND_TEAM: '&c&lDisband Team' +ALL_TEAMS: '&e&lView Current Teams' +LEAVE_TEAM: '&c&lLeave Team' +PING: '&aPing: &l%ping%' +PING_TARGET: '&a%target% ping: &l%ping%' +MATCH_TIMER: 5 +MATCH_WAIT_MESSAGE: '&eMatch starting in &c%timer% &eseconds' +MATCH_START_MESSAGE: '&eMatch started' +DUEL_INVENTORY: '&cDuel Inventory' +UNRANKED_INVENTORY: '&cUnranked Inventory' +RANKED_INVENTORY: '&cRanked Inventory' +KIT_EDITOR_INVENTORY: '&cKit Editor' +FFA_INVENTORY: '&cFFA inventory' +GAME_MODES_INVENTORY: '&cGame modes' +TEAM_DUEL_INVENTORY: '&cTeam Duel Inventory' +ELO_MATCH_FOUND: '&6&lFound a match agains &e%opponent% &7(%opponentelo%)' +SCOREBOARD: + TITLE: '&6&lIranPvP &f| &e&lPractice' + LINE_TOP: '--------' + LINE_BOTTOM: '-------' + ENDERPEARL: '&bEnderpearl: ' + ENERGY: '&eEnergy: ' + KOTH: + OPPONENT: '&cOpponent: ' + CAPPER: '&dCapper: ' + ARENA: '&a%arena%:' + LOBBY: + ONLINE: '&3Online: ' + QUEUE: '&6Queue: ' + TEAM: + OPPONENT: '&cOpponent: ' + ALIVE: 'Alive' + ARENA: '&cArena' + FFA: + ALIVE: 'Players Alive: ' + DUEL: + OPPONENT: '&cOpponent: ' + DURATION: '&aDuration:' +ITEM_LORE: + RANKED: '&aRanked: &l%size%' + UNRANKED: '&bUnranked: &l%size%' +ELO_MESSAGE: + LINE: '&7&m--------------------------------------------------' + MESSAGE_1: '%winner% +&a%elo% &7(%newelo%) Gametype &6%gametype%' + MESSAGE_2: '%loser% -&c%elo% &7(%newelo%) Gametype &6%gametype%' +TEAM_INVITE_MESSAGE: + LINE: '&7&m--------------------------------------------------' + MESSAGE: '&bYou have been invited to join team %team%' + CLICK: '&a&l[Click Me to Join]' +TEAM_RECIEVE_INVITE: + LINE: '&7&m--------------------------------------------------' + MESSAGE: '&6Team &e%team% &6has sent a &lTeam Duel &c(Gametype &l%gametype%&c)' + CLICK: '&a&l[Click Me to Accept]' +KOTH_RECIEVE_INVITE: + LINE: '&7&m--------------------------------------------------' + MESSAGE: '&6Team &e%team% &6has sent a &lKOTH Duel &c(Gametype &l%gametype%&c)' + CLICK: '&a&l[Click Me to Accept]' +DUEL_RECIEVE_INVITE: + LINE: '&7&m--------------------------------------------------' + MESSAGE: '&6Team &e%player% &6has sent a duel request &c(Gametype &l%gametype%&c)' + CLICK: '&a&l[Click Me to Accept]' +BARD: + STRENGTH: + POWER: 30 + COOLDOWN: 10 + DURATION: 5 + AMPLIFIER: 1 + SPEED: + POWER: 10 + COOLDOWN: 5 + DURATION: 10 + AMPLIFIER: 1 + REGENERATION: + POWER: 35 + COOLDOWN: 15 + DURATION: 5 + AMPLIFIER: 1 + JUMP_BOOST: + POWER: 15 + COOLDOWN: 5 + DURATION: 5 + AMPLIFIER: 1 + FIRE_RESISTANCE: + POWER: 5 + COOLDOWN: 3 + DURATION: 15 + AMPLIFIER: 1 + RESISTANCE: + POWER: 25 + COOLDOWN: 10 + DURATION: 10 + AMPLIFIER: 1 + MESSAGE: '&c%bard% has used %effect%' +KOTH: + LIVES: 2 + COOLDOWN: 10 +ITEM_COLOR: + UNRANKED: '&a' + RANKED: '&c' + KIT_EDITOR: '&b' + TEAM_DUEL: '&e' + \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..3e344e6 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,43 @@ +name: IranPvP +main: me.iran.iranpvp.IranPvP +version: 1.0 +commands: + elo: + description: elo + view: + description: view + toggleplayers: + description: toggle players + duel: + description: duel + accept: + description: accept + arena: + description: arena + deny: + description: deny + ping: + description: ping + aliases: [itwo] + team: + description: team + aliases: [t] + setpracticespawn: + description: setspawn + gametype: + description: gametype + iranpvpitems: + description: items + items: + description: items + seteditor: + description: set editor + spectate: + description: spec + aliases: [spec] + leave: + description: leave ffa + join: + description: join ffa + ffa: + description: start ffa \ No newline at end of file diff --git a/src/com/comphenix/example/EntityHider.java b/src/com/comphenix/example/EntityHider.java new file mode 100644 index 0000000..0031f73 --- /dev/null +++ b/src/com/comphenix/example/EntityHider.java @@ -0,0 +1,305 @@ +package com.comphenix.example; + +import static com.comphenix.protocol.PacketType.Play.Server.*; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Map; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.plugin.Plugin; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.google.common.base.Preconditions; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + +public class EntityHider implements Listener { + protected Table observerEntityMap = HashBasedTable.create(); + + // Packets that update remote player entities + private static final PacketType[] ENTITY_PACKETS = { + ENTITY_EQUIPMENT, BED, ANIMATION, NAMED_ENTITY_SPAWN, + COLLECT, SPAWN_ENTITY, SPAWN_ENTITY_LIVING, SPAWN_ENTITY_PAINTING, SPAWN_ENTITY_EXPERIENCE_ORB, + ENTITY_VELOCITY, REL_ENTITY_MOVE, ENTITY_LOOK, ENTITY_MOVE_LOOK, ENTITY_MOVE_LOOK, + ENTITY_TELEPORT, ENTITY_HEAD_ROTATION, ENTITY_STATUS, ATTACH_ENTITY, ENTITY_METADATA, + ENTITY_EFFECT, REMOVE_ENTITY_EFFECT, BLOCK_BREAK_ANIMATION + + // We don't handle DESTROY_ENTITY though + }; + + /** + * The current entity visibility policy. + * @author Kristian + */ + public enum Policy { + /** + * All entities are invisible by default. Only entities specifically made visible may be seen. + */ + WHITELIST, + + /** + * All entities are visible by default. An entity can only be hidden explicitly. + */ + BLACKLIST, + } + + private ProtocolManager manager; + + // Listeners + private Listener bukkitListener; + private PacketAdapter protocolListener; + + // Current policy + protected final Policy policy; + + /** + * Construct a new entity hider. + * @param plugin - the plugin that controls this entity hider. + * @param policy - the default visibility policy. + */ + public EntityHider(Plugin plugin, Policy policy) { + Preconditions.checkNotNull(plugin, "plugin cannot be NULL."); + + // Save policy + this.policy = policy; + this.manager = ProtocolLibrary.getProtocolManager(); + + // Register events and packet listener + plugin.getServer().getPluginManager().registerEvents( + bukkitListener = constructBukkit(), plugin); + manager.addPacketListener( + protocolListener = constructProtocol(plugin)); + } + + /** + * Set the visibility status of a given entity for a particular observer. + * @param observer - the observer player. + * @param entity - ID of the entity that will be hidden or made visible. + * @param visible - TRUE if the entity should be made visible, FALSE if not. + * @return TRUE if the entity was visible before this method call, FALSE otherwise. + */ + protected boolean setVisibility(Player observer, int entityID, boolean visible) { + switch (policy) { + case BLACKLIST: + // Non-membership means they are visible + return !setMembership(observer, entityID, !visible); + case WHITELIST: + return setMembership(observer, entityID, visible); + default : + throw new IllegalArgumentException("Unknown policy: " + policy); + } + } + + /** + * Add or remove the given entity and observer entry from the table. + * @param observer - the player observer. + * @param entityID - ID of the entity. + * @param member - TRUE if they should be present in the table, FALSE otherwise. + * @return TRUE if they already were present, FALSE otherwise. + */ + // Helper method + protected boolean setMembership(Player observer, int entityID, boolean member) { + if (member) { + return observerEntityMap.put(observer.getEntityId(), entityID, true) != null; + } else { + return observerEntityMap.remove(observer.getEntityId(), entityID) != null; + } + } + + /** + * Determine if the given entity and observer is present in the table. + * @param observer - the player observer. + * @param entityID - ID of the entity. + * @return TRUE if they are present, FALSE otherwise. + */ + protected boolean getMembership(Player observer, int entityID) { + return observerEntityMap.contains(observer.getEntityId(), entityID); + } + + /** + * Determine if a given entity is visible for a particular observer. + * @param observer - the observer player. + * @param entityID - ID of the entity that we are testing for visibility. + * @return TRUE if the entity is visible, FALSE otherwise. + */ + protected boolean isVisible(Player observer, int entityID) { + // If we are using a whitelist, presence means visibility - if not, the opposite is the case + boolean presence = getMembership(observer, entityID); + + return policy == Policy.WHITELIST ? presence : !presence; + } + + /** + * Remove the given entity from the underlying map. + * @param entity - the entity to remove. + * @param destroyed - TRUE if the entity was killed, FALSE if it is merely unloading. + */ + protected void removeEntity(Entity entity, boolean destroyed) { + int entityID = entity.getEntityId(); + + for (Map maps : observerEntityMap.rowMap().values()) { + maps.remove(entityID); + } + } + + /** + * Invoked when a player logs out. + * @param player - the player that jused logged out. + */ + protected void removePlayer(Player player) { + // Cleanup + observerEntityMap.rowMap().remove(player.getEntityId()); + } + + /** + * Construct the Bukkit event listener. + * @return Our listener. + */ + private Listener constructBukkit() { + return new Listener() { + @EventHandler + public void onEntityDeath(EntityDeathEvent e) { + removeEntity(e.getEntity(), true); + } + + @EventHandler + public void onChunkUnload(ChunkUnloadEvent e) { + for (Entity entity : e.getChunk().getEntities()) { + removeEntity(entity, false); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) { + removePlayer(e.getPlayer()); + } + }; + } + + /** + * Construct the packet listener that will be used to intercept every entity-related packet. + * @param plugin - the parent plugin. + * @return The packet listener. + */ + private PacketAdapter constructProtocol(Plugin plugin) { + return new PacketAdapter(plugin, ENTITY_PACKETS) { + @Override + public void onPacketSending(PacketEvent event) { + int entityID = event.getPacket().getIntegers().read(0); + + // See if this packet should be cancelled + if (!isVisible(event.getPlayer(), entityID)) { + event.setCancelled(true); + } + } + }; + } + + /** + * Toggle the visibility status of an entity for a player. + *

+ * If the entity is visible, it will be hidden. If it is hidden, it will become visible. + * @param observer - the player observer. + * @param entity - the entity to toggle. + * @return TRUE if the entity was visible before, FALSE otherwise. + */ + public final boolean toggleEntity(Player observer, Entity entity) { + if (isVisible(observer, entity.getEntityId())) { + return hideEntity(observer, entity); + } else { + return !showEntity(observer, entity); + } + } + + /** + * Allow the observer to see an entity that was previously hidden. + * @param observer - the observer. + * @param entity - the entity to show. + * @return TRUE if the entity was hidden before, FALSE otherwise. + */ + public final boolean showEntity(Player observer, Entity entity) { + validate(observer, entity); + boolean hiddenBefore = !setVisibility(observer, entity.getEntityId(), true); + + // Resend packets + if (manager != null && hiddenBefore) { + manager.updateEntity(entity, Arrays.asList(observer)); + } + return hiddenBefore; + } + + /** + * Prevent the observer from seeing a given entity. + * @param observer - the player observer. + * @param entity - the entity to hide. + * @return TRUE if the entity was previously visible, FALSE otherwise. + */ + public final boolean hideEntity(Player observer, Entity entity) { + validate(observer, entity); + boolean visibleBefore = setVisibility(observer, entity.getEntityId(), false); + + if (visibleBefore) { + PacketContainer destroyEntity = new PacketContainer(ENTITY_DESTROY); + destroyEntity.getIntegerArrays().write(0, new int[] { entity.getEntityId() }); + + // Make the entity disappear + try { + manager.sendServerPacket(observer, destroyEntity); + } catch (InvocationTargetException e) { + throw new RuntimeException("Cannot send server packet.", e); + } + } + return visibleBefore; + } + + /** + * Determine if the given entity has been hidden from an observer. + *

+ * Note that the entity may very well be occluded or out of range from the perspective + * of the observer. This method simply checks if an entity has been completely hidden + * for that observer. + * @param observer - the observer. + * @param entity - the entity that may be hidden. + * @return TRUE if the player may see the entity, FALSE if the entity has been hidden. + */ + public final boolean canSee(Player observer, Entity entity) { + validate(observer, entity); + + return isVisible(observer, entity.getEntityId()); + } + + // For valdiating the input parameters + private void validate(Player observer, Entity entity) { + Preconditions.checkNotNull(observer, "observer cannot be NULL."); + Preconditions.checkNotNull(entity, "entity cannot be NULL."); + } + + /** + * Retrieve the current visibility policy. + * @return The current visibility policy. + */ + public Policy getPolicy() { + return policy; + } + + public void close() { + if (manager != null) { + HandlerList.unregisterAll(bukkitListener); + manager.removePacketListener(protocolListener); + manager = null; + } + } +} \ No newline at end of file diff --git a/src/me/iran/iranpvp/IranPvP.java b/src/me/iran/iranpvp/IranPvP.java new file mode 100644 index 0000000..dd61bcd --- /dev/null +++ b/src/me/iran/iranpvp/IranPvP.java @@ -0,0 +1,335 @@ +package me.iran.iranpvp; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import me.iran.iranpvp.arena.ArenaManager; +import me.iran.iranpvp.cmd.arena.ArenaCommands; +import me.iran.iranpvp.cmd.pvp.EloCommands; +import me.iran.iranpvp.cmd.pvp.PvPCommands; +import me.iran.iranpvp.cmd.pvp.specevent.SpectatorEvents; +import me.iran.iranpvp.cmd.team.TeamCommands; +import me.iran.iranpvp.duel.DuelManager; +import me.iran.iranpvp.duel.team.TeamDuelManager; +import me.iran.iranpvp.events.duel.ClickDuelInventoryEvent; +import me.iran.iranpvp.events.duel.DeathInventory; +import me.iran.iranpvp.events.duel.PlayerBreakBlockEvent; +import me.iran.iranpvp.events.duel.PlayerDeathWhileInPvP; +import me.iran.iranpvp.events.duel.PlayerDisconnectWhileInPvP; +import me.iran.iranpvp.events.duel.ProtocolEvents; +import me.iran.iranpvp.events.duel.RespawnEvent; +import me.iran.iranpvp.events.duel.TeamClickInventoryEvent; +import me.iran.iranpvp.events.inhanditems.AddItemsOnJoin; +import me.iran.iranpvp.events.inhanditems.DropItemsInHandEvent; +import me.iran.iranpvp.events.inhanditems.InteractWithItemsInHand; +import me.iran.iranpvp.events.teamfight.DisconnectWhileInTeam; +import me.iran.iranpvp.events.teamfight.KothDeathEvent; +import me.iran.iranpvp.events.teamfight.TeamDamageTeam; +import me.iran.iranpvp.events.teamfight.TeamFightEvent; +import me.iran.iranpvp.ffa.FFACommand; +import me.iran.iranpvp.ffa.FFAEvent; +import me.iran.iranpvp.ffa.FFARunnable; +import me.iran.iranpvp.kit.KitEvents; +import me.iran.iranpvp.kit.KitManager; +import me.iran.iranpvp.kit.bard.Bard; +import me.iran.iranpvp.kit.bard.BardEvent; +import me.iran.iranpvp.runnable.Run; +import me.iran.iranpvp.teams.Team; +import me.iran.iranpvp.teams.TeamChat; +import me.iran.iranpvp.teams.TeamManager; +import me.iran.iranpvp.type.GameTypeCommands; +import me.iran.iranpvp.type.GameTypeManager; +import me.iran.iranpvp.type.RankedEvent; +import me.iran.iranpvp.utils.EnderpearlCooldown; +import me.iran.iranpvp.utils.Queue; +import me.iran.iranpvp.utils.TeleportSpawn; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import com.comphenix.example.EntityHider; +import com.comphenix.example.EntityHider.Policy; + +public class IranPvP extends JavaPlugin implements Listener { + + File file = null; + + public static Plugin plugin; + + private Run run = new Run(this); + + private TeleportSpawn spawn = new TeleportSpawn(); + private KitManager km = new KitManager(); + private Bard bard = new Bard(); + private FFARunnable ffaRun = new FFARunnable(this); + + private Queue queue = new Queue(); + + private RankedEvent rank = new RankedEvent(this); + + private static ArrayList toggle = new ArrayList(); + + @SuppressWarnings("deprecation") + public void onEnable() { + + IranPvP.plugin = this; + + ArenaManager.getManager().loadArena(); + GameTypeManager.getManager().loadGameTypes(); + + file = new File(this.getDataFolder(), "gametype.yml"); + + if(!file.exists()) { + file = new File(this.getDataFolder(), "gametype.yml"); + + new YamlConfiguration(); + + YamlConfiguration gConfig = YamlConfiguration.loadConfiguration(file); + + gConfig.createSection("gametype"); + + try { + gConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + file = new File(this.getDataFolder(), "arena.yml"); + + if(!file.exists()) { + + System.out.println("[IranPvP] Could not find any Arenas, Creating new file"); + + file = new File(this.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + arenaConfig.createSection("arena"); + + try { + arenaConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + getConfig().options().copyDefaults(true); + saveConfig(); + + Bukkit.getPluginManager().registerEvents(this, this); + Bukkit.getPluginManager().registerEvents(new ClickDuelInventoryEvent(this), this); + Bukkit.getPluginManager().registerEvents(new InteractWithItemsInHand(this), this); + Bukkit.getPluginManager().registerEvents(new DropItemsInHandEvent(this), this); + Bukkit.getPluginManager().registerEvents(new PlayerDeathWhileInPvP(this), this); + Bukkit.getPluginManager().registerEvents(new PlayerDisconnectWhileInPvP(this), this); + Bukkit.getPluginManager().registerEvents(new AddItemsOnJoin(this), this); + Bukkit.getPluginManager().registerEvents(new TeamClickInventoryEvent(this), this); + Bukkit.getPluginManager().registerEvents(new TeamFightEvent(this), this); + Bukkit.getPluginManager().registerEvents(new EnderpearlCooldown(this), this); + Bukkit.getPluginManager().registerEvents(new TeamDamageTeam(this), this); + Bukkit.getPluginManager().registerEvents(new PlayerBreakBlockEvent(this), this); + Bukkit.getPluginManager().registerEvents(new RespawnEvent(this), this); + Bukkit.getPluginManager().registerEvents(new DisconnectWhileInTeam(this), this); + Bukkit.getPluginManager().registerEvents(new BardEvent(this), this); + Bukkit.getPluginManager().registerEvents(new KitEvents(this), this); + Bukkit.getPluginManager().registerEvents(new DeathInventory(this), this); + Bukkit.getPluginManager().registerEvents(new SpectatorEvents(this), this); + Bukkit.getPluginManager().registerEvents(new FFAEvent(this), this); + Bukkit.getPluginManager().registerEvents(new RankedEvent(this), this); + Bukkit.getPluginManager().registerEvents(new TeamChat(this), this); + Bukkit.getPluginManager().registerEvents(new GameTypeCommands(this), this); + Bukkit.getPluginManager().registerEvents(new KothDeathEvent(this), this); + //Bukkit.getPluginManager().registerEvents(new ProtocolEvents(this), this); + + getCommand("ffa").setExecutor(new FFACommand(this)); + getCommand("leave").setExecutor(new FFACommand(this)); + getCommand("join").setExecutor(new FFACommand(this)); + + getCommand("elo").setExecutor(new EloCommands(this)); + + getCommand("duel").setExecutor(new PvPCommands(this)); + getCommand("ping").setExecutor(new PvPCommands(this)); + getCommand("accept").setExecutor(new PvPCommands(this)); + getCommand("spectate").setExecutor(new PvPCommands(this)); + getCommand("deny").setExecutor(new PvPCommands(this)); + getCommand("arena").setExecutor(new ArenaCommands(this)); + getCommand("team").setExecutor(new TeamCommands(this)); + getCommand("gametype").setExecutor(new GameTypeCommands(this)); + getCommand("iranpvpitems").setExecutor(new ItemsCommand(this)); + + run.runTaskTimer(this, 0L, 20L); + ffaRun.runTaskTimer(this, 0L, 20L); + bard.runTaskTimer(this, 0L, 10L); + + if(Bukkit.getOnlinePlayers().length > 0) { + for(Player p : Bukkit.getOnlinePlayers()) { + rank.createFiles(p); + } + } + + } + + @Override + @SuppressWarnings("deprecation") + public void onDisable() { + if(Bukkit.getOnlinePlayers().length > 0) { + for(Player p : Bukkit.getOnlinePlayers()) { + rank.saveElo(p); + } + } + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + + if(!(sender instanceof Player)) { + return true; + } + + Player player = (Player) sender; + + if(cmd.getName().equalsIgnoreCase("setpracticespawn")) { + + if(!player.hasPermission("iranpvp.setloc")) { return true; } + + if(!this.getConfig().contains("spawn")) { + this.getConfig().createSection("spawn.x"); + this.getConfig().createSection("spawn.y"); + this.getConfig().createSection("spawn.z"); + this.getConfig().createSection("spawn.pitch"); + this.getConfig().createSection("spawn.yaw"); + this.getConfig().createSection("spawn.world"); + + this.getConfig().set("spawn.x", player.getLocation().getBlockX()); + this.getConfig().set("spawn.y", player.getLocation().getBlockY()); + this.getConfig().set("spawn.z", player.getLocation().getBlockZ()); + this.getConfig().set("spawn.pitch", player.getLocation().getPitch()); + this.getConfig().set("spawn.yaw", player.getLocation().getYaw()); + this.getConfig().set("spawn.world", player.getLocation().getWorld().getName()); + this.saveConfig(); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("SET_SPAWN"))); + } else { + this.getConfig().set("spawn.x", player.getLocation().getBlockX()); + this.getConfig().set("spawn.y", player.getLocation().getBlockY()); + this.getConfig().set("spawn.z", player.getLocation().getBlockZ()); + this.getConfig().set("spawn.pitch", player.getLocation().getPitch()); + this.getConfig().set("spawn.yaw", player.getLocation().getYaw()); + this.getConfig().set("spawn.world", player.getLocation().getWorld().getName()); + this.saveConfig(); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("SET_SPAWN"))); + } + } + + if(cmd.getName().equalsIgnoreCase("seteditor")) { + + if(!player.hasPermission("iranpvp.setloc")) { + + return true; + + } + + if(!this.getConfig().contains("kit")) { + this.getConfig().createSection("kit.x"); + this.getConfig().createSection("kit.y"); + this.getConfig().createSection("kit.z"); + this.getConfig().createSection("kit.pitch"); + this.getConfig().createSection("kit.yaw"); + this.getConfig().createSection("kit.world"); + + this.getConfig().set("kit.x", player.getLocation().getBlockX()); + this.getConfig().set("kit.y", player.getLocation().getBlockY()); + this.getConfig().set("kit.z", player.getLocation().getBlockZ()); + this.getConfig().set("kit.pitch", player.getLocation().getPitch()); + this.getConfig().set("kit.yaw", player.getLocation().getYaw()); + this.getConfig().set("kit.world", player.getLocation().getWorld().getName()); + this.saveConfig(); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("SET_EDITOR_SPAWN"))); + } else { + this.getConfig().set("kit.x", player.getLocation().getBlockX()); + this.getConfig().set("kit.y", player.getLocation().getBlockY()); + this.getConfig().set("kit.z", player.getLocation().getBlockZ()); + this.getConfig().set("kit.pitch", player.getLocation().getPitch()); + this.getConfig().set("kit.yaw", player.getLocation().getYaw()); + this.getConfig().set("kit.world", player.getLocation().getWorld().getName()); + this.saveConfig(); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("SET_EDITOR_SPAWN"))); + } + } + + if(cmd.getName().equalsIgnoreCase("items")) { + if(TeamManager.getManager().isInTeam(player)) { + Team team = TeamManager.getManager().getTeamByPlayer(player); + if(TeamDuelManager.getManager().isInDuel(team)) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("IN_DUEL_ERROR"))); + return true; + } + } + + if(DuelManager.getManager().isInDuel(player)) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("IN_DUEL_ERROR"))); + return true; + } + + if(queue.isInUnranked(player)) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("IN_QUEUE_ERROR"))); + return true; + } + + if(queue.isInRanked(player)) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("IN_QUEUE_ERROR"))); + return true; + } + + if(FFACommand.fighters.contains(player.getName())) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("IN_FFA_ERROR"))); + return true; + } + + if (ArenaManager.getManager().isSpectator(player)) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("IN_SPECTATOR_ERROR"))); + return true; + } + + spawn.teleportSpawn(player); + } + + if(cmd.getName().equalsIgnoreCase("view")) { + + if(args.length < 1) { + player.sendMessage(ChatColor.RED + "/view player"); + } + + Player target = Bukkit.getPlayer(args[0]); + + if(target == null) { + player.sendMessage(ChatColor.RED + "Couldn't find player"); + return true; + } + + if(DeathInventory.getTimer().containsKey(target.getName())) { + player.openInventory(DeathInventory.deadInv(target)); + } + + } + + return true; + } + + + public ArrayList getToggle() { + return toggle; + } + +} diff --git a/src/me/iran/iranpvp/ItemsCommand.java b/src/me/iran/iranpvp/ItemsCommand.java new file mode 100644 index 0000000..5dac12a --- /dev/null +++ b/src/me/iran/iranpvp/ItemsCommand.java @@ -0,0 +1,67 @@ +package me.iran.iranpvp; + +import me.iran.iranpvp.duel.DuelManager; +import me.iran.iranpvp.duel.team.TeamDuelManager; +import me.iran.iranpvp.teams.Team; +import me.iran.iranpvp.teams.TeamManager; +import me.iran.iranpvp.utils.TeleportSpawn; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ItemsCommand implements CommandExecutor { + + IranPvP plugin; + + public ItemsCommand(IranPvP plugin) { + this.plugin = plugin; + } + + TeleportSpawn spawn = new TeleportSpawn(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + + if(!(sender instanceof Player)) { + if(cmd.getName().equalsIgnoreCase("iranpvpitems")) { + + if(args.length < 1) { + sender.sendMessage(ChatColor.RED + "/items "); + return true; + } + + Player player = Bukkit.getPlayer(args[0]); + + if(player == null) { + return true; + } + + if (TeamManager.getManager().isInTeam(player)) { + Team team = TeamManager.getManager() + .getTeamByPlayer(player); + if (TeamDuelManager.getManager().isInDuel(team)) { + player.sendMessage(ChatColor.RED + "Can't do this while in a duel"); + return true; + } + } + + if (DuelManager.getManager().isInDuel(player)) { + player.sendMessage(ChatColor.RED + "Can't do this while in a duel"); + return true; + } + + spawn.teleportSpawn(player); + } + + + + } + + return true; + } + +} diff --git a/src/me/iran/iranpvp/arena/Arena.java b/src/me/iran/iranpvp/arena/Arena.java new file mode 100644 index 0000000..230b12a --- /dev/null +++ b/src/me/iran/iranpvp/arena/Arena.java @@ -0,0 +1,338 @@ +package me.iran.iranpvp.arena; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; + +public class Arena { + + Location loc1; + Location loc2; + + int x1; + int y1; + int z1; + + int x2; + int y2; + int z2; + + float pitch1; + float yaw1; + + float pitch2; + float yaw2; + + int loc1x; + int loc1y; + int loc1z; + + int loc2x; + int loc2y; + int loc2z; + + private String name; + private String creator; + + private List fighters; + private int timer; + private int time; + private ArrayList cappers; + private boolean active; + private boolean teamArena; + + private ArrayList spec; + + private String world; + + public Arena (Location loc1, Location loc2, int timer, String name, String world) { + this.loc1 = loc1; + this.loc2 = loc2; + this.timer = timer; + this.time = timer; + this.name = name; + this.world = world; + active = false; + teamArena = true; + spec = new ArrayList(); + fighters = new ArrayList(); + cappers = new ArrayList(); + this.creator = "Anonymous"; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public String getCreator() { + return creator; + } + + public ArrayList getSpec() { + return spec; + } + + public void setSpec(ArrayList spec) { + this.spec = spec; + } + + public void addSpec(String spec) { + this.spec.add(spec); + } + + public void removeSpec(String spec){ + this.spec.remove(spec); + } + + public boolean isSpec(String player) { + if(spec.contains(player)) { + return true; + } + + return false; + } + + //Team 1 + + public void setXTeam1(int x) { + this.x1 = x; + } + + public void setYTeam1(int y) { + this.y1 = y; + } + + public void setZTeam1(int z) { + this.z1 = z; + } + + public void setPitchTeam1(float pitch) { + this.pitch1 = pitch; + } + + public void setYawTeam1(float yaw) { + this.yaw1 = yaw; + } + + public float getPitchTeam1() { + return this.pitch1; + } + + public float getYawTeam1() { + return this.yaw1; + } + + public int getXTeam1() { + return x1; + } + + public int getYTeam1() { + return y1; + } + + public int getZTeam1() { + return z1; + } + + //Team 2 + + public void setXTeam2(int x) { + this.x2 = x; + } + + public void setYTeam2(int y) { + this.y2 = y; + } + + public void setZTeam2(int z) { + this.z2 = z; + } + + public void setPitchTeam2(float pitch) { + this.pitch2 = pitch; + } + + public void setYawTeam2(float yaw) { + this.yaw2 = yaw; + } + + public float getPitchTeam2() { + return this.pitch2; + } + + public float getYawTeam2() { + return this.yaw2; + } + + public int getXTeam2() { + return x2; + } + + public int getYTeam2() { + return y2; + } + + public int getZTeam2() { + return z2; + } + + //KOTH + + public void setLoc1(Location loc1) { + this.loc1 = loc1; + } + + public void setLoc2(Location loc2) { + this.loc2 = loc2; + } + + public Location getLoc1() { + return this.loc1; + } + + public Location getLoc2() { + return this.loc2; + } + + public void setLoc1X(int x) { + this.loc1x = x; + } + + public void setLoc1Y(int y) { + this.loc1y = y; + } + + public void setLoc1Z(int z) { + this.loc1z = z; + } + + public void setLoc2X(int x) { + this.loc2x = x; + } + + public void setLoc2Y(int y) { + this.loc2y = y; + } + + public void setLoc2Z(int z) { + this.loc2z = z; + } + + //KOTH min + public int getMaxX() { + return Math.max(loc1.getBlockX(), loc2.getBlockX()); + } + + public int getMaxZ() { + return Math.max(loc1.getBlockZ(), loc2.getBlockZ()); + } + + public int getMaxY() { + return Math.max(loc1.getBlockY(), loc2.getBlockY()); + } + + public int getMinX() { + return Math.min(loc1.getBlockX(), loc2.getBlockX()); + } + + public int getMinZ() { + return Math.min(loc1.getBlockZ(), loc2.getBlockZ()); + } + + public int getMinY() { + return Math.min(loc1.getBlockY(), loc2.getBlockY()); + } + + //Name + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + //Timer + + public int getTimer() { + return timer; + } + + public void setTimer(int timer) { + this.timer = timer; + } + + public void setArenaTimer(int time) { + this.time = time; + } + + public int getArenaTimer() { + return this.time; + } + + //Fighters + public List getFighters() { + return fighters; + } + + public void setFightersList(List fighters) { + this.fighters = fighters; + } + + public void addFighter(String name) { + fighters.add(name); + } + + public void removeFighter(String name) { + fighters.remove(name); + } + + //Cappers + public ArrayList getCappers() { + return cappers; + } + + public void setCapperList(ArrayList cappers) { + this.cappers = cappers; + } + + public void setCapper(String capper) { + cappers.add(0, capper); + } + + public String getCapper() { + return cappers.get(0); + } + + //Active + + public boolean isActive() { + return active; + } + + public void setActive() { + active = true; + } + + public void setInactive() { + active = false; + } + + public String getWorld() { + return world; + } + + public void setWorld(String world) { + this.world = world; + } + + public boolean isTeamArena() { + return teamArena; + } + + public void setTeamArena(boolean teamArena) { + this.teamArena = teamArena; + } +} diff --git a/src/me/iran/iranpvp/arena/ArenaManager.java b/src/me/iran/iranpvp/arena/ArenaManager.java new file mode 100644 index 0000000..986caa5 --- /dev/null +++ b/src/me/iran/iranpvp/arena/ArenaManager.java @@ -0,0 +1,796 @@ +package me.iran.iranpvp.arena; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import me.iran.iranpvp.IranPvP; +import me.iran.iranpvp.runnable.Run; +import me.iran.iranpvp.teams.Team; +import me.iran.iranpvp.utils.TeleportSpawn; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +public class ArenaManager { + + File file = null; + + public static ArrayList arenas = new ArrayList(); + public static ArrayList available = new ArrayList(); + public static ArrayList pAvailable = new ArrayList(); + + private static ArenaManager am; + + private ArenaManager() {} + + public static ArenaManager getManager() { + if (am == null) + am = new ArenaManager(); + + return am; + } + + TeleportSpawn spawn = new TeleportSpawn(); + + public void loadArena() { + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + if(!file.exists()) { + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + System.out.println("[IranPvP] Could not find any Arenas, Creating new file"); + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + arenaConfig.createSection("arena"); + + try { + arenaConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.println("[IranPvP] Created arena file, now you can create arenas"); + } else { + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + for(String a : arenaConfig.getConfigurationSection("arena").getKeys(false)) { + int teamx1 = arenaConfig.getInt("arena." + a + ".team1.x"); + int teamy1 = arenaConfig.getInt("arena." + a + ".team1.y"); + int teamz1 = arenaConfig.getInt("arena." + a + ".team1.z"); + float team1pitch = (float) arenaConfig.getDouble("arena." + a + ".team1.pitch"); + float team1yaw = (float) arenaConfig.getDouble("arena." + a + ".team1.yaw"); + + int teamx2 = arenaConfig.getInt("arena." + a + ".team2.x"); + int teamy2 = arenaConfig.getInt("arena." + a + ".team2.y"); + int teamz2 = arenaConfig.getInt("arena." + a + ".team2.z"); + float teampitch2 = (float) arenaConfig.getDouble("arena." + a + ".team2.pitch"); + float teamyaw2 = (float) arenaConfig.getDouble("arena." + a + ".team2.yaw"); + + int timer = arenaConfig.getInt("arena." + a + ".timer"); + int time = arenaConfig.getInt("arena." + a + ".time"); + + int loc1x = arenaConfig.getInt("arena." + a + ".loc1.x"); + int loc1y = arenaConfig.getInt("arena." + a + ".loc1.y"); + int loc1z = arenaConfig.getInt("arena." + a + ".loc1.z"); + + int loc2x = arenaConfig.getInt("arena." + a + ".loc2.x"); + int loc2y = arenaConfig.getInt("arena." + a + ".loc2.y"); + int loc2z = arenaConfig.getInt("arena." + a + ".loc2.z"); + + String world = arenaConfig.getString("arena." + a + ".world"); + + String name = arenaConfig.getString("arena." + a + ".name"); + + String creator = arenaConfig.getString("arena." + a + ".creator"); + + /////NEW/////// + boolean teamArena = arenaConfig.getBoolean("arena." + a + ".teamarena"); + + /////NEW/////// + + + Location loc1 = new Location(Bukkit.getWorld(world), loc1x, loc1y, loc1z); + Location loc2 = new Location(Bukkit.getWorld(world), loc2x, loc2y, loc2z); + + Location team1 = new Location(Bukkit.getWorld(world), teamx1, teamy1, teamz1); + Location team2 = new Location(Bukkit.getWorld(world), teamx2, teamy2, teamz2); + + team1.setPitch(team1pitch); + team1.setYaw(team1yaw); + + team2.setPitch(teampitch2); + team2.setYaw(teamyaw2); + + Arena arena = new Arena(loc1, loc2, timer, name, world); + arena.setName(name); + arena.setLoc1(loc1); + arena.setLoc2(loc2); + + arena.setXTeam1(teamx1); + arena.setYTeam1(teamy1); + arena.setZTeam1(teamz1); + arena.setPitchTeam1(team1pitch); + arena.setYawTeam1(team1yaw); + + arena.setXTeam2(teamx2); + arena.setYTeam2(teamy2); + arena.setZTeam2(teamz2); + arena.setPitchTeam2(teampitch2); + arena.setYawTeam2(teamyaw2); + arena.setTeamArena(teamArena); + + arena.setCreator(creator); + + arena.setWorld(world); + arena.setArenaTimer(time);; + arena.setTimer(arena.getArenaTimer()); + + arenas.add(arena); + + + } + + + } + + for(Arena a : arenas) { + if(a.isTeamArena() == true) { + available.add(a); + } else if(a.isTeamArena() == false) { + pAvailable.add(a); + } + } + + System.out.println("Team Fight Arenas: " + available.size()); + System.out.println("1v1 Arenas: " + pAvailable.size()); + } + + public void saveArena() { + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + + if(!file.exists()) { + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + System.out.println("[IranPvP] Could not find any Arenas, Creating new file"); + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + arenaConfig.createSection("arena"); + + try { + arenaConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.println("[IranPvP] Created arena file, now you can create arenas"); + } else { + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + for(int i = 0; i < arenas.size(); i++) { + + String a = arenas.get(i).getName(); + + Arena arena = getArenaByName(a); + + arenaConfig.set("arena." + a + ".name", a); + arenaConfig.set("arena." + a + ".creator", arena.getCreator()); + + arenaConfig.set("arena." + a + ".team1.x", arena.getXTeam1()); + arenaConfig.set("arena." + a + ".team1.y", arena.getYTeam1()); + arenaConfig.set("arena." + a + ".team1.z", arena.getZTeam1()); + arenaConfig.set("arena." + a + ".team1.pitch", arena.getPitchTeam1()); + arenaConfig.set("arena." + a + ".team1.yaw", arena.getYawTeam1()); + + arenaConfig.set("arena." + a + ".team2.x", arena.getXTeam2()); + arenaConfig.set("arena." + a + ".team2.y", arena.getYTeam2()); + arenaConfig.set("arena." + a + ".team2.z", arena.getZTeam2()); + arenaConfig.set("arena." + a + ".team2.pitch", arena.getPitchTeam2()); + arenaConfig.set("arena." + a + ".team2.yaw", arena.getYawTeam2()); + + arenaConfig.set("arena." + a + ".xmin", arena.getMinX()); + arenaConfig.set("arena." + a + ".ymin", arena.getMinY()); + arenaConfig.set("arena." + a + ".zmin", arena.getMinZ()); + + arenaConfig.set("arena." + a + ".xmax", arena.getMaxX()); + arenaConfig.set("arena." + a + ".ymax", arena.getMaxY()); + arenaConfig.set("arena." + a + ".zmax", arena.getMaxZ()); + + arenaConfig.set("arena." + a + ".loc1.x", arena.getLoc1().getBlockX()); + arenaConfig.set("arena." + a + ".loc1.y", arena.getLoc1().getBlockY()); + arenaConfig.set("arena." + a + ".loc1.z", arena.getLoc1().getBlockZ()); + + arenaConfig.set("arena." + a + ".loc2.x", arena.getLoc2().getBlockX()); + arenaConfig.set("arena." + a + ".loc2.y", arena.getLoc2().getBlockY()); + arenaConfig.set("arena." + a + ".loc2.z", arena.getLoc2().getBlockZ()); + + arenaConfig.set("arena." + a + ".world", arena.getWorld()); + arenaConfig.set("arena." + a + ".active", false); + arenaConfig.set("arena." + a + ".teamarena", arena.isTeamArena()); + arenaConfig.set("arena." + a + ".timer", arena.getArenaTimer()); + arenaConfig.set("arena." + a + ".time", arena.getArenaTimer()); + arenaConfig.set("arena." + a + ".world", arena.getWorld()); + + } + + try { + arenaConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + + public void deleteArena(String name, Player player) { + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + if(file.exists()) { + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + Arena arena = getArenaByName(name); + + if(!arenas.contains(arena)) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_REMOVE_FAIL").replace("%arena%", arena.getName()))); + return; + } + + if(arena.isActive()) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_REMOVE_FAIL").replace("%arena%", arena.getName()))); + return; + } + arenaConfig.set("arena." + name, null); + + player.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_REMOVE_SUCCESS").replace("%arena%", arena.getName()))); + + arenas.remove(arena); + available.remove(arena); + + + + try { + arenaConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public void createArena(Location loc1, Location loc2, int timer, String name, Player player) { + + if(arenas.contains(getArenaByName(name))) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_CREATE_FAIL").replace("%arena%", name))); + + return; + } + + Arena arena = new Arena (loc1, loc2, timer, name, player.getLocation().getWorld().getName()); + + arenas.add(arena); + available.add(arena); + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + if(!file.exists()) { + System.out.println("[IranPvP] Could not find any Arenas, Creating new file"); + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + arenaConfig.createSection("arena." + name + ".name"); + arenaConfig.createSection("arena." + name + ".creator"); + + arenaConfig.createSection("arena." + name + ".team1.x"); + arenaConfig.createSection("arena." + name + ".team1.y"); + arenaConfig.createSection("arena." + name + ".team1.z"); + arenaConfig.createSection("arena." + name + ".team1.pitch"); + arenaConfig.createSection("arena." + name + ".team1.yaw"); + + arenaConfig.createSection("arena." + name + ".team2.x"); + arenaConfig.createSection("arena." + name + ".team2.y"); + arenaConfig.createSection("arena." + name + ".team2.z"); + arenaConfig.createSection("arena." + name + ".team2.pitch"); + arenaConfig.createSection("arena." + name + ".team2.yaw"); + + arenaConfig.createSection("arena." + name + ".xmin"); + arenaConfig.createSection("arena." + name + ".ymin"); + arenaConfig.createSection("arena." + name + ".zmin"); + + arenaConfig.createSection("arena." + name + ".xmax"); + arenaConfig.createSection("arena." + name + ".ymax"); + arenaConfig.createSection("arena." + name + ".zmax"); + + arenaConfig.createSection("arena." + name + ".timer"); + arenaConfig.createSection("arena." + name + ".time"); + + arenaConfig.createSection("arena." + name + ".world"); + arenaConfig.createSection("arena." + name + ".active"); + + arenaConfig.createSection("arena." + name + ".loc1.x"); + arenaConfig.createSection("arena." + name + ".loc1.y"); + arenaConfig.createSection("arena." + name + ".loc1.z"); + + arenaConfig.createSection("arena." + name + ".loc2.x"); + arenaConfig.createSection("arena." + name + ".loc2.y"); + arenaConfig.createSection("arena." + name + ".loc2.z"); + arenaConfig.createSection("arena." + name + ".teamarena"); + + arenaConfig.set("arena." + name + ".name", name); + arenaConfig.set("arena." + name + ".creator", arena.getCreator()); + + arenaConfig.set("arena." + name + ".team1.x", arena.getXTeam1()); + arenaConfig.set("arena." + name + ".team1.y", arena.getYTeam1()); + arenaConfig.set("arena." + name + ".team1.z", arena.getZTeam1()); + arenaConfig.set("arena." + name + ".team1.pitch", arena.getPitchTeam1()); + arenaConfig.set("arena." + name + ".team1.yaw", arena.getYawTeam1()); + + arenaConfig.set("arena." + name + ".team2.x", arena.getXTeam2()); + arenaConfig.set("arena." + name + ".team2.y", arena.getYTeam2()); + arenaConfig.set("arena." + name + ".team2.z", arena.getZTeam2()); + arenaConfig.set("arena." + name + ".team2.pitch", arena.getPitchTeam2()); + arenaConfig.set("arena." + name + ".team2.yaw", arena.getYawTeam2()); + + arenaConfig.set("arena." + name + ".xmin", arena.getMinX()); + arenaConfig.set("arena." + name + ".ymin", arena.getMinY()); + arenaConfig.set("arena." + name + ".zmin", arena.getMinZ()); + + arenaConfig.set("arena." + name + ".xmax", arena.getMaxX()); + arenaConfig.set("arena." + name + ".ymax", arena.getMaxY()); + arenaConfig.set("arena." + name + ".zmax", arena.getMaxZ()); + + arenaConfig.set("arena." + name + ".timer", timer); + arenaConfig.set("arena." + name + ".time", timer); + + arenaConfig.set("arena." + name + ".loc1.x", arena.getLoc1().getBlockX()); + arenaConfig.set("arena." + name + ".loc1.y", arena.getLoc1().getBlockY()); + arenaConfig.set("arena." + name + ".loc1.z", arena.getLoc1().getBlockZ()); + + arenaConfig.set("arena." + name + ".loc2.x", arena.getLoc2().getBlockX()); + arenaConfig.set("arena." + name + ".loc2.y", arena.getLoc2().getBlockY()); + arenaConfig.set("arena." + name + ".loc2.z", arena.getLoc2().getBlockZ()); + + arenaConfig.set("arena." + name + ".world", arena.getWorld()); + arenaConfig.set("arena." + name + ".active", false); + arenaConfig.set("arena." + name + ".teamarena", true); + + try { + arenaConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + + player.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_CREATE_SUCCESS").replace("%arena%", arena.getName()))); + + + } else { + + file = new File(IranPvP.plugin.getDataFolder(), "arena.yml"); + + new YamlConfiguration(); + + YamlConfiguration arenaConfig = YamlConfiguration.loadConfiguration(file); + + arenaConfig.createSection("arena." + name + ".name"); + arenaConfig.createSection("arena." + name + ".creator"); + + arenaConfig.createSection("arena." + name + ".team1.x"); + arenaConfig.createSection("arena." + name + ".team1.y"); + arenaConfig.createSection("arena." + name + ".team1.z"); + arenaConfig.createSection("arena." + name + ".team1.pitch"); + arenaConfig.createSection("arena." + name + ".team1.yaw"); + + arenaConfig.createSection("arena." + name + ".team2.x"); + arenaConfig.createSection("arena." + name + ".team2.y"); + arenaConfig.createSection("arena." + name + ".team2.z"); + arenaConfig.createSection("arena." + name + ".team2.pitch"); + arenaConfig.createSection("arena." + name + ".team2.yaw"); + + arenaConfig.createSection("arena." + name + ".xmin"); + arenaConfig.createSection("arena." + name + ".ymin"); + arenaConfig.createSection("arena." + name + ".zmin"); + + arenaConfig.createSection("arena." + name + ".xmax"); + arenaConfig.createSection("arena." + name + ".ymax"); + arenaConfig.createSection("arena." + name + ".zmax"); + + arenaConfig.createSection("arena." + name + ".timer"); + arenaConfig.createSection("arena." + name + ".time"); + + arenaConfig.createSection("arena." + name + ".loc1.x"); + arenaConfig.createSection("arena." + name + ".loc1.y"); + arenaConfig.createSection("arena." + name + ".loc1.z"); + + arenaConfig.createSection("arena." + name + ".loc2.x"); + arenaConfig.createSection("arena." + name + ".loc2.y"); + arenaConfig.createSection("arena." + name + ".loc2.z"); + + arenaConfig.createSection("arena." + name + ".world"); + arenaConfig.createSection("arena." + name + ".active"); + arenaConfig.createSection("arena." + name + ".teamarena"); + + arenaConfig.set("arena." + name + ".name", name); + arenaConfig.set("arena." + name + ".creator", arena.getCreator()); + + arenaConfig.set("arena." + name + ".team1.x", arena.getXTeam1()); + arenaConfig.set("arena." + name + ".team1.y", arena.getYTeam1()); + arenaConfig.set("arena." + name + ".team1.z", arena.getZTeam1()); + arenaConfig.set("arena." + name + ".team1.pitch", arena.getPitchTeam1()); + arenaConfig.set("arena." + name + ".team1.yaw", arena.getYawTeam1()); + + arenaConfig.set("arena." + name + ".team2.x", arena.getXTeam2()); + arenaConfig.set("arena." + name + ".team2.y", arena.getYTeam2()); + arenaConfig.set("arena." + name + ".team2.z", arena.getZTeam2()); + arenaConfig.set("arena." + name + ".team2.pitch", arena.getPitchTeam2()); + arenaConfig.set("arena." + name + ".team2.yaw", arena.getYawTeam2()); + + arenaConfig.set("arena." + name + ".xmin", arena.getMinX()); + arenaConfig.set("arena." + name + ".ymin", arena.getMinY()); + arenaConfig.set("arena." + name + ".zmin", arena.getMinZ()); + + arenaConfig.set("arena." + name + ".xmax", arena.getMaxX()); + arenaConfig.set("arena." + name + ".ymax", arena.getMaxY()); + arenaConfig.set("arena." + name + ".zmax", arena.getMaxZ()); + + arenaConfig.set("arena." + name + ".timer", timer); + arenaConfig.set("arena." + name + ".time", timer); + + arenaConfig.set("arena." + name + ".loc1.x", arena.getLoc1().getBlockX()); + arenaConfig.set("arena." + name + ".loc1.y", arena.getLoc1().getBlockY()); + arenaConfig.set("arena." + name + ".loc1.z", arena.getLoc1().getBlockZ()); + + arenaConfig.set("arena." + name + ".loc2.x", arena.getLoc2().getBlockX()); + arenaConfig.set("arena." + name + ".loc2.y", arena.getLoc2().getBlockY()); + arenaConfig.set("arena." + name + ".loc2.z", arena.getLoc2().getBlockZ()); + + arenaConfig.set("arena." + name + ".world", arena.getWorld()); + arenaConfig.set("arena." + name + ".active", false); + arenaConfig.set("arena." + name + ".teamarena", true); + try { + arenaConfig.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + + player.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_CREATE_SUCCESS").replace("%arena%", arena.getName()))); + + } + + } + + + + public Arena getArenaByName(String name) { + for(Arena arena : arenas) { + if(arena.getName().equalsIgnoreCase(name)) { + return arena; + } + } + + return null; + } + + public Arena getArenaByPlayer(Player player) { + for(Arena arena : arenas) { + if(arena.getFighters().contains(player.getName())) { + return arena; + } + } + + return null; + } + + //team fights + @SuppressWarnings("deprecation") + public void teleportTeams(Team team1, Team team2) { + Arena arena = available.get(0); + + if(arena == null) { + return; + } + + available.remove(arena); + arena.setInactive(); + + int x1 = arena.getXTeam1(); + int y1 = arena.getYTeam1(); + int z1 = arena.getZTeam1(); + + int x2 = arena.getXTeam2(); + int y2 = arena.getYTeam2(); + int z2 = arena.getZTeam2(); + + float pitch1 = arena.getPitchTeam1(); + float yaw1 = arena.getYawTeam1(); + + float pitch2 = arena.getPitchTeam2(); + float yaw2 = arena.getYawTeam2(); + + Location loc1 = new Location(Bukkit.getWorld(arena.getWorld()), x1, y1, z1); + loc1.setPitch(pitch1); + loc1.setYaw(yaw1); + + Location loc2 = new Location(Bukkit.getWorld(arena.getWorld()), x2, y2, z2); + loc2.setPitch(pitch2); + loc2.setYaw(yaw2); + + + for(Player p : Bukkit.getOnlinePlayers()) { + if(team1.getTeamMembers().contains(p.getName())) { + p.teleport(loc1); + arena.getFighters().add(p.getName()); + } + } + + for(Player p : Bukkit.getOnlinePlayers()) { + if(team2.getTeamMembers().contains(p.getName())) { + p.teleport(loc2); + arena.getFighters().add(p.getName()); + } + } + + } + + @SuppressWarnings("deprecation") + public void teleportKothTeams(Team team1, Team team2) { + Arena arena = available.get(0); + + if(arena == null) { + return; + } + + available.remove(arena); + arena.setActive(); + + int x1 = arena.getXTeam1(); + int y1 = arena.getYTeam1(); + int z1 = arena.getZTeam1(); + + int x2 = arena.getXTeam2(); + int y2 = arena.getYTeam2(); + int z2 = arena.getZTeam2(); + + float pitch1 = arena.getPitchTeam1(); + float yaw1 = arena.getYawTeam1(); + + float pitch2 = arena.getPitchTeam2(); + float yaw2 = arena.getYawTeam2(); + + Location loc1 = new Location(Bukkit.getWorld(arena.getWorld()), x1, y1, z1); + loc1.setPitch(pitch1); + loc1.setYaw(yaw1); + + Location loc2 = new Location(Bukkit.getWorld(arena.getWorld()), x2, y2, z2); + loc2.setPitch(pitch2); + loc2.setYaw(yaw2); + + + for(Player p : Bukkit.getOnlinePlayers()) { + if(team1.getTeamMembers().contains(p.getName())) { + p.teleport(loc1); + arena.getFighters().add(p.getName()); + } + } + + for(Player p : Bukkit.getOnlinePlayers()) { + if(team2.getTeamMembers().contains(p.getName())) { + p.teleport(loc2); + arena.getFighters().add(p.getName()); + } + } + + for(Player p : Bukkit.getOnlinePlayers()) { + if(arena.getFighters().contains(p.getName())) { + p.sendMessage(ChatColor.GOLD + "Arena: " + ChatColor.YELLOW + arena.getName()); + p.sendMessage(ChatColor.GOLD + "Timer: " + ChatColor.YELLOW + Run.toMMSS(arena.getArenaTimer())); + p.sendMessage(ChatColor.GOLD + "Active: " + ChatColor.YELLOW + arena.isActive()); + } + } + + } + + //1v1's + public void teleportPlayers(Player player1, Player player2) { + Arena arena = pAvailable.get(0); + + if(arena == null) { + return; + } + + pAvailable.remove(arena); + arena.setInactive(); + + arena.addFighter(player1.getName()); + arena.addFighter(player2.getName()); + + int x1 = arena.getXTeam1(); + int y1 = arena.getYTeam1(); + int z1 = arena.getZTeam1(); + + int x2 = arena.getXTeam2(); + int y2 = arena.getYTeam2(); + int z2 = arena.getZTeam2(); + + float pitch1 = arena.getPitchTeam1(); + float yaw1 = arena.getYawTeam1(); + + float pitch2 = arena.getPitchTeam2(); + float yaw2 = arena.getYawTeam2(); + + Location loc1 = new Location(Bukkit.getWorld(arena.getWorld()), x1, y1, z1); + loc1.setPitch(pitch1); + loc1.setYaw(yaw1); + + Location loc2 = new Location(Bukkit.getWorld(arena.getWorld()), x2, y2, z2); + loc2.setPitch(pitch2); + loc2.setYaw(yaw2); + + + player1.teleport(loc1); + player2.teleport(loc2); + + player1.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_TELEPORT").replace("%creator%", arena.getCreator()).replace("%arena%", arena.getName()))); + + player2.sendMessage(ChatColor.translateAlternateColorCodes('&', IranPvP.plugin.getConfig().getString("ARENA_TELEPORT").replace("%creator%", arena.getCreator()).replace("%arena%", arena.getName()))); + } + + //remove teams + public void removeTeams(Player player) { + final Arena arena = getArenaByPlayer(player); + + if(!arenas.contains(arena)) { + return; + } + + for(Player p : Bukkit.getOnlinePlayers()) { + + if(arena.getSpec().contains(p.getName())) { + spawn.teleportSpawn(p); + p.setGameMode(GameMode.SURVIVAL); + p.setAllowFlight(false); + arena.getSpec().remove(p.getName()); + } + } + + for(Player p : Bukkit.getOnlinePlayers()) { + + if(arena.getFighters().contains(p.getName())) { + + p.getInventory().clear(); + p.getInventory().setArmorContents(null); + + } + } + + arena.setTimer(arena.getArenaTimer()); + arena.setInactive(); + arena.getCappers().clear(); + + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(IranPvP.plugin, new Runnable() { + + @Override + public void run() { + + for(Player p : Bukkit.getOnlinePlayers()) { + + if(arena.getFighters().contains(p.getName())) { + spawn.teleportSpawn(p); + } + } + + available.add(arena); + + arena.getFighters().clear(); + arena.getSpec().clear(); + } + + }, 60); + + } + + //remove 1v1's + public void removePlayer(Player player) { + Arena arena = getArenaByPlayer(player); + + if(!arenas.contains(arena)) { + return; + } + + pAvailable.add(arena); + + arena.setInactive(); + arena.setTimer(arena.getArenaTimer()); + arena.getFighters().clear(); + arena.getCappers().clear(); + + for(Player p : Bukkit.getOnlinePlayers()) { + if(arena.getSpec().contains(p.getName())) { + spawn.teleportSpawn(p); + p.setAllowFlight(false); + p.setGameMode(GameMode.SURVIVAL); + arena.getSpec().remove(p.getName()); + player.showPlayer(p); + + } + } + + arena.getSpec().clear(); + } + + public boolean insideCube(Player player, Location loc) { + Arena arena = getArenaByPlayer(player); + + if(!arenas.contains(arena)) { + return false; + } + + if((loc.getBlockX() >= arena.getMinX()) && (loc.getBlockX() <= arena.getMaxX())) { + if((loc.getBlockZ() >= arena.getMinZ()) && (loc.getBlockZ() <= arena.getMaxZ())) { + if((loc.getBlockY() >= arena.getMinY()) && (loc.getBlockY() <= arena.getMaxY())) { + return true; + } + } + } + + return false; + } + + public boolean isSpectator(Player player) { + for(Arena arena : arenas) { + if(arena.getSpec().contains(player.getName())) { + return true; + } + } + + return false; + } + + public Arena getArenaBySpectator(Player player) { + for(Arena arena : arenas) { + if(arena.getSpec().contains(player.getName())) { + return arena; + } + } + return null; + } + + public ArrayList getAllArena() { + return arenas; + } + + public ArrayList getAllAvailable() { + return available; + } +} \ No newline at end of file diff --git a/src/me/iran/iranpvp/cmd/arena/ArenaCommands.java b/src/me/iran/iranpvp/cmd/arena/ArenaCommands.java new file mode 100644 index 0000000..9abe5f8 --- /dev/null +++ b/src/me/iran/iranpvp/cmd/arena/ArenaCommands.java @@ -0,0 +1,295 @@ +package me.iran.iranpvp.cmd.arena; + +import me.iran.iranpvp.IranPvP; +import me.iran.iranpvp.arena.Arena; +import me.iran.iranpvp.arena.ArenaManager; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ArenaCommands implements CommandExecutor { + + IranPvP plugin; + + public ArenaCommands(IranPvP plugin) { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + + if(!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Player command only");; + return true; + } + + Player player = (Player) sender; + + if(cmd.getName().equalsIgnoreCase("arena")) { + if(!player.hasPermission("kothpractice.staff")) { + player.sendMessage(ChatColor.RED + "Not Enough Permissions."); + return true; + } + + if(args.length < 1) { + player.sendMessage(ChatColor.RED + "/arena create "); + player.sendMessage(ChatColor.RED + "/arena setteam1 "); + player.sendMessage(ChatColor.RED + "/arena setteam2 "); + player.sendMessage(ChatColor.RED + "/arena setloc1 "); + player.sendMessage(ChatColor.RED + "/arena setloc2 "); + player.sendMessage(ChatColor.RED + "/arena setteamarena true|false"); + player.sendMessage(ChatColor.RED + "/arena settime