Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable GUI #328

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>**/*.yml</include>
<include>*.properties</include>
</includes>
</resource>
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>**/*.yml</include>
<include>*.properties</include>
</includes>
</resource>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package net.sacredlabyrinth.phaed.simpleclans.ui;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import net.sacredlabyrinth.phaed.simpleclans.SimpleClans;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;

/**
*
* @author RoinujNosde
Expand All @@ -17,10 +25,12 @@ public abstract class SCFrame {
private final SCFrame parent;
private final Player viewer;
private final Set<SCComponent> components = ConcurrentHashMap.newKeySet();
protected final FileConfiguration config;

public SCFrame(@Nullable SCFrame parent, @NotNull Player viewer) {
this.parent = parent;
this.viewer = viewer;
this.config = readConfig(); //todo async
}

@NotNull
Expand Down Expand Up @@ -79,4 +89,31 @@ public int hashCode() {
return getTitle().hashCode() + Integer.hashCode(getSize()) + getComponents().hashCode();
}

protected FileConfiguration readConfig() {
RoinujNosde marked this conversation as resolved.
Show resolved Hide resolved
SimpleClans plugin = SimpleClans.getInstance();

String configPath = getConfigPath();
File externalFile = new File(plugin.getDataFolder(), configPath);
InputStream resource = plugin.getResource(configPath);
YamlConfiguration config = YamlConfiguration.loadConfiguration(externalFile);
if (resource != null) {
YamlConfiguration defaults = YamlConfiguration.loadConfiguration(new InputStreamReader(resource));
config.setDefaults(defaults);
if (!externalFile.exists()) { // TODO Move to startup
try {
defaults.save(externalFile);
} catch (IOException e) {
plugin.getLogger().log(Level.SEVERE, String.format("Error saving defaults to %s", configPath), e);
}
}
}
return config;
}

private String getConfigPath() {
String name = getClass().getName().replace("net.sacredlabyrinth.phaed.simpleclans.ui.frames.", "");

return ("frames." + name).replace(".", File.separator) + ".yml";
}

}
53 changes: 53 additions & 0 deletions src/main/resources/frames/staff/StaffFrame.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
title: "{@@gui.staff.title}"
rows: 3
components:
panels:
slots: [0, 1, 2, 3, 5, 6, 7, 8]
display_name: " "
material: GRAY_STAINED_GLASS_PANE
clans:
material: PURPLE_BANNER
slot: 9
display_name: "{@@gui.main.clan.list.title}"
lore:
- "{@@gui.staff.clan.list.lore.left.click}"
- "{@@gui.staff.clan.list.lore.right.click}"
actions:
left_click:
run: "openClansFrame()"
right_click:
run: "openUnverifiedClansFrame()"
players:
material: WHITE_BANNER
slot: 10
display_name: "{@@gui.staff.player.list.title}"
lore:
- "{@@gui.staff.player.list.lore.left.click}"
- "{@@gui.staff.player.list.lore.right.click}"
actions:
left_click:
run: "openPlayersFrame()"
right_click:
run: "openOnlinePlayersFrame()"
reload:
material: SPAWNER
slot: 17
display_name: "{@@gui.staff.reload.title}"
lore:
- "{@@gui.staff.reload.lore}"
actions:
left_click:
run: "reloadPlugin()"
permission: "simpleclans.admin.reload"
confirmation_required: true
global_ff:
material: DIAMOND_SWORD
slot: 12
display_name: "{@@gui.staff.global.ff.title}"
lore:
- "{@@gui.staff.global.ff.lore.status}"
- "{@@gui.staff.global.ff.lore.toggle}"
actions:
left_click:
run: "toggleGlobalFf()"
permission: "simpleclans.mod.globalff"