Search in sources :

Example 1 with PollCommand

use of com.ebicep.warlords.poll.PollCommand in project Warlords by ebicep.

the class Warlords method onEnable.

@Override
public void onEnable() {
    instance = this;
    VERSION = this.getDescription().getVersion();
    serverIP = this.getServer().getIp();
    taskChainFactory = BukkitTaskChainFactory.create(this);
    gameManager = new GameManager();
    /*
         * Each map instance presents a game server, every map can hold up to 3 games at once.
         *
         * Adding a new map must start with -0 at the end and increment from there on out.
         *
         * Adding additional game servers will require a config update in @see MultiWorld Plugin
         */
    gameManager.addGameHolder("Rift-0", GameMap.RIFT, new LocationFactory(Bukkit.getWorld("Rift-0")));
    gameManager.addGameHolder("Rift-1", GameMap.RIFT, new LocationFactory(Bukkit.getWorld("Rift-1")));
    gameManager.addGameHolder("Rift-2", GameMap.RIFT, new LocationFactory(Bukkit.getWorld("Rift-2")));
    gameManager.addGameHolder("Crossfire-0", GameMap.CROSSFIRE, new LocationFactory(Bukkit.getWorld("Crossfire-0")));
    gameManager.addGameHolder("Crossfire-1", GameMap.CROSSFIRE, new LocationFactory(Bukkit.getWorld("Crossfire-1")));
    gameManager.addGameHolder("Crossfire-2", GameMap.CROSSFIRE, new LocationFactory(Bukkit.getWorld("Crossfire-2")));
    gameManager.addGameHolder("Valley-0", GameMap.VALLEY, new LocationFactory(Bukkit.getWorld("Atherrough_Valley-0")));
    gameManager.addGameHolder("Valley-1", GameMap.VALLEY, new LocationFactory(Bukkit.getWorld("Atherrough_Valley-1")));
    gameManager.addGameHolder("Valley-2", GameMap.VALLEY, new LocationFactory(Bukkit.getWorld("Atherrough_Valley-2")));
    gameManager.addGameHolder("Warsong-0", GameMap.WARSONG, new LocationFactory(Bukkit.getWorld("Warsong-0")));
    gameManager.addGameHolder("Warsong-1", GameMap.WARSONG, new LocationFactory(Bukkit.getWorld("Warsong-1")));
    gameManager.addGameHolder("Warsong-2", GameMap.WARSONG, new LocationFactory(Bukkit.getWorld("Warsong-2")));
    gameManager.addGameHolder("Aperture-0", GameMap.APERTURE, new LocationFactory(Bukkit.getWorld("Aperture-0")));
    gameManager.addGameHolder("Aperture-1", GameMap.APERTURE, new LocationFactory(Bukkit.getWorld("Aperture-1")));
    gameManager.addGameHolder("Aperture-2", GameMap.APERTURE, new LocationFactory(Bukkit.getWorld("Aperture-2")));
    gameManager.addGameHolder("Arathi-0", GameMap.ARATHI, new LocationFactory(Bukkit.getWorld("Arathi-0")));
    gameManager.addGameHolder("Arathi-1", GameMap.ARATHI, new LocationFactory(Bukkit.getWorld("Arathi-1")));
    gameManager.addGameHolder("Arathi-2", GameMap.ARATHI, new LocationFactory(Bukkit.getWorld("Arathi-2")));
    // CURRENTLY DISABLED
    // gameManager.addGameHolder("SimulationRift-0", GameMap.SIMULATION_RIFT, new LocationFactory(Bukkit.getWorld("SimulationRift")));
    // gameManager.addGameHolder("SimulationCrossfire-0", GameMap.SIMULATION_CROSSFIRE, new LocationFactory(Bukkit.getWorld("SimulationCrossfire")));
    // gameManager.addGameHolder("Debug-0", GameMap.DEBUG, new LocationFactory(Bukkit.getWorld("TestWorld")));
    // gameManager.addGameHolder("Heaven-0", GameMap.HEAVEN_WILL, new LocationFactory(Bukkit.getWorld("Heaven")));
    Thread.currentThread().setContextClassLoader(getClassLoader());
    ConfigurationSerialization.registerClass(PlayerSettings.class);
    getServer().getPluginManager().registerEvents(new WarlordsEvents(), this);
    getServer().getPluginManager().registerEvents(new MenuEventListener(this), this);
    getServer().getPluginManager().registerEvents(new PartyListener(), this);
    getServer().getPluginManager().registerEvents(new BotListener(), this);
    getServer().getPluginManager().registerEvents(new RecklessCharge(), this);
    getServer().getPluginManager().registerEvents(new FutureMessageManager(), this);
    new GameStartCommand().register(this);
    new GameTerminateCommand().register(this);
    new GameKillCommand().register(this);
    new GameListCommand().register(this);
    new MenuCommand().register(this);
    new ShoutCommand().register(this);
    new HotkeyModeCommand().register(this);
    new DebugCommand().register(this);
    new ClassCommand().register(this);
    new GetPlayersCommand().register(this);
    new TestCommand().register(this);
    new ParticleQualityCommand().register(this);
    new SpawnTestDummyCommand().register(this);
    new PartyCommand().register(this);
    new StreamCommand().register(this);
    new RecordAverageDamage().register(this);
    new ChatChannelCommand().register(this);
    new BotCommands().register(this);
    new LeaderboardCommand().register(this);
    new RecordGamesCommand().register(this);
    new GamesCommand().register(this);
    new SpectateCommand().register(this);
    new DebugModeCommand().register(this);
    new MyLocationCommand().register(this);
    new MessageCommand().register(this);
    new ExperienceCommand().register(this);
    new QueueCommand().register(this);
    new ImposterCommand().register(this);
    new LobbyCommand().register(this);
    new DiscordCommand().register(this);
    new PollCommand().register(this);
    new AchievementsCommand().register(this);
    new FindPlayer().register(this);
    updateHeads();
    readKeysConfig();
    readWeaponConfig();
    saveWeaponConfig();
    TimeZone.setDefault(TimeZone.getTimeZone("EST"));
    holographicDisplaysEnabled = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
    citizensEnabled = Bukkit.getPluginManager().isPluginEnabled("Citizens");
    Bukkit.getOnlinePlayers().forEach(player -> {
        playerScoreboards.put(player.getUniqueId(), new CustomScoreboard(player));
    });
    // connects to the database
    Warlords.newChain().async(DatabaseManager::init).execute();
    try {
        BotManager.connect();
    } catch (LoginException e) {
        e.printStackTrace();
    }
    ProtocolManager protocolManager;
    protocolManager = ProtocolLibrary.getProtocolManager();
    protocolManager.removePacketListeners(this);
    protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.HIGHEST, PacketType.Play.Server.WORLD_PARTICLES) {

        int counter = 0;

        @Override
        public void onPacketSending(PacketEvent event) {
            // Item packets (id: 0x29)
            if (event.getPacketType() == PacketType.Play.Server.WORLD_PARTICLES) {
                Player player = event.getPlayer();
                if (Warlords.hasPlayer(player)) {
                    if (counter++ % playerSettings.get(player.getUniqueId()).getParticleQuality().particleReduction == 0) {
                        event.setCancelled(true);
                    }
                }
            }
        }
    });
    protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.HIGHEST, PacketType.Play.Client.STEER_VEHICLE) {

        @Override
        public void onPacketReceiving(PacketEvent e) {
            if (e.getPacketType() == PacketType.Play.Client.STEER_VEHICLE) {
                if (e.getPacket().getHandle() instanceof PacketPlayInSteerVehicle) {
                    boolean dismount = e.getPacket().getBooleans().read(1);
                    Field f;
                    try {
                        f = PacketPlayInSteerVehicle.class.getDeclaredField("d");
                        f.setAccessible(true);
                        f.set(e.getPacket().getHandle(), false);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                    if (dismount && e.getPlayer().getVehicle() != null) {
                        e.getPlayer().getVehicle().remove();
                    }
                }
            }
        }
    });
    startMainLoop();
    getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[Warlords] Plugin is enabled");
    for (String command : this.getDescription().getCommands().keySet()) {
        if (getCommand(command).getExecutor() == this) {
            getServer().getConsoleSender().sendMessage(ChatColor.GOLD + "[Warlords] Warning, command " + command + " is specified in plugin.yml, but not defined in the plugins");
        }
    }
}
Also used : PartyCommand(com.ebicep.warlords.party.PartyCommand) BotCommands(com.ebicep.jda.BotCommands) PacketAdapter(com.comphenix.protocol.events.PacketAdapter) BotListener(com.ebicep.jda.BotListener) Player(org.bukkit.entity.Player) FireWorkEffectPlayer(com.ebicep.warlords.effects.FireWorkEffectPlayer) QueueCommand(com.ebicep.warlords.queuesystem.QueueCommand) PacketPlayInSteerVehicle(net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle) WarlordsEvents(com.ebicep.warlords.events.WarlordsEvents) ProtocolManager(com.comphenix.protocol.ProtocolManager) LoginException(javax.security.auth.login.LoginException) PartyListener(com.ebicep.warlords.party.PartyListener) Field(java.lang.reflect.Field) LeaderboardCommand(com.ebicep.warlords.database.leaderboards.LeaderboardCommand) PollCommand(com.ebicep.warlords.poll.PollCommand) FutureMessageManager(com.ebicep.warlords.database.FutureMessageManager) LoginException(javax.security.auth.login.LoginException) LocationFactory(com.ebicep.warlords.util.bukkit.LocationFactory) MenuEventListener(com.ebicep.warlords.menu.MenuEventListener) PacketEvent(com.comphenix.protocol.events.PacketEvent) StreamCommand(com.ebicep.warlords.party.StreamCommand)

