cn.nukkit.plugin.Plugin Java Examples

The following examples show how to use cn.nukkit.plugin.Plugin. 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: HandlerList.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<RegisteredListener> getRegisteredListeners(Plugin plugin) {
    ArrayList<RegisteredListener> listeners = new ArrayList<>();
    synchronized (allLists) {
        for (HandlerList h : allLists) {
            synchronized (h) {
                for (List<RegisteredListener> list : h.handlerslots.values()) {
                    for (RegisteredListener listener : list) {
                        if (listener.getPlugin().equals(plugin)) {
                            listeners.add(listener);
                        }
                    }
                }
            }
        }
    }
    return listeners;
}
 
Example #2
Source File: ServerScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private TaskHandler addTask(Plugin plugin, Runnable task, int delay, int period, boolean asynchronous) {
    if (plugin != null && plugin.isDisabled()) {
        throw new PluginException("Plugin '" + plugin.getName() + "' attempted to register a task while disabled.");
    }
    if (delay < 0 || period < 0) {
        throw new PluginException("Attempted to register a task with negative delay or period.");
    }

    TaskHandler taskHandler = new TaskHandler(plugin, task, nextTaskId(), asynchronous);
    taskHandler.setDelay(delay);
    taskHandler.setPeriod(period);
    taskHandler.setNextRunTick(taskHandler.isDelayed() ? currentTick + taskHandler.getDelay() : currentTick);

    if (task instanceof Task) {
        ((Task) task).setHandler(taskHandler);
    }

    pending.offer(taskHandler);
    taskMap.put(taskHandler.getTaskId(), taskHandler);

    return taskHandler;
}
 
Example #3
Source File: NKServiceManager.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<RegisteredServiceProvider<?>> cancel(Plugin plugin) {
    ImmutableList.Builder<RegisteredServiceProvider<?>> builder = ImmutableList.builder();

    Iterator<RegisteredServiceProvider<?>> it;
    RegisteredServiceProvider<?> registered;

    synchronized (handle) {
        for (List<RegisteredServiceProvider<?>> list : handle.values()) {
            it = list.iterator();

            while (it.hasNext()) {
                registered = it.next();
                if (registered.getPlugin() == plugin) {
                    it.remove();
                    builder.add(registered);
                }
            }

        }
    }

    return builder.build();
}
 
Example #4
Source File: ServerScheduler.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private TaskHandler addTask(Plugin plugin, Runnable task, int delay, int period, boolean asynchronous) {
    if (plugin != null && plugin.isDisabled()) {
        throw new PluginException("Plugin '" + plugin.getName() + "' attempted to register a task while disabled.");
    }
    if (delay < 0 || period < 0) {
        throw new PluginException("Attempted to register a task with negative delay or period.");
    }

    TaskHandler taskHandler = new TaskHandler(plugin, task, nextTaskId(), asynchronous);
    taskHandler.setDelay(delay);
    taskHandler.setPeriod(period);
    taskHandler.setNextRunTick(taskHandler.isDelayed() ? currentTick + taskHandler.getDelay() : currentTick);

    if (task instanceof Task) {
        ((Task) task).setHandler(taskHandler);
    }

    pending.offer(taskHandler);
    taskMap.put(taskHandler.getTaskId(), taskHandler);

    return taskHandler;
}
 
Example #5
Source File: PermissibleBase.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) {
    if (plugin == null) {
        throw new PluginException("Plugin cannot be null");
    } else if (!plugin.isEnabled()) {
        throw new PluginException("Plugin " + plugin.getDescription().getName() + " is disabled");
    }

    PermissionAttachment result = new PermissionAttachment(plugin, this.parent != null ? this.parent : this);
    this.attachments.add(result);
    if (name != null && value != null) {
        result.setPermission(name, value);
    }
    this.recalculatePermissions();

    return result;
}
 
