本文整理了Java中org.bukkit.Bukkit.getServer()
方法的一些代码示例,展示了Bukkit.getServer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bukkit.getServer()
方法的具体详情如下:
包路径:org.bukkit.Bukkit
类名称:Bukkit
方法名:getServer
[英]Gets the current Server singleton
[中]获取当前服务器单例
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Returns the current GlowServer instance.
* @return the GlowServer instance
*/
public static Server getServer() {
return mockServer == null ? Bukkit.getServer() : mockServer;
}
}
代码示例来源:origin: EngineHub/WorldEdit
@Override
public boolean isActive() {
// This is a thread safe call on CraftBukkit because it uses a
// CopyOnWrite list for the list of players, but the Bukkit
// specification doesn't require thread safety (though the
// spec is extremely incomplete)
return Bukkit.getServer().getPlayer(uuid) != null;
}
代码示例来源:origin: EngineHub/WorldEdit
@Override
public Collection<Actor> getConnectedUsers() {
List<Actor> users = new ArrayList<>();
for (org.bukkit.entity.Player player : Bukkit.getServer().getOnlinePlayers()) {
users.add(new BukkitPlayer(plugin, player));
}
return users;
}
}
代码示例来源:origin: Bukkit/Bukkit
public synchronized void clearPermissions() {
Set<String> perms = permissions.keySet();
for (String name : perms) {
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent);
}
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent);
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent);
permissions.clear();
}
代码示例来源:origin: EngineHub/WorldEdit
public static boolean isFakeNijiPerms(Plugin plugin) {
PluginCommand permsCommand = Bukkit.getServer().getPluginCommand("permissions");
return permsCommand == null || !(permsCommand.getPlugin().equals(plugin));
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Gets a set containing every {@link Permissible} that has this
* permission.
* <p>
* This set cannot be modified.
*
* @return Set containing permissibles with this permission
*/
public Set<Permissible> getPermissibles() {
return Bukkit.getServer().getPluginManager().getPermissionSubscriptions(name);
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Loads a list of Permissions from a map of data, usually used from
* retrieval from a yaml file.
* <p>
* The data may contain a list of name:data, where the data contains the
* following keys:
* <ul>
* <li>default: Boolean true or false. If not specified, false.
* <li>children: Map<String, Boolean> of child permissions. If not
* specified, empty list.
* <li>description: Short string containing a very small description of
* this description. If not specified, empty string.
* </ul>
*
* @param data Map of permissions
* @param error An error message to show if a permission is invalid.
* @param def Default permission value to use if missing
* @return Permission object
*/
public static List<Permission> loadPermissions(Map<?, ?> data, String error, PermissionDefault def) {
List<Permission> result = new ArrayList<Permission>();
for (Map.Entry<?, ?> entry : data.entrySet()) {
try {
result.add(Permission.loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, result));
} catch (Throwable ex) {
Bukkit.getServer().getLogger().log(Level.SEVERE, String.format(error, entry.getKey()), ex);
}
}
return result;
}
代码示例来源: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> matchedTopics = new ArrayList<String>();
String searchString = args[0];
for (HelpTopic topic : Bukkit.getServer().getHelpMap().getHelpTopics()) {
String trimmedTopic = topic.getName().startsWith("/") ? topic.getName().substring(1) : topic.getName();
if (trimmedTopic.startsWith(searchString)) {
matchedTopics.add(trimmedTopic);
}
}
return matchedTopics;
}
return ImmutableList.of();
}
代码示例来源:origin: Bukkit/Bukkit
private void calculateChildPermissions(Map<String, Boolean> children, boolean invert, PermissionAttachment attachment) {
Set<String> keys = children.keySet();
for (String name : keys) {
Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
boolean value = children.get(name) ^ invert;
String lname = name.toLowerCase();
permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value));
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
if (perm != null) {
calculateChildPermissions(perm.getChildren(), !value, attachment);
}
}
}
代码示例来源:origin: Bukkit/Bukkit
protected HelpTopic findPossibleMatches(String searchString) {
int maxDistance = (searchString.length() / 5) + 3;
Set<HelpTopic> possibleMatches = new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance());
if (searchString.startsWith("/")) {
searchString = searchString.substring(1);
}
for (HelpTopic topic : Bukkit.getServer().getHelpMap().getHelpTopics()) {
String trimmedTopic = topic.getName().startsWith("/") ? topic.getName().substring(1) : topic.getName();
if (trimmedTopic.length() < searchString.length()) {
continue;
}
if (Character.toLowerCase(trimmedTopic.charAt(0)) != Character.toLowerCase(searchString.charAt(0))) {
continue;
}
if (damerauLevenshteinDistance(searchString, trimmedTopic.substring(0, searchString.length())) < maxDistance) {
possibleMatches.add(topic);
}
}
if (possibleMatches.size() > 0) {
return new IndexHelpTopic("Search", null, null, possibleMatches, "Search for: " + searchString);
} else {
return null;
}
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Register a provider of a service.
*
* @param <T> Provider
* @param service service class
* @param provider provider to register
* @param plugin plugin with the provider
* @param priority priority of the provider
*/
public <T> void register(Class<T> service, T provider, Plugin plugin, ServicePriority priority) {
RegisteredServiceProvider<T> registeredProvider = null;
synchronized (providers) {
List<RegisteredServiceProvider<?>> registered = providers.get(service);
if (registered == null) {
registered = new ArrayList<RegisteredServiceProvider<?>>();
providers.put(service, registered);
}
registeredProvider = new RegisteredServiceProvider<T>(service, provider, priority, plugin);
// Insert the provider into the collection, much more efficient big O than sort
int position = Collections.binarySearch(registered, registeredProvider);
if (position < 0) {
registered.add(-(position + 1), registeredProvider);
} else {
registered.add(position, registeredProvider);
}
}
Bukkit.getServer().getPluginManager().callEvent(new ServiceRegisterEvent(registeredProvider));
}
代码示例来源:origin: EngineHub/WorldEdit
/**
* Create a Bukkit world from a WorldEdit world.
*
* @param world the WorldEdit world
* @return a Bukkit world
*/
public static org.bukkit.World adapt(World world) {
checkNotNull(world);
if (world instanceof BukkitWorld) {
return ((BukkitWorld) world).getWorld();
} else {
org.bukkit.World match = Bukkit.getServer().getWorld(world.getName());
if (match != null) {
return match;
} else {
throw new IllegalArgumentException("Can't find a Bukkit world for " + world);
}
}
}
代码示例来源: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
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
sender.sendMessage("Usage: " + usageMessage);
return false;
}
String modeArg = args[0];
int value = -1;
try {
value = Integer.parseInt(modeArg);
} catch (NumberFormatException ex) {}
GameMode mode = GameMode.getByValue(value);
if (mode == null) {
if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
mode = GameMode.CREATIVE;
} else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
mode = GameMode.ADVENTURE;
} else {
mode = GameMode.SURVIVAL;
}
}
Bukkit.getServer().setDefaultGameMode(mode);
Command.broadcastCommandMessage(sender, "Default game mode set to " + mode.toString().toLowerCase());
return true;
}
代码示例来源: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: Bukkit/Bukkit
/**
* Recalculates all {@link Permissible}s that contain this permission.
* <p>
* This should be called after modifying the children, and is
* automatically called after modifying the default value
*/
public void recalculatePermissibles() {
Set<Permissible> perms = getPermissibles();
Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(this);
for (Permissible p : perms) {
p.recalculatePermissions();
}
}
代码示例来源:origin: Bukkit/Bukkit
public void recalculatePermissions() {
clearPermissions();
Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
for (Permission perm : defaults) {
String name = perm.getName().toLowerCase();
permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true));
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
calculateChildPermissions(perm.getChildren(), false, null);
}
for (PermissionAttachment attachment : attachments) {
calculateChildPermissions(attachment.getPermissions(), false, attachment);
}
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Adds this permission to the specified parent permission.
* <p>
* If the parent permission does not exist, it will be created and
* registered.
*
* @param name Name of the parent permission
* @param value The value to set this permission to
* @return Parent permission it created or loaded
*/
public Permission addParent(String name, boolean value) {
PluginManager pm = Bukkit.getServer().getPluginManager();
String lname = name.toLowerCase();
Permission perm = pm.getPermission(lname);
if (perm == null) {
perm = new Permission(lname);
pm.addPermission(perm);
}
addParent(perm, value);
return perm;
}
代码示例来源:origin: Bukkit/Bukkit
public boolean hasPermission(String inName) {
if (inName == null) {
throw new IllegalArgumentException("Permission name cannot be null");
}
String name = inName.toLowerCase();
if (isPermissionSet(name)) {
return permissions.get(name).getValue();
} else {
Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
if (perm != null) {
return perm.getDefault().getValue(isOp());
} else {
return Permission.DEFAULT_PERMISSION.getValue(isOp());
}
}
}
代码示例来源:origin: Bukkit/Bukkit
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 1) {
int minutes;
try {
minutes = getInteger(sender, args[0], 0, Integer.MAX_VALUE, true);
} catch (NumberFormatException ex) {
sender.sendMessage(ex.getMessage());
return true;
}
Bukkit.getServer().setIdleTimeout(minutes);
Command.broadcastCommandMessage(sender, "Successfully set the idle timeout to " + minutes + " minutes.");
return true;
}
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
内容来源于网络,如有侵权,请联系作者删除!