org.bukkit.plugin.Plugin类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中org.bukkit.plugin.Plugin类的一些代码示例,展示了Plugin类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Plugin类的具体详情如下:
包路径:org.bukkit.plugin.Plugin
类名称:Plugin

Plugin介绍

[英]Represents a Plugin

The use of PluginBase is recommended for actual Implementation
[中]表示一个插件
建议在实际实现中使用PluginBase

代码示例

代码示例来源:origin: EngineHub/WorldEdit

public CommandMap getCommandMap() {
  CommandMap commandMap = ReflectionUtil.getField(plugin.getServer().getPluginManager(), "commandMap");
  if (commandMap == null) {
    if (fallbackCommands != null) {
      commandMap = fallbackCommands;
    } else {
      Bukkit.getServer().getLogger().severe(plugin.getDescription().getName() +
          ": Could not retrieve server CommandMap, using fallback instead!");
      fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer());
      Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin);
    }
  }
  return commandMap;
}

代码示例来源:origin: Bukkit/Bukkit

sender.sendMessage("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")");
} else {
  StringBuilder name = new StringBuilder();
  Plugin exactPlugin = Bukkit.getPluginManager().getPlugin(pluginName);
  if (exactPlugin != null) {
    describeToSender(exactPlugin, sender);
  for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
    if (plugin.getName().toLowerCase().contains(pluginName)) {
      describeToSender(plugin, sender);
      found = true;

代码示例来源:origin: Bukkit/Bukkit

public void enablePlugin(final Plugin plugin) {
  Validate.isTrue(plugin instanceof JavaPlugin, "Plugin is not associated with this PluginLoader");
  if (!plugin.isEnabled()) {
    plugin.getLogger().info("Enabling " + plugin.getDescription().getFullName());
    JavaPlugin jPlugin = (JavaPlugin) plugin;
    String pluginName = jPlugin.getDescription().getName();
    if (!loaders.containsKey(pluginName)) {
      loaders.put(pluginName, (PluginClassLoader) jPlugin.getClassLoader());
    }
    try {
      jPlugin.setEnabled(true);
    } catch (Throwable ex) {
      server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
    }
    // Perhaps abort here, rather than continue going, but as it stands,
    // an abort is not possible the way it's currently written
    server.getPluginManager().callEvent(new PluginEnableEvent(plugin));
  }
}

代码示例来源:origin: Bukkit/Bukkit

public PermissionAttachment(Plugin plugin, Permissible Permissible) {
  if (plugin == null) {
    throw new IllegalArgumentException("Plugin cannot be null");
  } else if (!plugin.isEnabled()) {
    throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
  }
  this.permissible = Permissible;
  this.plugin = plugin;
}

代码示例来源:origin: Bukkit/Bukkit

private String getPluginList() {
    StringBuilder pluginList = new StringBuilder();
    Plugin[] plugins = Bukkit.getPluginManager().getPlugins();

    for (Plugin plugin : plugins) {
      if (pluginList.length() > 0) {
        pluginList.append(ChatColor.WHITE);
        pluginList.append(", ");
      }

      pluginList.append(plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED);
      pluginList.append(plugin.getDescription().getName());
    }

    return "(" + plugins.length + "): " + pluginList.toString();
  }
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Creates a new PluginLogger that extracts the name from a plugin.
 *
 * @param context A reference to the plugin
 */
public PluginLogger(Plugin context) {
  super(context.getClass().getCanonicalName(), null);
  String prefix = context.getDescription().getPrefix();
  pluginName = prefix != null ? new StringBuilder().append("[").append(prefix).append("] ").toString() : "[" + context.getDescription().getName() + "] ";
  setParent(context.getServer().getLogger());
  setLevel(Level.ALL);
}

代码示例来源:origin: MilkBowl/Vault

public Permission_KPerms(Plugin plugin) {
  super();
  this.vault = plugin;
  Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), vault);
  if (kperms == null) {
    Plugin perms = plugin.getServer().getPluginManager().getPlugin("KPerms");
    if (perms != null && perms.isEnabled()) {
      this.kperms = (KPermsPlugin) perms;
      plugin.getLogger().info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), "KPerms"));
    }
  }
}

代码示例来源:origin: webbukkit/dynmap

public static NijikokunPermissions create(Server server, String name) {
  Plugin permissionsPlugin = server.getPluginManager().getPlugin("Permissions");
  if (permissionsPlugin == null)
    return null;
  
  server.getPluginManager().enablePlugin(permissionsPlugin);
  if(permissionsPlugin.isEnabled() == false)
    return null;
  
  Log.info("Using Permissions " + permissionsPlugin.getDescription().getVersion() + " for access control");
  return new NijikokunPermissions(permissionsPlugin, name);
}

代码示例来源:origin: MilkBowl/Vault

@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
  if (chat.overPerms == null) {
    Plugin chat = plugin.getServer().getPluginManager().getPlugin("OverPermissions");
    if (chat != null) {
      this.chat.overPerms = (OverPermissions) chat;
      plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", new Object[] {plugin.getDescription().getName(), getName()}));
    }
  }
}

代码示例来源:origin: artex-development/Lukkit

