org.bukkit.plugin.java.JavaPlugin Java Examples
The following examples show how to use
org.bukkit.plugin.java.JavaPlugin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkriptAddon.java From Skript with GNU General Public License v3.0 | 6 votes |
/** * Package-private constructor. Use {@link Skript#registerAddon(JavaPlugin)} to get a SkriptAddon for your plugin. * * @param p */ SkriptAddon(final JavaPlugin p) { plugin = p; name = "" + p.getName(); Version v; try { v = new Version("" + p.getDescription().getVersion()); } catch (final IllegalArgumentException e) { final Matcher m = Pattern.compile("(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?").matcher(p.getDescription().getVersion()); if (!m.find()) throw new IllegalArgumentException("The version of the plugin " + p.getName() + " does not contain any numbers: " + p.getDescription().getVersion()); v = new Version(Utils.parseInt("" + m.group(1)), m.group(2) == null ? 0 : Utils.parseInt("" + m.group(2)), m.group(3) == null ? 0 : Utils.parseInt("" + m.group(3))); Skript.warning("The plugin " + p.getName() + " uses a non-standard version syntax: '" + p.getDescription().getVersion() + "'. Skript will use " + v + " instead."); } version = v; }
Example #2
Source File: SimpleCommandExecutor.java From AstralEdit with Apache License 2.0 | 6 votes |
/** * Initializes a new commandExecutor by all required parameters * * @param command command * @param useAge useAge * @param description description * @param permission permission * @param permissionMessage permissionMessage * @param plugin plugin */ public UnRegistered(String command, String useAge, String description, String permission, String permissionMessage, JavaPlugin plugin) { super(command); if (useAge == null) throw new IllegalArgumentException("Useage cannot be null!"); if (description == null) throw new IllegalArgumentException("Description cannot be null!"); if (permission == null) throw new IllegalArgumentException("Permission cannot be null!"); if (permissionMessage == null) throw new IllegalArgumentException("PermissionMessage cannot be null!"); if (plugin == null) throw new IllegalArgumentException("Plugin cannot be null!"); this.description = description; this.usageMessage = useAge; this.plugin = plugin; this.setPermission(permission); this.setPermissionMessage(permissionMessage); this.setAliases(new ArrayList<>()); this.registerDynamicCommand(command); }
Example #3
Source File: PerworldInventoryCommandHandlingTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Before public void setUpPlugin() throws IOException { File dataFolder = temporaryFolder.newFolder(); // Set mock server setField(Bukkit.class, "server", null, server); given(server.getLogger()).willReturn(mock(Logger.class)); // PluginDescriptionFile is final and so cannot be mocked PluginDescriptionFile descriptionFile = new PluginDescriptionFile( "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName()); JavaPluginLoader pluginLoader = new JavaPluginLoader(server); plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null); setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class)); Injector injector = new InjectorBuilder().addDefaultHandlers("me.gnat008.perworldinventory").create(); injector.register(PermissionManager.class, permissionManager); injector.register(ConvertCommand.class, convertCommand); injector.register(HelpCommand.class, helpCommand); injector.register(PerWorldInventoryCommand.class, pwiCommand); injector.register(ReloadCommand.class, reloadCommand); injector.register(SetWorldDefaultCommand.class, setWorldDefaultsCommand); injector.register(VersionCommand.class, versionCommand); plugin.registerCommands(injector); TestHelper.setField(PerWorldInventory.class, "permissionManager", plugin, permissionManager); }
Example #4
Source File: XParticle.java From XSeries with MIT License | 6 votes |
/** * A sin/cos based smoothly animated explosion wave. * Source: https://www.youtube.com/watch?v=n8W7RxW5KB4 * * @param rate the distance between each cos/sin lines. * @since 1.0.0 */ public static void explosionWave(JavaPlugin plugin, double rate, ParticleDisplay display, ParticleDisplay secDisplay) { new BukkitRunnable() { final double addition = Math.PI * 0.1; final double rateDiv = Math.PI / rate; double times = Math.PI / 4; public void run() { times += addition; for (double theta = 0; theta <= PII; theta += rateDiv) { double x = times * Math.cos(theta); double y = 2 * Math.exp(-0.1 * times) * Math.sin(times) + 1.5; double z = times * Math.sin(theta); display.spawn(x, y, z); theta = theta + Math.PI / 64; x = times * Math.cos(theta); //y = 2 * Math.exp(-0.1 * times) * Math.sin(times) + 1.5; z = times * Math.sin(theta); secDisplay.spawn(x, y, z); } if (times > 20) cancel(); } }.runTaskTimerAsynchronously(plugin, 0L, 1L); }
Example #5
Source File: TraitCombatLogX.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@Override public void run() { if(this.ticksUntilRemove > 0) { this.ticksUntilRemove--; return; } long survivalSeconds = getSurvivalSeconds(); if(survivalSeconds < 0) return; Player enemy = getEnemy(); ICombatLogX plugin = this.expansion.getPlugin(); if(enemy != null && waitUntilEnemyEscape()) { ICombatManager combatManager = plugin.getCombatManager(); if(combatManager.isInCombat(enemy)) return; } Runnable task = () -> { NPC npc = getNPC(); npc.despawn(DespawnReason.PLUGIN); }; JavaPlugin javaPlugin = plugin.getPlugin(); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(javaPlugin, task, 1L); }
Example #6
Source File: ListenerLogin.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onJoin(PlayerJoinEvent e) { Player player = e.getPlayer(); player.setCanPickupItems(false); NPCManager npcManager = this.expansion.getNPCManager(); NPC npc = npcManager.getNPC(player); if(npc != null) npc.despawn(DespawnReason.PLUGIN); Runnable task = () -> { punish(player); player.setCanPickupItems(true); }; JavaPlugin plugin = this.expansion.getPlugin().getPlugin(); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(plugin, task, 1L); }
Example #7
Source File: Gui.java From IF with The Unlicense | 6 votes |
/** * Calls the specified consumer (if it's not null) with the specified parameter, * catching and logging all exceptions it might throw. * * @param callback the consumer to call if it isn't null * @param event the value the consumer should accept * @param callbackName the name of the action, used for logging * @param <T> the type of the value the consumer is accepting */ private <T extends InventoryEvent> void callCallback(@Nullable Consumer<T> callback, @NotNull T event, @NotNull String callbackName) { if (callback == null) { return; } try { callback.accept(event); } catch (Throwable t) { Logger logger = JavaPlugin.getProvidingPlugin(getClass()).getLogger(); String message = "Exception while handling " + callbackName + " in inventory '" + title + "', state=" + state; if (event instanceof InventoryClickEvent) { InventoryClickEvent clickEvent = (InventoryClickEvent) event; message += ", slot=" + clickEvent.getSlot(); } logger.log(Level.SEVERE, message, t); } }
Example #8
Source File: PerworldInventoryCommandHandlingTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Before public void setUpPlugin() throws IOException { File dataFolder = temporaryFolder.newFolder(); // Set mock server setField(Bukkit.class, "server", null, server); given(server.getLogger()).willReturn(mock(Logger.class)); // PluginDescriptionFile is final and so cannot be mocked PluginDescriptionFile descriptionFile = new PluginDescriptionFile( "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName()); JavaPluginLoader pluginLoader = new JavaPluginLoader(server); plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null); setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class)); Injector injector = new InjectorBuilder().addDefaultHandlers("me.gnat008.perworldinventory").create(); injector.register(PermissionManager.class, permissionManager); injector.register(ConvertCommand.class, convertCommand); injector.register(HelpCommand.class, helpCommand); injector.register(PerWorldInventoryCommand.class, pwiCommand); injector.register(ReloadCommand.class, reloadCommand); injector.register(SetWorldDefaultCommand.class, setWorldDefaultsCommand); injector.register(VersionCommand.class, versionCommand); plugin.registerCommands(injector); TestHelper.setField(PerWorldInventory.class, "permissionManager", plugin, permissionManager); }
Example #9
Source File: Opener.java From CratesPlus with GNU General Public License v3.0 | 6 votes |
public File getOpenerConfigFile() { File openersDir = new File(JavaPlugin.getPlugin(CratesPlus.class).getDataFolder(), "openers"); if (!openersDir.exists()) if (!openersDir.mkdirs()) return null; File configurationFile = new File(openersDir, getName() + ".yml"); if (!configurationFile.exists()) try { if (!configurationFile.createNewFile()) return null; } catch (IOException e) { e.printStackTrace(); return null; } return configurationFile; }
Example #10
Source File: CompatibilityFactions.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@Override public boolean canEnable() { try { ICombatLogX plugin = getPlugin(); JavaPlugin javaPlugin = plugin.getPlugin(); FactionsHandler<?> factionsHandler = new FactionsHandler<>(javaPlugin); this.hookFactions = factionsHandler.getFactionsHook(); return (this.hookFactions != null); } catch(IllegalStateException ex) { Logger logger = getLogger(); logger.info("A Factions plugin could not be found. This expansion will be automatically disabled."); return false; } }
Example #11
Source File: SQL.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static void init(JavaPlugin plugin) throws SQLException { hostname = plugin.getConfig().getString("mysql.hostname"); port = plugin.getConfig().getString("mysql.port"); db_name = plugin.getConfig().getString("mysql.db_name"); username = plugin.getConfig().getString("mysql.username"); password = plugin.getConfig().getString("mysql.password"); salt = plugin.getConfig().getString("salt"); dsn = "jdbc:mysql://"+hostname+":"+port+"/"+db_name; connect(); }
Example #12
Source File: ExpansionManager.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
public void registerListener(Expansion expansion, Listener listener) { PluginManager manager = Bukkit.getPluginManager(); JavaPlugin plugin = this.plugin.getPlugin(); manager.registerEvents(listener, plugin); this.expansionListenerMap.computeIfAbsent(expansion, e -> new ArrayList<>()).add(listener); }
Example #13
Source File: ItemLine.java From Holograms with MIT License | 5 votes |
@Override public double getHeight() { HologramPlugin plugin = JavaPlugin.getPlugin(HologramPlugin.class); if (plugin.getEntityController().getMinecraftVersion() == MinecraftVersion.V1_8_R1) { return 1.60; } return 0.5; }
Example #14
Source File: VoteMapManager.java From AnnihilationPro with MIT License | 5 votes |
public static void registerListener(JavaPlugin plugin) { voteMap = new HashMap<String,String>(); board = Bukkit.getScoreboardManager().getNewScoreboard(); obj = board.registerNewObjective("Voting", "CAT CERASET"); //active = false; Loader l = new Loader(); plugin.getCommand("Vote").setExecutor(l); Bukkit.getPluginManager().registerEvents(l, plugin); //AnniEvent.registerListener(l); }
Example #15
Source File: XParticle.java From XSeries with MIT License | 5 votes |
/** * Spawns a galaxy-like vortex. * Note that the speed of the particle is important. * Speed 0 will spawn static lines. * * @param plugin the timer handler. * @param points the points of the vortex. * @param rate the speed of the vortex. * @return the task handling the animation. * @since 2.0.0 */ public static BukkitTask vortex(JavaPlugin plugin, int points, double rate, ParticleDisplay display) { double rateDiv = Math.PI / rate; display.directional(); return new BukkitRunnable() { double theta = 0; @Override public void run() { theta += rateDiv; for (int i = 0; i < points; i++) { // Calculate our starting point in a circle radius. double multiplier = (PII * ((double) i / points)); double x = Math.cos(theta + multiplier); double z = Math.sin(theta + multiplier); // Calculate our direction of the spreading particles based on their angle. double angle = Math.atan2(z, x); double xDirection = Math.cos(angle); double zDirection = Math.sin(angle); display.offset(xDirection, 0, zDirection); display.spawn(x, 0, z); } } }.runTaskTimerAsynchronously(plugin, 0L, 1L); }
Example #16
Source File: ItemMenuListener.java From AnnihilationPro with MIT License | 5 votes |
/** * Registers the events of the {@link ninja.amp.ampmenus.MenuListener} to a * plugin. * * @param plugin * The plugin used to register the events. */ public void register(JavaPlugin plugin) { if (!isRegistered(plugin)) { plugin.getServer().getPluginManager() .registerEvents(INSTANCE, plugin); this.plugin = plugin; } }
Example #17
Source File: Notifier.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@Override public void onEnable() { ICombatLogX combat = getPlugin(); JavaPlugin plugin = combat.getPlugin(); PluginManager manager = Bukkit.getPluginManager(); manager.registerEvents(new ListenerNotifier(this), plugin); CommandNotifier commandNotifier = new CommandNotifier(this); combat.registerCommand("notifier", commandNotifier, "Toggle the boss bar, scoreboard, and action bar.", "/notifier bossbar/actionbar/scoreboard", "clx-toggle"); hookIfEnabled("MVdWPlaceholderAPI"); hookIfEnabled("PlaceholderAPI"); hookIfEnabled("TitleManager"); }
Example #18
Source File: ConfigHandler.java From HubBasics with GNU Lesser General Public License v3.0 | 5 votes |
/** * Manage custom configurations and files */ public ConfigHandler(JavaPlugin plugin) { Instance = this; this.plugin = plugin; this.loadDefaults(); this.setupLogger(); }
Example #19
Source File: Assemble.java From Assemble with GNU General Public License v3.0 | 5 votes |
public Assemble(JavaPlugin plugin, AssembleAdapter adapter) { if (plugin == null) { throw new RuntimeException("Assemble can not be instantiated without a plugin instance!"); } this.plugin = plugin; this.adapter = adapter; this.boards = new ConcurrentHashMap<>(); this.setup(); }
Example #20
Source File: TaskCloserTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Before public void initAuthMe() { Server server = mock(Server.class); given(server.getScheduler()).willReturn(bukkitScheduler); ReflectionTestUtils.setField(JavaPlugin.class, authMe, "server", server); given(authMe.getLogger()).willReturn(logger); taskCloser = spy(new TaskCloser(authMe, dataSource)); }
Example #21
Source File: SimpleCommandExecutor.java From AstralEdit with Apache License 2.0 | 5 votes |
/** * Initializes a new commandExecutor by command, plugin * * @param command command * @param plugin plugin */ public Registered(String command, JavaPlugin plugin) { super(); if (plugin == null) throw new IllegalArgumentException("Plugin cannot be null!"); if (command == null) throw new IllegalArgumentException("Command cannot be null!"); this.plugin = plugin; plugin.getCommand(command).setExecutor(this); }
Example #22
Source File: QuickShopAPI.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
/** * DO NOT CALL ME, IT JUST A INTERNAL METHOD, BUT BECAUSE CROSS-PACKAGE ACCESS, IT IS PUBLIC, SO DO NOT EXECUTE IT. * Go away =w= * * @param qs The QuickShop plugin instance */ public static void setupApi(@NotNull JavaPlugin qs) { if(!(qs instanceof QuickShop)){ throw new IllegalArgumentException("You can't setup API, it should only access by QuickShop internal calling."); } plugin = (QuickShop) qs; }
Example #23
Source File: SelectionManager.java From AstralEdit with Apache License 2.0 | 5 votes |
/** * Places an undos * @param counter counter * @param container container * @param containers containers * @param nextContainer nextContainer */ private void placeUndo(final int counter, final Container container, final List<Container> containers, final int nextContainer) { if (counter > 100) { Bukkit.getServer().getScheduler().runTaskLater(JavaPlugin.getPlugin(AstralEditPlugin.class), () -> this.placeUndoCalc(0, container, containers, nextContainer), 1L); } else { this.placeUndoCalc(counter, container, containers, nextContainer); } }
Example #24
Source File: FileUtils.java From AdditionsAPI with MIT License | 5 votes |
/** * * @param plugin * @return the jar file of the given plugin */ public static String getPluginJarPath(JavaPlugin plugin) { String path = new File(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()) .getAbsolutePath(); try { path = URLDecoder.decode(path, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return path; }
Example #25
Source File: FileUtils.java From AdditionsAPI with MIT License | 5 votes |
/** * copy a resource file inside the plugin's jar file */ public static void copyResource(JavaPlugin plugin, String resource, File fileOut) throws IOException { InputStream in = plugin.getResource(resource); if (!fileOut.exists()) { createFileAndPath(fileOut); } FileOutputStream out = new FileOutputStream(fileOut); copyStreams(in, out); }
Example #26
Source File: AdditionsAPIInitializationEvent.java From AdditionsAPI with MIT License | 5 votes |
public AdditionsAPIInitializationEvent addResourcePack(JavaPlugin plugin, InputStream inputstream) { try { ResourcePackManager.registerResource(plugin, inputstream); } catch (IOException e) { e.printStackTrace(); } return this; }
Example #27
Source File: PaginatedGUI.java From SpigotPaginatedGUI with MIT License | 5 votes |
/** * Simply an alias to register the Inventory listeners for a certain plugin. * Intended to improve code readability. * * @param plugin The Spigot plugin instance that you wish to register the listeners for. */ public static void prepare(JavaPlugin plugin){ if(inventoryListenerGUI == null){ inventoryListenerGUI = new InventoryListenerGUI(); plugin.getServer().getPluginManager().registerEvents(inventoryListenerGUI, plugin); } }
Example #28
Source File: BukkitPluginResolver.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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; } }
Example #29
Source File: SkriptYaml.java From skript-yaml with MIT License | 5 votes |
/** * Registers a tag (ie. !location) to a class using a supplied represented and constructed class. * <br><br> * * <b>Fails to register if:</b><br> * <ol> * <li> the class being registered doesn't match the type used in the constructed and represented classes * <li> the class is already registered * <li> the tag is already registered * <ol> * <br> * @param plugin * @param tag tag being registered * @param c class being registered * @param rc represented class * @param cc constructed class * <br> * @see me.sashie.skriptyaml.api.RepresentedClass * @see me.sashie.skriptyaml.api.ConstructedClass * */ public static void registerTag(JavaPlugin plugin, String tag, Class<?> c, RepresentedClass<?> rc, ConstructedClass<?> cc) { String prefix = plugin.getName().toLowerCase() + "-"; if (!tag.startsWith(prefix)) tag = prefix + tag; if (!REGISTERED_TAGS.containsKey(tag)) { if (!representer.contains(c)) { if (SkriptYamlUtils.getType(rc.getClass()) == c) { if (SkriptYamlUtils.getType(cc.getClass()) == c) { REGISTERED_TAGS.put(tag, plugin.getName()); representer.register(tag, c, rc); constructor.register(tag, cc); } else { warn("The class '" + c.getSimpleName() + "' that the plugin '" + plugin.getName() + "' is trying to register does not match constructed class '" + SkriptYamlUtils.getType(cc.getClass()).getSimpleName() + "' for constructor '" + cc.getClass().getSimpleName() + "' the tag '" + tag + "' was not registered"); } } else { warn("The class '" + c.getSimpleName() + "' that the plugin '" + plugin.getName() + "' is trying to register does not match represented class '" + SkriptYamlUtils.getType(rc.getClass()).getSimpleName() + "' for representer '" + rc.getClass().getSimpleName() + "' the tag '" + tag + "' was not registered"); } } else { warn("The class '" + c.getSimpleName() + "' that the plugin '" + plugin.getName() + "' is trying to register for the tag '" + tag + "' is already registered"); } } else { warn("The plugin '" + plugin.getName() + "' is trying to register the tag '" + tag + "' but it's already registered to '" + REGISTERED_TAGS.get(tag) + "'"); } }
Example #30
Source File: WorldBorderDataTagType.java From WorldBorderAPI with MIT License | 5 votes |
public WorldBorderDataTagType(JavaPlugin javaPlugin) { this.sizeKey = new NamespacedKey(javaPlugin, "size"); this.xKey = new NamespacedKey(javaPlugin, "center_x"); this.zKey = new NamespacedKey(javaPlugin, "center_z"); this.damageBufferInBlocksKey = new NamespacedKey(javaPlugin, "damage_buffer_in_blocks"); this.damageAmountKey = new NamespacedKey(javaPlugin, "damage_amount"); this.warningTimeSecondsKey = new NamespacedKey(javaPlugin, "warning_time_seconds"); this.warningDistanceKey = new NamespacedKey(javaPlugin, "warning_distance"); }