org.bukkit.event.player.PlayerShearEntityEvent Java Examples
The following examples show how to use
org.bukkit.event.player.PlayerShearEntityEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShearObjective.java From BetonQuest with GNU General Public License v3.0 | 7 votes |
@EventHandler(ignoreCancelled = true) public void onShear(PlayerShearEntityEvent event) { if (event.getEntity().getType() != EntityType.SHEEP) return; String playerID = PlayerConverter.getID(event.getPlayer()); if (!containsPlayer(playerID)) return; if (name != null && (event.getEntity().getCustomName() == null || !event.getEntity().getCustomName().equals(name))) return; if (color != null && !((Sheep) event.getEntity()).getColor().toString().equalsIgnoreCase(color)) return; SheepData data = (SheepData) dataMap.get(playerID); if (checkConditions(playerID)) { data.shearSheep(); // complete quest or notify if (data.getAmount() <= 0) completeObjective(playerID); else if (notify && data.getAmount() % notifyInterval == 0) Config.sendNotify(playerID, "sheep_to_shear", new String[]{String.valueOf(data.getAmount())}, "sheep_to_shear,info"); } }
Example #2
Source File: ShearingTaskType.java From Quests with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onShear(PlayerShearEntityEvent event) { if (!(event.getEntity() instanceof Sheep)) { return; } Player player = event.getPlayer(); QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true); QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); for (Quest quest : super.getRegisteredQuests()) { if (questProgressFile.hasStartedQuest(quest)) { QuestProgress questProgress = questProgressFile.getQuestProgress(quest); for (Task task : quest.getTasksOfType(super.getType())) { TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); if (taskProgress.isCompleted()) { continue; } int sheepNeeded = (int) task.getConfigValue("amount"); int progressSheared; if (taskProgress.getProgress() == null) { progressSheared = 0; } else { progressSheared = (int) taskProgress.getProgress(); } taskProgress.setProgress(progressSheared + 1); if (((int) taskProgress.getProgress()) >= sheepNeeded) { taskProgress.setCompleted(true); } } } } }
Example #3
Source File: CustomItemShearEntity.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onCustomItemShearEntity(CustomItemShearEntityEvent customEvent) { if (customEvent.isCancelled()) return; CustomItem cItem = customEvent.getCustomItem(); PlayerShearEntityEvent event = customEvent.getPlayerShearEntityEvent(); Player player = event.getPlayer(); if (cItem.getDurabilityMechanics() instanceof ShearDurability) { ItemStack item = customEvent.getCustomItemStack().getItemStack(); ShearDurability mechanics = (ShearDurability) cItem.getDurabilityMechanics(); Bukkit.getServer().getPluginManager() .callEvent(new PlayerCustomItemDamageEvent(player, item, mechanics.getShearSheep(), cItem)); } }
Example #4
Source File: PlayerShearEntity.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerShearEntity(PlayerShearEntityEvent event) { PlayerInventory inv = event.getPlayer().getInventory(); ItemStack item = inv.getItemInMainHand(); if (ItemType.getItemType(item) != ItemType.SHEARS) { item = inv.getItemInOffHand(); if (ItemType.getItemType(item) != ItemType.SHEARS) return; } if (AdditionsAPI.isCustomItem(item)) { CustomItemShearEntityEvent customEvent = new CustomItemShearEntityEvent(event, new CustomItemStack(item)); Bukkit.getServer().getPluginManager().callEvent(customEvent); } }
Example #5
Source File: GriefEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onShearEvent(PlayerShearEntityEvent event) { Player player = event.getPlayer(); if (!shearingEnabled || !plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld())) { return; // Not our concern } if (player.hasPermission("usb.mod.bypassprotection")) { return; } if (!plugin.playerIsOnIsland(player)) { event.setCancelled(true); } }
Example #6
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW) public void onShear(final PlayerShearEntityEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } if (inWorld(e.getPlayer())) { if (actionAllowed(e.getPlayer(), e.getEntity().getLocation(), SettingsFlag.SHEARING)) { return; } // Not allowed Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); e.setCancelled(true); return; } }
Example #7
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldHandleSimpleCancelableEvents() { withServiceMock(listenerService) .check(listener::onPlayerShear, PlayerShearEntityEvent.class) .check(listener::onPlayerFish, PlayerFishEvent.class) .check(listener::onPlayerBedEnter, PlayerBedEnterEvent.class) .check(listener::onPlayerDropItem, PlayerDropItemEvent.class) .check(listener::onPlayerHitPlayerEvent, EntityDamageByEntityEvent.class) .check(listener::onPlayerConsumeItem, PlayerItemConsumeEvent.class) .check(listener::onPlayerInteract, PlayerInteractEvent.class) .check(listener::onPlayerPickupItem, PlayerPickupItemEvent.class) .check(listener::onPlayerInteractEntity, PlayerInteractEntityEvent.class) .check(listener::onPlayerHeldItem, PlayerItemHeldEvent.class); }
Example #8
Source File: ShearEvent.java From StackMob-3 with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onSheepShear(PlayerShearEntityEvent event) { if(!(StackTools.hasSizeMoreThanOne(event.getEntity()))){ return; } if(event.isCancelled()){ return; } Entity oldEntity = event.getEntity(); int stackSize = StackTools.getSize(oldEntity); if(oldEntity instanceof Sheep){ Sheep sheep = (Sheep) oldEntity; ItemStack item = event.getPlayer().getInventory().getItemInMainHand(); if(sm.getLogic().doSheepShearAll(sheep, item)){ ItemTools.damageItemInHand(event.getPlayer(), stackSize); }else{ sm.getLogic().doSheepShearSingle(sheep); } } // TODO: Make method in stacklogic class for this as well. if(oldEntity instanceof MushroomCow){ if(sm.getCustomConfig().getBoolean("multiply.mooshroom-mushrooms") && ItemTools.hasEnoughDurability(event.getPlayer(), stackSize)){ // Duplicate mushrooms ItemStack mushrooms = new ItemStack(Material.RED_MUSHROOM,1); sm.getDropTools().dropDrops(mushrooms, (stackSize - 1) * 5, oldEntity.getLocation()); // Spawn separate normal cow for the rest of the stack. Entity cow = oldEntity.getWorld().spawnEntity(oldEntity.getLocation(), EntityType.COW); StackTools.setSize(cow,stackSize - 1); // Set the required damage as if done separately ItemTools.damageItemInHand(event.getPlayer(), stackSize); StackTools.removeSize(oldEntity); }else if (sm.getCustomConfig().getBoolean("divide-on.mooshroom-shear")){ Entity mushroomCow = oldEntity.getWorld().spawnEntity(oldEntity.getLocation(), EntityType.MUSHROOM_COW); StackTools.setSize(mushroomCow,stackSize - 1); StackTools.makeSingle(oldEntity); } } }
Example #9
Source File: CustomItemShearEntityEvent.java From AdditionsAPI with MIT License | 4 votes |
public CustomItemShearEntityEvent(PlayerShearEntityEvent event, CustomItemStack cStack) { super(cStack); this.playerShearEntityEvent = event; }
Example #10
Source File: CustomItemShearEntityEvent.java From AdditionsAPI with MIT License | 4 votes |
public PlayerShearEntityEvent getPlayerShearEntityEvent() { return playerShearEntityEvent; }
Example #11
Source File: SheepHandler.java From EliteMobs with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onShear(PlayerShearEntityEvent event) { if (event.getEntity() instanceof Sheep && EntityTracker.isSuperMob(event.getEntity())) { Sheep sheep = (Sheep) event.getEntity(); for (int i = 0; i < 50; i++) { sheep.getWorld().dropItem(sheep.getLocation(), woolStackRandomizer(sheep)).setVelocity(ItemDropVelocity.ItemDropVelocity()); } } }
Example #12
Source File: MushroomCowHandler.java From EliteMobs with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onShear(PlayerShearEntityEvent event) { if (event.getEntity() instanceof MushroomCow && EntityTracker.isSuperMob(event.getEntity())) { MushroomCow mushroomCow = (MushroomCow) event.getEntity(); ItemStack mushroomStack = new ItemStack(RED_MUSHROOM, 5); for (int i = 0; i < 50; i++) { mushroomCow.getWorld().dropItem(mushroomCow.getLocation(), mushroomStack).setVelocity(ItemDropVelocity.ItemDropVelocity()); } } }
Example #13
Source File: TimesShornListener.java From Statz with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onShear(final PlayerShearEntityEvent event) { final PlayerStat stat = PlayerStat.TIMES_SHORN; // Get player final Player player = event.getPlayer(); // Do general check if (!plugin.doGeneralCheck(player, stat)) return; PlayerStatSpecification specification = new TimesShornSpecification(player.getUniqueId(), 1, player.getWorld().getName()); // Update value to new stat. plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery()); }
Example #14
Source File: PlayerListener.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerShear(PlayerShearEntityEvent event) { if (listenerService.shouldCancelEvent(event)) { event.setCancelled(true); } }