Revert "Async shop creation"

This reverts commit 80626e823f.

It doesn't seem like a good idea to create 1000+ threads
(even if just for a minute)
This commit is contained in:
Eric 2018-07-31 11:47:46 +02:00
parent 80626e823f
commit 1a3641a377
4 changed files with 36 additions and 45 deletions

View File

@ -73,6 +73,9 @@ public class ChestProtectListener implements Listener {
public void onResult(Void result) { public void onResult(Void result) {
newShop.create(true); newShop.create(true);
shopUtils.addShop(newShop, true); shopUtils.addShop(newShop, true);
for (Player player : shop.getLocation().getWorld().getPlayers()) {
shopUtils.updateShops(player, true);
}
} }
}); });
} else { } else {
@ -268,6 +271,9 @@ public class ChestProtectListener implements Listener {
newShop.create(true); newShop.create(true);
shopUtils.addShop(newShop, true); shopUtils.addShop(newShop, true);
plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
for (Player player : shop.getLocation().getWorld().getPlayers()) {
shopUtils.updateShops(player, true);
}
} }
}); });
} else { } else {

View File

@ -769,6 +769,11 @@ public class ShopInteractListener implements Listener {
} else { } else {
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_CREATED, placeholder)); executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_CREATED, placeholder));
} }
// next update will display the new shop
for (Player player : location.getWorld().getPlayers()) {
plugin.getShopUtils().resetPlayerLocation(player);
}
} }
/** /**

View File

@ -10,8 +10,6 @@ import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.nms.Hologram;
import de.epiceric.shopchest.utils.ItemUtils; import de.epiceric.shopchest.utils.ItemUtils;
import de.epiceric.shopchest.utils.Utils; import de.epiceric.shopchest.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -21,10 +19,8 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest; import org.bukkit.block.DoubleChest;
import org.bukkit.block.data.Directional; import org.bukkit.block.data.Directional;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.*; import java.util.*;
@ -113,14 +109,8 @@ public class Shop {
return false; return false;
} }
new BukkitRunnable() { if (hologram == null || !hologram.exists()) createHologram();
@Override if (item == null) createItem();
public void run() {
if (hologram == null || !hologram.exists()) {
createHologram();
}
}
}.runTaskAsynchronously(plugin);
created = true; created = true;
return true; return true;
@ -162,13 +152,6 @@ public class Shop {
itemStack.setAmount(1); itemStack.setAmount(1);
item = new ShopItem(plugin, itemStack, itemLocation); item = new ShopItem(plugin, itemStack, itemLocation);
// Shop done loading, update shops for everyone
plugin.getUpdater().beforeNext(() -> {
for (Player player : location.getWorld().getPlayers()) {
plugin.getShopUtils().resetPlayerLocation(player);
}
});
} }
} }
@ -205,18 +188,10 @@ public class Shop {
face = ((Directional) chests[0].getBlockData()).getFacing(); face = ((Directional) chests[0].getBlockData()).getFacing();
} }
final String[] holoText = getHologramText(); String[] holoText = getHologramText();
final Location holoLocation = getHologramLocation(doubleChest, chests, face); Location holoLocation = getHologramLocation(doubleChest, chests, face);
new BukkitRunnable(){
@Override
public void run() {
// Create hologram synchronously because the
// constructor is modifying world lists
hologram = new Hologram(plugin, holoText, holoLocation); hologram = new Hologram(plugin, holoText, holoLocation);
if (item == null) createItem();
}
}.runTask(plugin);
} }
/** /**
@ -304,40 +279,41 @@ public class Shop {
} }
private Location getHologramLocation(boolean doubleChest, Chest[] chests, BlockFace face) { private Location getHologramLocation(boolean doubleChest, Chest[] chests, BlockFace face) {
World w = location.getWorld(); Block b = location.getBlock();
int x = location.getBlockX(); Location holoLocation;
int y = location.getBlockY();
int z = location.getBlockZ();
Location holoLocation = new Location(w, x, y, z); World w = b.getWorld();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
double deltaY = -0.6; double subtractY = 0.6;
if (Config.hologramFixedBottom) deltaY = -0.85; if (Config.hologramFixedBottom) subtractY = 0.85;
if (doubleChest) { if (doubleChest) {
Chest c1 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[1] : chests[0]; Chest c1 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[1] : chests[0];
Chest c2 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[0] : chests[1]; Chest c2 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[0] : chests[1];
if (holoLocation.equals(c1.getLocation())) { if (b.getLocation().equals(c1.getLocation())) {
if (c1.getX() != c2.getX()) { if (c1.getX() != c2.getX()) {
holoLocation.add(0, deltaY, 0.5); holoLocation = new Location(w, x, y - subtractY, z + 0.5);
} else if (c1.getZ() != c2.getZ()) { } else if (c1.getZ() != c2.getZ()) {
holoLocation.add(0.5, deltaY, 0); holoLocation = new Location(w, x + 0.5, y - subtractY, z);
} else { } else {
holoLocation.add(0.5, deltaY, 0.5); holoLocation = new Location(w, x + 0.5, y - subtractY, z + 0.5);
} }
} else { } else {
if (c1.getX() != c2.getX()) { if (c1.getX() != c2.getX()) {
holoLocation.add(1, deltaY, 0.5); holoLocation = new Location(w, x + 1, y - subtractY, z + 0.5);
} else if (c1.getZ() != c2.getZ()) { } else if (c1.getZ() != c2.getZ()) {
holoLocation.add(0.5, deltaY, 1); holoLocation = new Location(w, x + 0.5, y - subtractY, z + 1);
} else { } else {
holoLocation.add(0.5, deltaY, 0.5); holoLocation = new Location(w, x + 0.5, y - subtractY, z + 0.5);
} }
} }
} else { } else {
holoLocation.add(0.5, deltaY, 0.5); holoLocation = new Location(w, x + 0.5, y - subtractY, z + 0.5);
} }
holoLocation.add(0, Config.hologramLift, 0); holoLocation.add(0, Config.hologramLift, 0);

View File

@ -251,6 +251,10 @@ public class ShopUtils {
} }
} }
for (Player player : Bukkit.getOnlinePlayers()) {
updateShops(player, true);
}
if (callback != null) callback.callSyncResult(result.size()); if (callback != null) callback.callSyncResult(result.size());
} }