本文整理匯總了Java中org.bukkit.event.player.PlayerItemConsumeEvent.setCancelled方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerItemConsumeEvent.setCancelled方法的具體用法?Java PlayerItemConsumeEvent.setCancelled怎麽用?Java PlayerItemConsumeEvent.setCancelled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.event.player.PlayerItemConsumeEvent
的用法示例。
在下文中一共展示了PlayerItemConsumeEvent.setCancelled方法的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: 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);
}
}
示例3: 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);
}
}
示例4: 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);
}
}
}
示例5: 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);
}
}
示例6: 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);
}
}
}
示例7: 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;
}
}
}
示例8: 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);
}
}
}
示例9: onPotionDrink
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onPotionDrink(PlayerItemConsumeEvent event){
if(Minigame.getCurrentMinigame()!=null){
switch(Minigame.getCurrentMinigame().getMap().getType()){
case CIRCLE_OF_BOOM:
if(Team.getTeam(event.getPlayer()).equals(Minigame.getObservers())){
event.setCancelled(true);
} else {
if(!Minigame.getCurrentMinigame().getState().equals(MatchState.STARTED)){
}
}
break;
case KEY_QUEST:
break;
case WATER_THE_MONUMENT:
break;
default:
break;
}
}
}
示例10: onPlayerConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
/**
* Checks to see if the player is attempting to drink a potion, and checks
* the potion to see if it is allowed.
*
* @param event The PlayerItemConsumeEvent involving the player.
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
if (event.getItem().getType() != Material.POTION) {
return;
}
// Check the type of potion in the player's hand
Potion potion = Potion.fromItemStack(event.getItem());
Collection<PotionEffect> effects = potion.getEffects();
for (PotionEffect e : effects) {
if (!(Util.canUsePotion(event.getPlayer(), e.getType()))) {
// If we get here, we cancel this event and all is done.
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You cannot use that potion here!");
Util.removeDisallowedEffects(event.getPlayer());
return; // We don't need to check any more.
}
}
}
示例11: onUseHealItem
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onUseHealItem(PlayerItemConsumeEvent e) {
final Player p = e.getPlayer();
if (!RUtils.isInInfectedWorld(p)) return;
final ItemStack hand = e.getItem();
if (hand == null || hand.getType() != Material.MELON || hand.getDurability() != (short) 14) return;
if (p.getMaxHealth() == p.getHealth() && p.getFoodLevel() >= 20) {
e.setCancelled(true); // don't waste medpacks - should never happen, though
return;
}
double newHealth = p.getHealth() + 8D;
int newFood = p.getFoodLevel() + 8;
if (newHealth > p.getMaxHealth()) newHealth = p.getMaxHealth();
if (newFood > 20) newFood = 20;
p.setHealth(newHealth);
p.setFoodLevel(newFood);
}
示例12: onDrinky
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onDrinky(PlayerItemConsumeEvent e) {
final Player p = e.getPlayer();
final ItemStack hand = e.getItem();
if (hand == null || hand.getType() != Material.POTION || hand.getDurability() != (short) 0 || !RUtils.isInInfectedWorld(p))
return;
PConfManager pcm = PConfManager.getPConfManager(p);
float thirst = pcm.getFloat("thirst");
if (!pcm.isSet("thirst")) thirst = 1F;
if (thirst >= 1F) {
e.setCancelled(true); // let's not waste water bottles
return;
}
thirst += Config.thirstRestorePercent / 100F;
if (thirst > 1F) thirst = 1F;
pcm.set("thirst", thirst);
pcm.set("thirstSaturation", (float) Config.thirstSaturationMax);
p.setExp(thirst);
}
示例13: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
if(!Survival.settings.getBoolean("Mechanics.Thirst.Enabled"))
{
if(event.isCancelled()) return;
Player player = event.getPlayer();
if(event.getItem().getType() == Material.BEETROOT_SOUP)
{
event.setCancelled(true);
}
}
}
示例14: onConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOWEST)
public void onConsume(PlayerItemConsumeEvent event) {
Player player = event.getPlayer();
InventoryData data = InventoryData.getData(player);
boolean canCheckFastConsume = CHECK_MANAGER.canCheckPlayer(player, CheckType.FASTCONSUME);
if (canCheckFastConsume) {
// check and cancel if we failed.
boolean cancel = FAST_CONSUME.check(player, data);
event.setCancelled(cancel);
}
}
示例15: onPlayerConsume
import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
ItemStack stack = event.getItem();
if (stack != null && stack.getType() == Material.GOLDEN_APPLE && stack.getDurability() == 1) {
Player player = event.getPlayer();
if (setCooldown(player, player.getUniqueId(), defaultCooldown, false, new Predicate<Long>() {
@Override
public boolean apply(@Nullable Long value) {
return false;
}
})) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588&e\u2588\u2588&c\u2588\u2588\u2588"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588\u2588\u2588&e\u2588&c\u2588\u2588\u2588\u2588 &6&l " + this.name + ": ")));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588 &7 Consumed"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&f\u2588&6\u2588&6\u2588\u2588&c\u2588"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588&f\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &6 Cooldown Remaining:"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &7 " + DurationFormatter.getRemaining(getRemaining(player), true, false))));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
} else {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You still have a " + getDisplayName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD
+ DurationFormatter.getRemaining(getRemaining(player), true, false) + ChatColor.RED + '.');
}
}
}