mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-25 18:27: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 bungeeOnlineFormat;
|
||||||
public static String bungeeOfflineFormat;
|
public static String bungeeOfflineFormat;
|
||||||
public static SimpleDateFormat timeFormat;
|
public static SimpleDateFormat timeFormat;
|
||||||
|
public static boolean redisBungee;
|
||||||
|
|
||||||
// Used for the updater.
|
// Used for the updater.
|
||||||
public static String newVersion;
|
public static String newVersion;
|
||||||
|
@ -130,13 +130,13 @@ public class HolographicDisplays extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
if (VersionUtils.isMCPCOrCauldron()) {
|
||||||
getLogger().info("Trying to enable Cauldron/MCPC+ support...");
|
getLogger().info("Trying to enable Cauldron/MCPC+ support...");
|
||||||
}
|
}
|
||||||
|
|
||||||
nmsManager.registerCustomEntities();
|
nmsManager.registerCustomEntities();
|
||||||
|
|
||||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
if (VersionUtils.isMCPCOrCauldron()) {
|
||||||
getLogger().info("Successfully added support for Cauldron/MCPC+!");
|
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.bungeeRefreshSeconds = ConfigNode.BUNGEE_REFRESH_SECONDS.getInt(getConfig());
|
||||||
Configuration.bungeeOnlineFormat = StringUtils.toReadableFormat(ConfigNode.BUNGEE_ONLINE_FORMAT.getString(getConfig()));
|
Configuration.bungeeOnlineFormat = StringUtils.toReadableFormat(ConfigNode.BUNGEE_ONLINE_FORMAT.getString(getConfig()));
|
||||||
Configuration.bungeeOfflineFormat = StringUtils.toReadableFormat(ConfigNode.BUNGEE_OFFLINE_FORMAT.getString(getConfig()));
|
Configuration.bungeeOfflineFormat = StringUtils.toReadableFormat(ConfigNode.BUNGEE_OFFLINE_FORMAT.getString(getConfig()));
|
||||||
|
Configuration.redisBungee = ConfigNode.BUNGEE_USE_REDIS_BUNGEE.getBoolean(getConfig());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Configuration.timeFormat = new SimpleDateFormat(StringUtils.toReadableFormat(ConfigNode.TIME_FORMAT.getString(getConfig())));
|
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.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
import com.gmail.filoghost.holograms.Configuration;
|
||||||
import com.gmail.filoghost.holograms.HolographicDisplays;
|
import com.gmail.filoghost.holograms.HolographicDisplays;
|
||||||
|
|
||||||
public class BungeeChannel implements PluginMessageListener {
|
public class BungeeChannel implements PluginMessageListener {
|
||||||
@ -23,6 +24,8 @@ public class BungeeChannel implements PluginMessageListener {
|
|||||||
instance = new BungeeChannel();
|
instance = new BungeeChannel();
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(HolographicDisplays.getInstance(), "BungeeCord");
|
Bukkit.getMessenger().registerOutgoingPluginChannel(HolographicDisplays.getInstance(), "BungeeCord");
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(HolographicDisplays.getInstance(), "BungeeCord", instance);
|
Bukkit.getMessenger().registerIncomingPluginChannel(HolographicDisplays.getInstance(), "BungeeCord", instance);
|
||||||
|
Bukkit.getMessenger().registerOutgoingPluginChannel(HolographicDisplays.getInstance(), "RedisBungee");
|
||||||
|
Bukkit.getMessenger().registerIncomingPluginChannel(HolographicDisplays.getInstance(), "RedisBungee", instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BungeeChannel instance() {
|
public static BungeeChannel instance() {
|
||||||
@ -34,7 +37,7 @@ public class BungeeChannel implements PluginMessageListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
if (!channel.equals("BungeeCord")) {
|
if (!channel.equals("BungeeCord") || !channel.equals("RedisBungee")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +83,7 @@ public class BungeeChannel implements PluginMessageListener {
|
|||||||
// OR, if you don't need to send it to a specific player
|
// OR, if you don't need to send it to a specific player
|
||||||
Player[] players = Bukkit.getOnlinePlayers();
|
Player[] players = Bukkit.getOnlinePlayers();
|
||||||
if (players.length > 0) {
|
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")
|
@SuppressWarnings("rawtypes")
|
||||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
if (VersionUtils.isMCPCOrCauldron()) {
|
||||||
// MCPC+ / Cauldron entity registration.
|
// MCPC+ / Cauldron entity registration.
|
||||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_6_R3.EntityTypes");
|
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_6_R3.EntityTypes");
|
||||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
if (VersionUtils.isMCPCOrCauldron()) {
|
||||||
// MCPC+ / Cauldron entity registration.
|
// MCPC+ / Cauldron entity registration.
|
||||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R1.EntityTypes");
|
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R1.EntityTypes");
|
||||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
if (VersionUtils.isMCPCOrCauldron()) {
|
||||||
// MCPC+ / Cauldron entity registration.
|
// MCPC+ / Cauldron entity registration.
|
||||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R2.EntityTypes");
|
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R2.EntityTypes");
|
||||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
if (VersionUtils.isMCPCOrCauldron()) {
|
||||||
// MCPC+ / Cauldron entity registration.
|
// MCPC+ / Cauldron entity registration.
|
||||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R3.EntityTypes");
|
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R3.EntityTypes");
|
||||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||||
|
@ -33,7 +33,7 @@ public class NmsManagerImpl implements NmsManager {
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
|
||||||
if (VersionUtils.isMCPC() || VersionUtils.isCauldron()) {
|
if (VersionUtils.isMCPCOrCauldron()) {
|
||||||
// MCPC+ / Cauldron entity registration.
|
// MCPC+ / Cauldron entity registration.
|
||||||
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R4.EntityTypes");
|
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_7_R4.EntityTypes");
|
||||||
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
package com.gmail.filoghost.holograms.object;
|
package com.gmail.filoghost.holograms.object;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.filoghost.holograms.Configuration;
|
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.exception.SpawnFailedException;
|
||||||
|
import com.gmail.filoghost.holograms.object.pieces.FloatingItemDoubleEntity;
|
||||||
import com.gmail.filoghost.holograms.object.pieces.HologramLine;
|
import com.gmail.filoghost.holograms.object.pieces.HologramLine;
|
||||||
|
import com.gmail.filoghost.holograms.utils.ItemUtils;
|
||||||
import com.gmail.filoghost.holograms.utils.Validator;
|
import com.gmail.filoghost.holograms.utils.Validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,9 +40,42 @@ public class APICraftHologram extends CraftHologram {
|
|||||||
|
|
||||||
for (String text : textLines) {
|
for (String text : textLines) {
|
||||||
|
|
||||||
HologramLine lineEntity = new HologramLine(text);
|
if (text.length() >= 5 && text.substring(0, 5).toLowerCase().equals("icon:")) {
|
||||||
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;
|
currentY -= lineSpacing;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public class ProtocolLibHook {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // Entity metadata packet
|
} else if (packet.getType() == PacketType.Play.Server.ENTITY_METADATA) {
|
||||||
|
|
||||||
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
WrapperPlayServerEntityMetadata entityMetadataPacket = new WrapperPlayServerEntityMetadata(packet);
|
||||||
Entity entity = entityMetadataPacket.getEntity(event);
|
Entity entity = entityMetadataPacket.getEntity(event);
|
||||||
|
@ -13,6 +13,7 @@ public enum ConfigNode {
|
|||||||
BUNGEE_REFRESH_SECONDS("bungee-refresh-seconds", 3),
|
BUNGEE_REFRESH_SECONDS("bungee-refresh-seconds", 3),
|
||||||
BUNGEE_ONLINE_FORMAT("bungee-online-format", "&aOnline"),
|
BUNGEE_ONLINE_FORMAT("bungee-online-format", "&aOnline"),
|
||||||
BUNGEE_OFFLINE_FORMAT("bungee-offline-format", "&cOffline"),
|
BUNGEE_OFFLINE_FORMAT("bungee-offline-format", "&cOffline"),
|
||||||
|
BUNGEE_USE_REDIS_BUNGEE("bungee-use-RedisBungee-plugin", false),
|
||||||
TIME_FORMAT("time-format", "H:mm");
|
TIME_FORMAT("time-format", "H:mm");
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
@ -25,11 +25,8 @@ public class VersionUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMCPC() {
|
public static boolean isMCPCOrCauldron() {
|
||||||
return Bukkit.getVersion().contains("MCPC-Plus");
|
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