Browse Source

Improved handling for invalid (used/duped) coupons.

master
Stefatorus 4 years ago
parent
commit
7097df12c1
  1. 2
      ERCoupons/src/com/entryrise/coupons/Data.java
  2. 40
      ERCoupons/src/com/entryrise/coupons/listeners/CouponListener.java

2
ERCoupons/src/com/entryrise/coupons/Data.java

@ -152,7 +152,7 @@ public class Data {
long credits = data.getLong(loc, -1);
PlayerInventory pinv = p.getInventory();
if (credits == -1L) {
if (credits == -1) {
for (int i = 0; i < pinv.getSize(); ++i) {
final ItemStack itm = pinv.getItem(i);
if (itm != null) {

40
ERCoupons/src/com/entryrise/coupons/listeners/CouponListener.java

@ -4,43 +4,51 @@
package com.entryrise.coupons.listeners;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.EventPriority;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.entity.Player;
import com.entryrise.coupons.Data;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.Listener;
public class CouponListener implements Listener
{
public class CouponListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onCouponInteract(final PlayerInteractEvent e) {
public void onCouponInteract(PlayerInteractEvent e) {
final Player p = e.getPlayer();
final ItemStack itm = e.getItem();
if (e.getAction() != Action.RIGHT_CLICK_AIR) {
if (e.getAction().toString().contains("RIGHT_CLICK")) {
e.setCancelled(true);
return;
}
Data.couponAction(p, itm, true);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onGUIClick(final InventoryClickEvent e) {
final Player p = (Player)e.getWhoClicked();
public void onGUIClick(InventoryClickEvent e) {
final Player p = (Player) e.getWhoClicked();
final ItemStack itm = e.getCurrentItem();
Data.couponAction(p, itm, false);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onGUIDrag(final InventoryDragEvent e) {
final Player p = (Player)e.getWhoClicked();
public void onGUIDrag(InventoryDragEvent e) {
final Player p = (Player) e.getWhoClicked();
final ItemStack itm = e.getOldCursor();
if (Data.couponAction(p, itm, false)) {
e.setCancelled(true);
e.setCursor((ItemStack)null);
e.setCursor((ItemStack) null);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onGUIDrag(PlayerDropItemEvent e) {
if (Data.couponAction(e.getPlayer(), e.getItemDrop().getItemStack(), false)) {
e.getItemDrop().remove();
}
}
}

Loading…
Cancel
Save