mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-10 09:47:42 +01:00
Settings permissions
This commit is contained in:
parent
ef34164d50
commit
842243a9c7
@ -13,7 +13,7 @@ public class SettingsCommand extends SubCommand {
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
SoundManager soundManager = plugin.getSoundManager();
|
||||
|
||||
plugin.getGuiManager().showGUI(player, new GuiPermissionsSelector(plugin, null, null));
|
||||
plugin.getGuiManager().showGUI(player, new GuiPermissionsSelector(plugin, player, null, null));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class SettingsCommand extends SubCommand {
|
||||
&& (permissionManager.hasPermission(island, "Visitor", IslandRole.Operator)
|
||||
|| permissionManager.hasPermission(island, "Member", IslandRole.Operator)))
|
||||
|| island.hasRole(IslandRole.Owner, player.getUniqueId())) {
|
||||
plugin.getGuiManager().showGUI(player, new GuiPermissionsSelector(plugin, island, null));
|
||||
plugin.getGuiManager().showGUI(player, new GuiPermissionsSelector(plugin, player, island, null));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F);
|
||||
} else{
|
||||
messageManager.sendMessage(player,
|
||||
|
@ -23,6 +23,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -33,22 +34,24 @@ public class GuiPermissions extends Gui {
|
||||
private final SoundManager soundManager;
|
||||
private final IslandRole role;
|
||||
private final Island island;
|
||||
private final Player player;
|
||||
private final FileConfiguration languageLoad;
|
||||
private final FileConfiguration configLoad;
|
||||
private final FileManager.Config config;
|
||||
private final Gui returnGui;
|
||||
|
||||
public GuiPermissions(SkyBlock plugin, Island island, IslandRole role, Gui returnGui) {
|
||||
public GuiPermissions(SkyBlock plugin, Player player, Island island, IslandRole role, Gui returnGui) {
|
||||
super(6, returnGui);
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.permissionManager = plugin.getPermissionManager();
|
||||
this.soundManager = plugin.getSoundManager();
|
||||
this.role = role;
|
||||
this.island = island;
|
||||
this.returnGui = returnGui;
|
||||
this.configLoad = plugin.getFileManager()
|
||||
this.languageLoad = plugin.getFileManager()
|
||||
.getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration();
|
||||
this.config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml"));
|
||||
setTitle(TextUtils.formatText(configLoad.getString("Menu.Settings." + role.name() + ".Title")));
|
||||
this.configLoad = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration();
|
||||
setTitle(TextUtils.formatText(languageLoad.getString("Menu.Settings." + role.name() + ".Title")));
|
||||
setDefaultItem(null);
|
||||
paint();
|
||||
}
|
||||
@ -59,22 +62,22 @@ public class GuiPermissions extends Gui {
|
||||
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) -> {
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
soundManager.playSound(event.player, CompatibleSound.BLOCK_CHEST_CLOSE.getSound(), 1f, 1f);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
});
|
||||
|
||||
if (role == IslandRole.Visitor) {
|
||||
if (config.getFileConfiguration().getBoolean("Island.Visitor.Welcome.Enable"))
|
||||
if (configLoad.getBoolean("Island.Visitor.Welcome.Enable"))
|
||||
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"))),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Visitor.Item.Welcome.Displayname")),
|
||||
TextUtils.formatText(languageLoad.getStringList("Menu.Settings.Visitor.Item.Welcome.Lore"))),
|
||||
(event) -> guiManager.showGUI(event.player, new GuiWelcomeEditor(plugin, this, island)));
|
||||
|
||||
if (config.getFileConfiguration().getBoolean("Island.Visitor.Signature.Enable")) {
|
||||
if (configLoad.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"))),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Visitor.Item.Signature.Displayname")),
|
||||
TextUtils.formatText(languageLoad.getStringList("Menu.Settings.Visitor.Item.Signature.Lore"))),
|
||||
(event) -> guiManager.showGUI(event.player, new GuiSignatureEditor(plugin, this, island)));
|
||||
}
|
||||
|
||||
@ -91,7 +94,7 @@ public class GuiPermissions extends Gui {
|
||||
configAddress = "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Whitelisted.Lore";
|
||||
break;
|
||||
}
|
||||
List<String> welcomeLore = TextUtils.formatText(configLoad.getStringList(configAddress));
|
||||
List<String> welcomeLore = TextUtils.formatText(languageLoad.getStringList(configAddress));
|
||||
|
||||
List<String> welcomeFinal = new ArrayList<>();
|
||||
|
||||
@ -102,7 +105,7 @@ public class GuiPermissions extends Gui {
|
||||
}
|
||||
|
||||
setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.PAINTING,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname")),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname")),
|
||||
welcomeFinal),
|
||||
(event -> {
|
||||
switch (island.getStatus()) {
|
||||
@ -124,7 +127,7 @@ public class GuiPermissions extends Gui {
|
||||
}
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Exit.Displayname"))), (event) -> {
|
||||
soundManager.playSound(event.player, CompatibleSound.BLOCK_CHEST_CLOSE.getSound(), 1f, 1f);
|
||||
guiManager.showGUI(event.player, returnGui);
|
||||
});
|
||||
@ -132,12 +135,18 @@ public class GuiPermissions extends Gui {
|
||||
List<BasicPermission> permissions = permissionManager.getPermissions().stream()
|
||||
.filter(p -> p.getType() == getType(role))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if(configLoad.getBoolean("Island.Settings.Permission")) {
|
||||
permissions.removeIf(permission -> !player.hasPermission("fabledskyblock.settings." +
|
||||
role.name().toLowerCase() + "." + permission.getName().toLowerCase()));
|
||||
}
|
||||
|
||||
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"))),
|
||||
TextUtils.formatText(languageLoad.getString("Menu.Settings.Categories.Item.Last.Displayname"))),
|
||||
(event) -> {
|
||||
page--;
|
||||
paint();
|
||||
@ -145,33 +154,37 @@ public class GuiPermissions extends Gui {
|
||||
|
||||
if (page != pages)
|
||||
setButton(5, 6, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
||||
TextUtils.formatText(configLoad.getString("Menu.Settings.Categories.Item.Next.Displayname"))),
|
||||
TextUtils.formatText(languageLoad.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;
|
||||
|
||||
setButton(i, permission.getItem(island, role), (event) -> {
|
||||
if (!hasPermission(island, event.player, role)) {
|
||||
plugin.getMessageManager().sendMessage(event.player, configLoad
|
||||
.getString("Command.Island.Settings.Permission.Change.Message"));
|
||||
soundManager.playSound(event.player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f);
|
||||
|
||||
return;
|
||||
if(!permissions.isEmpty()) {
|
||||
for (int i = 9; i < 45; i++) {
|
||||
int current = ((page - 1) * 36) - 9;
|
||||
if (current + i >= permissions.size()) {
|
||||
setItem(i, null);
|
||||
continue;
|
||||
}
|
||||
IslandPermission islandPermission = island.getPermission(role, permission);
|
||||
islandPermission.setStatus(!islandPermission.getStatus());
|
||||
paint();
|
||||
});
|
||||
BasicPermission permission = permissions.get(current + i);
|
||||
if (permission == null) continue;
|
||||
|
||||
setButton(i, permission.getItem(island, role), (event) -> {
|
||||
if (!hasPermission(island, event.player, role)) {
|
||||
plugin.getMessageManager().sendMessage(event.player, languageLoad
|
||||
.getString("Command.Island.Settings.Permission.Change.Message"));
|
||||
soundManager.playSound(event.player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f);
|
||||
|
||||
return;
|
||||
}
|
||||
IslandPermission islandPermission = island.getPermission(role, permission);
|
||||
islandPermission.setStatus(!islandPermission.getStatus());
|
||||
paint();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
setItem(31, CompatibleMaterial.BARRIER.getItem()); // TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandRole;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -17,7 +18,7 @@ import java.io.File;
|
||||
|
||||
public class GuiPermissionsSelector extends Gui {
|
||||
|
||||
public GuiPermissionsSelector(@Nonnull SkyBlock plugin, @Nullable Island island, @Nullable Gui returnGui) {
|
||||
public GuiPermissionsSelector(@Nonnull SkyBlock plugin, @Nullable Player player, @Nullable Island island, @Nullable Gui returnGui) {
|
||||
super(1, returnGui);
|
||||
setDefaultItem(null);
|
||||
|
||||
@ -34,21 +35,21 @@ public class GuiPermissionsSelector extends Gui {
|
||||
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)));
|
||||
new GuiPermissions(plugin, player, island, IslandRole.Visitor, this)));
|
||||
|
||||
setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.PAINTING,
|
||||
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)));
|
||||
new GuiPermissions(plugin, player, island, IslandRole.Member, this)));
|
||||
|
||||
setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.ITEM_FRAME,
|
||||
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)));
|
||||
new GuiPermissions(plugin, player, island, IslandRole.Operator, this)));
|
||||
|
||||
boolean isCoop = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml")).getFileConfiguration()
|
||||
.getBoolean("Island.Coop.Enable");
|
||||
@ -65,14 +66,14 @@ public class GuiPermissionsSelector extends Gui {
|
||||
TextUtils.formatText(configLoad.getStringList("Menu.Settings.Categories.Item.Coop.Lore"))), (event) ->
|
||||
guiManager.showGUI(event.player, island == null ?
|
||||
new GuiAdminPermissions(plugin, IslandRole.Coop, this) :
|
||||
new GuiPermissions(plugin, island, IslandRole.Coop, this)));
|
||||
new GuiPermissions(plugin, player, island, IslandRole.Coop, this)));
|
||||
|
||||
setButton(isCoop ? 7 : 8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_SAPLING.getItem(),
|
||||
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)));
|
||||
new GuiPermissions(plugin, player, island, IslandRole.Owner, this)));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -291,6 +291,9 @@ Island:
|
||||
# items in their inventory if they die at an island.
|
||||
Enable: true
|
||||
Settings:
|
||||
# With this option true the players will need fabledskyblock.settings.<role>.<settingName> permission
|
||||
# Roles and settings name can be found in the settings.yml file
|
||||
Permission: false
|
||||
# When any of these options are disabled, the setting will be removed from the settings menu
|
||||
# menu.
|
||||
KeepItemsOnDeath:
|
||||
|
Loading…
Reference in New Issue
Block a user