Aggregations

ProtocolManager (com.comphenix.protocol.ProtocolManager)1 PacketAdapter (com.comphenix.protocol.events.PacketAdapter)1 PacketEvent (com.comphenix.protocol.events.PacketEvent)1 BotCommands (com.ebicep.jda.BotCommands)1 BotListener (com.ebicep.jda.BotListener)1 FutureMessageManager (com.ebicep.warlords.database.FutureMessageManager)1 LeaderboardCommand (com.ebicep.warlords.database.leaderboards.LeaderboardCommand)1 FireWorkEffectPlayer (com.ebicep.warlords.effects.FireWorkEffectPlayer)1 WarlordsEvents (com.ebicep.warlords.events.WarlordsEvents)1 MenuEventListener (com.ebicep.warlords.menu.MenuEventListener)1 PartyCommand (com.ebicep.warlords.party.PartyCommand)1 PartyListener (com.ebicep.warlords.party.PartyListener)1 StreamCommand (com.ebicep.warlords.party.StreamCommand)1 PollCommand (com.ebicep.warlords.poll.PollCommand)1 QueueCommand (com.ebicep.warlords.queuesystem.QueueCommand)1 LocationFactory (com.ebicep.warlords.util.bukkit.LocationFactory)1 Field (java.lang.reflect.Field)1 LoginException (javax.security.auth.login.LoginException)1 PacketPlayInSteerVehicle (net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle)1 Player (org.bukkit.entity.Player)1