mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Fixed a few issues with holograms
This commit is contained in:
parent
e1f076bfcd
commit
cb8eb29112
@ -20,10 +20,11 @@ public class HologramFormat {
|
||||
}
|
||||
|
||||
private ShopChest plugin;
|
||||
private File configFile;
|
||||
private YamlConfiguration config;
|
||||
|
||||
public HologramFormat(ShopChest plugin) {
|
||||
File configFile = new File(plugin.getDataFolder(), "hologram-format.yml");
|
||||
this.configFile = new File(plugin.getDataFolder(), "hologram-format.yml");
|
||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -48,14 +49,12 @@ public class HologramFormat {
|
||||
for (String sReq : requirements) {
|
||||
for (Requirement req : values.keySet()) {
|
||||
if (sReq.contains(req.toString())) {
|
||||
if (!sReq.replace(req.toString(), "").trim().isEmpty()) {
|
||||
if (!eval(sReq, values)) {
|
||||
continue optionLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
@ -63,6 +62,10 @@ public class HologramFormat {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
/** Returns whether the hologram text has to change dynamically without reloading */
|
||||
public boolean isDynamic() {
|
||||
int count = getLineCount();
|
||||
@ -70,10 +73,18 @@ public class HologramFormat {
|
||||
ConfigurationSection options = config.getConfigurationSection("lines." + i + ".options");
|
||||
|
||||
for (String key : options.getKeys(false)) {
|
||||
String format = options.getConfigurationSection(key).getString("format");
|
||||
ConfigurationSection option = options.getConfigurationSection(key);
|
||||
|
||||
String format = option.getString("format");
|
||||
if (format.contains(Regex.STOCK.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String req : option.getStringList("requirements")) {
|
||||
if (req.contains(Requirement.IN_STOCK.toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.epiceric.shopchest.nms;
|
||||
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.utils.Utils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -24,6 +25,7 @@ public class Hologram {
|
||||
private Location location;
|
||||
private List<Player> visible = new ArrayList<>();
|
||||
private ShopChest plugin;
|
||||
private Config config;
|
||||
|
||||
private Class<?> entityArmorStandClass = Utils.getNMSClass("EntityArmorStand");
|
||||
private Class<?> packetPlayOutSpawnEntityLivingClass = Utils.getNMSClass("PacketPlayOutSpawnEntityLiving");
|
||||
@ -32,6 +34,7 @@ public class Hologram {
|
||||
|
||||
public Hologram(ShopChest plugin, String[] lines, Location location) {
|
||||
this.plugin = plugin;
|
||||
this.config = plugin.getShopChestConfig();
|
||||
this.location = location;
|
||||
|
||||
Class[] requiredClasses = new Class[] {
|
||||
@ -54,16 +57,27 @@ public class Hologram {
|
||||
|
||||
text = ChatColor.translateAlternateColorCodes('&', text);
|
||||
|
||||
if (config.hologram_fixed_bottom) {
|
||||
for (int i = 0; i < line; i++) {
|
||||
ArmorStand stand = armorStands.get(i);
|
||||
stand.teleport(stand.getLocation().add(0, 0.25, 0));
|
||||
}
|
||||
} else {
|
||||
for (int i = line; i < armorStands.size(); i++) {
|
||||
ArmorStand stand = armorStands.get(i);
|
||||
stand.teleport(stand.getLocation().subtract(0, 0.25, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (line >= armorStands.size()) {
|
||||
line = armorStands.size();
|
||||
}
|
||||
|
||||
Location location = this.location.clone().subtract(0, line * 0.25, 0);
|
||||
Location location = this.location.clone();
|
||||
|
||||
if (!config.hologram_fixed_bottom) {
|
||||
location.subtract(0, line * 0.25, 0);
|
||||
}
|
||||
|
||||
try {
|
||||
ArmorStand armorStand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||
@ -92,7 +106,7 @@ public class Hologram {
|
||||
|
||||
text = ChatColor.translateAlternateColorCodes('&', text);
|
||||
|
||||
if (armorStands.size() <= line) {
|
||||
if (line >= armorStands.size()) {
|
||||
addLine(line, text);
|
||||
return;
|
||||
}
|
||||
@ -101,12 +115,19 @@ public class Hologram {
|
||||
}
|
||||
|
||||
public void removeLine(int line) {
|
||||
if (line < armorStands.size()) {
|
||||
if (config.hologram_fixed_bottom) {
|
||||
for (int i = 0; i < line; i++) {
|
||||
ArmorStand stand = armorStands.get(i);
|
||||
stand.teleport(stand.getLocation().subtract(0, 0.25, 0));
|
||||
}
|
||||
} else {
|
||||
for (int i = line + 1; i < armorStands.size(); i++) {
|
||||
ArmorStand stand = armorStands.get(i);
|
||||
stand.teleport(stand.getLocation().add(0, 0.25, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (armorStands.size() > line) {
|
||||
armorStands.get(line).remove();
|
||||
armorStands.remove(line);
|
||||
nmsArmorStands.remove(line);
|
||||
|
@ -271,29 +271,33 @@ public class Shop {
|
||||
int y = b.getY();
|
||||
int z = b.getZ();
|
||||
|
||||
double subtractY = 0.6;
|
||||
|
||||
if (config.hologram_fixed_bottom) subtractY = 0.85;
|
||||
|
||||
if (doubleChest) {
|
||||
Chest r = chests[0];
|
||||
Chest l = chests[1];
|
||||
|
||||
if (b.getLocation().equals(r.getLocation())) {
|
||||
if (r.getX() != l.getX()) {
|
||||
holoLocation = new Location(w, x, y - 0.6, z + 0.5);
|
||||
holoLocation = new Location(w, x, y - subtractY, z + 0.5);
|
||||
} else if (r.getZ() != l.getZ()) {
|
||||
holoLocation = new Location(w, x + 0.5, y - 0.6, z);
|
||||
holoLocation = new Location(w, x + 0.5, y - subtractY, z);
|
||||
} else {
|
||||
holoLocation = new Location(w, x + 0.5, y - 0.6, z + 0.5);
|
||||
holoLocation = new Location(w, x + 0.5, y - subtractY, z + 0.5);
|
||||
}
|
||||
} else {
|
||||
if (r.getX() != l.getX()) {
|
||||
holoLocation = new Location(w, x + 1, y - 0.6, z + 0.5);
|
||||
holoLocation = new Location(w, x + 1, y - subtractY, z + 0.5);
|
||||
} else if (r.getZ() != l.getZ()) {
|
||||
holoLocation = new Location(w, x + 0.5, y - 0.6, z + 1);
|
||||
holoLocation = new Location(w, x + 0.5, y - subtractY, z + 1);
|
||||
} else {
|
||||
holoLocation = new Location(w, x + 0.5, y - 0.6, z + 0.5);
|
||||
holoLocation = new Location(w, x + 0.5, y - subtractY, z + 0.5);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
holoLocation = new Location(w, x + 0.5, y - 0.6, z + 0.5);
|
||||
holoLocation = new Location(w, x + 0.5, y - subtractY, z + 0.5);
|
||||
}
|
||||
|
||||
holoLocation.add(0, config.hologram_lift, 0);
|
||||
|
@ -3,6 +3,7 @@ package de.epiceric.shopchest.utils;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.config.Config;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -205,6 +206,7 @@ public class ShopUtils {
|
||||
|
||||
if (reloadConfig) {
|
||||
plugin.getShopChestConfig().reload(false, true, showConsoleMessages);
|
||||
plugin.getHologramFormat().reload();
|
||||
plugin.getUpdater().setMaxDelta(plugin.getShopChestConfig().update_quality.getTime());
|
||||
}
|
||||
|
||||
@ -227,6 +229,11 @@ public class ShopUtils {
|
||||
addShop(shop, false);
|
||||
}
|
||||
}
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
updateShops(player, true);
|
||||
}
|
||||
|
||||
if (callback != null) callback.callSyncResult(shops.length);
|
||||
}
|
||||
}
|
||||
@ -247,7 +254,16 @@ public class ShopUtils {
|
||||
* @param player Player to show the updates
|
||||
*/
|
||||
public void updateShops(Player player) {
|
||||
if (player.getLocation().equals(playerLocation.get(player))) {
|
||||
updateShops(player, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update hologram and item of all shops for a player
|
||||
* @param player Player to show the updates
|
||||
* @param force Whether update should be forced even if player has not moved
|
||||
*/
|
||||
public void updateShops(Player player, boolean force) {
|
||||
if (!force && player.getLocation().equals(playerLocation.get(player))) {
|
||||
// Player has not moved, so don't calculate shops again.
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user