Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

feature/UCA-801-roleplay-activity-subdirectories #802

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public File getAddonActivityScreenDir(String type) {
return addonScreenshotDir.exists() || addonScreenshotDir.mkdir() ? addonScreenshotDir : null;
}

public File getAddonRoleplayActivityScreenDir(String type) {
if (getAddonActivityScreenDir("roleplay") == null)
return null;
File addonRoleplayScreenshotDir = new File(getAddonActivityScreenDir("roleplay").getAbsolutePath() + "/" + type);
return addonRoleplayScreenshotDir.exists() || addonRoleplayScreenshotDir.mkdir() ? addonRoleplayScreenshotDir : null;
}

public File getDataFile() throws IOException {
if (getUnicacityAddonDir() == null)
return null;
Expand Down Expand Up @@ -110,6 +117,24 @@ public File getNewActivityImageFile(String type) throws IOException {
return newImageFile.createNewFile() ? newImageFile : null;
}

public File getNewRoleplayActivityImageFile(String type) throws IOException {
if (getAddonRoleplayActivityScreenDir(type) == null)
return null;

String date = DATE_FORMAT.format(new Date());
StringBuilder sb = new StringBuilder(date);
int i = 1;
while (new File(Objects.requireNonNull(getAddonRoleplayActivityScreenDir(type)).getAbsolutePath() + "/" + sb + "-" + type + ".jpg").exists()) {
if (i == 1)
sb.append("_").append(i++);
else
sb.replace(sb.length() - 1, sb.length(), String.valueOf(i));
}

File newImageFile = new File(Objects.requireNonNull(getAddonRoleplayActivityScreenDir(type)).getAbsolutePath() + "/" + sb + "-" + type + ".jpg");
return newImageFile.createNewFile() ? newImageFile : null;
}

/**
* Quote: "Wenn du keine Brüste hast, rede ich nicht mehr mit dir!" - Dimiikou zu RettichLP, 25.09.2022
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,33 @@ public boolean execute(String[] arguments) {
.createComponent());

AtomicInteger overallCount = new AtomicInteger();
screenshotTypeList.stream().map(ScreenshotType::getDirectoryName).sorted().forEach(s -> {
File addonActivityScreenDir = this.unicacityAddon.fileService().getAddonActivityScreenDir(s);
File[] files = new File[0];
if (addonActivityScreenDir != null) {
files = addonActivityScreenDir.listFiles((dir, name) -> name.endsWith("-" + s + ".jpg"));
}
screenshotTypeList.stream()
.map(ScreenshotType::getDirectoryName)
.sorted()
.forEach(s -> {
File addonActivityScreenDir = this.unicacityAddon.fileService().getAddonActivityScreenDir(s);
File[] files = new File[0];
if (addonActivityScreenDir != null) {
files = addonActivityScreenDir.listFiles((dir, name) -> name.endsWith("-" + s + ".jpg"));
}

int entryCount = files != null ? files.length : 0;
// exclude roleplay directory from (overall)count
int entryCount = files != null && !s.equalsIgnoreCase("roleplay") ? files.length : 0;

overallCount.addAndGet(entryCount);
if (entryCount > 0) {
p.sendMessage(Message.getBuilder()
.of("»").color(ColorCode.GRAY).advance().space()
.of(Character.toUpperCase(s.charAt(0)) + s.substring(1)).color(ColorCode.GRAY).advance()
.of(":").color(ColorCode.GRAY).advance().space()
.of(String.valueOf(entryCount)).color(ColorCode.AQUA).advance().space()
.of("[↗]").color(ColorCode.BLUE)
.hoverEvent(HoverEvent.Action.SHOW_TEXT, Message.getBuilder().of("Ordner öffnen").color(ColorCode.RED).advance().createComponent())
.clickEvent(ClickEvent.Action.OPEN_FILE, this.unicacityAddon.fileService().getAddonActivityScreenDir(s).getAbsolutePath())
.advance()
.createComponent());
}
});
overallCount.addAndGet(entryCount);
if (entryCount > 0) {
p.sendMessage(Message.getBuilder()
.of("»").color(ColorCode.GRAY).advance().space()
.of(Character.toUpperCase(s.charAt(0)) + s.substring(1)).color(ColorCode.GRAY).advance()
.of(":").color(ColorCode.GRAY).advance().space()
.of(String.valueOf(entryCount)).color(ColorCode.AQUA).advance().space()
.of("[↗]").color(ColorCode.BLUE)
.hoverEvent(HoverEvent.Action.SHOW_TEXT, Message.getBuilder().of("Ordner öffnen").color(ColorCode.RED).advance().createComponent())
.clickEvent(ClickEvent.Action.OPEN_FILE, this.unicacityAddon.fileService().getAddonActivityScreenDir(s).getAbsolutePath())
.advance()
.createComponent());
}
});

p.sendMessage(Message.getBuilder()
.of("»").color(ColorCode.GRAY).advance().space()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.rettichlp.unicacityaddon.base.io.api.API.find;

/**
* @author Dimiikou
*/
Expand All @@ -33,18 +35,16 @@ public boolean execute(String[] arguments) {
return true;
}

ScreenshotType screenshotType = Arrays.stream(ScreenshotType.values())
.filter(st -> st.getDirectoryName().equals(arguments[0]))
.findFirst()
.orElse(null);

ScreenshotType screenshotType = find(Arrays.asList(ScreenshotType.values()), st -> st.getDirectoryName().equals(arguments[0]));
if (screenshotType == null) {
sendUsage();
return true;
}

try {
File file = this.unicacityAddon.fileService().getNewActivityImageFile(arguments[0]);
File file = screenshotType.equals(ScreenshotType.ROLEPLAY) && arguments.length > 1
? this.unicacityAddon.fileService().getNewRoleplayActivityImageFile(arguments[1])
: this.unicacityAddon.fileService().getNewActivityImageFile(arguments[0]);
ScreenshotBuilder.getBuilder(this.unicacityAddon).file(file).save();
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down