mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2026-01-04 15:31:47 +00:00
zip
This commit is contained in:
@@ -21,6 +21,7 @@ public abstract class CustomNameplatesPlugin extends JavaPlugin {
|
||||
protected TeamManager teamManager;
|
||||
protected NameplateManager nameplateManager;
|
||||
protected ActionBarManager actionBarManager;
|
||||
protected WidthManager widthManager;
|
||||
|
||||
protected CustomNameplatesPlugin() {
|
||||
instance = this;
|
||||
@@ -104,6 +105,11 @@ public abstract class CustomNameplatesPlugin extends JavaPlugin {
|
||||
return nameplateManager;
|
||||
}
|
||||
|
||||
/* Get the width manager */
|
||||
public WidthManager getWidthManager() {
|
||||
return widthManager;
|
||||
}
|
||||
|
||||
/* debug get config by file name */
|
||||
public abstract YamlConfiguration getConfig(String file);
|
||||
|
||||
|
||||
@@ -56,4 +56,13 @@ public class Tuple<L, M, R> {
|
||||
public void setRight(R right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tuple{" +
|
||||
"left=" + left +
|
||||
", mid=" + mid +
|
||||
", right=" + right +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,10 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public interface AdventureManager {
|
||||
|
||||
net.momirealms.customnameplates.api.common.Key keyToKey(Key key);
|
||||
|
||||
Key keyToKey(net.momirealms.customnameplates.api.common.Key key);
|
||||
|
||||
Object getIChatComponentFromMiniMessage(String text);
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,4 @@ public interface ResourcePackManager {
|
||||
void generateResourcePack();
|
||||
|
||||
void deleteDirectory(File file);
|
||||
|
||||
String native2ascii(char c);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
package net.momirealms.customnameplates.api.manager;
|
||||
|
||||
import net.momirealms.customnameplates.api.common.Key;
|
||||
import net.momirealms.customnameplates.api.mechanic.font.FontData;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface WidthManager {
|
||||
|
||||
boolean registerFontData(Key key, FontData fontData);
|
||||
|
||||
boolean unregisterFontData(Key key);
|
||||
|
||||
@Nullable FontData getFontData(Key key);
|
||||
|
||||
int getTextWidth(String textWithTags);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.momirealms.customnameplates.api.mechanic.font;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class FontData {
|
||||
|
||||
private final HashMap<Character, Integer> widthData;
|
||||
private final int defaultWidth;
|
||||
|
||||
public FontData(int defaultWidth) {
|
||||
this.widthData = new HashMap<>();
|
||||
this.defaultWidth = defaultWidth;
|
||||
}
|
||||
|
||||
public void registerCharWidth(char c, int width) {
|
||||
widthData.put(c, width);
|
||||
}
|
||||
|
||||
public int getWidth(char c) {
|
||||
return widthData.getOrDefault(c, defaultWidth);
|
||||
}
|
||||
|
||||
public HashMap<Character, Integer> getWidthData() {
|
||||
return widthData;
|
||||
}
|
||||
|
||||
public void overrideWith(FontData fontData) {
|
||||
if (fontData == null) return;
|
||||
widthData.putAll(fontData.getWidthData());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.momirealms.customnameplates.api.util;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
|
||||
public class FontUtils {
|
||||
|
||||
private static String namespace;
|
||||
@@ -60,7 +62,7 @@ public class FontUtils {
|
||||
* @return width
|
||||
*/
|
||||
public static int getTextWidth(String text) {
|
||||
return 0;
|
||||
return CustomNameplatesPlugin.get().getWidthManager().getTextWidth(text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user