本文整理匯總了Java中org.bukkit.event.player.PlayerItemConsumeEvent類的典型用法代碼示例。如果您正苦於以下問題:Java PlayerItemConsumeEvent類的具體用法?Java PlayerItemConsumeEvent怎麽用?Java PlayerItemConsumeEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PlayerItemConsumeEvent類屬於org.bukkit.event.player包,在下文中一共展示了PlayerItemConsumeEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPlayerItemConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
for (String itemString : Thirst.getInstance().getYAMLConfig().thirstQuenchingItems)
{
ThirstItem item = Thirst.getInstance().getYAMLConfig().new ThirstItem(itemString);
ItemStack is = new ItemStack(Material.valueOf(item.getItem()), 1);
//casting due to spigot api subject to change.
is.setData(new MaterialData(is.getType(), (byte) item.getMetaData()));
int quenchPercent = item.getQuenchPercent();
if (is.getType() == event.getItem().getType() && event.getItem().getData().toString().equals(is.getData().toString())) {
if (Thirst.getInstance().getYAMLConfig().itemConsumption || ThirstManager.getThirst().getPlayerThirst(event.getPlayer()) != 100)
ThirstManager.getThirst().setThirst(event.getPlayer(), ThirstManager.getThirst().getPlayerThirst(event.getPlayer()) + quenchPercent);
else {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Thirst.getInstance().getYAMLConfig().itemConsumeMessage.replace("%player%", event.getPlayer().getName())));
event.setCancelled(true);
}
}
}
}
示例2: onItemConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onItemConsume(PlayerItemConsumeEvent e){
Player p = e.getPlayer();
ItemStack item = e.getItem();
Material type = item != null ? item.getType() : Material.AIR;
int thirst = p.getLevel();
if (type == Material.POTION && item.getDurability() == 0 && p.getInventory().getItemInMainHand().isSimilar(item)){
p.getInventory().getItemInMainHand().setType(Material.AIR);
for (ItemStack i : p.getInventory().getContents()){
if (i.getType() == Material.GLASS_BOTTLE){
i.setType(Material.AIR);
}
}
p.setLevel(0);
if (thirst + 256 >= 1000){
p.setLevel(1000);
return;
}
p.setLevel(thirst + 256);
p.sendMessage(p.getLevel() + " // " + thirst + 256);
}
}
示例3: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
if(event.isCancelled()) return;
Player player = event.getPlayer();
if(event.getItem().getType() == Material.POISONOUS_POTATO)
{
for (PotionEffect effect : player.getActivePotionEffects())
player.removePotionEffect(effect.getType());
Random rand = new Random();
if(rand.nextInt(10) + 1 <= 6)
{
player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0), true);
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 0), true);
}
}
}
示例4: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
if(event.isCancelled()) return;
Player player = event.getPlayer();
if(event.getItem().getType() == Material.BEETROOT)
{
int amp = 0;
int dur = 200;
for (PotionEffect effect : player.getActivePotionEffects())
{
if(effect.getType().equals(PotionEffectType.INCREASE_DAMAGE))
{
dur += effect.getDuration();
if(dur > 600) dur = 600;
player.removePotionEffect(effect.getType());
}
}
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, dur, amp));
}
}
示例5: onPlayerItemConsumeEvent
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
Player player = event.getPlayer();
if (!WorldGuardUtils.hasBypass(player))
{
ItemMeta itemMeta = event.getItem().getItemMeta();
if (itemMeta instanceof PotionMeta)
{
WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
}
else
{
Material material = event.getItem().getType();
if (material == Material.MILK_BUCKET)
{
WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkMilk(player);
}
}
}
}
示例6: onEat
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEat(final PlayerItemConsumeEvent event) {
final PlayerStat stat = PlayerStat.FOOD_EATEN;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
final String foodName = StatzUtil.getFoodName(event.getItem());
if (foodName == null)
return;
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "foodEaten", foodName, "world",
player.getWorld().getName()));
}
示例7: onPlayerItemConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
Player player = event.getPlayer();
ItemStack item = event.getItem();
// if the item is not a potion we don't want to care.
if (item == null || item.getType() != Material.POTION) {
return;
}
// if the potion has the durability of a strength 2 potion, tell them and cancel.
if (item.getDurability() == 8233) {
player.sendMessage(ChatColor.RED + "Strength II is disabled.");
event.setCancelled(true);
}
}
示例8: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
if(e.getItem() == null){
return;
}
Player p = e.getPlayer();
//deny potion
if (p == null){
return;
}
Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
if (r != null && e.getItem().getType().equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)){
RPLang.sendMessage(p, "playerlistener.region.cantuse");
e.setCancelled(true);
}
}
示例9: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
if(e.getItem() == null){
return;
}
Player p = e.getPlayer();
Location l = p.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
//deny item usage
List<String> items = RPConfig.getGlobalFlagList(p.getWorld().getName()+".deny-item-usage.items");
if (e.getItem() != null && items.contains(e.getItem().getType().name())){
if (r != null && ((!RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && r.canBuild(p)) ||
(RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && !r.canBuild(p)))){
RPLang.sendMessage(p, "playerlistener.region.cantuse");
e.setCancelled(true);
return;
}
if (r == null && !RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-wilderness") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.world")){
RPLang.sendMessage(p, "playerlistener.region.cantuse");
e.setCancelled(true);
}
}
}
示例10: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
if(e.getItem() == null){
return;
}
Player p = e.getPlayer();
//deny potion
if (p == null){
return;
}
if(RPUtil.denyPotion(e.getItem(), p)){
e.setCancelled(true);
}
}
示例11: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.LOW)
public void onConsume(PlayerItemConsumeEvent event) {
if (ItemManager.getId(event.getItem()) == CivData.GOLDEN_APPLE) {
CivMessage.sendError(event.getPlayer(), "You cannot use golden apples.");
event.setCancelled(true);
return;
}
if (event.getItem().getType().equals(Material.POTION)) {
ConfigTechPotion pot = CivSettings.techPotions.get(Integer.valueOf(event.getItem().getDurability()));
if (pot != null) {
if (!pot.hasTechnology(event.getPlayer())) {
CivMessage.sendError(event.getPlayer(), "You cannot use "+pot.name+" potions. You do not have the technology yet.");
event.setCancelled(true);
return;
}
if (pot.hasTechnology(event.getPlayer())) {
event.setCancelled(false);
}
} else {
CivMessage.sendError(event.getPlayer(), "You cannot use this type of potion.");
event.setCancelled(true);
}
}
}
示例12: OnPlayerConsumeEvent
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void OnPlayerConsumeEvent(PlayerItemConsumeEvent event) {
ItemStack stack = event.getItem();
/* Disable notch apples */
if (ItemManager.getId(event.getItem()) == ItemManager.getId(Material.GOLDEN_APPLE)) {
if (event.getItem().getDurability() == (short)0x1) {
CivMessage.sendError(event.getPlayer(), "You cannot use notch apples. Sorry.");
event.setCancelled(true);
return;
}
}
if (stack.getType().equals(Material.POTION)) {
int effect = event.getItem().getDurability() & 0x000F;
if (effect == 0xE) {
event.setCancelled(true);
CivMessage.sendError(event.getPlayer(), "You cannot use invisibility potions for now... Sorry.");
return;
}
}
}
示例13: onPlayerItemConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
/**
* On player item consume.
*
* @param event the event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
Player player = event.getPlayer();
IPlayerConfEntry entry;
if((entry = playerConf.get(player)) != null
&& !entry.isAdminMod()) {
IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea(player.getLocation());
if (!checkPermission(land, player, PermissionList.EAT.getPermissionType())) {
messagePermission(player);
event.setCancelled(true);
}
}
}
示例14: onConsumePotion
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConsumePotion(PlayerItemConsumeEvent event) {
if (Settings.INDICATOR_ENABLE.getValue("potion")) {
if (event.getItem().getType() == Material.POTION) {
Potion potion = Potion.fromItemStack(event.getItem());
if (potion != null) {
this.showPotionHologram(event.getPlayer(), potion.getEffects());
}
} else if (event.getItem().getType() == Material.GOLDEN_APPLE) {
String msg = Settings.INDICATOR_FORMAT.getValue("potion", "goldenapple");
if (event.getItem().getDurability() == 1) {
msg = Settings.INDICATOR_FORMAT.getValue("potion", "godapple");
}
Location l = event.getPlayer().getLocation().clone();
l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, msg.replace("%effect%", "Golden Apple"));
}
}
}
示例15: onPlayerEat
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onPlayerEat(PlayerItemConsumeEvent e) {
final Player player = e.getPlayer();
ItemStack itemConsumed = e.getItem();
if (itemConsumed.isSimilar(CraftingAndRecipes.redstoneApple())) {
player.setVelocity(player.getVelocity().setY(0.4));
player.sendMessage(ChatColor.RED + "[CPU] You just got shocked by eating a redstone apple!");
player.sendMessage(ChatColor.RED + "[CPU] You can't move that well!");
CPUPlugin.bukkitScheduler.scheduleSyncDelayedTask(CPUPlugin.plugin, new BukkitRunnable() {
@Override
public void run() {
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 2000, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 2000, 4));
}
}, 60);
}
}