Search in sources :

Example 41 with PluginManager

use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.

the class EssentialsAntiBuild method onEnable.

@Override
public void onEnable() {
    final PluginManager pm = this.getServer().getPluginManager();
    final Plugin essPlugin = pm.getPlugin("Essentials");
    if (essPlugin == null || !essPlugin.isEnabled()) {
        return;
    }
    ess = new EssentialsConnect(essPlugin, this);
    final EssentialsAntiBuildListener blockListener = new EssentialsAntiBuildListener(this);
    pm.registerEvents(blockListener, this);
    if (metrics == null) {
        metrics = new MetricsWrapper(this, 3813, false);
    }
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) MetricsWrapper(com.earth2me.essentials.metrics.MetricsWrapper) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 42 with PluginManager

use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.

the class EssentialsChat method onEnable.

@Override
public void onEnable() {
    final PluginManager pluginManager = getServer().getPluginManager();
    ess = (IEssentials) pluginManager.getPlugin("Essentials");
    if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
        getLogger().log(Level.WARNING, tl("versionMismatchAll"));
    }
    if (!ess.isEnabled()) {
        this.setEnabled(false);
        return;
    }
    final Map<AsyncPlayerChatEvent, ChatStore> chatStore = Collections.synchronizedMap(new HashMap<>());
    final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatStore);
    final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatStore);
    final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatStore);
    pluginManager.registerEvents(playerListenerLowest, this);
    pluginManager.registerEvents(playerListenerNormal, this);
    pluginManager.registerEvents(playerListenerHighest, this);
    if (metrics == null) {
        metrics = new MetricsWrapper(this, 3814, false);
    }
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) MetricsWrapper(com.earth2me.essentials.metrics.MetricsWrapper)

Example 43 with PluginManager

use of org.bukkit.plugin.PluginManager in project EvenMoreFish by Oheers.

the class Reward method run.

public void run(OfflinePlayer player, Location hookLocation) {
    Player p = null;
    if (player.isOnline())
        p = (Player) player;
    switch(type) {
        case COMMAND:
            String inputCommand = this.action.replace("{player}", player.getName());
            if (hookLocation != null) {
                inputCommand = inputCommand.replace("{x}", Double.toString(hookLocation.getX())).replace("{y}", Double.toString(hookLocation.getY())).replace("{z}", Double.toString(hookLocation.getZ())).replace("{world}", hookLocation.getWorld().getName());
            }
            // running the command
            String finalCommand = inputCommand;
            Bukkit.getScheduler().callSyncMethod(plugin, () -> Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), finalCommand));
            break;
        case EFFECT:
            if (p != null) {
                String[] parsedEffect = action.split(",");
                // Adds a potion effect in accordance to the config.yml "EFFECT:" value
                p.addPotionEffect(new PotionEffect(Objects.requireNonNull(PotionEffectType.getByName(parsedEffect[0])), Integer.parseInt(parsedEffect[2]) * 20, Integer.parseInt(parsedEffect[1])));
            }
            break;
        case HEALTH:
            if (p != null) {
                if (!(p.getHealth() > 20)) {
                    double newhealth = p.getHealth() + Integer.parseInt(action);
                    // checking the new health won't go above 20
                    if (newhealth > 20) {
                        p.setHealth(20);
                    } else {
                        p.setHealth(newhealth);
                    }
                }
            }
            break;
        case HUNGER:
            if (p != null) {
                p.setFoodLevel(p.getFoodLevel() + Integer.parseInt(action));
            }
            break;
        case ITEM:
            if (p != null) {
                String[] parsedItem = action.split(",");
                FishUtils.giveItems(Collections.singletonList(new ItemStack(Material.getMaterial(parsedItem[0]), Integer.parseInt(parsedItem[1]))), p);
            }
            break;
        case MESSAGE:
            if (p != null) {
                p.sendMessage(FishUtils.translateHexColorCodes(action));
            }
            break;
        case MONEY:
            EvenMoreFish.econ.depositPlayer(player, Integer.parseInt(action));
            break;
        case OTHER:
            PluginManager pM = Bukkit.getPluginManager();
            EMFRewardEvent event = new EMFRewardEvent(this, p, fishVelocity, hookLocation);
            pM.callEvent(event);
            break;
        default:
            EvenMoreFish.logger.log(Level.SEVERE, "Error in loading a reward.");
    }
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) EMFRewardEvent(com.oheers.fish.api.EMFRewardEvent) PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack)

