Skip to content

Commit 23422b5

Browse files
committed
Fixed an issue not taking into account Player sell limits (Reported by andrewfb)
Reorganised code for clearing display entities Signed-off-by: petulikan1 <petulikan@gmail.com> Took 1 hour 52 minutes
1 parent 714c2c6 commit 23422b5

4 files changed

Lines changed: 43 additions & 33 deletions

File tree

Core/src/main/java/xzot1k/plugins/ds/DisplayShops.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.bukkit.configuration.InvalidConfigurationException;
1717
import org.bukkit.configuration.file.FileConfiguration;
1818
import org.bukkit.configuration.file.YamlConfiguration;
19+
import org.bukkit.entity.Entity;
20+
import org.bukkit.entity.EntityType;
1921
import org.bukkit.entity.Player;
2022
import org.bukkit.inventory.ItemStack;
2123
import org.bukkit.inventory.Recipe;
@@ -138,9 +140,8 @@ public void onEnable() {
138140

139141
fixConfig();
140142

141-
if (getDisplayManager() != null) {
142-
Display.ClearAllEntities();
143-
}
143+
ClearAllEntities();
144+
144145

145146
menuMap = new HashMap<>();
146147
shopMemory = new HashMap<>();
@@ -255,11 +256,37 @@ else if (isOutdated())
255256
+ getLatestVersion() + "'. You are currently running '" + getDescription().getVersion() + "'.");
256257
}
257258

259+
public static void ClearAllEntities() {
260+
for (World world : DisplayShops.getPluginInstance().getServer().getWorlds()) {
261+
for (Entity entity : world.getEntities()) {
262+
if ((entity.getType() == EntityType.ARMOR_STAND || entity.getType() == EntityType.ITEM_FRAME || entity.getType().name().endsWith("_DISPLAY"))
263+
&& (entity.hasMetadata("DisplayShops-Entity") || entity.getPersistentDataContainer().has(Display.key))) {
264+
entity.remove();
265+
}
266+
}
267+
}
268+
if(getPluginInstance().getDisplayManager()==null)
269+
return;
270+
271+
for (Map.Entry<UUID, Display> entry : DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().entrySet()) {
272+
Display display = entry.getValue();
273+
if (display.getItemHolder() != null) {display.getItemHolder().remove();}
274+
if (display.getGlass() != null) {display.getGlass().remove();}
275+
if (display.getTextDisplay() != null) {display.getTextDisplay().remove();}
276+
277+
World world = DisplayShops.getPluginInstance().getServer().getWorld(display.getShop().getBaseLocation().getWorldName());
278+
if (world != null) {
279+
world.getEntities().stream().filter(entity -> display.getEntityIds().contains(entity.getUniqueId())).forEach(Entity::remove);
280+
}
281+
}
282+
}
283+
258284
@Override
259285
public void onDisable() {
260286
getServer().getScheduler().cancelTasks(this);
261287

262-
if (getDisplayManager() != null) {Display.ClearAllEntities();}
288+
ClearAllEntities();
289+
263290

264291
if (getManager() != null) {
265292
final int[] shopSaveCount = {0};

Core/src/main/java/xzot1k/plugins/ds/core/Commands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ private void runCleanUp(CommandSender commandSender) {
14661466
if (DisplayShops.getPluginInstance().getDisplayManager() != null) {
14671467
DisplayShops.getPluginInstance().getInSightTask().setPaused(true);
14681468

1469-
Display.ClearAllEntities();
1469+
DisplayShops.ClearAllEntities();
14701470

14711471
for (Map.Entry<UUID, Display> entry : new ArrayList<>(DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().entrySet())) {
14721472
entry.getValue().delete();
@@ -1843,7 +1843,7 @@ private void runReload(CommandSender commandSender) {
18431843

18441844
// clear displays
18451845
if (getPluginInstance().getDisplayManager() != null) {
1846-
Display.ClearAllEntities();
1846+
DisplayShops.ClearAllEntities();
18471847

18481848
for (Map.Entry<UUID, Display> entry : new ArrayList<>(DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().entrySet())) {
18491849
entry.getValue().delete();

Core/src/main/java/xzot1k/plugins/ds/core/gui/MenuListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,8 @@ private void operateTransactionMenu(InventoryClickEvent e, Inventory inventory,
908908
}
909909

910910
sellableUnits = Math.min(sellableUnits, ((int) remainingLimit));
911-
} else if (shop.getGlobalSellLimit() > 0) {
912-
long remainingLimit = dataPack.getCurrentTransactionCounter(shop, false);
911+
} else if (shop.getPlayerBuyLimit() > 0) {
912+
long remainingLimit = shop.getPlayerSellLimit()-dataPack.getCurrentTransactionCounter(shop, false);
913913
if (remainingLimit <= 0) {
914914
player.closeInventory();
915915
INSTANCE.getManager().sendMessage(player, INSTANCE.getLangConfig().getString("sell-limit-exceeded"));

Core/src/main/java/xzot1k/plugins/ds/core/packets/Display.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
44
import net.md_5.bungee.api.ChatColor;
55
import org.bukkit.*;
6-
import org.bukkit.entity.*;
6+
import org.bukkit.entity.Entity;
7+
import org.bukkit.entity.ItemDisplay;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.entity.TextDisplay;
710
import org.bukkit.event.player.PlayerTeleportEvent;
811
import org.bukkit.inventory.ItemStack;
912
import org.bukkit.metadata.FixedMetadataValue;
@@ -14,7 +17,10 @@
1417
import xzot1k.plugins.ds.DisplayShops;
1518
import xzot1k.plugins.ds.api.objects.Shop;
1619

17-
import java.util.*;
20+
import java.util.ArrayList;
21+
import java.util.Collections;
22+
import java.util.List;
23+
import java.util.UUID;
1824

1925
public class Display {
2026

@@ -31,29 +37,6 @@ public Display(@NotNull Shop shop) {
3137
this.shop = shop;
3238
}
3339

34-
public static void ClearAllEntities() {
35-
for (World world : DisplayShops.getPluginInstance().getServer().getWorlds()) {
36-
for (Entity entity : world.getEntities()) {
37-
if ((entity.getType() == EntityType.ARMOR_STAND || entity.getType() == EntityType.ITEM_FRAME || entity.getType().name().endsWith("_DISPLAY"))
38-
&& (entity.hasMetadata("DisplayShops-Entity") || entity.getPersistentDataContainer().has(key))) {
39-
entity.remove();
40-
}
41-
}
42-
}
43-
44-
for (Map.Entry<UUID, Display> entry : DisplayShops.getPluginInstance().getDisplayManager().getShopDisplays().entrySet()) {
45-
Display display = entry.getValue();
46-
if (display.getItemHolder() != null) {display.getItemHolder().remove();}
47-
if (display.getGlass() != null) {display.getGlass().remove();}
48-
if (display.getTextDisplay() != null) {display.getTextDisplay().remove();}
49-
50-
World world = DisplayShops.getPluginInstance().getServer().getWorld(display.getShop().getBaseLocation().getWorldName());
51-
if (world != null) {
52-
world.getEntities().stream().filter(entity -> display.getEntityIds().contains(entity.getUniqueId())).forEach(Entity::remove);
53-
}
54-
}
55-
}
56-
5740
public void Clear() {
5841
World world = DisplayShops.getPluginInstance().getServer().getWorld(shop.getBaseLocation().getWorldName());
5942

0 commit comments

Comments
 (0)