Split up and reorder event listeners

This commit is contained in:
PikaMug 2020-04-20 02:25:13 -04:00
parent 2aa4242800
commit 98d50f4f91
6 changed files with 353 additions and 233 deletions

View File

@ -84,8 +84,10 @@ import me.blackvein.quests.exceptions.ActionFormatException;
import me.blackvein.quests.exceptions.QuestFormatException;
import me.blackvein.quests.exceptions.StageFormatException;
import me.blackvein.quests.interfaces.ReloadCallback;
import me.blackvein.quests.listeners.BlockListener;
import me.blackvein.quests.listeners.CmdExecutor;
import me.blackvein.quests.listeners.DungeonsListener;
import me.blackvein.quests.listeners.ItemListener;
import me.blackvein.quests.listeners.NpcListener;
import me.blackvein.quests.listeners.PartiesListener;
import me.blackvein.quests.listeners.PlayerListener;
@ -119,8 +121,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
private ConversationFactory npcConversationFactory;
private QuestFactory questFactory;
private ActionFactory eventFactory;
private PlayerListener playerListener;
private BlockListener blockListener;
private ItemListener itemListener;
private NpcListener npcListener;
private PlayerListener playerListener;
private NpcEffectThread effThread;
private PlayerMoveThread moveThread;
private DungeonsListener dungeonsListener;
@ -137,12 +141,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
settings = new Settings(this);
localeQuery = new LocaleQuery(this);
localeQuery.setBukkitVersion(bukkitVersion);
playerListener = new PlayerListener(this);
effThread = new NpcEffectThread(this);
moveThread = new PlayerMoveThread(this);
blockListener = new BlockListener(this);
itemListener = new ItemListener(this);
npcListener = new NpcListener(this);
playerListener = new PlayerListener(this);
dungeonsListener = new DungeonsListener();
partiesListener = new PartiesListener();
effThread = new NpcEffectThread(this);
moveThread = new PlayerMoveThread(this);
questFactory = new QuestFactory(this);
eventFactory = new ActionFactory(this);
depends = new Dependencies(this);
@ -195,13 +201,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
.withLocalEcho(false).addConversationAbandonedListener(this);
// 10 - Register listeners
getServer().getPluginManager().registerEvents(playerListener, this);
getServer().getPluginManager().registerEvents(blockListener, this);
getServer().getPluginManager().registerEvents(itemListener, this);
if (depends.getCitizens() != null) {
getServer().getPluginManager().registerEvents(npcListener, this);
if (settings.canNpcEffects()) {
getServer().getScheduler().scheduleSyncRepeatingTask(this, effThread, 20, 20);
}
}
getServer().getPluginManager().registerEvents(playerListener, this);
if (settings.getStrictPlayerMovement() > 0) {
long ticks = settings.getStrictPlayerMovement() * 20;
getServer().getScheduler().scheduleSyncRepeatingTask(this, moveThread, ticks, ticks);
@ -333,10 +341,26 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return eventFactory;
}
public ItemListener getItemListener() {
return itemListener;
}
public NpcListener getNpcListener() {
return npcListener;
}
public PlayerListener getPlayerListener() {
return playerListener;
}
public DungeonsListener getDungeonsListener() {
return dungeonsListener;
}
public PartiesListener getPartiesListener() {
return partiesListener;
}
public DenizenTrigger getDenizenTrigger() {
return trigger;
}

View File

