本文整理匯總了Java中org.bukkit.Bukkit類的典型用法代碼示例。如果您正苦於以下問題:Java Bukkit類的具體用法?Java Bukkit怎麽用?Java Bukkit使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Bukkit類屬於org.bukkit包,在下文中一共展示了Bukkit類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onLeave
import org.bukkit.Bukkit; //導入依賴的package包/類
@EventHandler
public void onLeave(PlayerQuitEvent event){
Player p = event.getPlayer();
if(Files.user.contains("Users." + p.getName())){
try{
Files.user.save(Files.users);
Files.user.load(Files.users);
}catch(IOException | InvalidConfigurationException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
if(manager.isInPvP(p)){
p.setHealth(0D);
Bukkit.broadcastMessage(Message.prefix + ChatColor.GRAY + " ¡" + ChatColor.GOLD + p.getName() + Message.leave_in_pvp);
}
}
}
示例2: mute
import org.bukkit.Bukkit; //導入依賴的package包/類
/**
* mutes a KingdomFactionsPlayer
*
* @param muted
* the KingdomFactionsPlayer who gets muted
* @param byWho
* the muter
*/
public void mute(KingdomFactionsPlayer muted, KingdomFactionsPlayer byWho) {
ChannelMuteEvent event = new ChannelMuteEvent(this, muted, byWho);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
try {
event.getChannel().setRankFor(event.getMuted(), new ListenerChannelRank());
} catch (ChannelRankException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
event.getChannel().whisperTo(event.getMuted(),
Messages.getInstance().getPrefix() + "Je kunt niet langer praten in dit chatkanaal.");
event.getChannel().whisperTo(event.getByWho(),
Messages.getInstance().getPrefix() + event.getMuted().getName() + " kan niet langer praten.");
}
}
示例3: createscrollsb
import org.bukkit.Bukkit; //導入依賴的package包/類
public static void createscrollsb(Player p, String title) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
playerScoreboard = scoreboard.registerNewObjective("sklib", "dummy"); //The name of the scoreboard is the name of the player, not that it really needs to be
playerScoreboard.setDisplayName("Placeholder"); //Will not show to the user, we just need to set this to make bukkit happy
playerScoreboard.setDisplaySlot(DisplaySlot.SIDEBAR);
p.setScoreboard(scoreboard);
new BukkitRunnable()
{
Scroller scroller = new Scroller(p, title, 16, 4, '&');
public void run()
{
playerScoreboard.setDisplayName(scroller.next(p));
}
}.runTaskTimer(Main.getInstance(), 0L, 3L); // runs every 3 ticks
}
示例4: spawn
import org.bukkit.Bukkit; //導入依賴的package包/類
public void spawn(Location location) {
final PetBlockSpawnEvent event = new PetBlockSpawnEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCanceled()) {
NMSRegistry.accessWorldGuardSpawn(location);
this.rabbit.spawn(location);
final net.minecraft.server.v1_8_R1.World mcWorld = ((org.bukkit.craftbukkit.v1_8_R1.CraftWorld) location.getWorld()).getHandle();
this.setPosition(location.getX(), location.getY(), location.getZ());
mcWorld.addEntity(this, SpawnReason.CUSTOM);
final net.minecraft.server.v1_8_R1.NBTTagCompound compound = new net.minecraft.server.v1_8_R1.NBTTagCompound();
compound.setBoolean("invulnerable", true);
compound.setBoolean("Invisible", true);
compound.setBoolean("PersistenceRequired", true);
compound.setBoolean("ShowArms", true);
compound.setBoolean("NoBasePlate", true);
this.a(compound);
((ArmorStand)this.getArmorStand()).setBodyPose(new EulerAngle(0, 0, 2878));
((ArmorStand)this.getArmorStand()).setLeftArmPose(new EulerAngle(2878, 0, 0));
((ArmorStand)this.getArmorStand()).setMetadata("keep", this.getKeepField());
NMSRegistry.rollbackWorldGuardSpawn(location);
((ArmorStand)this.getArmorStand()).setCustomNameVisible(true);
((ArmorStand)this.getArmorStand()).setCustomName(this.petMeta.getPetDisplayName());
((ArmorStand)this.getArmorStand()).setRemoveWhenFarAway(false);
((LivingEntity) this.rabbit.getEntity()).setRemoveWhenFarAway(false);
this.health = ConfigPet.getInstance().getCombat_health();
if (this.petMeta == null)
return;
PetBlockHelper.setItemConsideringAge(this);
}
}
示例5: SimpleScoreboard
import org.bukkit.Bukkit; //導入依賴的package包/類
public SimpleScoreboard(String id, Player holder) {
this.holder = holder;
// Initiate the Bukkit scoreboard
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
scoreboard.registerNewObjective(id, "dummy").setDisplaySlot(DisplaySlot.SIDEBAR);
objective = scoreboard.getObjective(DisplaySlot.SIDEBAR);
}
示例6: onPlayerLogin
import org.bukkit.Bukkit; //導入依賴的package包/類
@EventHandler
public void onPlayerLogin(PlayerLoginEvent event)
{
//Don't force if player is hided moderator
Bukkit.getScheduler().runTaskLater(pluginAPI, () -> {
if(!pluginAPI.getAPI().getJoinManager().getModeratorsExpected().contains(event.getPlayer().getUniqueId()))
{
try{
sendPlayerToAll(event.getPlayer());
sendAllToPlayer(event.getPlayer());
}catch (Exception e)
{
e.printStackTrace();
}
}
}, 5L);
}
示例7: onEnable
import org.bukkit.Bukkit; //導入依賴的package包/類
@Override
public void onEnable() {
// Copy config.yml file
saveDefaultConfig();
// Load Objects
loadObjects();
// Load online players
createAll();
// Register command and events
Bukkit.getPluginCommand("proscoreboard").setExecutor(this);
Bukkit.getPluginManager().registerEvents(this, this);
// Create task for update the scoreboards
long ticks = getConfig().getLong("Options.update-ticks");
new BukkitRunnable() {
@Override
public void run() {
updateAll();
}
}.runTaskTimer(this, ticks, ticks);
}
示例8: sendData
import org.bukkit.Bukkit; //導入依賴的package包/類
/**
* Sends the data to the bStats server.
*
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(JSONObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.write(compressedData);
outputStream.flush();
outputStream.close();
connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
示例9: captured
import org.bukkit.Bukkit; //導入依賴的package包/類
@Override
public void captured(MatchTeam matchTeam) {
Bukkit.broadcastMessage(matchTeam.getColor() + ChatColor.BOLD.toString() + matchTeam.getAlias() + ChatColor.WHITE
+ " took control of " + ChatColor.AQUA + ChatColor.BOLD.toString() + definition.getName());
kothModule.incrementPoints(matchTeam, definition.getPointsPerTick());
kothModule.updateScoreboardControlPointLine(definition);
for (MatchTeam team : match.getModule(TeamManagerModule.class).getTeams()) {
for (PlayerContext playerContext : team.getMembers()) {
if (team == matchTeam || team.isSpectator()) {
playerContext.getPlayer().playSound(playerContext.getPlayer().getLocation(), Sound.BLOCK_PORTAL_TRAVEL, 0.7f, 2f);
} else {
playerContext.getPlayer().playSound(playerContext.getPlayer().getLocation(), Sound.ENTITY_BLAZE_DEATH, 0.8f, 0.8f);
}
}
}
}
示例10: onClose
import org.bukkit.Bukkit; //導入依賴的package包/類
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onClose(InventoryCloseEvent event) {
if (!(event.getInventory().getHolder() instanceof MenuLink))
return;
final VPPlayer player = VanillaPlusCore.getPlayerManager().getPlayer((Player) event.getPlayer());
final MenuLink menu = ((MenuLink) event.getInventory().getHolder());
Bukkit.getScheduler().scheduleSyncDelayedTask(VanillaPlus.getInstance(), new Runnable() {
@Override
public void run() {
if(player.getPlayer().getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING){
menu.getIconMenu().closed(player, menu);
}else{
menu.getIconMenu().changed(player, menu);
}
}
});
}
示例11: checkPluginUpToDateAndPrintMessage
import org.bukkit.Bukkit; //導入依賴的package包/類
/**
* Checks if the given plugin version and spigot resource Id is the same by doing and webRequest and printing the result into the console
*
* @param resourceId spigot resourceId
* @param prefix prefix
* @param pluginName pluginName
* @param plugin plugin
* @throws IOException exception
*/
public static void checkPluginUpToDateAndPrintMessage(long resourceId, String prefix, String pluginName, Plugin plugin) throws IOException {
if (!isPluginUpToDate(resourceId, plugin)) {
if (plugin.getDescription().getVersion().endsWith("SNAPSHOT")) {
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + "================================================");
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + "You are using a snapshot of " + pluginName);
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + "Please check regularly if there is a new version");
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + "================================================");
} else {
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + "================================================");
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + pluginName + " is outdated");
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + "Please download the latest version from spigotmc.org");
Bukkit.getServer().getConsoleSender().sendMessage(prefix + ChatColor.YELLOW + "================================================");
}
}
}
示例12: onMatchEnd
import org.bukkit.Bukkit; //導入依賴的package包/類
@EventHandler(priority = EventPriority.LOW)
public void onMatchEnd(MatchEndEvent event) {
Match match = event.getMatch();
Tourney plugin = Tourney.get();
this.session.appendMatch(match, plugin.getMatchManager().getTeamManager().teamToEntrant(Iterables.getOnlyElement(event.getMatch().needMatchModule(VictoryMatchModule.class).winners(), null)));
Entrant winningParticipation = this.session.calculateWinner();
int matchesPlayed = this.session.getMatchesPlayed();
if (winningParticipation != null) {
Bukkit.broadcastMessage(ChatColor.YELLOW + "A winner has been determined!");
Bukkit.broadcastMessage(ChatColor.AQUA + WordUtils.capitalize(winningParticipation.team().name()) + ChatColor.RESET + ChatColor.YELLOW + " wins! Congratulations!");
plugin.clearKDMSession();
} else if (matchesPlayed < 3) {
Bukkit.broadcastMessage(ChatColor.YELLOW + "A winner has not yet been determined! Beginning match #" + (matchesPlayed + 1) + "...");
match.needMatchModule(CycleMatchModule.class).startCountdown(Duration.ofSeconds(15), session.getMap());
} else {
Bukkit.broadcastMessage(ChatColor.YELLOW + "There is a tie! Congratulations to both teams!");
Tourney.get().clearKDMSession();
}
}
示例13: onTabComplete
import org.bukkit.Bukkit; //導入依賴的package包/類
@Override
public List<String> onTabComplete(CommandSender sender, String[] args) {
if (args.length == 0 || args[0].equals("")) {
return Bukkit.getOnlinePlayers().stream().map(player -> player.getName()).collect(Collectors.toList());
} else {
ArrayList<String> returnList = new ArrayList<>();
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getName().toLowerCase().startsWith(args[0].toLowerCase())) {
returnList.add(p.getName());
}
}
return returnList;
}
}
示例14: execute
import org.bukkit.Bukkit; //導入依賴的package包/類
@Override
public void execute() {
if (this.target == null)
return;
Entity e = getEntity();
Location goal = this.target.clone();
goal.setWorld(e.getWorld());
BukkitTask[] task = new BukkitTask[1];
final double walkSpeed = e.getLocation().distance(goal) / (double) getEvent().getTickDelay();
task[0] = Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> stepLocation(e, goal, walkSpeed), 0L, 1L); // Move the entity closer every tick.
Bukkit.getScheduler().runTaskLater(Core.getInstance(), task[0]::cancel, getEvent().getTickDelay() - 1);
}
示例15: appendTo
import org.bukkit.Bukkit; //導入依賴的package包/類
@Override
public void appendTo(@Nonnull Bindings bindings) {
// provide exports to access the exports registry & core server classes
bindings.put("exports", exports);
bindings.put("server", Bukkit.getServer());
bindings.put("plugin", plugin);
bindings.put("services", Bukkit.getServicesManager());
// some util functions
bindings.put("colorize", (Function<Object, String>) HelperScriptBindings::colorize);
bindings.put("newMetadataKey", (Function<Object, MetadataKey>) HelperScriptBindings::newMetadataKey);
bindings.put("newEmptyScheme", (Supplier<MenuScheme>) HelperScriptBindings::newScheme);
bindings.put("newScheme", (Function<SchemeMapping, MenuScheme>) HelperScriptBindings::newScheme);
// some general functions for working with java collections in js
GeneralScriptBindings.appendTo(bindings);
// provide hook into the resolvePackageWildcard method below, used by the importWildcardPackage function
bindings.put("resolvePackageWildcard", (Function<String, List<String>>) HelperScriptBindings::resolvePackageWildcard);
}