mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-19 15:27:45 +01:00
Small refactoring
This commit is contained in:
parent
aa8aad2b83
commit
b2b03f3e40
@ -7,19 +7,20 @@ package me.filoghost.holographicdisplays.common;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* Converts a generic array to an array of Strings using the method toString().
|
||||
* @param array the array to convert
|
||||
* @return the new generated array of Strings
|
||||
* Converts a generic array to a list of Strings using the method toString().
|
||||
*/
|
||||
public static String[] arrayToStrings(Object... array) {
|
||||
String[] result = new String[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
result[i] = array[i] != null ? array[i].toString() : null;
|
||||
public static List<String> toStringList(Object... array) {
|
||||
List<String> result = new ArrayList<>(array.length);
|
||||
for (Object obj : array) {
|
||||
result.add(Objects.toString(obj));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class AnimationsRegister {
|
||||
lines.set(i, StringConverter.toReadableFormat(lines.get(i)));
|
||||
}
|
||||
|
||||
animations.put(file.getFileName().toString(), new Placeholder(HolographicDisplays.getInstance(), file.getFileName().toString(), speed, new CyclicPlaceholderReplacer(lines.toArray(new String[0]))));
|
||||
animations.put(file.getFileName().toString(), new Placeholder(HolographicDisplays.getInstance(), file.getFileName().toString(), speed, new CyclicPlaceholderReplacer(lines)));
|
||||
DebugLogger.info("Successfully loaded animation '" + file.getFileName() + "', speed = " + speed + ".");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -7,22 +7,24 @@ package me.filoghost.holographicdisplays.placeholder;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CyclicPlaceholderReplacer implements PlaceholderReplacer {
|
||||
|
||||
String[] frames;
|
||||
List<String> frames;
|
||||
private int index;
|
||||
|
||||
public CyclicPlaceholderReplacer(String[] frames) {
|
||||
public CyclicPlaceholderReplacer(List<String> frames) {
|
||||
this.frames = frames;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String update() {
|
||||
String result = frames[index];
|
||||
String result = frames.get(index);
|
||||
|
||||
index++;
|
||||
if (index >= frames.length) {
|
||||
if (index >= frames.size()) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
package me.filoghost.holographicdisplays.placeholder;
|
||||
|
||||
import me.filoghost.holographicdisplays.HolographicDisplays;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.common.Utils;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -40,7 +40,7 @@ public class PlaceholdersRegister {
|
||||
return Configuration.timeFormat.format(new Date());
|
||||
}));
|
||||
|
||||
register(new Placeholder(HolographicDisplays.getInstance(), "&u", 0.2, new CyclicPlaceholderReplacer(Utils.arrayToStrings(
|
||||
register(new Placeholder(HolographicDisplays.getInstance(), "&u", 0.2, new CyclicPlaceholderReplacer(Utils.toStringList(
|
||||
ChatColor.RED,
|
||||
ChatColor.GOLD,
|
||||
ChatColor.YELLOW,
|
||||
|
Loading…
Reference in New Issue
Block a user