Java Code Examples for org.bukkit.Bukkit.getServer()

The following are Jave code examples for showing how to use getServer() of the org.bukkit.Bukkit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PetBlocks   File: PlayerMetaSQLiteControllerIT.java   View Source Code Vote up 6 votes
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;
}
 
Example 2
Project: PetBlocks   File: PlayerMetaMySQLControllerIT.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: BlockBall   File: StatsMySQLControllerTest.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: BlockBall   File: PlayerMetaMySQLControllerTest.java   View Source Code Vote up 6 votes
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;
}
 
Example 5
Project: BlockBall   File: PlayerMetaSQLiteControllerTest.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: Zabbigot   File: Show.java   View Source Code Vote up 6 votes
@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());
}
 
Example 7
Project: PetBlocks   File: ParticleEffectMetaSQLiteControllerIT.java   View Source Code Vote up 5 votes
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;
}
 
Example 8
Project: SamaGamesAPI   File: Reflection.java   View Source Code Vote up 5 votes
/**
 * Gets the version string from the package name of the CraftBukkit server implementation.
 * This is needed to bypass the JAR package name changing on each update.
 * @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
 */
public synchronized static String getVersion() {
    if(_versionString == null){
        if(Bukkit.getServer() == null){
            // The server hasn't started, static initializer call?
            return null;
        }
        String name = Bukkit.getServer().getClass().getPackage().getName();
        _versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
    }

    return _versionString;
}
 
Example 9
Project: ZentrelaCore   File: Reflection.java   View Source Code Vote up 5 votes
/**
 * Gets the version string from the package name of the CraftBukkit server implementation.
 * This is needed to bypass the JAR package name changing on each update.
 * @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
 */
public synchronized static String getVersion() {
    if (_versionString == null) {
        if (Bukkit.getServer() == null) {
            // The server hasn't started, static initializer call?
            return null;
        }
        String name = Bukkit.getServer().getClass().getPackage().getName();
        _versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
    }

    return _versionString;
}
 
Example 10
Project: SurvivalAPI   File: NbtFactory.java   View Source Code Vote up 5 votes
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";
    }
}
 
Example 11
Project: EchoPet   File: RemappedClassHandler.java   View Source Code Vote up 5 votes
protected RemappedClassHandler initialize() throws UnsupportedOperationException, IllegalStateException {
    if (Bukkit.getServer() == null || !Bukkit.getServer().getVersion().contains("MCPC-Plus")) {
        throw new UnsupportedOperationException("Remapper not available!");
    }

    this.remapper = ClassTemplate.create(this.classLoader.getClass()).getField("remapper").get(getClass().getClassLoader());

    if (this.remapper == null) {
        throw new IllegalStateException("Remapper is NULL!");
    }

    Class<?> remapperClass = this.remapper.getClass();
    this.map = ClassTemplate.create(remapperClass).getMethod("map", String.class);
    return this;
}
 
Example 12
Project: Uranium   File: CraftMinecartCommand.java   View Source Code Vote up 4 votes
@Override
public Server getServer() {
    return Bukkit.getServer();
}
 
Example 13
Project: Minecordbot   File: DiscordConsoleCommandSender.java   View Source Code Vote up 4 votes
@Override
public Server getServer() {
    return Bukkit.getServer();
}
 
Example 14
Project: helper   File: Helper.java   View Source Code Vote up 4 votes
public static Server server() {
    return Bukkit.getServer();
}
 
Example 15
Project: FlexMC   File: FlexEntity.java   View Source Code Vote up 4 votes
@Override
public Server getServer() {
    return Bukkit.getServer();
}
 
Example 16
Project: SuperiorCraft   File: SuperiorCraftPackage.java   View Source Code Vote up 4 votes
public Server getServer() {
	return Bukkit.getServer();
}
 
Example 17
Project: ProjectAres   File: NullCommandSender.java   View Source Code Vote up 4 votes
@Override
public Server getServer() {
    return Bukkit.getServer();
}
 
Example 18
Project: Kineticraft   File: DiscordSender.java   View Source Code Vote up 4 votes
@Override
public Server getServer() {
    return Bukkit.getServer();
}
 
Example 19
Project: MCLibrary   File: Injector.java   View Source Code Vote up 4 votes
public static void injectServer(Server server) {
    if (Bukkit.getServer() == null) {
        Bukkit.setServer(server);
    }
}
 
Example 20
Project: Minecordbot   File: DiscordCommandSender.java   View Source Code Vote up 4 votes
@Override
public Server getServer() {
    return Bukkit.getServer();
}