mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-02 14:29:07 +01:00
Villager trade as valid action
Fix for leather dye actions
This commit is contained in:
parent
f72c3b37e6
commit
9a0d8a0cd6
@ -26,6 +26,7 @@ public enum ActionType {
|
||||
MMKILL("MMKill"),
|
||||
FISH("Fish"),
|
||||
CRAFT("Craft"),
|
||||
VTRADE("Villager Trade"),
|
||||
SMELT("Smelt"),
|
||||
BREW("Brew"),
|
||||
ENCHANT("Enchant"),
|
||||
|
@ -44,6 +44,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -65,7 +66,9 @@ import org.bukkit.event.inventory.BrewEvent;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
@ -113,6 +116,91 @@ public class JobsPaymentListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void villagerTradeInventoryClick(InventoryClickEvent event) {
|
||||
//disabling plugin in world
|
||||
if (event.getWhoClicked() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld()))
|
||||
return;
|
||||
// make sure plugin is enabled
|
||||
if (!this.plugin.isEnabled())
|
||||
return;
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
// If event is nothing or place, do nothing
|
||||
switch (event.getAction()) {
|
||||
case NOTHING:
|
||||
case PLACE_ONE:
|
||||
case PLACE_ALL:
|
||||
case PLACE_SOME:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (event.getInventory().getType() != InventoryType.MERCHANT)
|
||||
return;
|
||||
|
||||
if (event.getSlot() != 2)
|
||||
return;
|
||||
|
||||
if (!event.getSlotType().equals(SlotType.RESULT))
|
||||
return;
|
||||
|
||||
ItemStack resultStack = event.getCurrentItem();
|
||||
|
||||
if (resultStack == null)
|
||||
return;
|
||||
|
||||
if (!(event.getWhoClicked() instanceof Player))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
//Check if inventory is full and using shift click, possible money dupping fix
|
||||
if (player.getInventory().firstEmpty() == -1 && event.isShiftClick()) {
|
||||
player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("message.crafting.fullinventory"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||
return;
|
||||
|
||||
if (!event.isLeftClick() && !event.isRightClick())
|
||||
return;
|
||||
|
||||
// check if in creative
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative())
|
||||
return;
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
|
||||
if (jPlayer == null)
|
||||
return;
|
||||
|
||||
// Checking how much player traded
|
||||
ItemStack toCraft = event.getCurrentItem();
|
||||
ItemStack toStore = event.getCursor();
|
||||
// Make sure we are actually traded anything
|
||||
if (hasItems(toCraft))
|
||||
if (event.isShiftClick())
|
||||
schedulePostDetection(player, toCraft.clone(), jPlayer, resultStack.clone());
|
||||
else {
|
||||
// The items are stored in the cursor. Make sure there's enough space.
|
||||
if (isStackSumLegal(toCraft, toStore)) {
|
||||
int newItemsCount = toCraft.getAmount();
|
||||
while (newItemsCount >= 1) {
|
||||
newItemsCount--;
|
||||
if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName())
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(ChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.VTRADE));
|
||||
else
|
||||
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.VTRADE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCowMilking(PlayerInteractEntityEvent event) {
|
||||
//disabling plugin in world
|
||||
@ -249,7 +337,7 @@ public class JobsPaymentListener implements Listener {
|
||||
Player player = jPlayer.getPlayer();
|
||||
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||
return;
|
||||
return;
|
||||
|
||||
ItemStack contents = event.getContents().getIngredient();
|
||||
|
||||
@ -258,7 +346,7 @@ public class JobsPaymentListener implements Listener {
|
||||
|
||||
Jobs.action(jPlayer, new ItemActionInfo(contents, ActionType.BREW));
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
//disabling plugin in world
|
||||
@ -279,7 +367,7 @@ public class JobsPaymentListener implements Listener {
|
||||
return;
|
||||
|
||||
// check if in creative
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative())
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative())
|
||||
return;
|
||||
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||
@ -421,7 +509,7 @@ public class JobsPaymentListener implements Listener {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({ "deprecation", "incomplete-switch" })
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryCraft(CraftItemEvent event) {
|
||||
//disabling plugin in world
|
||||
@ -485,10 +573,12 @@ public class JobsPaymentListener implements Listener {
|
||||
for (int i = 0; i < sourceItems.length; i++) {
|
||||
if (sourceItems[i] == null)
|
||||
continue;
|
||||
|
||||
if (CMIMaterial.isDye(sourceItems[i].getType()))
|
||||
DyeStack.add(sourceItems[i]);
|
||||
|
||||
int id = sourceItems[i].getType().getId();
|
||||
if (id > 0) {
|
||||
if (id == 351)
|
||||
DyeStack.add(sourceItems[i]);
|
||||
y++;
|
||||
if (y == 0)
|
||||
first = id;
|
||||
@ -498,14 +588,13 @@ public class JobsPaymentListener implements Listener {
|
||||
third = id;
|
||||
}
|
||||
|
||||
if (id == 299)
|
||||
leather = true;
|
||||
if (id == 300)
|
||||
leather = true;
|
||||
if (id == 301)
|
||||
leather = true;
|
||||
if (id == 298)
|
||||
switch (CMIMaterial.get(sourceItems[i])) {
|
||||
case LEATHER_BOOTS:
|
||||
case LEATHER_CHESTPLATE:
|
||||
case LEATHER_HELMET:
|
||||
case LEATHER_LEGGINGS:
|
||||
leather = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (jPlayer == null)
|
||||
@ -520,7 +609,7 @@ public class JobsPaymentListener implements Listener {
|
||||
|
||||
// Check Dyes
|
||||
if (y >= 2) {
|
||||
if ((third == 351 || second == 351) && leather) {
|
||||
if ((CMIMaterial.get(third).isDye() || CMIMaterial.get(second).isDye()) && leather) {
|
||||
Jobs.action(jPlayer, new ItemActionInfo(sourceItems[0], ActionType.DYE));
|
||||
for (ItemStack OneDye : DyeStack) {
|
||||
Jobs.action(jPlayer, new ItemActionInfo(OneDye, ActionType.DYE));
|
||||
|
Loading…
Reference in New Issue
Block a user