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