mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-27 04:35:46 +01:00
Reworked admin settings GUI and adapted to new system
This commit is contained in:
parent
74a9037f05
commit
fbd41321fc
@ -2,18 +2,28 @@ package com.songoda.skyblock.command.commands.admin;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.skyblock.command.SubCommand;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.gui.GuiPermissionsSelector;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.island.IslandRole;
|
||||
import com.songoda.skyblock.menus.admin.Settings;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.permission.PermissionManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SettingsCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
|
||||
Settings.getInstance().open(player, Settings.Type.Categories, null);
|
||||
skyblock.getGuiManager().showGUI(player, new GuiPermissionsSelector(skyblock, null, null));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
|
126
src/main/java/com/songoda/skyblock/gui/GuiAdminPermissions.java
Normal file
126
src/main/java/com/songoda/skyblock/gui/GuiAdminPermissions.java
Normal file
@ -0,0 +1,126 @@
|
||||
package com.songoda.skyblock.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandPermission;
|
||||
import com.songoda.skyblock.island.IslandRole;
|
||||
import com.songoda.skyblock.permission.BasicPermission;
|
||||
import com.songoda.skyblock.permission.PermissionManager;
|
||||
import com.songoda.skyblock.permission.PermissionType;
|
||||
import com.songoda.skyblock.visit.Visit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GuiAdminPermissions extends Gui {
|
||||
|
||||
private final PermissionManager permissionManager;
|
||||
private final IslandRole role;
|
||||
private final FileConfiguration configLoad;
|
||||
private final FileManager.Config settingsConfig;
|
||||
private final FileConfiguration settingsConfigLoad;
|
||||
private final Gui returnGui;
|
||||
|
||||
public GuiAdminPermissions(SkyBlock plugin, IslandRole role, Gui returnGui) {
|
||||
super(6, returnGui);
|
||||
this.permissionManager = plugin.getPermissionManager();
|
||||
this.role = role;
|
||||
this.returnGui = returnGui;
|
||||
this.configLoad = plugin.getFileManager()
|
||||
.getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration();
|
||||
settingsConfig = plugin.getFileManager()
|
||||
.getConfig(new File(plugin.getDataFolder(), "settings.yml"));
|
||||
settingsConfigLoad = settingsConfig.getFileConfiguration();
|
||||
setTitle(TextUtils.formatText(configLoad.getString("Menu.Settings." + role.name() + ".Title")));
|
||||
setDefaultItem(null);
|
||||
paint();
|
||||
}
|
||||
|
||||
public void paint() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
setActionForRange(0, 0, 5, 9, null);
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
});
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
});
|
||||
|
||||
List<BasicPermission> permissions = permissionManager.getPermissions().stream()
|
||||
.filter(p -> p.getType() == getType(role))
|
||||
.collect(Collectors.toList());
|
||||
double itemCount = permissions.size();
|
||||
this.pages = (int) Math.max(1, Math.ceil(itemCount / 36));
|
||||
|
||||
if (page != 1)
|
||||
setButton(5, 2, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Last.Displayname"))),
|
||||
(event) -> {
|
||||
page--;
|
||||
paint();
|
||||
});
|
||||
|
||||
if (page != pages)
|
||||
setButton(5, 6, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Next.Displayname"))),
|
||||
(event) -> {
|
||||
page++;
|
||||
paint();
|
||||
});
|
||||
|
||||
for (int i = 9; i < 45; i++) {
|
||||
int current = ((page - 1) * 36) - 9;
|
||||
if (current + i >= permissions.size()) {
|
||||
setItem(i, null);
|
||||
continue;
|
||||
}
|
||||
BasicPermission permission = permissions.get(current + i);
|
||||
if (permission == null) continue;
|
||||
|
||||
final String path = "Settings." + role.name() + "." + permission.getName();
|
||||
boolean setting = settingsConfigLoad.getBoolean(path);
|
||||
setButton(i, permission.getItem(setting, role), (event) -> {
|
||||
settingsConfigLoad.set(path, !setting);
|
||||
try {
|
||||
settingsConfigLoad.save(settingsConfig.getFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
paint();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public PermissionType getType(IslandRole role) {
|
||||
switch (role) {
|
||||
default:
|
||||
case Visitor:
|
||||
case Member:
|
||||
case Coop:
|
||||
return PermissionType.GENERIC;
|
||||
case Operator:
|
||||
return PermissionType.OPERATOR;
|
||||
case Owner:
|
||||
return PermissionType.ISLAND;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class GuiPermissions extends Gui {
|
||||
|
||||
private SkyBlock plugin;
|
||||
private final SkyBlock plugin;
|
||||
private final PermissionManager permissionManager;
|
||||
private final IslandRole role;
|
||||
private final Island island;
|
||||
@ -63,17 +63,13 @@ public class GuiPermissions extends Gui {
|
||||
setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Item.Welcome.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Visitor.Item.Welcome.Lore"))),
|
||||
(event) -> {
|
||||
guiManager.showGUI(event.player, new GuiWelcomeEditor(plugin, this, island));
|
||||
});
|
||||
(event) -> guiManager.showGUI(event.player, new GuiWelcomeEditor(plugin, this, island)));
|
||||
|
||||
if (config.getFileConfiguration().getBoolean("Island.Visitor.Signature.Enable")) {
|
||||
setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Item.Signature.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Visitor.Item.Signature.Lore"))),
|
||||
(event) -> {
|
||||
guiManager.showGUI(event.player, new GuiSignatureEditor(plugin, this, island));
|
||||
});
|
||||
(event) -> guiManager.showGUI(event.player, new GuiSignatureEditor(plugin, this, island)));
|
||||
}
|
||||
|
||||
Visit visit = island.getVisit();
|
||||
|
@ -11,54 +11,68 @@ import com.songoda.skyblock.island.IslandRole;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
|
||||
public class GuiPermissionsSelector extends Gui {
|
||||
|
||||
public GuiPermissionsSelector(SkyBlock plugin, Island island, Gui returnGui) {
|
||||
public GuiPermissionsSelector(@Nonnull SkyBlock plugin, @Nullable Island island, @Nullable Gui returnGui) {
|
||||
super(1, returnGui);
|
||||
setDefaultItem(null);
|
||||
|
||||
String admin = island == null ? "Admin." : "";
|
||||
|
||||
FileConfiguration configLoad = plugin.getFileManager()
|
||||
.getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration();
|
||||
|
||||
setTitle(ChatColor.translateAlternateColorCodes('&',
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Title"))));
|
||||
TextUtils.formatText(configLoad.getString("Menu." + admin + "Settings.Categories.Title"))));
|
||||
|
||||
setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_SIGN,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Visitor.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Visitor.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Visitor, this)));
|
||||
TextUtils.formatText(configLoad.getString("Menu." + admin + "Settings.Categories.Item.Visitor.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu." + admin + "Settings.Categories.Item.Visitor.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, island == null ?
|
||||
new GuiAdminPermissions(plugin, IslandRole.Visitor, this) :
|
||||
new GuiPermissions(plugin, island, IslandRole.Visitor, this)));
|
||||
|
||||
setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.PAINTING,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Member.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Member.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Member, this)));
|
||||
TextUtils.formatText(configLoad.getString("Menu." + admin + "Settings.Categories.Item.Member.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu." + admin + "Settings.Categories.Item.Member.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, island == null ?
|
||||
new GuiAdminPermissions(plugin, IslandRole.Member, this) :
|
||||
new GuiPermissions(plugin, island, IslandRole.Member, this)));
|
||||
|
||||
setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.ITEM_FRAME,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Operator.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Operator.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Operator, this)));
|
||||
TextUtils.formatText(configLoad.getString("Menu." + admin + "Settings.Categories.Item.Operator.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu." + admin + "Settings.Categories.Item.Operator.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, island == null ?
|
||||
new GuiAdminPermissions(plugin, IslandRole.Operator, this) :
|
||||
new GuiPermissions(plugin, island, IslandRole.Operator, this)));
|
||||
|
||||
boolean isCoop = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration()
|
||||
.getBoolean("Island.Coop.Enable");
|
||||
|
||||
setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
TextUtils.formatText(configLoad.getString("Menu." + admin + "Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
CompatibleSound.BLOCK_CHEST_CLOSE.play(event.player);
|
||||
event.player.closeInventory();
|
||||
});
|
||||
|
||||
if (isCoop)
|
||||
setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.NAME_TAG,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Coop.Displayname")),
|
||||
TextUtils.formatText(configLoad.getString("Menu." + admin + "Settings.Categories.Item.Coop.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Coop.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Coop, this)));
|
||||
guiManager.showGUI(event.player, island == null ?
|
||||
new GuiAdminPermissions(plugin, IslandRole.Coop, this) :
|
||||
new GuiPermissions(plugin, island, IslandRole.Coop, this)));
|
||||
|
||||
setButton(isCoop ? 7 : 8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_SAPLING.getItem(),
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Owner.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Owner.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, new GuiPermissions(plugin, island, IslandRole.Owner, this)));
|
||||
TextUtils.formatText(configLoad.getString("Menu." + admin + "Settings.Categories.Item.Owner.Displayname")),
|
||||
TextUtils.formatText(configLoad.getStringList("Menu." + admin + "Settings.Categories.Item.Owner.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, island == null ?
|
||||
new GuiAdminPermissions(plugin, IslandRole.Owner, this) :
|
||||
new GuiPermissions(plugin, island, IslandRole.Owner, this)));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ public abstract class BasicPermission {
|
||||
}
|
||||
|
||||
public ItemStack getItem(Island island, IslandRole role) {
|
||||
return getItem(island.hasPermission(role, this), role);
|
||||
}
|
||||
|
||||
public ItemStack getItem(boolean permissionEnabled, IslandRole role) {
|
||||
ItemStack is = icon.getItem();
|
||||
FileManager.Config config = SkyBlock.getInstance().getFileManager()
|
||||
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "language.yml"));
|
||||
@ -50,7 +54,7 @@ public abstract class BasicPermission {
|
||||
|
||||
for (String itemLoreList : configLoad
|
||||
.getStringList("Menu.Settings." + roleName + ".Item.Setting.Status."
|
||||
+ (island.hasPermission(role, this) ? "Enabled" : "Disabled") + ".Lore"))
|
||||
+ (permissionEnabled ? "Enabled" : "Disabled") + ".Lore"))
|
||||
itemLore.add(TextUtils.formatText(itemLoreList));
|
||||
|
||||
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
|
Loading…
Reference in New Issue
Block a user