mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-24 23:41:29 +01:00
add CMI hologram support
This commit is contained in:
parent
7dcd71573b
commit
d2102c78b6
@ -195,6 +195,12 @@
|
||||
<version>2.9.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zrips</groupId>
|
||||
<artifactId>CMI</artifactId>
|
||||
<version>8.4.0.2_1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.tnemc</groupId>
|
||||
<artifactId>Reserve</artifactId>
|
||||
|
@ -4,6 +4,7 @@ import com.songoda.core.hooks.economies.Economy;
|
||||
import com.songoda.core.hooks.economies.PlayerPointsEconomy;
|
||||
import com.songoda.core.hooks.economies.ReserveEconomy;
|
||||
import com.songoda.core.hooks.economies.VaultEconomy;
|
||||
import com.songoda.core.hooks.holograms.CMIHolograms;
|
||||
import com.songoda.core.hooks.stackers.StackMob;
|
||||
import com.songoda.core.hooks.stackers.Stacker;
|
||||
import com.songoda.core.hooks.stackers.UltimateStacker;
|
||||
@ -33,6 +34,7 @@ public final class PluginHook <T extends Class> {
|
||||
public static final PluginHook STACKER_STACK_MOB = new PluginHook(Stacker.class, "StackMob", StackMob.class);
|
||||
public static final PluginHook HOLO_DISPLAYS = new PluginHook(Holograms.class, "HolographicDisplays", HolographicDisplaysHolograms.class);
|
||||
public static final PluginHook HOLO_HOLOGRAMS = new PluginHook(Holograms.class, "Holograms", HologramsHolograms.class);
|
||||
public static final PluginHook HOLO_CMI = new PluginHook(Holograms.class, "CMI", CMIHolograms.class);
|
||||
|
||||
/******* Start Manager stuff *******/
|
||||
|
||||
|
@ -0,0 +1,135 @@
|
||||
package com.songoda.core.hooks.holograms;
|
||||
|
||||
import com.Zrips.CMI.CMI;
|
||||
import com.Zrips.CMI.Modules.Holograms.CMIHologram;
|
||||
import com.Zrips.CMI.Modules.Holograms.HologramManager;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class CMIHolograms extends Holograms {
|
||||
|
||||
CMI cmi;
|
||||
HologramManager cmiHologramManager;
|
||||
HashSet<String> ourHolograms = new HashSet();
|
||||
Method cmi_CMIHologram_getLines;
|
||||
|
||||
{
|
||||
try {
|
||||
// test if we need to watch if the lines is an array
|
||||
if (CMIHologram.class.getDeclaredField("lines").getDeclaringClass() == String[].class) {
|
||||
cmi_CMIHologram_getLines = CMIHologram.class.getMethod("getLines");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public CMIHolograms(Plugin plugin) {
|
||||
super(plugin);
|
||||
cmi = (CMI) Bukkit.getPluginManager().getPlugin("CMI");
|
||||
if (cmi != null) {
|
||||
cmiHologramManager = cmi.getHologramManager();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CMI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return cmi != null && cmi.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double defaultHeightOffset() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createHologram(Location location, List<String> lines) {
|
||||
createAt(fixLocation(location), lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHologram(Location location) {
|
||||
location = fixLocation(location);
|
||||
final String id = locStr(location);
|
||||
CMIHologram holo = cmiHologramManager.getByName(id);
|
||||
if (holo != null) {
|
||||
cmiHologramManager.removeHolo(holo);
|
||||
}
|
||||
ourHolograms.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllHolograms() {
|
||||
for (String id : ourHolograms) {
|
||||
CMIHologram holo = cmiHologramManager.getByName(id);
|
||||
if (holo != null) {
|
||||
cmiHologramManager.removeHolo(holo);
|
||||
}
|
||||
}
|
||||
ourHolograms.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateHologram(Location location, List<String> lines) {
|
||||
location = fixLocation(location);
|
||||
CMIHologram holo = cmiHologramManager.getByName(locStr(location));
|
||||
if (holo != null) {
|
||||
// only update if there is a change to the text
|
||||
List<String> holoLines;
|
||||
if (cmi_CMIHologram_getLines != null) {
|
||||
try {
|
||||
holoLines = Arrays.asList((String[]) cmi_CMIHologram_getLines.invoke(holo));
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(CMIHolograms.class.getName()).log(Level.SEVERE, "CMI Hologram error!", ex);
|
||||
holoLines = Collections.EMPTY_LIST;
|
||||
}
|
||||
} else {
|
||||
holoLines = holo.getLines();
|
||||
}
|
||||
boolean isChanged = lines.size() != holoLines.size();
|
||||
if (!isChanged) {
|
||||
// double-check the lines
|
||||
for (int i = 0; !isChanged && i < lines.size(); ++i) {
|
||||
isChanged = !holo.getLine(i).equals(lines.get(i));
|
||||
}
|
||||
}
|
||||
if (isChanged) {
|
||||
holo.setLines(lines);
|
||||
holo.update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
createAt(location, lines);
|
||||
}
|
||||
|
||||
private String locStr(Location loc) {
|
||||
return String.format("%s-%d-%d-%d", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
|
||||
private void createAt(Location location, List<String> lines) {
|
||||
|
||||
final String id = locStr(location);
|
||||
CMIHologram holo = new CMIHologram(id, location);
|
||||
holo.setLines(lines);
|
||||
|
||||
cmiHologramManager.addHologram(holo);
|
||||
holo.update();
|
||||
|
||||
if (!ourHolograms.contains(id)) {
|
||||
ourHolograms.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -5,11 +5,10 @@ import com.sainttx.holograms.api.HologramPlugin;
|
||||
import com.sainttx.holograms.api.line.HologramLine;
|
||||
import com.sainttx.holograms.api.line.TextLine;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class HologramsHolograms extends Holograms {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user