@Override
public void enablePlugin(Plugin plugin) {
  plugin.getLogger().info("Enabling " + plugin.getDescription().getFullName());
  LukkitPluginEnableEvent event = new LukkitPluginEnableEvent((LukkitPlugin) plugin);
  Bukkit.getServer().getPluginManager().callEvent(event);
  if (!event.isCancelled()) {
    plugin.onEnable();
  } else {
    if (plugin.isEnabled())
      Bukkit.getPluginManager().disablePlugin(plugin);
  }
}

代码示例来源:origin: MilkBowl/Vault

public Chat_TotalPermissions(Plugin plugin, Permission perms) {
  super(perms);
  this.plugin = plugin;
  Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
  if (totalPermissions == null) {
    Plugin chat = plugin.getServer().getPluginManager().getPlugin("TotalPermissions");
    if (chat != null) {
      if (chat.isEnabled()) {
        totalPermissions = (TotalPermissions) chat;
        plugin.getLogger().info(String.format("[Chat] %s hooked.", name));
      }
    }
  }
}

代码示例来源:origin: Bukkit/Bukkit

public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
  if (plugin == null) {
    throw new IllegalArgumentException("Plugin cannot be null");
  } else if (!plugin.isEnabled()) {
    throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
  }
  PermissionAttachment result = addAttachment(plugin);
  if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveAttachmentRunnable(result), ticks) == -1) {
    Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
    result.remove();
    return null;
  } else {
    return result;
  }
}

代码示例来源:origin: io.github.bedwarsrel/BedwarsRel-Common

public static ArrayList<String> getPlugins() {
 ArrayList<String> pluginList = new ArrayList<String>();
 Plugin[] plugins = BedwarsRel.getInstance().getServer().getPluginManager().getPlugins();
 for (Plugin plugin : plugins) {
  pluginList.add(plugin.getName() + " (" + plugin.getDescription().getVersion() + ")");
 }
 return pluginList;
}

代码示例来源:origin: Bukkit/Bukkit

output = Bukkit.getConsoleSender();
String[] split = name.split(":", 2);
String id = (split.length > 1) ? split[1] : null;
Plugin plugin = Bukkit.getPluginManager().getPlugin(split[0]);
} else if (!plugin.isEnabled()) {
  output.sendMessage("Could not set generator for world '" + world + "': Plugin '" + plugin.getDescription().getFullName() + "' is not enabled");
} else {
  result = plugin.getDefaultWorldGenerator(world, id);

代码示例来源:origin: artex-development/Lukkit

@SuppressWarnings("SuspiciousMethodCalls")
@Override
public void disablePlugin(Plugin plugin) {
  plugin.getLogger().info("Disabling " + plugin.getDescription().getFullName());
  LukkitPluginDisableEvent event = new LukkitPluginDisableEvent((LukkitPlugin) plugin);
  Bukkit.getServer().getPluginManager().callEvent(event);
  HandlerList.unregisterAll(plugin);
  plugin.onDisable();
  this.loadedPlugins.remove(plugin);
}

代码示例来源:origin: r-clancy/PlugMan

/**
 * Returns a List of plugin names.
 *
 * @return list of plugin names
 */
public static List<String> getPluginNames(boolean fullName) {
  List<String> plugins = new ArrayList<>();
  for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
    plugins.add(fullName ? plugin.getDescription().getFullName() : plugin.getName());
  }
  return plugins;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
  public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1) {
      List<String> completions = new ArrayList<String>();
      String toComplete = args[0].toLowerCase();
      for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
        if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) {
          completions.add(plugin.getName());
        }
      }
      return completions;
    }
    return ImmutableList.of();
  }
}

代码示例来源:origin: Bukkit/Bukkit

public void disablePlugin(final Plugin plugin) {
  if (plugin.isEnabled()) {
    try {
      plugin.getPluginLoader().disablePlugin(plugin);
    } catch (Throwable ex) {
      server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
    }
    try {
      server.getScheduler().cancelTasks(plugin);
    } catch (Throwable ex) {
      server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while cancelling tasks for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
    }
    try {
      server.getServicesManager().unregisterAll(plugin);
    } catch (Throwable ex) {
      server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering services for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
    }
    try {
      HandlerList.unregisterAll(plugin);
    } catch (Throwable ex) {
      server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering events for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
    }
    try {
      server.getMessenger().unregisterIncomingPluginChannel(plugin);
      server.getMessenger().unregisterOutgoingPluginChannel(plugin);
    } catch(Throwable ex) {
      server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while unregistering plugin channels for " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
    }
  }
}

代码示例来源:origin: Bukkit/Bukkit

return false;
if (!sender.getServer().getPluginManager().useTimings()) {
  sender.sendMessage("Please enable timings by setting \"settings.plugin-profiling\" to true in bukkit.yml");
  return true;
      fileNames = new PrintStream(names);
    for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
      pluginIdx++;
      long totalTime = 0;
      if (separate) {
        fileNames.println(pluginIdx + " " + plugin.getDescription().getFullName());
        fileTimings.println("Plugin " + pluginIdx);
      else fileTimings.println(plugin.getDescription().getFullName());
      for (RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
        if (listener instanceof TimedRegisteredListener) {

代码示例来源:origin: EngineHub/WorldEdit

void register(Plugin plugin) {
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
  }
}

相关文章