@Override public void postSpawn(HCF plugin) { if (this.world.addEntity((Entity)this)) { Bukkit.getConsoleSender().sendMessage(String.format((Object)ChatColor.GOLD + "Combat logger of " + this.getName() + " has spawned at %.2f, %.2f, %.2f", this.locX, this.locY, this.locZ)); MinecraftServer.getServer().getPlayerList().playerFileData.load((EntityHuman)this); } else { Bukkit.getConsoleSender().sendMessage(String.format((Object)ChatColor.RED + "Combat logger of " + this.getName() + " failed to spawned at %.2f, %.2f, %.2f", this.locX, this.locY, this.locZ)); } this.removalTask = new BukkitRunnable(){ public void run() { MinecraftServer.getServer().getPlayerList().sendAll((Packet)PacketPlayOutPlayerInfo.removePlayer((EntityPlayer)LoggerEntityHuman.this.getBukkitEntity().getHandle())); LoggerEntityHuman.this.destroy(); } }.runTaskLater((Plugin)plugin, SettingsYML.COMBAT_LOG_DESPAWN_TICKS); }
public void setTemporarySidebar(final SidebarProvider provider, final long expiration) { if (this.removed.get()) { throw new IllegalStateException("Cannot update whilst board is removed"); } this.temporaryProvider = provider; this.updateObjective(); new BukkitRunnable() { public void run() { if (PlayerBoard.this.removed.get()) { this.cancel(); return; } if (PlayerBoard.this.temporaryProvider == provider) { PlayerBoard.access$4(PlayerBoard.this, null); PlayerBoard.this.updateObjective(); } } }.runTaskLaterAsynchronously((Plugin)this.plugin, expiration); }
@Override public void onEnable() { instance=this; new ConfigManager(); new Database(); new Cacher(); new Commands(); Plugin papi= Bukkit.getPluginManager().getPlugin("PlaceholderAPI"); if(papi==null){ Bukkit.getConsoleSender().sendMessage("§6§lGlobalPrefix §7>>> §c无法找到PlaceholderAPI插件,请检查是否安装"); } else{ if(!new PrefixPlaceholder().hook()){ Bukkit.getConsoleSender().sendMessage("§6§lGlobalPrefix §7>>> §c注册PlaceholderAPI变量失败!"); } } new Metrics(instance); Bukkit.getConsoleSender().sendMessage("§6§lGlobalPrefix §7>>> §a插件加载完成!"); }
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; }
public void setDefaultSidebar(final SidebarProvider provider, final long updateInterval) { if (provider != this.defaultProvider) { this.defaultProvider = provider; if (this.runnable != null) { this.runnable.cancel(); } if (provider == null) { this.scoreboard.clearSlot(DisplaySlot.SIDEBAR); return; } (this.runnable = new BukkitRunnable() { public void run() { if (PlayerBoard.this.removed.get()) { this.cancel(); return; } if (provider == PlayerBoard.this.defaultProvider) { PlayerBoard.this.updateObjective(); } } }).runTaskTimerAsynchronously((Plugin)this.plugin, updateInterval, updateInterval); } }
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); 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; }
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; }
public static void uninject(Plugin plg) { if (plg != null) { for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) { if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) { try { FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class); Runnable runnable = field.get(pendingTask); if (runnable instanceof SchedulerTaskInjector) { field.set(pendingTask, ((SchedulerTaskInjector) runnable).getRunnable()); } } catch (Exception e) { e.printStackTrace(); } } } } }
public Object call() throws Exception { StringWriter value = new StringWriter(); try { value.append("\n Running: ").append(Bukkit.getName()).append(" version ").append(Bukkit.getVersion()).append(" (Implementing API version ").append(Bukkit.getBukkitVersion()).append(") ").append(String.valueOf(net.minecraft.server.MinecraftServer.getServer().isServerInOnlineMode())); value.append("\n Plugins: {"); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { PluginDescriptionFile description = plugin.getDescription(); value.append(' ').append(description.getFullName()).append(' ').append(description.getMain()).append(' ').append(Arrays.toString(description.getAuthors().toArray())).append(','); } value.append("}\n Warnings: ").append(Bukkit.getWarningState().name()); value.append("\n Threads: {"); for (Map.Entry<Thread, ? extends Object[]> entry : Thread.getAllStackTraces().entrySet()) { value.append(' ').append(entry.getKey().getState().name()).append(' ').append(entry.getKey().getName()).append(": ").append(Arrays.toString(entry.getValue())).append(','); } value.append("}\n ").append(Bukkit.getScheduler().toString()); } catch (Throwable t) { value.append("\n Failed to handle CraftCrashReport:\n"); PrintWriter writer = new PrintWriter(value); t.printStackTrace(writer); writer.flush(); } return value.toString(); }
public static void loadConfig(Plugin plugin) { pl = plugin; file = new File(pl.getDataFolder(), "Config/Global/OnJoin/Gamemode-OnJoin.yml"); Config = YamlConfiguration.loadConfiguration(file); if (!pl.getDataFolder().exists()) { pl.getDataFolder().mkdir(); } create(); int gamemode = Config.getInt("On-Join.Spawn.Gamemode.Gamemode"); if ((gamemode != 0) && (gamemode != 1) && (gamemode != 2) && (gamemode != 3)) { Config.set("Gamemode.Value", Integer.valueOf(0)); } }
static Parser<Double> doubleValue() { return new Parser<Double>() { @Override public Double load(Plugin plugin, Object object) { if (object instanceof Number) return ((Number) object).doubleValue(); else if (object instanceof String) return Double.parseDouble((String) object); else throw new IllegalArgumentException("Cannot parse " + object + " as short"); } @Override public Object save(Double s) { return s; } }; }
public NavyCraft_Timer(Plugin plug, int seconds, Craft vehicle, Player p, String state, boolean forward) { //toolkit = Toolkit.getDefaultToolkit(); plugin = plug; this.craft = vehicle; this.player = p; timer = new Timer(); if(state.equals("engineCheck")) timer.scheduleAtFixedRate(new EngineTask(), 1000, 1000); else if(state.equals("engineCheck")) timer.schedule(new AutoMoveTask(forward), 1000); else if(state.equals("abandonCheck")) timer.scheduleAtFixedRate(new ReleaseTask(), seconds * 1000, 60000); else if(state.equals("takeoverCheck")) timer.scheduleAtFixedRate(new TakeoverTask(), seconds * 1000, 60000); else if(state.equals("takeoverCaptainCheck")) timer.scheduleAtFixedRate(new TakeoverCaptainTask(), seconds * 1000, 60000); }
@SuppressWarnings("unchecked") static Parser<List<Action>> actionsValue() { return new Parser<List<Action>>() { @Override public List<Action> load(Plugin plugin, Object object) { if (object instanceof Collection) return ActionType.deserialize(plugin, (Collection<Map<String, Object>>) object); else throw new IllegalArgumentException("Cannot parse " + object + " as short"); } @Override public Object save(List<Action> s) { return ActionType.serialize(s); } }; }
@Override public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { if (oldpermissible == null) { return super.addAttachment(plugin, name, value, ticks); } return oldpermissible.addAttachment(plugin, name, value, ticks); }
public void setPermsSystem() { PluginManager pm = Bukkit.getServer().getPluginManager(); for(Plugin pl : pm.getPlugins()){ if(pl.isEnabled()){ String plName = pl.getName(); if(app.contains(plName)){ permsPlugin = pm.getPlugin(plName); } } } }
@Override public @Nullable <T extends Plugin> T getPlugin(Class<T> cls) { try { return (T) JavaPlugin.getPlugin(cls.asSubclass(JavaPlugin.class)); } catch(IllegalArgumentException e) { return null; } }
@Override public PermissionAttachment addAttachment(Plugin plugin) { if (oldpermissible == null) { return super.addAttachment(plugin); } return oldpermissible.addAttachment(plugin); }
public static Map<String, MonitorRecord> getEventTimingsByPlugin(Plugin plg) { Map<String, MonitorRecord> record = new HashMap<>(); if (plg == null) { return record; } for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) { try { FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class); EventExecutor executor = field.get(listener); if (executor instanceof EventExecutorInjector) { EventExecutorInjector eventExecutorInjector = (EventExecutorInjector) executor; String eventName = eventExecutorInjector.getEventName(); if (eventName != null) { MonitorRecord monitorRecord = getMonitorRecord(eventName, eventExecutorInjector.getTotalTime(), eventExecutorInjector.getTotalCount(), eventExecutorInjector.getMaxExecuteTime()); if (record.containsKey(eventName)) { MonitorRecord otherMonitorRecord = record.get(eventName); record.put(eventName, otherMonitorRecord.merge(monitorRecord)); } else { record.put(eventName, monitorRecord); } } } } catch (Exception e) { e.printStackTrace(); } } return record; }
public static void loadConfig(Plugin plugin) { pl = plugin; file = new File(pl.getDataFolder(), "Config/Global/Fun/DoubleJump.yml"); Config = YamlConfiguration.loadConfiguration(file); if (!pl.getDataFolder().exists()) { pl.getDataFolder().mkdir(); } create(); }
@Override public BukkitTask runTaskTimerAsynchronously(Plugin plugin, BukkitRunnable bukkitRunnable, long l, long l1) throws IllegalArgumentException { TaskedRunnable wrapped = new TaskedRunnable(bukkitRunnable); BukkitTask bukkitTask = delegate.runTaskTimerAsynchronously(plugin, wrapped, l, l1); wrapped.setTaskID(bukkitTask.getTaskId()); return bukkitTask; }
public LinkLoader(Plugin plugin) { setPlugin(plugin); File[] files = plugin.getDataFolder().listFiles(); for (File file : files) { if (file.getName().equalsIgnoreCase("mclink.yml")) setConfig(YamlConfiguration.loadConfiguration(file)); } }
public static void loadConfig(Plugin plugin) { pl = plugin; file = new File(pl.getDataFolder(), "Config/Command/Spawn.yml"); Config = YamlConfiguration.loadConfiguration(file); if (!pl.getDataFolder().exists()) { pl.getDataFolder().mkdir(); } create(); }
private JsonObject getChacheFile(Plugin plugin){ File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json"); if(file.exists()){ try{ JsonParser parser = new JsonParser(); JsonElement jsonElement = parser.parse(new FileReader(file)); return jsonElement.getAsJsonObject(); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } }else return null; }
@Override public void onEnable() { Cooldowns.createCooldown("medic_cooldown"); HCF.plugin = this; BasePlugin.getPlugin().init(this); ProtocolLibHook.hook(this); Plugin wep = getServer().getPluginManager().getPlugin("WorldEdit"); this.worldEdit = wep instanceof WorldEditPlugin && wep.isEnabled() ? (WorldEditPlugin) wep : null; CustomEntityRegistration.registerCustomEntities(); this.craftBukkitVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; SettingsYML.init(this); this.effectRestorer = new EffectRestorer(this); this.registerConfiguration(); this.registerCommands(); this.registerManagers(); this.registerListeners(); this.setupPermissions(); new BukkitRunnable() { @Override public void run() { getServer().broadcast(ChatColor.GREEN.toString() + ChatColor.BOLD + "Saving!" + "\n" + ChatColor.GREEN + "Saved all faction and player data to the database." + "\n" + ChatColor.GRAY + "Current TPS: " + ChatColor.GRAY, "hcf.seesaves"); saveData(); } }.runTaskTimerAsynchronously(plugin, TimeUnit.MINUTES.toMillis(10L), TimeUnit.MINUTES.toMillis(10L)); }
public static void inject(Plugin plg) { if (plg != null) { for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) { try { FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class); EventExecutor fieldEventExecutor = field.get(listener); field.set(listener, new EventExecutorInjector(plg, fieldEventExecutor)); } catch (Exception e) { e.printStackTrace(); } } } }
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) { Map<String, MonitorRecord> record = new HashMap<>(); if (plg == null) { return record; } try { SimpleCommandMap simpleCommandMap = Reflection .getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class) .get(Bukkit.getPluginManager()); for (Command command : simpleCommandMap.getCommands()) { if (command instanceof PluginCommand) { PluginCommand pluginCommand = (PluginCommand) command; if (plg.equals(pluginCommand.getPlugin())) { FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class); CommandExecutor executor = commandField.get(pluginCommand); if (executor instanceof CommandInjector) { CommandInjector commandInjector = (CommandInjector) executor; record = mergeRecordMap(record, commandInjector.getMonitorRecordMap()); } } } } } catch (Exception e) { e.printStackTrace(); } return record; }
public SpigotUpdateChecker(Plugin plugin, String spigotFullId) { super(plugin, spigotFullId); String[] parts = spigotFullId.split("\\."); try { resId = Integer.parseInt(parts[parts.length - 1]); } catch (Exception e) { throw new IllegalArgumentException("Invalid id: " + spigotFullId); } }
public int scheduleAsyncRepeatingTask(Plugin plugin, BukkitRunnable task, long delay, long period) { TaskedRunnable wrapped = new TaskedRunnable(task); wrapped.setTaskID(delegate.scheduleAsyncRepeatingTask(plugin, wrapped, delay, period)); return wrapped.getTaskID(); }
public EffectLib getEffectLib() { Plugin effectLib = this.getServer().getPluginManager().getPlugin("EffectLib"); if (effectLib == null || !(effectLib instanceof EffectLib)) return null; return (EffectLib) effectLib; }
public static boolean isDepend(String superPluginName, Plugin checkPlugin) { PluginDescriptionFile desc = checkPlugin.getDescription(); List<String> softDepend = desc.getSoftDepend(); List<String> depend = desc.getDepend(); return softDepend != null && softDepend.contains(superPluginName) || depend != null && depend.contains(superPluginName); }
@Inject PlayerListener(Plugin lobby, LobbyConfig config, MinecraftService minecraftService, OnlinePlayers onlinePlayers, Audiences audiences, BossBarFactory bossBarFactory, ComponentRenderContext renderer, EventBus eventBus, GeneralFormatter generalFormatter) { this.lobby = lobby; this.config = config; this.minecraftService = minecraftService; this.onlinePlayers = onlinePlayers; this.audiences = audiences; this.bossBarFactory = bossBarFactory; this.renderer = renderer; this.eventBus = eventBus; this.generalFormatter = generalFormatter; }
public static void loadConfig(Plugin plugin) { pl = plugin; file = new File(pl.getDataFolder(), "Config/Command/Ping.yml"); Config = YamlConfiguration.loadConfiguration(file); if (!pl.getDataFolder().exists()) { pl.getDataFolder().mkdir(); } create(); }
public static void enable() { enable = true; enable_time = System.currentTimeMillis(); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { if (plugin != null && plugin.isEnabled()) { EventExecutorInjector.inject(plugin); SchedulerTaskInjector.inject(plugin); CommandInjector.inject(plugin); } } }
public static void loadConfig(Plugin plugin) { pl = plugin; file = new File(pl.getDataFolder(), "Config/Global/Server-Protection.yml"); Config = YamlConfiguration.loadConfiguration(file); if (!pl.getDataFolder().exists()) { pl.getDataFolder().mkdir(); } create(); }
public void enablePlugins(PluginLoadOrder type) { // Cauldron start - initialize mod wrappers org.bukkit.craftbukkit.block.CraftBlock.initMappings(); org.bukkit.craftbukkit.entity.CraftEntity.initMappings(); // Cauldron end if (type == PluginLoadOrder.STARTUP) { helpMap.clear(); helpMap.initializeGeneralTopics(); } Plugin[] plugins = pluginManager.getPlugins(); for (Plugin plugin : plugins) { if ((!plugin.isEnabled()) && (plugin.getDescription().getLoad() == type)) { loadPlugin(plugin); } } if (type == PluginLoadOrder.POSTWORLD) { commandMap.setFallbackCommands(); setVanillaCommands(); commandMap.registerServerAliases(); loadCustomPermissions(); DefaultPermissions.registerCorePermissions(); helpMap.initializeCommands(); } }
/** * Construct a new instance of TinyProtocol, and start intercepting packets for all connected clients and future clients. * <p> * You can construct multiple instances per plugin. * * @param plugin - the plugin. */ public TinyProtocol(final Plugin plugin) { this.plugin = plugin; // Compute handler name this.handlerName = getHandlerName(); // Prepare existing players registerBukkitEvents(); try { registerChannelHandler(); registerPlayers(plugin); } catch (IllegalArgumentException ex) { // Damn you, late bind plugin.getLogger().info("[TinyProtocol] Delaying server channel injection due to late bind."); new BukkitRunnable() { @Override public void run() { registerChannelHandler(); registerPlayers(plugin); plugin.getLogger().info("[TinyProtocol] Late bind injection successful."); } }.runTask(plugin); } }
public void prepareTheBlacknessFor(Plugin plugin) { if (!readyAlready) { Bukkit.getPluginManager().registerEvents( new InventoryActionsListener(), Objects.requireNonNull(plugin) ); readyAlready = true; } }