@Deprecated public ExecutorService getExecutorService() { if ( service == null ) { String name = ( getDescription() == null ) ? "unknown" : getDescription().getName(); service = Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat( name + " Pool Thread #%1$d" ) .setThreadFactory( new GroupedThreadFactory( this, name ) ).build() ); } return service; } //
/** * Gets the data folder where this plugin may store arbitrary data. It will * be a child of {@link ProxyServer#getPluginsFolder()}. * * @return the data folder of this plugin */ public final File getDataFolder() { return new File( getProxy().getPluginsFolder(), getDescription().getName() ); }
plugin.onDisable(); for ( Handler handler : plugin.getLogger().getHandlers() ) getLogger().log( Level.SEVERE, "Exception disabling plugin " + plugin.getDescription().getName(), t ); plugin.getExecutorService().shutdownNow();
public void enablePlugins() { for ( Plugin plugin : plugins.values() ) { try { plugin.onEnable(); ProxyServer.getInstance().getLogger().log( Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[] { plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getAuthor() } ); } catch ( Throwable t ) { ProxyServer.getInstance().getLogger().log( Level.WARNING, "Exception encountered when loading plugin: " + plugin.getDescription().getName(), t ); } } }
public ProxyServer getProxy() { return plugin.getProxy(); }
/** * Gets the plugin specific data. * This method is called using Reflection. * * @return The plugin specific data. */ public JsonObject getPluginData() { JsonObject data = new JsonObject(); String pluginName = plugin.getDescription().getName(); String pluginVersion = plugin.getDescription().getVersion(); data.addProperty("pluginName", pluginName); data.addProperty("pluginVersion", pluginVersion); JsonArray customCharts = new JsonArray(); for (CustomChart customChart : charts) { // Add the data of the custom charts JsonObject chart = customChart.getRequestJsonObject(plugin.getLogger(), logFailedRequests); if (chart == null) { // If the chart is null, we skip it continue; } customCharts.add(chart); } data.add("customCharts", customCharts); return data; }
public Logger getLogger() { return plugin.getLogger(); }
private void triggerRandomEvent() { try { if (Math.random() <= 0.5 && online.size() > 0) { // do a server switch FakePlayer player = online.get((int) (Math.random() * online.size())); if (player.isRandomServerSwitchEnabled()) { player.changeServer(new ArrayList<>(plugin.getProxy().getServers().values()).get((int) (Math.random() * plugin.getProxy().getServers().values().size()))); } } else if (randomJoinLeaveEventsEnabled) { if (Math.random() < 0.7 && offline.size() > 0) { // add player String name = offline.get((int) (Math.random() * offline.size())); FakePlayer player = new FakePlayer(name, new ArrayList<>(plugin.getProxy().getServers().values()).get((int) (Math.random() * plugin.getProxy().getServers().values().size())), true); offline.remove(name); online.add(player); } else if (online.size() > 0) { // remove player FakePlayer fakePlayer = online.get((int) (online.size() * Math.random())); if (BungeeTabListPlus.getInstance().getConfig().fakePlayers.contains(fakePlayer.getName())) { removeFakePlayer(fakePlayer); } } } } catch (Throwable th) { plugin.getLogger().log(Level.SEVERE, "An error occurred while processing random fake player events", th); } }
if (!plugin.getDataFolder().exists()) { plugin.getDataFolder().mkdirs(); File file = new File(plugin.getDataFolder(), "config.yml"); if (!file.exists()) { config = new MainConfig(); plugin.getLogger().warning("Unable to load Config"); plugin.getLogger().log(Level.WARNING, null, ex); plugin.getLogger().warning("Disabling Plugin"); return; File headsFolder = new File(plugin.getDataFolder(), "heads"); ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(plugin.getFile())); if (!entry.isDirectory() && entry.getName().startsWith("heads/")) { try { File targetFile = new File(plugin.getDataFolder(), entry.getName()); targetFile.getParentFile().mkdirs(); if (!targetFile.exists()) { if (plugin.getProxy().getPluginManager().getPlugin("RedisBungee") != null) { redisPlayerManager = new RedisPlayerManager(connectedPlayerManager, this, getLogger()); playerProviders.add(redisPlayerManager); plugin.getLogger().info("Hooked RedisBungee"); plugin.getProxy().registerChannel(BridgeProtocolConstants.CHANNEL); bukkitBridge = new BukkitBridge(this);
/** * Gets the first bStat Metrics class. * * @return The first bStats metrics class. */ private Class<?> getFirstBStatsClass() { Path configPath = plugin.getDataFolder().toPath().getParent().resolve("bStats"); configPath.toFile().mkdirs(); File tempFile = new File(configPath.toFile(), "temp.txt"); try { String className = readFile(tempFile); if (className != null) { try { // Let's check if a class with the given name exists. return Class.forName(className); } catch (ClassNotFoundException ignored) { } } writeFile(tempFile, getClass().getName()); return getClass(); } catch (IOException e) { if (logFailedRequests) { plugin.getLogger().log(Level.WARNING, "Failed to get first bStats class!", e); } return null; } }
@Override public File getDataFolder() { return ((Plugin) getPlugin()).getDataFolder(); }
public class Server { Plugin plugin; SendCallback callback = new SendCallback() { public void doSend(Object toSend) { // logic to send object 'toSend' } } public Server() { plugin = new MyPlugin(); plugin.init(callback); } }
@Override public ExecutorService getExecutorService(Plugin plugin) { return plugin.getExecutorService(); } };
public ConsoleMessageHandler(Plugin plugin) { this.plugin = plugin; plugin.getProxy().registerChannel("Console"); }
URL url = new URL( "http://updates.codecrafter47.dyndns.eu/" + plugin. getDescription().getName() + "/version.txt"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.connect(); String runningVersion = plugin.getDescription().getVersion(); updateAvailable = compareVersions(newVersion, runningVersion); plugin.getLogger().info("A new version of BungeeTabListPlus (" + newVersion + ") is available. Download from http://www.spigotmc.org/resources/bungeetablistplus.313/"); if (latestBuildNumber > buildNumber) { newDevBuildAvailable = true; plugin.getLogger().info("A new dev-build is available at http://ci.codecrafter47.dyndns.eu/job/BungeeTabListPlus/");
public void reportError(Throwable th) { plugin.getLogger().log(Level.SEVERE, ChatColor.RED + "An internal error occurred! Please send the " + "following StackTrace to the developer in order to help" + " resolving the problem", th); }
if (e instanceof IOException && e.getMessage().contains("429")) { plugin.getLogger().warning("Hit mojang rate limits while fetching uuid for " + player + "."); String headerField = connection.getHeaderField("Retry-After"); plugin.getProxy().getScheduler().schedule(plugin, new Runnable() { @Override public void run() { } else { plugin.getLogger().warning("An error occurred while connecting to mojang servers: " + e.getMessage() + ". Will retry in 1 minute"); plugin.getProxy().getScheduler().schedule(plugin, new Runnable() { @Override public void run() {
public void enablePlugins() { for ( Plugin plugin : plugins.values() ) { try { plugin.onEnable(); ProxyServer.getInstance().getLogger().log( Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[] { plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getAuthor() } ); } catch ( Throwable t ) { ProxyServer.getInstance().getLogger().log( Level.WARNING, "Exception encountered when loading plugin: " + plugin.getDescription().getName(), t ); } } }
/** * Gets the first bStat Metrics class. * * @return The first bStats metrics class. */ private Class<?> getFirstBStatsClass() { Path configPath = plugin.getDataFolder().toPath().getParent().resolve("bStats"); configPath.toFile().mkdirs(); File tempFile = new File(configPath.toFile(), "temp.txt"); try { String className = readFile(tempFile); if (className != null) { try { // Let's check if a class with the given name exists. return Class.forName(className); } catch (ClassNotFoundException ignored) { } } writeFile(tempFile, getClass().getName()); return getClass(); } catch (IOException e) { if (logFailedRequests) { plugin.getLogger().log(Level.WARNING, "Failed to get first bStats class!", e); } return null; } }