本文整理汇总了Java中org.bukkit.Server类的典型用法代码示例。如果您正苦于以下问题:Java Server类的具体用法?Java Server怎么用?Java Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Server类属于org.bukkit包,在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mockPlugin
import org.bukkit.Server; //导入依赖的package包/类
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;
}
示例2: mockPlugin
import org.bukkit.Server; //导入依赖的package包/类
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;
}
示例3: mockPlugin
import org.bukkit.Server; //导入依赖的package包/类
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;
}
示例4: mockPlugin
import org.bukkit.Server; //导入依赖的package包/类
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;
}
示例5: mockPlugin
import org.bukkit.Server; //导入依赖的package包/类
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;
}
示例6: SurvivalGameLoop
import org.bukkit.Server; //导入依赖的package包/类
/**
* 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();
}
示例7: ReplaceCharBroadcastPlayerMoreGeneral
import org.bukkit.Server; //导入依赖的package包/类
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")))
);
}
}
示例8: getOnlinePlayers
import org.bukkit.Server; //导入依赖的package包/类
/**
* 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;
}
示例9: createMockServer
import org.bukkit.Server; //导入依赖的package包/类
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;
}
示例10: exec
import org.bukkit.Server; //导入依赖的package包/类
@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());
}
示例11: onCommand
import org.bukkit.Server; //导入依赖的package包/类
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;
}
示例12: setUp
import org.bukkit.Server; //导入依赖的package包/类
@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);
}
示例13: getOnlinePlayers
import org.bukkit.Server; //导入依赖的package包/类
/**
* 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;
}
示例14: onPlayerJoin
import org.bukkit.Server; //导入依赖的package包/类
@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);
}
示例15: getOnlinePlayers
import org.bukkit.Server; //导入依赖的package包/类
/**
* 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;
}