add config menu/command name & permission. also edit version number.

This commit is contained in:
alexcrea 2024-03-01 15:31:28 +01:00 committed by alexcrea
parent 321a2b1cc8
commit 6e0d1037bc
6 changed files with 54 additions and 14 deletions

View file

@ -30,10 +30,12 @@ ca.affected: Player with this permission will be affected by the plugin
ca.bypass.fuse: Allow player to combine every enchantments to every item (no custom limit) ca.bypass.fuse: Allow player to combine every enchantments to every item (no custom limit)
ca.bypass.level: Allow player to bypass every level limit (no custom limit) ca.bypass.level: Allow player to bypass every level limit (no custom limit)
ca.command.reload: Allow administrator to reload the plugin's configs ca.command.reload: Allow administrator to reload the plugin's configs
ca.config.edit: Allow administrator to reload the plugin's configs in game
``` ```
### Commands ### Commands
```yml ```yml
anvilconfigreload or carl: Reload every config of this plugin anvilconfigreload or carl: Reload every config of this plugin
customanvilconfig: open a menu for administrator to edit plugin's config in game
``` ```
--- ---
### Default Configuration: ### Default Configuration:

View file

@ -4,7 +4,7 @@ plugins {
} }
group = "xyz.alexcrea" group = "xyz.alexcrea"
version = "1.3" version = "1.3.0-alpha-1"
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -1,6 +1,8 @@
package xyz.alexcrea.cuanvil.gui.utils; package xyz.alexcrea.cuanvil.gui.utils;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import io.delilaheve.CustomAnvil;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
@ -12,7 +14,8 @@ import java.util.function.Consumer;
public class GuiGlobalActions { public class GuiGlobalActions {
public static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true); public final static String NO_EDIT_PERM = "§cYou do not have permission to edit the config";
public final static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true);
public static @NotNull Consumer<InventoryClickEvent> openGuiAction( public static @NotNull Consumer<InventoryClickEvent> openGuiAction(
@ -21,11 +24,18 @@ public class GuiGlobalActions {
@NotNull Object... args){ @NotNull Object... args){
return event -> { return event -> {
event.setCancelled(true); event.setCancelled(true);
HumanEntity player = event.getWhoClicked();
// Do not allow to open inventory if player do not have edit configuration permission
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(NO_EDIT_PERM);
return;
}
try { try {
Constructor<? extends Gui> constructor = clazz.getConstructor(argClass); Constructor<? extends Gui> constructor = clazz.getConstructor(argClass);
// Assume constructor is accessible // Assume constructor is accessible
Gui gui = constructor.newInstance(args); Gui gui = constructor.newInstance(args);
gui.show(event.getWhoClicked()); gui.show(player);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |
InstantiationException e) { InstantiationException e) {
@ -49,8 +59,15 @@ public class GuiGlobalActions {
public static @NotNull Consumer<InventoryClickEvent> openGuiAction(@NotNull Gui goal) { public static @NotNull Consumer<InventoryClickEvent> openGuiAction(@NotNull Gui goal) {
return event -> { return event -> {
HumanEntity player = event.getWhoClicked();
// Do not allow to open inventory if player do not have edit configuration permission
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(NO_EDIT_PERM);
return;
}
event.setCancelled(true); event.setCancelled(true);
goal.show(event.getWhoClicked()); goal.show(player);
}; };
} }
@ -59,14 +76,22 @@ public class GuiGlobalActions {
@NotNull ValueUpdatableGui goal) { @NotNull ValueUpdatableGui goal) {
return event -> { return event -> {
event.setCancelled(true); event.setCancelled(true);
HumanEntity player = event.getWhoClicked();
// Do not allow to save configuration if player do not have edit configuration permission
if(!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(NO_EDIT_PERM);
return;
}
// Save setting // Save setting
if(!setting.onSave()){ if(!setting.onSave()){
event.getWhoClicked().sendMessage("\u00A7cSomething wrong happen while saving the change of value."); player.sendMessage("\u00A7cSomething wrong happen while saving the change of value.");
} }
// Update gui for the one who have it open // Update gui for the one who have it open
goal.updateGuiValues(); goal.updateGuiValues();
// Then show // Then show
goal.show(event.getWhoClicked()); goal.show(player);
}; };
} }
} }

View file

@ -5,7 +5,7 @@ import org.bukkit.Bukkit
import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.configuration.file.YamlConfiguration
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
import xyz.alexcrea.cuanvil.command.ReloadExecutor import xyz.alexcrea.cuanvil.command.ReloadExecutor
import xyz.alexcrea.cuanvil.command.TestExecutor import xyz.alexcrea.cuanvil.command.EditConfigExecutor
import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.util.Metrics import xyz.alexcrea.cuanvil.util.Metrics
import xyz.alexcrea.cuanvil.util.MetricsUtil import xyz.alexcrea.cuanvil.util.MetricsUtil
@ -30,11 +30,13 @@ class CustomAnvil : JavaPlugin() {
const val bypassLevelPermission = "ca.bypass.level" const val bypassLevelPermission = "ca.bypass.level"
// Permission string required to reload the config // Permission string required to reload the config
const val commandReloadPermission = "ca.command.reload" const val commandReloadPermission = "ca.command.reload"
// Permission string required to edit the plugin's config
const val editConfigPermission = "ca.config.edit"
// Command Name to reload the config // Command Name to reload the config
const val commandReloadName = "anvilconfigreload" const val commandReloadName = "anvilconfigreload"
// Test command name // Test command name
const val commandTestName = "test" const val commandTestName = "customanvilconfig"
// Current plugin instance // Current plugin instance
lateinit var instance: CustomAnvil lateinit var instance: CustomAnvil
@ -113,7 +115,7 @@ class CustomAnvil : JavaPlugin() {
command?.setExecutor(ReloadExecutor()) command?.setExecutor(ReloadExecutor())
command = getCommand(commandTestName) command = getCommand(commandTestName)
command?.setExecutor(TestExecutor()) command?.setExecutor(EditConfigExecutor())
} }
} }

View file

@ -1,15 +1,20 @@
package xyz.alexcrea.cuanvil.command package xyz.alexcrea.cuanvil.command
import io.delilaheve.CustomAnvil
import org.bukkit.command.Command import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.entity.HumanEntity import org.bukkit.entity.HumanEntity
import xyz.alexcrea.cuanvil.gui.MainConfigGui import xyz.alexcrea.cuanvil.gui.MainConfigGui
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions
class TestExecutor : CommandExecutor { class EditConfigExecutor : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if(!sender.hasPermission(CustomAnvil.editConfigPermission)) {
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
return false
}
if(sender !is HumanEntity) return false if(sender !is HumanEntity) return false
MainConfigGui.INSTANCE.show(sender) MainConfigGui.INSTANCE.show(sender)

View file

@ -1,7 +1,7 @@
main: io.delilaheve.CustomAnvil main: io.delilaheve.CustomAnvil
name: CustomAnvil name: CustomAnvil
prefix: "Custom Anvil" prefix: "Custom Anvil"
version: 1.3 version: 1.3.0-alpha-1
description: Allow to customise anvil mechanics description: Allow to customise anvil mechanics
api-version: 1.18 api-version: 1.18
load: POSTWORLD load: POSTWORLD
@ -18,8 +18,11 @@ commands:
#- acreload # anvil config reload #- acreload # anvil config reload
#- careload # custom anvil reload #- careload # custom anvil reload
- carl # custom anvil reload - carl # custom anvil reload
test: customanvilconfig:
description: test cmd description: open a menu for administrator to edit plugin's config in game
permission: ca.config.edit
aliases:
- configanvil
permissions: permissions:
ca.affected: ca.affected:
@ -34,6 +37,9 @@ permissions:
ca.command.reload: ca.command.reload:
default: op default: op
description: Allow administrator to reload the plugin's configs description: Allow administrator to reload the plugin's configs
ca.config.edit:
default: op
description: Allow administrator to reload the plugin's configs in game
# soft depend on old name so I can disable it if it is on the same server # soft depend on old name so I can disable it if it is on the same server
# as it is the old name for this plugin # as it is the old name for this plugin