Skip to content

Commit 1b6e8b7

Browse files
committed
Fixed hopper update bug
1 parent c65036a commit 1b6e8b7

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/main/java/org/maxgamer/quickshop/listener/BlockListener.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.bukkit.event.block.BlockPlaceEvent;
3737
import org.bukkit.event.block.SignChangeEvent;
3838
import org.bukkit.event.inventory.InventoryMoveItemEvent;
39-
import org.bukkit.inventory.Inventory;
4039
import org.jetbrains.annotations.NotNull;
4140
import org.jetbrains.annotations.Nullable;
4241
import org.maxgamer.quickshop.Cache;
@@ -60,6 +59,7 @@ public class BlockListener extends AbstractProtectionListener {
6059

6160
public BlockListener(@NotNull final QuickShop plugin, @Nullable final Cache cache) {
6261
super(plugin, cache);
62+
init();
6363
}
6464

6565
private void init() {
@@ -169,20 +169,36 @@ private Shop getShopNextTo(@NotNull Location loc) {
169169
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
170170
public void onInventoryMove(InventoryMoveItemEvent event) {
171171
if (!this.update_sign_when_inventory_moving) {
172+
Util.debugLog("Sign update was disabled");
172173
return;
173174
}
174175

175-
final Inventory inventory = event.getDestination();
176-
final Location location = inventory.getLocation();
177-
178-
if (location == null) {
179-
return;
176+
Location destination = event.getDestination().getLocation();
177+
Location source = event.getSource().getLocation();
178+
Shop destShop = null;
179+
Shop sourceShop = null;
180+
if (destination != null) {
181+
destination = Util.getBlockLocation(destination);
182+
Util.debugLog("Destination found: " + destination);
183+
destShop = getShopPlayer(destination, true);
184+
}
185+
if (source != null) {
186+
source = Util.getBlockLocation(source);
187+
Util.debugLog("Source found: " + destination);
188+
sourceShop = getShopPlayer(source, true);
180189
}
181190

182-
// Delayed task. Event triggers when item is moved, not when it is received.
183-
final Shop shop = getShopRedstone(location, true);
184-
if (shop != null) {
185-
super.getPlugin().getSignUpdateWatcher().scheduleSignUpdate(shop);
191+
if (destShop != null) {
192+
Util.debugLog("Destination shop found: " + destShop);
193+
super.getPlugin().getSignUpdateWatcher().scheduleSignUpdate(destShop);
194+
} else {
195+
Util.debugLog("Destination shop not found.");
196+
}
197+
if (sourceShop != null) {
198+
Util.debugLog("Source shop found: " + sourceShop);
199+
super.getPlugin().getSignUpdateWatcher().scheduleSignUpdate(sourceShop);
200+
} else {
201+
Util.debugLog("Source shop not found.");
186202
}
187203
}
188204

src/main/java/org/maxgamer/quickshop/util/Util.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,4 +1330,19 @@ public static String createRegexFromGlob(@NotNull String glob) {
13301330
return out.toString();
13311331
}
13321332

1333+
/**
1334+
* Get location that converted to block position (.0)
1335+
*
1336+
* @param loc location
1337+
* @return blocked location
1338+
*/
1339+
@NotNull
1340+
public static Location getBlockLocation(@NotNull Location loc) {
1341+
loc = loc.clone();
1342+
loc.setX(loc.getBlockX());
1343+
loc.setY(loc.getBlockY());
1344+
loc.setZ(loc.getBlockZ());
1345+
return loc;
1346+
}
1347+
13331348
}

0 commit comments

Comments
 (0)