mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-24 17:57:36 +01:00
Allow API holograms to use "ICON:", added experimental RedisBungee
support (not tested).
This commit is contained in:
parent
45f9c2248f
commit
6276160023
@ -15,6 +15,7 @@ public class Configuration {
|
||||
public static String bungeeOnlineFormat;
|
||||
public static String bungeeOfflineFormat;
|
||||
public static SimpleDateFormat timeFormat;
|
||||
public static boolean redisBungee;
|
||||
|
||||
// Used for the updater.
|
||||
public static String newVersion;
|
||||
|
@ -130,13 +130,13 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
}
|
||||
|
||||
try {
|
||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
||||
if (VersionUtils.isMCPCOrCauldron()) {
|
||||
getLogger().info("Trying to enable Cauldron/MCPC+ support...");
|
||||
}
|
||||
|
||||
nmsManager.registerCustomEntities();
|
||||
|
||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
||||
if (VersionUtils.isMCPCOrCauldron()) {
|
||||
getLogger().info("Successfully added support for Cauldron/MCPC+!");
|
||||
}
|
||||
|
||||
@ -246,6 +246,7 @@ public class HolographicDisplays extends JavaPlugin {
|
||||
Configuration.bungeeRefreshSeconds = ConfigNode.BUNGEE_REFRESH_SECONDS.getInt(getConfig());
|
||||
Configuration.bungeeOnlineFormat = StringUtils.toReadableFormat(ConfigNode.BUNGEE_ONLINE_FORMAT.getString(getConfig()));
|
||||
Configuration.bungeeOfflineFormat = StringUtils.toReadableFormat(ConfigNode.BUNGEE_OFFLINE_FORMAT.getString(getConfig()));
|
||||
Configuration.redisBungee = ConfigNode.BUNGEE_USE_REDIS_BUNGEE.getBoolean(getConfig());
|
||||
|
||||
try {
|
||||
Configuration.timeFormat = new SimpleDateFormat(StringUtils.toReadableFormat(ConfigNode.TIME_FORMAT.getString(getConfig())));
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import com.gmail.filoghost.holograms.Configuration;
|
||||
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||
|
||||
public class BungeeChannel implements PluginMessageListener {
|
||||
@ -23,6 +24,8 @@ public class BungeeChannel implements PluginMessageListener {
|
||||
instance = new BungeeChannel();
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(HolographicDisplays.getInstance(), "BungeeCord");
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(HolographicDisplays.getInstance(), "BungeeCord", instance);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(HolographicDisplays.getInstance(), "RedisBungee");
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(HolographicDisplays.getInstance(), "RedisBungee", instance);
|
||||
}
|
||||
|
||||
public static BungeeChannel instance() {
|
||||
@ -34,7 +37,7 @@ public class BungeeChannel implements PluginMessageListener {
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if (!channel.equals("BungeeCord")) {
|
||||
if (!channel.equals("BungeeCord") || !channel.equals("RedisBungee")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,7 +83,7 @@ public class BungeeChannel implements PluginMessageListener {
|
||||
// OR, if you don't need to send it to a specific player
|
||||
Player[] players = Bukkit.getOnlinePlayers();
|
||||
if (players.length > 0) {
|
||||
players[0].sendPluginMessage(HolographicDisplays.getInstance(), "BungeeCord", b.toByteArray());
|
||||
players[0].sendPluginMessage(HolographicDisplays.getInstance(), Configuration.redisBungee ? "RedisBungee" : "BungeeCord", b.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
||||
if (VersionUtils.isMCPCOrCauldron()) {
|
||||
// MCPC+ / Cauldron entity registration.
|
||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_6_R3.EntityTypes");
|
||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
||||
if (VersionUtils.isMCPCOrCauldron()) {
|
||||
// MCPC+ / Cauldron entity registration.
|
||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R1.EntityTypes");
|
||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
||||
if (VersionUtils.isMCPCOrCauldron()) {
|
||||
// MCPC+ / Cauldron entity registration.
|
||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R2.EntityTypes");
|
||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
||||
if (VersionUtils.isMCPCOrCauldron()) {
|
||||
// MCPC+ / Cauldron entity registration.
|
||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R3.EntityTypes");
|
||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
||||
if (VersionUtils.isMCPCOrCauldron()) {
|
||||
// MCPC+ / Cauldron entity registration.
|
||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R4.EntityTypes");
|
||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||
|
@ -1,10 +1,16 @@
|
||||
package com.gmail.filoghost.holograms.object;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.filoghost.holograms.Configuration;
|
||||
import com.gmail.filoghost.holograms.commands.CommandValidator;
|
||||
import com.gmail.filoghost.holograms.exception.CommandException;
|
||||
import com.gmail.filoghost.holograms.exception.SpawnFailedException;
|
||||
import com.gmail.filoghost.holograms.object.pieces.FloatingItemDoubleEntity;
|
||||
import com.gmail.filoghost.holograms.object.pieces.HologramLine;
|
||||
import com.gmail.filoghost.holograms.utils.ItemUtils;
|
||||
import com.gmail.filoghost.holograms.utils.Validator;
|
||||
|
||||
/**
|
||||
@ -21,7 +27,7 @@ public class APICraftHologram extends CraftHologram {
|
||||
public boolean forceUpdate() {
|
||||
|
||||
Validator.checkState(!isDeleted(), "Hologram already deleted");
|
||||
|
||||
|
||||
// Remove previous entities.
|
||||
hide();
|
||||
|
||||
@ -33,10 +39,43 @@ public class APICraftHologram extends CraftHologram {
|
||||
double currentY = this.y;
|
||||
|
||||
for (String text : textLines) {
|
||||
|
||||
if (text.length() >= 5 && text.substring(0, 5).toLowerCase().equals("icon:")) {
|
||||
|
||||
HologramLine lineEntity = new HologramLine(text);
|
||||
lineEntity.spawn(this, bukkitWorld, x, currentY, z);
|
||||
linesEntities.add(lineEntity);
|
||||
// It's a floating icon!
|
||||
ItemStack icon;
|
||||
try {
|
||||
icon = CommandValidator.matchItemStack(text.substring(5));
|
||||
} catch (CommandException e) {
|
||||
icon = new ItemStack(Material.BEDROCK);
|
||||
}
|
||||
|
||||
// If the current Y has been changed, the item is NOT on top of the hologram.
|
||||
if (currentY != this.y) {
|
||||
// Extra space for the floating item, blocks are smaller
|
||||
if (ItemUtils.appearsAsBlock(icon.getType())) {
|
||||
currentY -= 0.27;
|
||||
} else {
|
||||
currentY -= 0.52;
|
||||
}
|
||||
}
|
||||
|
||||
FloatingItemDoubleEntity lineEntity = new FloatingItemDoubleEntity(icon);
|
||||
lineEntity.spawn(this, bukkitWorld, x, currentY, z);
|
||||
linesEntities.add(lineEntity);
|
||||
|
||||
// And some more space below.
|
||||
currentY -= 0.05;
|
||||
|
||||
} else {
|
||||
|
||||
HologramLine lineEntity = new HologramLine(text);
|
||||
lineEntity.spawn(this, bukkitWorld, x, currentY, z);
|
||||
linesEntities.add(lineEntity);
|
||||
|
||||
// Don't track placeholders for API holograms!
|
||||
// HolographicDisplays.getPlaceholderManager().trackIfNecessary(lineEntity.getHorse());
|
||||
}
|
||||
|
||||
currentY -= lineSpacing;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class ProtocolLibHook {
|
||||
return;
|
||||
}
|
||||
|
||||
} else { // Entity metadata packet
|
||||
} else if (packet.getType() == PacketType.Play.Server.ENTITY_METADATA) {
|
||||
|
||||
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
||||
Entity entity = entityMetadataPacket.getEntity(event);
|
||||
|
@ -13,6 +13,7 @@ public enum ConfigNode {
|
||||
BUNGEE_REFRESH_SECONDS("bungee-refresh-seconds", 3),
|
||||
BUNGEE_ONLINE_FORMAT("bungee-online-format", "&aOnline"),
|
||||
BUNGEE_OFFLINE_FORMAT("bungee-offline-format", "&cOffline"),
|
||||
BUNGEE_USE_REDIS_BUNGEE("bungee-use-RedisBungee-plugin", false),
|
||||
TIME_FORMAT("time-format", "H:mm");
|
||||
|
||||
private String path;
|
||||
|
@ -25,11 +25,8 @@ public class VersionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMCPC() {
|
||||
return Bukkit.getVersion().contains("MCPC-Plus");
|
||||
public static boolean isMCPCOrCauldron() {
|
||||
return Bukkit.getVersion().toLowerCase().contains("mcpc") || Bukkit.getVersion().toLowerCase().contains("cauldron");
|
||||
}
|
||||
|
||||
public static boolean isCauldron() {
|
||||
return Bukkit.getVersion().contains("Cauldron");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user