Skip to content

Commit

Permalink
fixed a critical duping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercake10 committed Jun 15, 2020
1 parent 0b0f6be commit fae2ef8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Plugin/src/main/java/de/Linus122/TimeIsMoney/ATM.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
Expand All @@ -32,6 +33,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -64,6 +66,8 @@ public class ATM implements Listener, CommandExecutor {
*/
private double[] worths = new double[4];

private List<Inventory> openATMs = new ArrayList<Inventory>();

/**
* Creates a new atm instance with the {@link de.Linus122.TimeIsMoney.Main} class.
*
Expand Down Expand Up @@ -213,11 +217,16 @@ public void onInteract(PlayerInteractEvent e) {
}
}

@EventHandler
public void onClose(InventoryCloseEvent e) {
if (e.getInventory() != null)
openATMs.remove(e.getInventory());
}

@EventHandler
public void onMove(InventoryMoveItemEvent e) {
if (e.getSource() == null || e.getSource().getViewers().size() == 0 || e.getSource().getViewers().get(0).getOpenInventory() == null) return;
if (e.getSource().getViewers().get(0).getOpenInventory().getTitle() == null) return;
if (e.getSource().getViewers().get(0).getOpenInventory().getTitle().equals(CC(Main.finalconfig.getString("atm_title")))) {
if (openATMs.contains(e.getSource().getViewers().get(0).getOpenInventory().getTopInventory())) {
e.setCancelled(true);
}
}
Expand All @@ -226,10 +235,8 @@ public void onMove(InventoryMoveItemEvent e) {
@EventHandler
public void onClick(InventoryClickEvent e) {
try {
if (e == null) return;
if (e.getInventory() == null) return;
if (e.getView().getTitle() == null) return;
if (e.getView().getTitle().equals(CC(Main.finalconfig.getString("atm_title")))) {
if (e == null || e.getInventory() == null) return;
if (openATMs.contains(e.getView().getTopInventory())) {
e.setResult(Result.DENY);
Player p = (Player) e.getWhoClicked();
//e.setCancelled(true);
Expand Down Expand Up @@ -346,15 +353,16 @@ private void openGUI(Player player) {
is.setItemMeta(im);
atm_gui.setItem(8, is);


openATMs.add(atm_gui);
player.openInventory(atm_gui);
}

@EventHandler
public void onInventoryDrag(InventoryDragEvent e) {
if (e == null) return;
if (e.getInventory() == null) return;
if (e.getView().getTitle() == null) return;
if (e.getView().getTitle().equals(CC(Main.finalconfig.getString("atm_title")))) {
if (e == null || e.getInventory() == null) return;

if (openATMs.contains(e.getView().getTopInventory())) {
e.setResult(Result.DENY);
}
}
Expand Down

0 comments on commit fae2ef8

Please sign in to comment.