本文整理了Java中org.bukkit.Bukkit
类的一些代码示例,展示了Bukkit
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bukkit
类的具体详情如下:
包路径:org.bukkit.Bukkit
类名称:Bukkit
[英]Represents the Bukkit core, for version and Server singleton handling
[中]表示Bukkit核心,用于版本和服务器单例处理
代码示例来源:origin: Bukkit/Bukkit
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
player = Bukkit.getPlayer(args[1]);
} else if (sender instanceof Player) {
player = (Player) sender;
sender.sendMessage("You must specify which player you wish to perform this action on.");
return true;
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
player.awardAchievement(achievement);
Achievement achievement = Bukkit.getUnsafe().getAchievementFromInternalName(statisticString);
Statistic statistic = Bukkit.getUnsafe().getStatisticFromInternalName(statisticString);
Bukkit.getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
代码示例来源: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);
sender.sendMessage("This server is not running any plugin by that name.");
sender.sendMessage("Use /plugins to get a list of plugins.");
代码示例来源:origin: Bukkit/Bukkit
/**
* Schedules this in the Bukkit scheduler to run on next tick.
*
* @param plugin the reference to the plugin scheduling task
* @return a BukkitTask that contains the id number
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see BukkitScheduler#runTask(Plugin, Runnable)
*/
public synchronized BukkitTask runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
checkState();
return setupId(Bukkit.getScheduler().runTask(plugin, (Runnable) this));
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Attempts to set the {@link Server} singleton.
* <p>
* This cannot be done if the Server is already set.
*
* @param server Server instance
*/
public static void setServer(Server server) {
if (Bukkit.server != null) {
throw new UnsupportedOperationException("Cannot redefine singleton Server");
}
Bukkit.server = server;
server.getLogger().info("This server is running " + getName() + " version " + getVersion() + " (Implementing API version " + getBukkitVersion() + ")");
}
代码示例来源:origin: Bukkit/Bukkit
private void processIPBan(String ip, CommandSender sender, String reason) {
Bukkit.getBanList(BanList.Type.IP).addBan(ip, reason, null, sender.getName());
// Find all matching players and kick
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getAddress().getAddress().getHostAddress().equals(ip)) {
player.kickPlayer("You have been IP banned.");
}
}
Command.broadcastCommandMessage(sender, "Banned IP Address " + ip);
}
代码示例来源:origin: Bukkit/Bukkit
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
StringBuilder online = new StringBuilder();
final Collection<? extends Player> players = Bukkit.getOnlinePlayers();
for (Player player : players) {
// If a player is hidden from the sender don't show them in the list
if (sender instanceof Player && !((Player) sender).canSee(player))
continue;
if (online.length() > 0) {
online.append(", ");
}
online.append(player.getDisplayName());
}
sender.sendMessage("There are " + players.size() + "/" + Bukkit.getMaxPlayers() + " players online:\n" + online.toString());
return true;
}
代码示例来源:origin: dzikoysk/WildSkript
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Block block, control;
if (event.getTo().getY() > event.getFrom().getY()) {
block = event.getPlayer().getWorld().getBlockAt(new Location(event.getPlayer().getWorld(), event.getTo().getX(), event.getTo().getY() + 2, event.getTo().getZ()));
control = event.getPlayer().getWorld().getBlockAt(new Location(event.getPlayer().getWorld(), event.getTo().getX(), event.getTo().getY() - 2, event.getTo().getZ()));
if (!(block.getTypeId() != 0 || control.getTypeId() == 0)) {
EvtJump custom = new EvtJump(event.getPlayer());
Bukkit.getServer().getPluginManager().callEvent(custom);
if (custom.isCancelled()) {
event.setCancelled(true);
}
}
}
}
代码示例来源:origin: Bkm016/TabooLib
@EventHandler
public void onJoin(PlayerJoinEvent e) {
if (UpdateTask.isHaveUpdate() && e.getPlayer().hasPermission("taboolib.update.notify")) {
TLocale.Logger.sendTo(e.getPlayer(), "UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(UpdateTask.getNewVersion()));
}
if (TranslateUUID.isEnabled()) {
Bukkit.getScheduler().runTaskAsynchronously(Main.getInst(), () -> TranslateUUID.updateUsername(e.getPlayer().getUniqueId(), e.getPlayer().getName()));
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
LocalizedStringImpl t
= new LocalizedStringImpl("glowstone.about._template", b);
sendBullet(sender, t, b, "glowstone.about.brand", Bukkit.getName());
sendBullet(sender, t, b, "glowstone.about.name", Bukkit.getServerName());
sendBullet(sender, t, b, "glowstone.about.version", Bukkit.getVersion());
sendBullet(sender, t, b, "glowstone.about.api-version", Bukkit.getBukkitVersion());
sendBullet(sender, t, b, "glowstone.about.players",
Bukkit.getOnlinePlayers().size());
sendBullet(sender, t, b, "glowstone.about.worlds", Bukkit.getWorlds().size());
sendBullet(sender, t, b, "glowstone.about.plugins",
Bukkit.getPluginManager().getPlugins().length);
sender.sendMessage(ChatColor.GOLD + "Glowstone command help:");
sender.sendMessage(helpForSubCommand(label, "about", "Information about this server"));
sender.sendMessage(helpForSubCommand(label, "eval <eval>", "Evaluate a reflection "
+ "string"));
sender.sendMessage(helpForSubCommand(label, "help", "Shows the help screen"));
return false;
Chunk chunk = CommandUtils.getLocation(sender).getChunk();
sender
.sendMessage(
代码示例来源:origin: eccentricdevotion/TARDIS
public static String getNick(Player player) {
if (Bukkit.getServer().getPluginManager().getPlugin("Essentials") != null) {
Essentials essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
User user = essentials.getUser(player.getUniqueId());
String prefix = essentials.getSettings().getNicknamePrefix();
return ChatColor.stripColor(user.getNick(false)).replace(prefix, "");
}
return player.getName();
}
代码示例来源:origin: eccentricdevotion/TARDIS
public static String getNick(UUID uuid) {
if (Bukkit.getServer().getPluginManager().getPlugin("Essentials") != null) {
Essentials essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
User user = essentials.getUser(uuid);
String prefix = essentials.getSettings().getNicknamePrefix();
return ChatColor.stripColor(user.getNick(false)).replace(prefix, "");
}
return Bukkit.getPlayer(uuid).getName();
}
代码示例来源:origin: EngineHub/WorldGuard
@Override
public void broadcastNotification(String message) {
Bukkit.broadcast(message, "worldguard.notify");
Set<Permissible> subs = Bukkit.getPluginManager().getPermissionSubscriptions("worldguard.notify");
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (!(subs.contains(player) && player.hasPermission("worldguard.notify")) &&
WorldGuardPlugin.inst().hasPermission(player, "worldguard.notify")) { // Make sure the player wasn't already broadcasted to.
player.sendMessage(message);
}
}
WorldGuard.logger.info(message);
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public boolean execute(CommandSender sender, String label, String[] args,
CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
Collection<String> messages =
new ArrayList<>(players.size() + 1);
messages.add(new LocalizedStringImpl("list.header", commandMessages.getResourceBundle())
.get(players.size(), Bukkit.getMaxPlayers()));
if (args.length > 0 && (Objects.equals(args[0], "uuids" /* NON-NLS */) || Objects
.equals(args[0], "ids" /* NON-NLS */))) {
LocalizedStringImpl nameAndUuidMessage = new LocalizedStringImpl("list.name-and-uuid",
commandMessages.getResourceBundle());
Bukkit.getOnlinePlayers().forEach(p -> messages.add(
nameAndUuidMessage.get(p.getName(), UuidUtils.toString(p.getUniqueId()))));
} else {
Bukkit.getOnlinePlayers().forEach(p -> messages.add(p.getName()));
}
sender.sendMessage(messages.toArray(EMPTY));
return true;
}
代码示例来源:origin: elBukkit/MagicPlugin
public static void swingOffhand(Entity entity, int range) {
int rangeSquared = range * range;
String worldName = entity.getWorld().getName();
Location center = entity.getLocation();
for (Player player : Bukkit.getOnlinePlayers()) {
if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > rangeSquared) {
continue;
}
swingOffhand(player, entity);
}
}
代码示例来源:origin: elBukkit/MagicPlugin
protected static void sendPacket(Server server, Location source, Collection<? extends Player> players, Object packet) throws Exception {
players = ((players != null && players.size() > 0) ? players : server.getOnlinePlayers());
int viewDistance = Bukkit.getServer().getViewDistance() * 16;
int viewDistanceSquared = viewDistance * viewDistance;
World sourceWorld = source.getWorld();
for (Player player : players) {
Location location = player.getLocation();
if (!location.getWorld().equals(sourceWorld)) continue;
if (location.distanceSquared(source) <= viewDistanceSquared) {
sendPacket(player, packet);
}
}
}
代码示例来源: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: NyaaCat/RPGItems-reloaded
private <TEvent extends Event, TPower extends Power, TResult, TReturn> void triggerPostFire(Player player, ItemStack itemStack, TEvent event, Trigger<TEvent, TPower, TResult, TReturn> trigger, Map<Power, PowerResult> resultMap, TReturn ret) {
RPGItemsPowersPostFireEvent<TEvent, TPower, TResult, TReturn> postFire = new RPGItemsPowersPostFireEvent<>(player, itemStack, event, this, trigger, resultMap, ret);
Bukkit.getServer().getPluginManager().callEvent(postFire);
Context.instance().cleanTemp(player.getUniqueId());
if (getItemStackDurability(itemStack).map(d -> d <= 0).orElse(false)) {
itemStack.setAmount(0);
itemStack.setType(Material.AIR);
}
}
代码示例来源:origin: Bkm016/TabooLib
@Override
public void run() {
// 载入数据
loadPlayerData(Main.getInst().getConfig().getBoolean("ENABLE-UUID") ? e.getPlayer().getUniqueId().toString() : e.getPlayer().getName());
// 载入完成
Bukkit.getPluginManager().callEvent(new PlayerLoadedEvent(e.getPlayer()));
}
}.runTaskAsynchronously(Main.getInst());
代码示例来源:origin: Bkm016/TabooLib
static void refreshPlayer(final Player player, final Player forWhom) {
Preconditions.checkState(Main.getInst().isEnabled(), "Not Enabled!");
Preconditions.checkNotNull(player, "player");
Preconditions.checkNotNull(forWhom, "forWhom");
if (player != forWhom && player.getWorld() == forWhom.getWorld() && forWhom.canSee(player)) {
forWhom.hidePlayer(player);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInst(), () -> forWhom.showPlayer(player), 2);
}
}
代码示例来源:origin: Bukkit/Bukkit
if (!testPermission(sender)) return true;
if (args.length != 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
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;
内容来源于网络,如有侵权,请联系作者删除!