Example #6
Source File: StandardMessenger.java    From SynapseAPI with GNU General Public License v3.0 6 votes vote down vote up
private void removeFromIncoming(Plugin plugin, String channel) {
    synchronized (this.incomingLock) {
        Set<PluginMessageListenerRegistration> registrations = this.incomingByPlugin.get(plugin);
        if (registrations != null) {
            PluginMessageListenerRegistration[] toRemove = registrations.toArray(new PluginMessageListenerRegistration[0]);
            int n = toRemove.length;
            int n2 = 0;
            while (n2 < n) {
                PluginMessageListenerRegistration registration = toRemove[n2];
                if (registration.getChannel().equals(channel)) {
                    this.removeFromIncoming(registration);
                }
                ++n2;
            }
        }
    }
}
 
Example #7
Source File: QueryRegenerateEvent.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public QueryRegenerateEvent(Server server, int timeout) {
    this.timeout = timeout;
    this.serverName = server.getMotd();
    this.listPlugins = (boolean) server.getConfig("settings.query-plugins", true);
    this.plugins = server.getPluginManager().getPlugins().values().toArray(new Plugin[server.getPluginManager().getPlugins().values().size()]);
    List<Player> players = new ArrayList<>();
    for (Player player : server.getOnlinePlayers().values()) {
        if (player.isOnline()) {
            players.add(player);
        }
    }
    this.players = players.toArray(new Player[players.size()]);

    this.gameType = (server.getDefaultGamemode() & 0x01) == 0 ? "SMP" : "CMP";
    this.version = server.getVersion();
    this.server_engine = server.getName() + " " + server.getNukkitVersion();
    this.map = server.getDefaultLevel() == null ? "unknown" : server.getDefaultLevel().getName();
    this.numPlayers = this.players.length;
    this.maxPlayers = server.getMaxPlayers();
    this.whitelist = server.hasWhitelist() ? "on" : "off";
    this.port = server.getPort();
    this.ip = server.getIp();
}
 
Example #8
Source File: StandardMessenger.java    From SynapseAPI with GNU General Public License v3.0 6 votes vote down vote up
private void removeFromOutgoing(Plugin plugin, String channel) {
    synchronized (this.outgoingLock) {
        Set<Plugin> plugins = this.outgoingByChannel.get(channel);
        Set<String> channels = this.outgoingByPlugin.get(plugin);
        if (plugins != null) {
            plugins.remove(plugin);
            if (plugins.isEmpty()) {
                this.outgoingByChannel.remove(channel);
            }
        }
        if (channels != null) {
            channels.remove(channel);
            if (channels.isEmpty()) {
                this.outgoingByChannel.remove(channel);
            }
        }
    }
}
 
Example #9
Source File: StandardMessenger.java    From SynapseAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Set<PluginMessageListenerRegistration> getIncomingChannelRegistrations(Plugin plugin, String channel) {
    if (plugin == null) {
        throw new IllegalArgumentException("Plugin cannot be null");
    }
    StandardMessenger.validateChannel(channel);

    synchronized (this.incomingLock) {
        Set<PluginMessageListenerRegistration> registrations = this.incomingByPlugin.get(plugin);
        if (registrations != null) {
            ImmutableSet.Builder builder = ImmutableSet.builder();
            for (PluginMessageListenerRegistration registration : registrations) {
                if (!registration.getChannel().equals(channel)) continue;
                builder.add(registration);
            }
            return builder.build();
        }
        return ImmutableSet.of();
    }
}
 
Example #10
Source File: StandardMessenger.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void registerOutgoingPluginChannel(Plugin plugin, String channel) {
    if (plugin == null) {
        throw new IllegalArgumentException("Plugin cannot be null");
    }
    StandardMessenger.validateChannel(channel);
    if (this.isReservedChannel(channel)) {
        throw new ReservedChannelException(channel);
    }
    this.addToOutgoing(plugin, channel);
}
 
Example #11
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void unregisterAll(Plugin plugin) {
    synchronized (allLists) {
        for (HandlerList h : allLists) {
            h.unregister(plugin);
        }
    }
}
 
Example #12
Source File: NukkitCommandManager.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean register(CommandInfo command, Plugin plugin, CommandExecutor executor) {
    if (command == null || commandMap == null) {
        return false;
    }
    DynamicPluginCommand cmd = new DynamicPluginCommand(
            command.getAliases(),
            command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(),
            executor,
            plugin);
    cmd.setPermissions(command.getPermissions());
    for (String alias : command.getAliases()) {
        commandMap.register(alias, cmd);
    }
    return true;
}
 
Example #13
Source File: BlockMetadataStore.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeMetadata(Object block, String metadataKey, Plugin owningPlugin) {
    if (!(block instanceof Block)) {
        throw new IllegalArgumentException("Object must be a Block");
    }
    if (((Block) block).getLevel() == this.owningLevel) {
        super.removeMetadata(block, metadataKey, owningPlugin);
    } else {
        throw new IllegalStateException("Block does not belong to world " + this.owningLevel.getName());
    }
}
 
Example #14
Source File: PluginsCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void sendPluginList(CommandSender sender) {
    String list = "";
    Map<String, Plugin> plugins = sender.getServer().getPluginManager().getPlugins();
    for (Plugin plugin : plugins.values()) {
        if (list.length() > 0) {
            list += TextFormat.WHITE + ", ";
        }
        list += plugin.isEnabled() ? TextFormat.GREEN : TextFormat.RED;
        list += plugin.getDescription().getFullName();
    }

    sender.sendMessage(new TranslationContainer("nukkit.command.plugins.success", String.valueOf(plugins.size()), list));
}
 
Example #15
Source File: Timings.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Timing getPluginEventTiming(Class<? extends Event> event, Listener listener, EventExecutor executor, Plugin plugin) {
    Timing group = TimingsManager.getTiming(plugin.getName(), "Combined Total", pluginEventTimer);

    return TimingsManager.getTiming(plugin.getName(), "Event: " + listener.getClass().getName() + "."
            + (executor instanceof MethodEventExecutor ? ((MethodEventExecutor) executor).getMethod().getName() : "???")
            + " (" + event.getSimpleName() + ")", group);
}
 
Example #16
Source File: StandardMessenger.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isOutgoingChannelRegistered(Plugin plugin, String channel) {
    if (plugin == null) {
        throw new IllegalArgumentException("Plugin cannot be null");
    }
    StandardMessenger.validateChannel(channel);

    synchronized (this.outgoingLock) {
        Set<String> channels = this.outgoingByPlugin.get(plugin);
        return channels != null && channels.contains(channel);
    }
}
 
Example #17
Source File: PermissionAttachment.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public PermissionAttachment(Plugin plugin, Permissible permissible) {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin " + plugin.getDescription().getName() + " is disabled");
    }
    this.permissible = permissible;
    this.plugin = plugin;
}
 
Example #18
Source File: Server.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void enablePlugins(PluginLoadOrder type) {
    for (Plugin plugin : new ArrayList<>(this.pluginManager.getPlugins().values())) {
        if (!plugin.isEnabled() && type == plugin.getDescription().getOrder()) {
            this.enablePlugin(plugin);
        }
    }

    if (type == PluginLoadOrder.POSTWORLD) {
        this.commandMap.registerServerAliases();
        DefaultPermissions.registerCorePermissions();
    }
}
 
Example #19
Source File: StandardMessenger.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<PluginMessageListenerRegistration> getIncomingChannelRegistrations(Plugin plugin) {
    if (plugin == null) {
        throw new IllegalArgumentException("Plugin cannot be null");
    }

    synchronized (this.incomingLock) {
        Set<PluginMessageListenerRegistration> registrations = this.incomingByPlugin.get(plugin);
        if (registrations != null) {
            return ImmutableSet.copyOf(registrations);
        }
        return ImmutableSet.of();
    }
}
 
Example #20
Source File: MetadataStore.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void setMetadata(Object subject, String metadataKey, MetadataValue newMetadataValue) {
    if (newMetadataValue == null) {
        throw new ServerException("Value cannot be null");
    }
    Plugin owningPlugin = newMetadataValue.getOwningPlugin();
    if (owningPlugin == null) {
        throw new PluginException("Plugin cannot be null");
    }
    String key = this.disambiguate((Metadatable) subject, metadataKey);
    Map<Plugin, MetadataValue> entry = this.metadataMap.computeIfAbsent(key, k -> new WeakHashMap<>(1));
    entry.put(owningPlugin, newMetadataValue);
}
 
Example #21
Source File: MetadataStore.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void removeMetadata(Object subject, String metadataKey, Plugin owningPlugin) {
    if (owningPlugin == null) {
        throw new PluginException("Plugin cannot be null");
    }
    String key = this.disambiguate((Metadatable) subject, metadataKey);
    Map entry = this.metadataMap.get(key);
    if (entry == null) {
        return;
    }
    entry.remove(owningPlugin);
    if (entry.isEmpty()) {
        this.metadataMap.remove(key);
    }
}
 
Example #22
Source File: LuckPermsPermissionAttachment.java    From LuckPerms with MIT License 5 votes vote down vote up
public LuckPermsPermissionAttachment(LuckPermsPermissible permissible, Plugin owner) {
    super(owner, null);
    this.permissible = permissible;
    this.owner = owner;

    injectFakeMap();
}
 
Example #23
Source File: LuckPermsPermissible.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public PermissionAttachment addAttachment(Plugin plugin, String permission) {
    Objects.requireNonNull(plugin, "plugin");
    Objects.requireNonNull(permission, "permission");

    PermissionAttachment attachment = addAttachment(plugin);
    attachment.setPermission(permission, true);
    return attachment;
}
 
Example #24
Source File: PluginsCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void sendPluginList(CommandSender sender) {
    String list = "";
    Map<String, Plugin> plugins = sender.getServer().getPluginManager().getPlugins();
    for (Plugin plugin : plugins.values()) {
        if (list.length() > 0) {
            list += TextFormat.WHITE + ", ";
        }
        list += plugin.isEnabled() ? TextFormat.GREEN : TextFormat.RED;
        list += plugin.getDescription().getFullName();
    }

    sender.sendMessage(new TranslationContainer("nukkit.command.plugins.success", new String[]{String.valueOf(plugins.size()), list}));
}
 
Example #25
Source File: MetadataStore.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void removeMetadata(Object subject, String metadataKey, Plugin owningPlugin) {
    if (owningPlugin == null) {
        throw new PluginException("Plugin cannot be null");
    }
    String key = this.disambiguate((Metadatable) subject, metadataKey);
    Map entry = this.metadataMap.get(key);
    if (entry == null) {
        return;
    }
    entry.remove(owningPlugin);
    if (entry.isEmpty()) {
        this.metadataMap.remove(key);
    }
}
 
Example #26
Source File: ServerScheduler.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public TaskHandler scheduleTask(Plugin plugin, Runnable task) {
    return addTask(plugin, task, 0, 0, false);
}
 
Example #27
Source File: PluginEnableEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PluginEnableEvent(Plugin plugin) {
    super(plugin);
}
 
Example #28
Source File: OfflinePlayer.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
    this.server.getPlayerMetadata().removeMetadata(this, metadataKey, owningPlugin);
}
 
Example #29
Source File: ServerScheduler.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public TaskHandler scheduleTask(Plugin plugin, Runnable task, boolean asynchronous) {
    return addTask(plugin, task, 0, 0, asynchronous);
}
 
Example #30
Source File: Server.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void enablePlugin(Plugin plugin) {
    this.pluginManager.enablePlugin(plugin);
}