Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
d0by1 committed Sep 30, 2023
2 parents 7c3e84f + ab4093f commit 7f46129
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public TabCompleteHandler getTabCompleteHandler() {
usage = "/dh line add <hologram> <page> [content]",
description = "Add a line to Hologram.",
aliases = {"append"},
playerOnly = true,
minArgs = 2
)
static class LineAddSub extends DecentCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

@Getter
public enum ConvertorType {
CMI(true, "CMI"),
FUTURE_HOLOGRAMS(true, "FutureHolograms", "fh", "fholograms"),
GHOLO(false, "GHolo", "gh"),
HOLOGRAPHIC_DISPLAYS(false, "HolographicDisplays", "HD", "hd"),
HOLOGRAPHIC_DISPLAYS(false, "HolographicDisplays", "hd"),
HOLOGRAMS(true, "Holograms"),
;

@Nullable
public static ConvertorType fromString(String alias) {
for (ConvertorType convertorType : ConvertorType.values()) {
if (convertorType.getName().equalsIgnoreCase(alias) || convertorType.getAliases().contains(alias)) {
if (convertorType.getName().equalsIgnoreCase(alias) || convertorType.getAliases().contains(alias.toLowerCase(Locale.ROOT))) {
return convertorType;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CMIConverter implements IConvertor {

@Override
public ConvertorResult convert() {
return convert(new File("plugins/CMI/holograms.yml"));
return convert(new File(PLUGIN.getDataFolder().getParent() + "/CMI/", "holograms.yml"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FutureHologramsConverter implements IConvertor {

@Override
public ConvertorResult convert(){
return convert(new File("plugins/FutureHolograms/holograms.yml"));
return convert(new File(PLUGIN.getDataFolder().getParent() + "/FutureHolograms/", "holograms.yml"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class GHoloConverter implements IConvertor {

@Override
public ConvertorResult convert(){
return convert(new File("plugins/GHolo/data/h.data"));
return convert(new File(PLUGIN.getDataFolder().getParent() + "/GHolo/data/", "h.data"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class HologramsConvertor implements IConvertor {

@Override
public ConvertorResult convert() {
return convert(new File("plugins/Holograms/holograms.yml"));
return convert(new File(PLUGIN.getDataFolder().getParent() + "/Holograms/", "holograms.yml"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class HolographicDisplaysConvertor implements IConvertor {

private static final DecentHolograms PLUGIN = DecentHologramsAPI.get();
private static final Pattern PAPI_PATTERN = Pattern.compile("\\{papi: (.+)}");

@Override
public ConvertorResult convert() {
return convert(new File("plugins/HolographicDisplays/database.yml"));
return convert(new File(PLUGIN.getDataFolder().getParent() + "/HolographicDisplays/", "database.yml"));
}

@Override
Expand Down Expand Up @@ -50,8 +54,26 @@ public ConvertorResult convert(final File file) {
}

@Override
public List<String> prepareLines(List<String> lines){
return lines.stream().map(line -> {
public List<String> prepareLines(List<String> lines) {
List<String> parsed = new ArrayList<>(lines.size());
// Go through each line and convert any {papi: <placeholder>} pattern to %<placeholder>%
for(String line : lines) {
String parsedLine = line;
Matcher matcher = PAPI_PATTERN.matcher(line);
if(matcher.find()) {
StringBuffer buffer = new StringBuffer();
do {
matcher.appendReplacement(buffer, "%" + matcher.group(1) + "%");
} while(matcher.find());

matcher.appendTail(buffer);
parsedLine = buffer.toString();
}

parsed.add(parsedLine);
}

return parsed.stream().map(line -> {
if (line.toUpperCase().startsWith("ICON:")) {
return "#" + line;
}
Expand Down

0 comments on commit 7f46129

Please sign in to comment.