1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Villager trade as valid action

Fix for leather dye actions
This commit is contained in:
Zrips 2018-08-06 15:50:08 +03:00
parent f72c3b37e6
commit 9a0d8a0cd6
2 changed files with 104 additions and 14 deletions

View File

@ -26,6 +26,7 @@ public enum ActionType {
MMKILL("MMKill"), MMKILL("MMKill"),
FISH("Fish"), FISH("Fish"),
CRAFT("Craft"), CRAFT("Craft"),
VTRADE("Villager Trade"),
SMELT("Smelt"), SMELT("Smelt"),
BREW("Brew"), BREW("Brew"),
ENCHANT("Enchant"), ENCHANT("Enchant"),

View File

@ -44,6 +44,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; 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.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent;
@ -113,6 +116,91 @@ public class JobsPaymentListener implements Listener {
this.plugin = plugin; 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) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCowMilking(PlayerInteractEntityEvent event) { public void onCowMilking(PlayerInteractEntityEvent event) {
//disabling plugin in world //disabling plugin in world
@ -249,7 +337,7 @@ public class JobsPaymentListener implements Listener {
Player player = jPlayer.getPlayer(); Player player = jPlayer.getPlayer();
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return; return;
ItemStack contents = event.getContents().getIngredient(); ItemStack contents = event.getContents().getIngredient();
@ -258,7 +346,7 @@ public class JobsPaymentListener implements Listener {
Jobs.action(jPlayer, new ItemActionInfo(contents, ActionType.BREW)); Jobs.action(jPlayer, new ItemActionInfo(contents, ActionType.BREW));
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
//disabling plugin in world //disabling plugin in world
@ -279,7 +367,7 @@ public class JobsPaymentListener implements Listener {
return; return;
// check if in creative // check if in creative
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative()) if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative())
return; return;
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) 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) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryCraft(CraftItemEvent event) { public void onInventoryCraft(CraftItemEvent event) {
//disabling plugin in world //disabling plugin in world
@ -485,10 +573,12 @@ public class JobsPaymentListener implements Listener {
for (int i = 0; i < sourceItems.length; i++) { for (int i = 0; i < sourceItems.length; i++) {
if (sourceItems[i] == null) if (sourceItems[i] == null)
continue; continue;
if (CMIMaterial.isDye(sourceItems[i].getType()))
DyeStack.add(sourceItems[i]);
int id = sourceItems[i].getType().getId(); int id = sourceItems[i].getType().getId();
if (id > 0) { if (id > 0) {
if (id == 351)
DyeStack.add(sourceItems[i]);
y++; y++;
if (y == 0) if (y == 0)
first = id; first = id;
@ -498,14 +588,13 @@ public class JobsPaymentListener implements Listener {
third = id; third = id;
} }
if (id == 299) switch (CMIMaterial.get(sourceItems[i])) {
leather = true; case LEATHER_BOOTS:
if (id == 300) case LEATHER_CHESTPLATE:
leather = true; case LEATHER_HELMET:
if (id == 301) case LEATHER_LEGGINGS:
leather = true;
if (id == 298)
leather = true; leather = true;
}
} }
if (jPlayer == null) if (jPlayer == null)
@ -520,7 +609,7 @@ public class JobsPaymentListener implements Listener {
// Check Dyes // Check Dyes
if (y >= 2) { 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)); Jobs.action(jPlayer, new ItemActionInfo(sourceItems[0], ActionType.DYE));
for (ItemStack OneDye : DyeStack) { for (ItemStack OneDye : DyeStack) {
Jobs.action(jPlayer, new ItemActionInfo(OneDye, ActionType.DYE)); Jobs.action(jPlayer, new ItemActionInfo(OneDye, ActionType.DYE));