下面列出了怎么用org.bukkit.craftbukkit.CraftServer的API类实例代码及写法,或者点击链接到github查看源代码。
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityPlayer who, int clickedX, int clickedY, int clickedZ, EnumFacing clickedFace, ItemStack itemstack, net.minecraft.item.Item item) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);
PlayerEvent event = null;
if (isFilling) {
event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
} else {
event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
}
craftServer.getPluginManager().callEvent(event);
return event;
}
private ICommandSender getListener(CommandSender sender) {
if (sender instanceof Player) {
return ((CraftPlayer) sender).getHandle();
}
if (sender instanceof BlockCommandSender) {
return ((CraftBlockCommandSender) sender).getTileEntity();
}
if (sender instanceof CommandMinecart) {
return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlockLogic();
}
if (sender instanceof RemoteConsoleCommandSender) {
return ((DedicatedServer) MinecraftServer.getServerCB()).rconConsoleSource;
}
if (sender instanceof ConsoleCommandSender) {
return ((CraftServer) sender.getServer()).getServer();
}
if (sender instanceof ProxiedCommandSender) {
return ((ProxiedNativeCommandSender) sender).getHandle();
}
if (sender instanceof CraftFunctionCommandSender) {
return ((CraftFunctionCommandSender) sender).getHandle();
}
throw new IllegalArgumentException("Cannot make " + sender + " a vanilla command listener");
}
@SuppressWarnings("unchecked")
public SimpleHelpMap(CraftServer server) {
this.helpTopics = new TreeMap<String, HelpTopic>(HelpTopicComparator.topicNameComparatorInstance()); // Using a TreeMap for its explicit sorting on key
this.topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>();
this.server = server;
this.yaml = new HelpYamlReader(server);
Predicate indexFilter = Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class));
if (!yaml.commandTopicsInMasterIndex()) {
indexFilter = Predicates.and(indexFilter, Predicates.not(new IsCommandTopicPredicate()));
}
this.defaultTopic = new IndexHelpTopic("Index", null, null, Collections2.filter(helpTopics.values(), indexFilter), "Use /help [n] to get page n of help.");
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
}
private net.minecraft.command.ICommandSender getListener(CommandSender sender) {
if (sender instanceof Player) {
return ((CraftPlayer) sender).getHandle();
}
if (sender instanceof BlockCommandSender) {
return ((CraftBlockCommandSender) sender).getTileEntity();
}
if (sender instanceof CommandMinecart) {
return ((net.minecraft.entity.EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).func_145822_e();
}
if (sender instanceof RemoteConsoleCommandSender) {
return net.minecraft.network.rcon.RConConsoleSource.instance;
}
if (sender instanceof ConsoleCommandSender) {
return ((CraftServer) sender.getServer()).getServer();
}
return null;
}
@SuppressWarnings("unchecked")
public SimpleHelpMap(CraftServer server) {
this.helpTopics = new TreeMap<String, HelpTopic>(HelpTopicComparator.topicNameComparatorInstance()); // Using a TreeMap for its explicit sorting on key
this.topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>();
this.server = server;
this.yaml = new HelpYamlReader(server);
Predicate indexFilter = Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class));
if (!yaml.commandTopicsInMasterIndex()) {
indexFilter = Predicates.and(indexFilter, Predicates.not(new IsCommandTopicPredicate()));
}
this.defaultTopic = new IndexHelpTopic("Index", null, null, Collections2.filter(helpTopics.values(), indexFilter), "Use /help [n] to get page n of help.");
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
}
public CraftLivingEntity(final CraftServer server, final net.minecraft.entity.EntityLivingBase entity) {
super(server, entity);
// Cauldron start
this.entityClass = entity.getClass();
this.entityName = EntityRegistry.getCustomEntityTypeName(entityClass);
if (entityName == null)
entityName = entity.getCommandSenderName();
// Cauldron end
if (entity instanceof net.minecraft.entity.EntityLiving) {
equipment = new CraftEntityEquipment(this);
}
}
public static net.minecraft.inventory.Container callInventoryOpenEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.inventory.Container container, boolean closeInv) {
if (player.openContainer != player.inventoryContainer && closeInv) { // fire INVENTORY_CLOSE if one already open
// Cauldron end
player.playerNetServerHandler.processCloseWindow(new net.minecraft.network.play.client.C0DPacketCloseWindow(player.openContainer.windowId));
}
CraftServer server = player.worldObj.getServer();
CraftPlayer craftPlayer = player.getBukkitEntity();
// Cauldron start - vanilla compatibility
try {
player.openContainer.transferTo(container, craftPlayer);
}
catch (AbstractMethodError e) {
// do nothing
}
// Cauldron end
InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
if (container.getBukkitView() != null) server.getPluginManager().callEvent(event); // Cauldron - allow vanilla mods to bypass
if (event.isCancelled()) {
container.transferTo(player.openContainer, craftPlayer);
// Cauldron start - handle close for modded containers
if (!closeInv) { // fire INVENTORY_CLOSE if one already open
player.openContainer = container; // make sure the right container is processed
player.closeScreen();
player.openContainer = player.inventoryContainer;
}
// Cauldron end
return null;
}
return container;
}
public CraftCaveSpider(CraftServer server, EntityCaveSpider entity) {
super(server, entity);
}
public CraftTameableAnimal(CraftServer server, net.minecraft.entity.passive.EntityTameable entity) {
super(server, entity);
}
public CraftMinecartChest(CraftServer server, EntityMinecartChest entity) {
super(server, entity);
inventory = new CraftInventory(entity);
}
public CraftTippedArrow(CraftServer server, EntityTippedArrow entity) {
super(server, entity);
}
public CraftMinecartFurnace(CraftServer server, net.minecraft.entity.item.EntityMinecartFurnace entity) {
super(server, entity);
}
public CraftCustomProjectile(CraftServer server, Entity entity) {
super(server, entity);
}
public CraftSnowman(CraftServer server, EntitySnowman entity) {
super(server, entity);
}
public CraftSkeleton(CraftServer server, net.minecraft.entity.monster.EntitySkeleton entity) {
super(server, entity);
}
public CraftAreaEffectCloud(CraftServer server, EntityAreaEffectCloud entity) {
super(server, entity);
}
public CraftEnderDragon(CraftServer server, EntityDragon entity) {
super(server, entity);
}
public CraftPainting(CraftServer server, net.minecraft.entity.item.EntityPainting entity) {
super(server, entity);
}
public CraftFish(CraftServer server, EntityFishHook entity) {
super(server, entity);
}
CraftMinecartMobSpawner(CraftServer server, net.minecraft.entity.ai.EntityMinecartMobSpawner entity) {
super(server, entity);
}
public CraftVillager(CraftServer server, net.minecraft.entity.passive.EntityVillager entity) {
super(server, entity);
}
CraftMinecartHopper(CraftServer server, EntityMinecartHopper entity) {
super(server, entity);
inventory = new CraftInventory(entity);
}
public CraftSplashPotion(CraftServer server, EntityPotion entity) {
super(server, entity);
}
public CraftEgg(CraftServer server, EntityEgg entity) {
super(server, entity);
}
public CraftSkeletonHorse(CraftServer server, EntitySkeletonHorse entity) {
super(server, entity);
}
public CraftAmbient(CraftServer server, EntityAmbientCreature entity) {
super(server, entity);
}
public CraftExperienceOrb(CraftServer server, EntityXPOrb entity) {
super(server, entity);
}
public CraftVehicle(CraftServer server, net.minecraft.entity.Entity entity) {
super(server, entity);
}
public CraftWaterMob(CraftServer server, net.minecraft.entity.passive.EntityWaterMob entity) {
super(server, entity);
}
public CraftVindicator(CraftServer server, EntityVindicator entity) {
super(server, entity);
}