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