@ -0,0 +1,175 @@
/*******************************************************************************************************
* Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************************************/
package me.blackvein.quests.listeners;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
public class BlockListener implements Listener {
private final Quests plugin;
public BlockListener(Quests plugin) {
this.plugin = plugin;
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent evt) {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState()
.getData().toItemStack().getDurability());
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (evt.isCancelled() == false) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("breakBlock")) {
if (!evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
quester.breakBlock(quest, blockItemStack);
}
}
quester.dispatchMultiplayerEverything(quest, "breakBlock", (Quester q) -> {
if (!evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
q.breakBlock(quest, blockItemStack);
}
return null;
});
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("placeBlock")) {
for (ItemStack is : quester.getQuestData(quest).blocksPlaced) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
int index = quester.getQuestData(quest).blocksPlaced.indexOf(is);
is.setAmount(is.getAmount() - 1);
quester.getQuestData(quest).blocksPlaced.set(index, is);
}
}
}
quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> {
for (ItemStack is : q.getQuestData(quest).blocksPlaced) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
int index = q.getQuestData(quest).blocksPlaced.indexOf(is);
is.setAmount(is.getAmount() - 1);
q.getQuestData(quest).blocksPlaced.set(index, is);
}
}
return null;
});
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("cutBlock")) {
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) {
quester.cutBlock(quest, blockItemStack);
}
}
quester.dispatchMultiplayerEverything(quest, "cutBlock", (Quester q) -> {
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) {
q.cutBlock(quest, blockItemStack);
}
return null;
});
}
}
}
}
@SuppressWarnings("deprecation") // since 1.13
@EventHandler
public void onBlockDamage(BlockDamageEvent evt) {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState()
.getData().toItemStack().getDurability());
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("damageBlock")) {
quester.damageBlock(quest, blockItemStack);
}
quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> {
q.placeBlock(quest, blockItemStack);
return null;
});
}
}
}
@SuppressWarnings("deprecation") // since 1.13
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent evt) {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState()
.getData().toItemStack().getDurability());
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (evt.isCancelled() == false) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("placeBlock")) {
quester.placeBlock(quest, blockItemStack);
}
quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> {
q.placeBlock(quest, blockItemStack);
return null;
});
}
}
}
}
@SuppressWarnings("deprecation") // since 1.13
@EventHandler
public void onBlockUse(PlayerInteractEvent evt) {
EquipmentSlot e = null;
try {
e = evt.getHand();
} catch (NoSuchMethodError err) {
// Do nothing, getHand() not present pre-1.9
}
if (e == null || e.equals(EquipmentSlot.HAND)) { //If the event is fired by HAND (main hand)
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
final Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (evt.isCancelled() == false) {
final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt
.getClickedBlock().getState().getData().toItemStack().getDurability());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("useBlock")) {
quester.useBlock(quest, blockItemStack);
}
quester.dispatchMultiplayerEverything(quest, "useBlock", (Quester q) -> {
q.useBlock(quest, blockItemStack);
return null;
});
}
}
}
}
}
}
}

View File

@ -25,6 +25,7 @@ import de.erethon.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
import me.blackvein.quests.util.Lang;
public class DungeonsListener implements Listener {
@EventHandler
public void onGroupCreate(DGroupCreateEvent event) {
if (Lang.get("questDungeonsCreate").length() > 0) {

View File

@ -0,0 +1,144 @@
/*******************************************************************************************************
* Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************************************/
package me.blackvein.quests.listeners;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.inventory.ItemStack;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
public class ItemListener implements Listener {
private final Quests plugin;
public ItemListener(Quests plugin) {
this.plugin = plugin;
}
@SuppressWarnings("deprecation")
@EventHandler
public void onCraftItem(CraftItemEvent evt) {
if (evt.getWhoClicked() instanceof Player) {
if (plugin.checkQuester(evt.getWhoClicked().getUniqueId()) == false) {
final ItemStack craftedItem = getCraftedItem(evt);
Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("craftItem")) {
quester.craftItem(quest, craftedItem);
}
quester.dispatchMultiplayerEverything(quest, "craftItem", (Quester q) -> {
q.craftItem(quest, craftedItem);
return null;
});
}
}
}
}
@SuppressWarnings("deprecation")
private ItemStack getCraftedItem(CraftItemEvent evt) {
if (evt.isShiftClick()) {
ItemStack result = evt.getRecipe().getResult();
int numberOfItems = result.getAmount();
int itemsChecked = 0;
for (ItemStack item : evt.getInventory().getMatrix()) {
if (item != null && !item.getType().equals(Material.AIR)) {
if (itemsChecked == 0) {
numberOfItems = item.getAmount();
} else {
numberOfItems = Math.min(numberOfItems, item.getAmount());
itemsChecked++;
}
}
}
return new ItemStack(result.getType(), numberOfItems, result.getDurability());
}
return evt.getCurrentItem();
}
@EventHandler
public void onInventoryClick(InventoryClickEvent evt) {
if (evt.getWhoClicked() instanceof Player) {
if (evt.getInventory().getType() == InventoryType.FURNACE
|| evt.getInventory().getType().name().equals("BLAST_FURNACE")
|| evt.getInventory().getType().name().equals("SMOKER")) {
if (evt.getSlotType() == SlotType.RESULT) {
Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("smeltItem")) {
quester.smeltItem(quest, evt.getCurrentItem());
}
quester.dispatchMultiplayerEverything(quest, "smeltItem", (Quester q) -> {
q.smeltItem(quest, evt.getCurrentItem());
return null;
});
}
}
} else if (evt.getInventory().getType() == InventoryType.BREWING) {
if (evt.getSlotType() == SlotType.CRAFTING) {
Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("brewItem")) {
quester.brewItem(quest, evt.getCurrentItem());
}
quester.dispatchMultiplayerEverything(quest, "brewItem", (Quester q) -> {
q.brewItem(quest, evt.getCurrentItem());
return null;
});
}
}
}
}
}
@EventHandler
public void onEnchantItem(EnchantItemEvent evt) {
if (plugin.canUseQuests(evt.getEnchanter().getUniqueId())) {
Quester quester = plugin.getQuester(evt.getEnchanter().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("enchantItem")) {
for (Enchantment e : evt.getEnchantsToAdd().keySet()) {
quester.enchantItem(quest, e, evt.getItem().getType());
}
}
quester.dispatchMultiplayerEverything(quest, "enchantItem", (Quester q) -> {
for (Enchantment e : evt.getEnchantsToAdd().keySet()) {
q.enchantItem(quest, e, evt.getItem().getType());
}
return null;
});
}
}
}
}