Example 44 with PluginManager

use of org.bukkit.plugin.PluginManager in project NextEconomy by NextPlugins.

the class PurseAPI method updatePurse.

/**
 * Change purse value with messages and calling event (Better way)
 *
 * @param newValue to purse
 */
public void updatePurse(int newValue) {
    val lastNextUpdate = nextUpdate;
    val duration = PurseValue.get(PurseValue::nextUpdate);
    setNextUpdate(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(duration));
    Bukkit.getScheduler().runTaskAsynchronously(NextEconomy.getInstance(), () -> {
        val asyncPurseUpdateEvent = new AsyncPurseUpdateEvent(newValue, purse, lastNextUpdate);
        PluginManager pluginManager = Bukkit.getPluginManager();
        pluginManager.callEvent(asyncPurseUpdateEvent);
    });
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) AsyncPurseUpdateEvent(com.nextplugins.economy.api.event.operations.AsyncPurseUpdateEvent) PurseValue(com.nextplugins.economy.configuration.PurseValue)

Example 45 with PluginManager

use of org.bukkit.plugin.PluginManager in project NoCheatPlus by NoCheatPlus.

the class PermissionUtil method addChildPermissionBySuffix.

/**
 * @param permissionName
 *            A permission already registered with Bukkit.
 * @param childPermissionSuffix
 *            The suffix to add, the resulting permission will b registered
 *            with the permissionRegistry and Bukkit, if not yet done. No
 *            leading dot, results in: permissionName.childPermissionSuffix
 * @param permissionDefault
 *            Default for child permissions.
 * @throws NullPointerException
 *             If no permission is registered for permissionName.
 */
public static void addChildPermissionBySuffix(final RegisteredPermission registeredPermission, final String childPermissionSuffix, final PermissionRegistry permissionRegistry, final PermissionDefault permissionDefault, final boolean childValue) {
    final String permissionName = registeredPermission.getStringRepresentation();
    final String childPermissionName = permissionName + "." + childPermissionSuffix;
    // Ensure it s registered like this.
    permissionRegistry.getOrRegisterPermission(childPermissionName);
    final PluginManager pm = Bukkit.getPluginManager();
    final Permission permission = pm.getPermission(permissionName);
    if (permission == null) {
        throw new NullPointerException("Permission is not registered: " + permissionName);
    }
    Permission childPermission = pm.getPermission(childPermissionName);
    if (childPermission == null) {
        childPermission = new Permission(childPermissionName, AUTO_GENERATED, permissionDefault);
        pm.addPermission(childPermission);
    }
    if (!permission.getChildren().containsKey(childPermissionName)) {
        childPermission.addParent(permission, childValue);
    }
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Permission(org.bukkit.permissions.Permission)

Aggregations

PluginManager (org.bukkit.plugin.PluginManager)148 Plugin (org.bukkit.plugin.Plugin)33 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)20 Permission (org.bukkit.permissions.Permission)16 MetricsWrapper (com.earth2me.essentials.metrics.MetricsWrapper)14 Player (org.bukkit.entity.Player)14 Test (org.junit.Test)13 SimplePluginManager (org.bukkit.plugin.SimplePluginManager)12 Map (java.util.Map)11 File (java.io.File)9 IOException (java.io.IOException)9 World (org.bukkit.World)9 PluginCommand (org.bukkit.command.PluginCommand)9 Command (org.bukkit.command.Command)8 Listener (org.bukkit.event.Listener)8 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)8 HashMap (java.util.HashMap)7 EventHandler (org.bukkit.event.EventHandler)7 ArrayList (java.util.ArrayList)6 Bukkit (org.bukkit.Bukkit)6