Java 类org.bukkit.Server 实例源码

项目:PetBlocks    文件:PlayerMetaSQLiteControllerIT.java   
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    if (Bukkit.getServer() == null) {
        final Server server = mock(Server.class);
        when(server.getLogger()).thenReturn(Logger.getGlobal());
        Bukkit.setServer(server);
    }
    new File("PetBlocks.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("PetBlocks"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:PetBlocks    文件:PlayerMetaMySQLControllerIT.java   
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    if (Bukkit.getServer() == null) {
        final Server server = mock(Server.class);
        when(server.getLogger()).thenReturn(Logger.getGlobal());
        Bukkit.setServer(server);
    }
    new File("PetBlocks.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("PetBlocks"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:BlockBall    文件:StatsMySQLControllerTest.java   
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    final Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    if (Bukkit.getServer() == null)
        Bukkit.setServer(server);
    new File("BlockBall/BlockBall.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("BlockBall"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:BlockBall    文件:PlayerMetaMySQLControllerTest.java   
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    final Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    if(Bukkit.getServer() == null)
        Bukkit.setServer(server);
    new File("BlockBall/BlockBall.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("BlockBall"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:BlockBall    文件:PlayerMetaSQLiteControllerTest.java   
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    final Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    if(Bukkit.getServer() == null)
        Bukkit.setServer(server);
    Factory.disable();
    new File("BlockBall/BlockBall.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("BlockBall"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:BlockBall    文件:StatsSQLiteControllerTest.java   
private static Plugin mockPlugin() {
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled", false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    final Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    if (Bukkit.getServer() == null)
        Bukkit.setServer(server);
    Factory.disable();
    new File("BlockBall/BlockBall.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("BlockBall"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:SurvivalAPI    文件:SurvivalGameLoop.java   
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param server Server instance
 * @param game Game instance
 */
public SurvivalGameLoop(JavaPlugin plugin, Server server, SurvivalGame game)
{
    this.game = game;
    this.plugin = plugin;
    this.server = server;
    this.world = server.getWorlds().get(0);
    this.objectives = new ConcurrentHashMap<>();

    this.seconds = 0;
    this.minutes = 0;
    this.episode = 1;

    this.episodeEnabled = false;
    this.blocksProtected = true;
    this.netherClosed = false;

    this.createWaitingBlockRemovingEvent();
}
项目:UltimateSpawn    文件:PlaceHolderMessageUtils.java   
public static void ReplaceCharBroadcastPlayerMoreGeneral(String str, Server server, Player player) {
    if (ConfigGlobal.getConfig().getBoolean("Plugin.Use.PlaceholderAPI")) {
        Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, str)
                .replaceAll("%player%", player.getName())
                .replaceAll("%DELAY%", String.valueOf(DelaychatCommand.delay))
                .replaceAll("%ping%", String.valueOf(PingCommand.getPing(player)))
                .replaceAll("%tps%", String.valueOf(Tps.getTPS()))
                .replaceAll("%timedelaypvcji%", String.valueOf(ConfigGPlayerVisibility.getConfig().getInt("PV.Option.Item-Delay.Delay")))
                .replaceAll("%timedelaypvcommands%", String.valueOf(ConfigCPlayerOption.getConfig().getInt("PlayerOption.PlayerVisivility.Delay.Delay")))
                ));
    } else {
        Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', str)
                .replaceAll("%player%", player.getName())
                .replaceAll("%DELAY%", String.valueOf(DelaychatCommand.delay))
                .replaceAll("%ping%", String.valueOf(PingCommand.getPing(player)))
                .replaceAll("%tps%", String.valueOf(Tps.getTPS()))
                .replaceAll("%timedelaypvcji%", String.valueOf(ConfigGPlayerVisibility.getConfig().getInt("PV.Option.Item-Delay.Delay")))
                .replaceAll("%timedelaypvcommands%", String.valueOf(ConfigCPlayerOption.getConfig().getInt("PlayerOption.PlayerVisivility.Delay.Delay")))
                );
    }
}
项目:RPGInventory    文件:Metrics.java   
/**
 * Gets the online player (backwards compatibility)
 *
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:MCLibrary    文件:MockFactory.java   
public static Server createMockServer() {
    ConsoleCommandSender commandSender = (ConsoleCommandSender) createCommandSender();
    Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    when(server.getPluginManager()).thenReturn(
            new SimplePluginManager(server, new SimpleCommandMap(server)));
    when(server.getItemFactory()).thenReturn(new MockItemFactory());
    doAnswer(invocation -> new MockInventory(InventoryType.CHEST, invocation.getArgument(1), invocation.getArgument(2)))
            .when(server).createInventory(any(), anyInt(), anyString());
    when(server.getBukkitVersion()).thenReturn("1.0");
    when(server.getConsoleSender()).thenReturn(commandSender);
    doAnswer(invocation -> createMockWorld())
            .when(server).getWorld(anyString());

    return server;
}
项目:Zabbigot    文件:Show.java   
@Override
protected void exec(CommandSender sender) {
    /*
     * ======== Zabbigot (Player: 0/20) ========
     * TPS: [####################] 20.00 (100.0%)
     * MEM: [###################_] 7832.4MB/8192.0MB (95.6%)
     */

    Server server = Bukkit.getServer();
    sender.sendMessage(ChatColor.GREEN + "========" + ChatColor.RESET
            + " Zabbigot (Player: "
            + server.getOnlinePlayers().size()
            + "/"
            + server.getMaxPlayers()
            + ") " + ChatColor.GREEN + "========");

    sender.sendMessage(formatTps(watcher.getTPS()));
    sender.sendMessage(formatMem());
}
项目:BasicSurvivalPlus    文件:ExpRateChangeCommand.java   
public boolean onCommand(CommandSender sender, String label, String[] args) {
    JavaPlugin plugin = CommandManager.plugin;
    Server server = plugin.getServer();

    if (args.length > 0) {
        if (!sender.hasPermission("exprate.change")) {
            sender.sendMessage("仅管理员可改变当前服务器经验倍率");
            return true;
        }
        plugin.getConfig().set("EXP_RATE", Integer.valueOf(args[0]));
        server.broadcastMessage(ChatColor.BLUE + "服务器经验倍率调整为" + ChatColor.GREEN + plugin.getConfig().getInt("EXP_RATE"));
        plugin.saveConfig();
    } else {
        sender.sendMessage(ChatColor.BLUE + "当前服务器经验倍率为" + ChatColor.GREEN + plugin.getConfig().getInt("EXP_RATE"));
    }
    return true;
}
项目:SignEdit    文件:SignEditTest.java   
@Before
public void setUp() throws Exception {
    Configuration config = new Configuration(File.createTempFile("SignEdit-", "-config.yml"));
    spyConfig = spy(config);
    listener = new Interact();
    doReturn(false).when(spyConfig).writeFullConfig(new YamlConfiguration());

    uiSignSubcommand = mock(UiSignSubcommand.class);
    whenNew(UiSignSubcommand.class).withAnyArguments().thenReturn(uiSignSubcommand);

    signCommand = new SignCommand(spyConfig, listener);

    player = mock(Player.class);
    command = mock(Command.class);
    sign = mock(Sign.class);
    block = mock(Block.class);
    when(player.hasPermission("SignEdit.use")).thenReturn(true);
    when(block.getState()).thenReturn(sign);

    server = mock(Server.class);
    pluginManager = mock(PluginManager.class);
    mockStatic(Bukkit.class);
    when(Bukkit.getServer()).thenReturn(server);
    when(server.getPluginManager()).thenReturn(pluginManager);
}
项目:SinglePlayerSleep    文件:MetricsLite.java   
/**
 * Gets the online player (backwards compatibility)
 * 
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:FactionsFramework    文件:Metrics.java   
/**
 * Gets the online player (backwards compatibility)
 * 
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:OpGuard    文件:MCStatsMetricsLite.java   
/**
 * Gets the online player (backwards compatibility)
 * 
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:CutePortals    文件:EventListener.java   
@EventHandler(ignoreCancelled = true)
void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    String playerName = player.getName();
    if (!status.contains(playerName)) status.add(player.getName());

    // Schedule a command executor task
    this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
        Server server = Bukkit.getServer();
        if (plugin.messages.containsKey(playerName)) {
            // Finally let's execute command!
            String command = plugin.messages.get(playerName);
            if (command.charAt(command.length() - 2) == '@') {
                command = command.substring(0, command.length() - 2);
                player.performCommand(command);
            } else {
                server.dispatchCommand(server.getConsoleSender(), command);
            }
            plugin.messages.remove(playerName);
        }
    }, 10L);

    // Schedule a slight delay (this prevents a player for reusing portal on target server)
    this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> status.remove(playerName), 40L);
}
项目:CutePortals    文件:Metrics.java   
/**
 * Gets the online player (backwards compatibility)
 *
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:nick    文件:MLite.java   
/**
 * Gets the online player (backwards compatibility)
 *
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:HoloGUIApi    文件:Metrics.java   
/**
 * Gets the online player (backwards compatibility)
 * 
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:Pokkit    文件:CraftServer.java   
public CraftServer(cn.nukkit.Server nukkitServer, Logger logger, File pluginFolder) {
    this.nukkit = Objects.requireNonNull(nukkitServer, "nukkitServer");
    this.pluginFolder = Objects.requireNonNull(pluginFolder, "pluginFolder");
    this.logger = Objects.requireNonNull(logger, "logger");

    this.commandMap = new NotSoSimpleCommandMap(this);
    this.scheduler = new PokkitScheduler(nukkitServer.getScheduler());
    this.pluginManager = new PokkitPluginManager(nukkitServer.getPluginManager(), this.commandMap);
    this.servicesManager = new SimpleServicesManager();
    this.commandFetcher = new PokkitCommandFetcher(nukkitServer::getPluginCommand);
    this.scoreboardManager = new PokkitScoreboardManager();
    this.onlinePlayerData = new OnlinePlayerData();
    this.metadataOverview = new AllMetadataStore();
    this.pokkitUnsafe = new PokkitUnsafe();
    this.itemFactory = new PokkitItemFactory();
    this.helpMap = new PokkitHelpMap();
    this.messenger = new PokkitPluginMessenger();

    PokkitEnchantment.registerNukkitEnchantmentsInBukkit();
}
项目:SimpleChatAlert    文件:Metrics.java   
/**
 * Gets the online player (backwards compatibility)
 *
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:skUtilities    文件:MetricsLiteO.java   
/**
 * Gets the online player (backwards compatibility)
 *
 * @return online player amount
 */
private int getOnlinePlayers() {
  try {
    Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
    if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
      return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
    } else {
      return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
    }
  } catch (Exception ex) {
    if (debug) {
      Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
    }
  }

  return 0;
}
项目:Skellett    文件:ExprTick.java   
@Override
@Nullable
protected Number[] get(Event e) {
    try {
        Server server = Bukkit.getServer();
        Field consoleField = server.getClass().getDeclaredField("console");
        consoleField.setAccessible(true);
        Object nmsServer = consoleField.get(server);
        Field tps = nmsServer.getClass().getSuperclass().getDeclaredField("ticks");
        tps.setAccessible(true);
        return new Number[]{tps.getInt(nmsServer)};
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException | SecurityException e1) {
        e1.printStackTrace();
    }
    return null;
}
项目:Breakpoint    文件:Breakpoint.java   
public void redirectCommands()
{
    Server server = getServer();

    server.getPluginCommand("bp").setExecutor(new BPCommandExecutor());
    server.getPluginCommand("helpop").setExecutor(new HelpOPCommandExecutor());
    server.getPluginCommand("clan").setExecutor(new ClanCommandExecutor());
    server.getPluginCommand("achievements").setExecutor(new AchievementsCommandExecutor());
    server.getPluginCommand("top").setExecutor(new TopCommandExecutor());
    server.getPluginCommand("topclans").setExecutor(new TopClansCommandExecutor());
    server.getPluginCommand("rank").setExecutor(new RankCommandExecutor());
    server.getPluginCommand("gm").setExecutor(new GMCommandExecutor());
    server.getPluginCommand("skull").setExecutor(new SkullCommandExecutor());
    server.getPluginCommand("fly").setExecutor(new FlyCommandExecutor());
    server.getPluginCommand("cw").setExecutor(new CWCommandExecutor());
}
项目:DiscordSRV    文件:MCStats.java   
/**
 * Gets the online player (backwards compatibility)
 *
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:DiscordSRV    文件:PlayerUtil.java   
/**
 * Method return type-safe version of Bukkit::getOnlinePlayers
 * @param filterVanishedPlayers whether or not to filter out vanished players
 * @return {@code ArrayList} containing online players
 */
public static List<Player> getOnlinePlayers(boolean filterVanishedPlayers) {
    List<Player> onlinePlayers = new ArrayList<>();

    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            for (Object o : ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer()))) {
                onlinePlayers.add((Player) o);
            }
        } else {
            Collections.addAll(onlinePlayers, ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (!filterVanishedPlayers) {
        return onlinePlayers;
    } else {
        return onlinePlayers.stream()
                .filter(player -> !PlayerUtil.isVanished(player))
                .collect(Collectors.toList());
    }
}
项目:WebInterface    文件:Metrics.java   
/**
 * Gets the online player (backwards compatibility)
 * 
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if(onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>)onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[])onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:MC2FA    文件:MCStats.java   
/**
 * Gets the online player (backwards compatibility)
 *
 * @return online player amount
 */
private int getOnlinePlayers() {
    try {
        Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers");
        if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
            return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size();
        } else {
            return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length;
        }
    } catch (Exception ex) {
        if (debug) {
            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
        }
    }

    return 0;
}
项目:Uranium    文件:CraftServer.java   
public void onPlayerJoin(Player player) {
    if ((updater.isEnabled()) && (updater.getCurrent() != null) && (player.hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE))) {
        if ((updater.getCurrent().isBroken()) && (updater.getOnBroken().contains(AutoUpdater.WARN_OPERATORS))) {
            player.sendMessage(ChatColor.DARK_RED + "The version of CraftBukkit that this server is running is known to be broken. Please consider updating to the latest version at dl.bukkit.org.");
        } else if ((updater.isUpdateAvailable()) && (updater.getOnUpdate().contains(AutoUpdater.WARN_OPERATORS))) {
            player.sendMessage(ChatColor.DARK_PURPLE + "The version of CraftBukkit that this server is running is out of date. Please consider updating to the latest version at dl.bukkit.org.");
        }
    }
}
项目:PetBlocks    文件:PetMetaSQLiteControllerIT.java   
private static Plugin mockPlugin() {
    final Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    if(Bukkit.getServer() == null)
        Bukkit.setServer(server);
    try {
        final Field field = PetBlocksPlugin.class.getDeclaredField("logger");
        field.setAccessible(true);
        field.set(null, Logger.getGlobal());
    } catch (IllegalAccessException | NoSuchFieldException e) {
        Assert.fail();
    }
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled",false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    new File("PetBlocks.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("PetBlocks"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:PetBlocks    文件:ParticleEffectMetaSQLiteControllerIT.java   
private static Plugin mockPlugin() {
    final Server server = mock(Server.class);
    when(server.getLogger()).thenReturn(Logger.getGlobal());
    if(Bukkit.getServer() == null)
        Bukkit.setServer(server);
    try {
        final Field field = PetBlocksPlugin.class.getDeclaredField("logger");
        field.setAccessible(true);
        field.set(null, Logger.getGlobal());
    } catch (IllegalAccessException | NoSuchFieldException e) {
        Assert.fail();
    }
    final YamlConfiguration configuration = new YamlConfiguration();
    configuration.set("sql.enabled",false);
    configuration.set("sql.host", "localhost");
    configuration.set("sql.port", 3306);
    configuration.set("sql.database", "db");
    configuration.set("sql.username", "root");
    configuration.set("sql.password", "");
    final Plugin plugin = mock(Plugin.class);
    new File("PetBlocks.db").delete();
    when(plugin.getDataFolder()).thenReturn(new File("PetBlocks"));
    when(plugin.getConfig()).thenReturn(configuration);
    when(plugin.getResource(any(String.class))).thenAnswer(invocationOnMock -> {
        final String file = invocationOnMock.getArgument(0);
        return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
    });
    return plugin;
}
项目:MooProject    文件:Lightning.java   
/**
 * Updates the serverInfo
 */
public void updateServerInfo() {
    Server server = getServer();
    String motd = server.getMotd();
    List<String> players = new ArrayList<>();
    server.getOnlinePlayers().forEach((Consumer<Player>) player -> players.add(player.getName() + ":" + player.getUniqueId()));
    int maxPlayers = server.getMaxPlayers();

    PacketMessenger.message(new PacketServerInfoUpdate(
            new InetSocketAddress(Lightning.getInstance().getServer().getIp(), Lightning.getInstance().getServer().getPort()),
            motd, players.size(), maxPlayers)
    );
}
项目:ProjectAres    文件:RestartListener.java   
@Inject RestartListener(Loggers loggers, RestartManager restartManager, MatchManager mm, Server server, AutoRestartConfiguration config) {
    this.restartManager = restartManager;
    this.logger = loggers.get(getClass());
    this.mm = mm;
    this.server = server;
    this.config = config;
    this.matchLimit = config.matchLimit() > 0 ? config.matchLimit() : null;
}
项目:ProjectAres    文件:VoteContext.java   
@Inject VoteContext(Tourney tourney, EntrantUtils entrantUtils, TeamManager teamManager, Match match, EventBus eventBus, Server bukkit) {
    this.tourney = tourney;
    this.entrantUtils = entrantUtils;
    this.teamManager = teamManager;
    this.match = match;
    this.eventBus = eventBus;
    this.bukkit = bukkit;
    this.vote = null;
}
项目:SurvivalAPI    文件:NbtFactory.java   
private String getPackageName() {
    Server server = Bukkit.getServer();
    String name = server != null ? server.getClass().getPackage().getName() : null;

    if (name != null && name.contains("craftbukkit")) {
        return name;
    } else {
        // Fallback
        return "org.bukkit.craftbukkit.v1_7_R3";
    }
}
项目:MiniWynn    文件:MiniWynnPlugin.java   
@Override public void onEnable() {
    Injector injector;

    log.info("Enabling plugin");
    try {
        RegisteredServiceProvider<Providers> rsp = checkNotNull(getServer().getServicesManager()
                .getRegistration(Providers.class));
        injector = checkNotNull(rsp.getProvider()).getInjector();
    } catch (NullPointerException e){
        log.error("Failed to get ProvidersLib providers");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }

    itemFactory = injector.getInstance(SimpleItemFactory.class);
    MiniWynnPlugin.injector = injector.createChildInjector(binder -> {
        binder.bind(Server.class).toInstance(getServer());
        binder.bind(Plugin.class).toInstance(this);
        binder.bind(ItemFactory.class).toInstance(itemFactory);
        binder.bind(PlayerManager.class).to(SimplePlayerManager.class).asEagerSingleton();
    });

    listeners.forEach(listener->{
        Listener listenerInst = getInjector().getInstance(listener);
        getServer().getPluginManager().registerEvents(listenerInst, this);
    });
}
项目:BasicSurvivalPlus    文件:PlayerLifercycleListener.java   
@EventHandler
public void onPlayerGainExp(PlayerExpChangeEvent event){
    Player player = event.getPlayer();
    Server server = player.getServer();
    int expNum = event.getAmount();
    if (expNum > 0){
        expNum = (int) (expNum * plugin.getConfig().getInt("EXP_RATE"));

        player.sendMessage("§d[状态]§e获得 §b"+expNum+" §e点经验!");
        event.setAmount(expNum);
    }
}
项目:DoubleRunner    文件:DoubleRunnerGameLoop.java   
public DoubleRunnerGameLoop(JavaPlugin plugin, Server server, SurvivalGame game)
{
    super(plugin, server, game);

    this.fallDamages = false;

    plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
项目:CutePortals    文件:PMListener.java   
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
        ByteArrayDataInput input = ByteStreams.newDataInput(message);
        String subchannel = input.readUTF();
        if (!subchannel.equals("MCraft")) return;

        short len = input.readShort();
        byte[] messagebytes = new byte[len];
        input.readFully(messagebytes);
        DataInputStream messagestream = new DataInputStream(new ByteArrayInputStream(messagebytes));

        try {
            String[] commandData = messagestream.readUTF().split("#"); // HERE WE READ A FULL COMMAND
            String command = commandData[0];
            String playerName = commandData[1];
            Server server = plugin.getServer();
            if (player.getName().equals(playerName)) {
                // Finally let's execute command!
                if (command.charAt(command.length() - 2) == '@') {
                    command = command.substring(0, command.length() - 2);
                    player.performCommand(command);
                } else {
                    server.dispatchCommand(server.getConsoleSender(), command.replace("{PLAYER}", playerName));
                }
            } else {
                plugin.messages.put(playerName, command);
                plugin.logger.log(Level.INFO, "New PM data put for: " + playerName + ", with command: " + command);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }, 5L);
}