View File

@ -49,8 +49,8 @@ public class NpcListener implements Listener {
private final Quests plugin;
public NpcListener(Quests newPlugin) {
plugin = newPlugin;
public NpcListener(Quests plugin) {
this.plugin = plugin;
}
@SuppressWarnings("deprecation")

View File

@ -25,7 +25,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -37,20 +36,14 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
@ -82,8 +75,8 @@ public class PlayerListener implements Listener {
private final Quests plugin;
public PlayerListener(Quests newPlugin) {
plugin = newPlugin;
public PlayerListener(Quests plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -196,19 +189,11 @@ public class PlayerListener implements Listener {
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
boolean hasObjective = false;
if (evt.isCancelled() == false) {
final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt
.getClickedBlock().getState().getData().toItemStack().getDurability());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("useBlock")) {
quester.useBlock(quest, blockItemStack);
hasObjective = true;
}
quester.dispatchMultiplayerEverything(quest, "useBlock", (Quester q) -> {
q.useBlock(quest, blockItemStack);
return null;
});
}
}
if (!hasObjective) {
@ -489,108 +474,6 @@ public class PlayerListener implements Listener {
}
}
@SuppressWarnings("deprecation") // since 1.13
@EventHandler
public void onBlockDamage(BlockDamageEvent evt) {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState()
.getData().toItemStack().getDurability());
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("damageBlock")) {
quester.damageBlock(quest, blockItemStack);
}
quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> {
q.placeBlock(quest, blockItemStack);
return null;
});
}
}
}
@SuppressWarnings("deprecation") // since 1.13
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent evt) {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState()
.getData().toItemStack().getDurability());
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (evt.isCancelled() == false) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("placeBlock")) {
quester.placeBlock(quest, blockItemStack);
}
quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> {
q.placeBlock(quest, blockItemStack);
return null;
});
}
}
}
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent evt) {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
final ItemStack blockItemStack = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState()
.getData().toItemStack().getDurability());
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (evt.isCancelled() == false) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("breakBlock")) {
if (!evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
quester.breakBlock(quest, blockItemStack);
}
}
quester.dispatchMultiplayerEverything(quest, "breakBlock", (Quester q) -> {
if (!evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
q.breakBlock(quest, blockItemStack);
}
return null;
});
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("placeBlock")) {
for (ItemStack is : quester.getQuestData(quest).blocksPlaced) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
int index = quester.getQuestData(quest).blocksPlaced.indexOf(is);
is.setAmount(is.getAmount() - 1);
quester.getQuestData(quest).blocksPlaced.set(index, is);
}
}
}
quester.dispatchMultiplayerEverything(quest, "placeBlock", (Quester q) -> {
for (ItemStack is : q.getQuestData(quest).blocksPlaced) {
if (evt.getBlock().getType().equals(is.getType()) && is.getAmount() > 0) {
int index = q.getQuestData(quest).blocksPlaced.indexOf(is);
is.setAmount(is.getAmount() - 1);
q.getQuestData(quest).blocksPlaced.set(index, is);
}
}
return null;
});
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("cutBlock")) {
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) {
quester.cutBlock(quest, blockItemStack);
}
}
quester.dispatchMultiplayerEverything(quest, "cutBlock", (Quester q) -> {
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) {
q.cutBlock(quest, blockItemStack);
}
return null;
});
}
}
}
}
@EventHandler
public void onPlayerShearEntity(PlayerShearEntityEvent evt) {
if (evt.getEntity().getType() == EntityType.SHEEP) {
@ -633,113 +516,6 @@ public class PlayerListener implements Listener {
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void onCraftItem(CraftItemEvent evt) {
if (evt.getWhoClicked() instanceof Player) {
if (plugin.checkQuester(evt.getWhoClicked().getUniqueId()) == false) {
final ItemStack craftedItem = getCraftedItem(evt);
Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("craftItem")) {
quester.craftItem(quest, craftedItem);
}
quester.dispatchMultiplayerEverything(quest, "craftItem", (Quester q) -> {
q.craftItem(quest, craftedItem);
return null;
});
}
}
}
}
@SuppressWarnings("deprecation")
private ItemStack getCraftedItem(CraftItemEvent evt) {
if (evt.isShiftClick()) {
ItemStack result = evt.getRecipe().getResult();
int numberOfItems = result.getAmount();
int itemsChecked = 0;
for (ItemStack item : evt.getInventory().getMatrix()) {
if (item != null && !item.getType().equals(Material.AIR)) {
if (itemsChecked == 0) {
numberOfItems = item.getAmount();
} else {
numberOfItems = Math.min(numberOfItems, item.getAmount());
itemsChecked++;
}
}
}
return new ItemStack(result.getType(), numberOfItems, result.getDurability());
}
return evt.getCurrentItem();
}
@EventHandler
public void onInventoryClick(InventoryClickEvent evt) {
if (evt.getWhoClicked() instanceof Player) {
if (evt.getInventory().getType() == InventoryType.FURNACE
|| evt.getInventory().getType().name().equals("BLAST_FURNACE")
|| evt.getInventory().getType().name().equals("SMOKER")) {
if (evt.getSlotType() == SlotType.RESULT) {
Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("smeltItem")) {
quester.smeltItem(quest, evt.getCurrentItem());
}
quester.dispatchMultiplayerEverything(quest, "smeltItem", (Quester q) -> {
q.smeltItem(quest, evt.getCurrentItem());
return null;
});
}
}
} else if (evt.getInventory().getType() == InventoryType.BREWING) {
if (evt.getSlotType() == SlotType.CRAFTING) {
Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("brewItem")) {
quester.brewItem(quest, evt.getCurrentItem());
}
quester.dispatchMultiplayerEverything(quest, "brewItem", (Quester q) -> {
q.brewItem(quest, evt.getCurrentItem());
return null;
});
}
}
}
}
}
@EventHandler
public void onEnchantItem(EnchantItemEvent evt) {
if (plugin.canUseQuests(evt.getEnchanter().getUniqueId())) {
Quester quester = plugin.getQuester(evt.getEnchanter().getUniqueId());
for (Quest quest : plugin.getQuests()) {
if (quester.getCurrentQuests().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective("enchantItem")) {
for (Enchantment e : evt.getEnchantsToAdd().keySet()) {
quester.enchantItem(quest, e, evt.getItem().getType());
}
}
quester.dispatchMultiplayerEverything(quest, "enchantItem", (Quester q) -> {
for (Enchantment e : evt.getEnchantsToAdd().keySet()) {
q.enchantItem(quest, e, evt.getItem().getType());
}
return null;
});
}
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent evt) {
if (evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {