本文整理汇总了Java中com.wasteofplastic.askyblock.nms.NMSAbstraction类的典型用法代码示例。如果您正苦于以下问题:Java NMSAbstraction类的具体用法?Java NMSAbstraction怎么用?Java NMSAbstraction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NMSAbstraction类属于com.wasteofplastic.askyblock.nms包,在下文中一共展示了NMSAbstraction类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkVersion
import com.wasteofplastic.askyblock.nms.NMSAbstraction; //导入依赖的package包/类
/**
* Checks what version the server is running and picks the appropriate NMS handler, or fallback
* @return NMSAbstraction class
* @throws ClassNotFoundException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
public static NMSAbstraction checkVersion() throws ClassNotFoundException, IllegalArgumentException,
SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
String serverPackageName = Bukkit.getServer().getClass().getPackage().getName();
String pluginPackageName = ASkyBlock.getPlugin().getClass().getPackage().getName();
String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1);
Class<?> clazz;
try {
//plugin.getLogger().info("Trying " + pluginPackageName + ".nms." + version + ".NMSHandler");
clazz = Class.forName(pluginPackageName + ".nms." + version + ".NMSHandler");
} catch (Exception e) {
Bukkit.getLogger().info("No NMS Handler found for " + version + ", falling back to Bukkit API.");
clazz = Class.forName(pluginPackageName + ".nms.fallback.NMSHandler");
}
//plugin.getLogger().info("DEBUG: " + serverPackageName);
//plugin.getLogger().info("DEBUG: " + pluginPackageName);
// Check if we have a NMSAbstraction implementing class at that location.
if (NMSAbstraction.class.isAssignableFrom(clazz)) {
return (NMSAbstraction) clazz.getConstructor().newInstance();
} else {
throw new IllegalStateException("Class " + clazz.getName() + " does not implement NMSAbstraction");
}
}
示例2: onWaterBottleDrink
import com.wasteofplastic.askyblock.nms.NMSAbstraction; //导入依赖的package包/类
/**
* Checks to see if a player is drinking acid
*
* @param e
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onWaterBottleDrink(final PlayerItemConsumeEvent e) {
if (Settings.acidDamage == 0D || !Settings.acidBottle)
return;
if (DEBUG)
plugin.getLogger().info("DEBUG: " + e.getEventName());
if (e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName) && e.getItem().getType().equals(Material.POTION)) {
if (DEBUG)
plugin.getLogger().info(e.getEventName() + " called for " + e.getItem().getType());
NMSAbstraction nms = null;
try {
nms = Util.checkVersion();
} catch (Exception ex) {
return;
}
if (!nms.isPotion(e.getItem())) {
plugin.getLogger().info(e.getPlayer().getName() + " " + plugin.myLocale().drankAcidAndDied);
if (!Settings.muteDeathMessages) {
for (Player p : plugin.getServer().getOnlinePlayers()) {
Util.sendMessage(p, e.getPlayer().getName() + " " + plugin.myLocale(p.getUniqueId()).drankAcid);
}
}
final ItemStack item = new ItemStack(Material.GLASS_BOTTLE);
e.getPlayer().setItemInHand(item);
e.getPlayer().setHealth(0D);
e.setCancelled(true);
}
}
}
示例3: paste
import com.wasteofplastic.askyblock.nms.NMSAbstraction; //导入依赖的package包/类
/**
* Paste this block at blockLoc
* @param nms
* @param blockLoc
*/
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
// Only paste air if it is below the sea level and in the overworld
Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
block.setBiome(biome);
nms.setBlockSuperFast(block, typeId, data, usePhysics);
if (signText != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Sign
Sign sign = (Sign) block.getState();
int index = 0;
for (String line : signText) {
sign.setLine(index++, line);
}
sign.update(true, false);
} else if (banner != null) {
banner.set(block);
} else if (skull != null){
skull.set(block);
} else if (pot != null){
pot.set(nms, block);
} else if (spawnerBlockType != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
CreatureSpawner cs = (CreatureSpawner)block.getState();
cs.setSpawnedType(spawnerBlockType);
//Bukkit.getLogger().info("DEBUG: setting spawner");
cs.update(true, false);
} else if (!chestContents.isEmpty()) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
//Bukkit.getLogger().info("DEBUG: inventory holder "+ block.getType());
// Check if this is a double chest
InventoryHolder chestBlock = (InventoryHolder) block.getState();
//InventoryHolder iH = chestBlock.getInventory().getHolder();
if (chestBlock instanceof DoubleChest) {
//Bukkit.getLogger().info("DEBUG: double chest");
DoubleChest doubleChest = (DoubleChest) chestBlock;
for (ItemStack chestItem: chestContents.values()) {
doubleChest.getInventory().addItem(chestItem);
}
} else {
// Single chest
for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
//Bukkit.getLogger().info("DEBUG: " + en.getKey() + "," + en.getValue());
chestBlock.getInventory().setItem(en.getKey(), en.getValue());
}
}
}
}
示例4: set
import com.wasteofplastic.askyblock.nms.NMSAbstraction; //导入依赖的package包/类
public boolean set(NMSAbstraction nms, Block block) {
if(potItem != Material.AIR){
nms.setFlowerPotBlock(block, new ItemStack(potItem, 1,(short) potItemData));
}
return true;
}
示例5: onWaterBottleFill
import com.wasteofplastic.askyblock.nms.NMSAbstraction; //导入依赖的package包/类
/**
* Event that covers filling a bottle
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onWaterBottleFill(final PlayerInteractEvent e) {
if (DEBUG)
plugin.getLogger().info("DEBUG: " + e.getEventName());
Player player = e.getPlayer();
if (!player.getWorld().getName().equalsIgnoreCase(Settings.worldName))
return;
if (Settings.acidDamage == 0D || !Settings.acidBottle)
return;
if (!player.getItemInHand().getType().equals(Material.GLASS_BOTTLE)) {
return;
}
// plugin.getLogger().info(e.getEventName() + " called");
// Look at what the player was looking at
BlockIterator iter = new BlockIterator(player, 10);
Block lastBlock = iter.next();
while (iter.hasNext()) {
lastBlock = iter.next();
if (lastBlock.getType() == Material.AIR)
continue;
break;
}
// plugin.getLogger().info(lastBlock.getType().toString());
if (lastBlock.getType().equals(Material.WATER) || lastBlock.getType().equals(Material.STATIONARY_WATER)
|| lastBlock.getType().equals(Material.CAULDRON)) {
// They *may* have filled a bottle with water
// Check inventory for POTIONS in a tick
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
// plugin.getLogger().info("Checking inventory");
PlayerInventory inv = e.getPlayer().getInventory();
if (inv.contains(Material.POTION)) {
// plugin.getLogger().info("POTION in inventory");
// They have a POTION of some kind in inventory
int i = 0;
for (ItemStack item : inv.getContents()) {
if (item != null) {
// plugin.getLogger().info(i + ":" +
// item.getType().toString());
if (item.getType().equals(Material.POTION)) {
NMSAbstraction nms = null;
try {
nms = Util.checkVersion();
} catch (Exception ex) {
return;
}
if (!nms.isPotion(item)) {
// plugin.getLogger().info("Water bottle found!");
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBottle);
// ArrayList<String> lore = new
// ArrayList<String>(Arrays.asList("Poison",
// "Beware!", "Do not drink!"));
meta.setLore(lore);
item.setItemMeta(meta);
inv.setItem(i, item);
}
}
}
i++;
}
}
}
});
}
}