mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancynpcs: Implemented inversed permission checks -> "!" prefix for perms (#139)
* Implemented feature from here: https://github.com/FancyInnovations/FancyPlugins/issues/86 * Implemented feature from here: https://github.com/FancyInnovations/FancyPlugins/issues/50
This commit is contained in:
@@ -20,7 +20,13 @@ public class NeedPermissionAction extends NpcAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.getPlayer().hasPermission(value)) {
|
boolean invertCheck = value.startsWith("!");
|
||||||
|
String permission = invertCheck ? value.substring(1) : value;
|
||||||
|
|
||||||
|
boolean hasPermission = context.getPlayer().hasPermission(permission);
|
||||||
|
boolean passesCheck = invertCheck ? !hasPermission : hasPermission;
|
||||||
|
|
||||||
|
if (!passesCheck) {
|
||||||
FancyNpcsPlugin.get().getTranslator().translate("action_missing_permissions").send(context.getPlayer());
|
FancyNpcsPlugin.get().getTranslator().translate("action_missing_permissions").send(context.getPlayer());
|
||||||
context.terminate();
|
context.terminate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ public class NpcModifyEvent extends Event implements Cancellable {
|
|||||||
LOCATION,
|
LOCATION,
|
||||||
MIRROR_SKIN,
|
MIRROR_SKIN,
|
||||||
PLAYER_COMMAND,
|
PLAYER_COMMAND,
|
||||||
|
ROTATION,
|
||||||
SERVER_COMMAND,
|
SERVER_COMMAND,
|
||||||
SHOW_IN_TAB,
|
SHOW_IN_TAB,
|
||||||
SKIN,
|
SKIN,
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ public final class CloudCommandManager {
|
|||||||
annotationParser.parse(NearbyCMD.INSTANCE);
|
annotationParser.parse(NearbyCMD.INSTANCE);
|
||||||
annotationParser.parse(HelpCMD.INSTANCE);
|
annotationParser.parse(HelpCMD.INSTANCE);
|
||||||
annotationParser.parse(RemoveCMD.INSTANCE);
|
annotationParser.parse(RemoveCMD.INSTANCE);
|
||||||
|
annotationParser.parse(RotateCMD.INSTANCE);
|
||||||
annotationParser.parse(ShowInTabCMD.INSTANCE);
|
annotationParser.parse(ShowInTabCMD.INSTANCE);
|
||||||
annotationParser.parse(SkinCMD.INSTANCE);
|
annotationParser.parse(SkinCMD.INSTANCE);
|
||||||
annotationParser.parse(TeleportCMD.INSTANCE);
|
annotationParser.parse(TeleportCMD.INSTANCE);
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package de.oliver.fancynpcs.commands.npc;
|
||||||
|
|
||||||
|
import de.oliver.fancylib.translations.Translator;
|
||||||
|
import de.oliver.fancynpcs.FancyNpcs;
|
||||||
|
import de.oliver.fancynpcs.api.Npc;
|
||||||
|
import de.oliver.fancynpcs.api.events.NpcModifyEvent;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.incendo.cloud.annotations.Command;
|
||||||
|
import org.incendo.cloud.annotations.Permission;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public enum RotateCMD {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
private final Translator translator = FancyNpcs.getInstance().getTranslator();
|
||||||
|
|
||||||
|
@Command("npc rotate <npc> <yaw> <pitch>")
|
||||||
|
@Permission("fancynpcs.command.npc.rotate")
|
||||||
|
public void onRotate(
|
||||||
|
final @NotNull CommandSender sender,
|
||||||
|
final @NotNull Npc npc,
|
||||||
|
final float yaw,
|
||||||
|
final float pitch
|
||||||
|
) {
|
||||||
|
final Location currentLocation = npc.getData().getLocation();
|
||||||
|
final Location newLocation = currentLocation.clone();
|
||||||
|
newLocation.setYaw(yaw);
|
||||||
|
newLocation.setPitch(pitch);
|
||||||
|
|
||||||
|
if (new NpcModifyEvent(npc, NpcModifyEvent.NpcModification.ROTATION, new float[]{yaw, pitch}, sender).callEvent()) {
|
||||||
|
npc.getData().setLocation(newLocation);
|
||||||
|
npc.updateForAll();
|
||||||
|
translator.translate("npc_rotate_set_success")
|
||||||
|
.replace("npc", npc.getData().getName())
|
||||||
|
.replace("yaw", String.valueOf(yaw))
|
||||||
|
.replace("pitch", String.valueOf(pitch))
|
||||||
|
.send(sender);
|
||||||
|
} else {
|
||||||
|
translator.translate("command_npc_modification_cancelled").send(sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -123,6 +123,7 @@ messages:
|
|||||||
npc_move_to: "<dark_gray>› <gray>Syntax: {primaryColor}/npc move_to {secondaryColor}(npc) (x) (y) (z) [world]"
|
npc_move_to: "<dark_gray>› <gray>Syntax: {primaryColor}/npc move_to {secondaryColor}(npc) (x) (y) (z) [world]"
|
||||||
npc_nearby: "<dark_gray>› <gray>Syntax: {primaryColor}/npc nearby {secondaryColor}[filters...]"
|
npc_nearby: "<dark_gray>› <gray>Syntax: {primaryColor}/npc nearby {secondaryColor}[filters...]"
|
||||||
npc_remove: "<dark_gray>› <gray>Syntax: {primaryColor}/npc remove {secondaryColor}(npc)"
|
npc_remove: "<dark_gray>› <gray>Syntax: {primaryColor}/npc remove {secondaryColor}(npc)"
|
||||||
|
npc_rotate: "<dark_gray>› <gray>Syntax: {primaryColor}/npc rotate {secondaryColor}(npc) (yaw) (pitch)"
|
||||||
npc_show_in_tab: "<dark_gray>› <gray>Syntax: {primaryColor}/npc show_in_tab {secondaryColor}(npc) (state)"
|
npc_show_in_tab: "<dark_gray>› <gray>Syntax: {primaryColor}/npc show_in_tab {secondaryColor}(npc) (state)"
|
||||||
npc_skin: "<dark_gray>› <gray>Syntax: {primaryColor}/npc skin {secondaryColor}(npc) (@none | @mirror | name | uuid | placeholder | url | file name) [--slim]"
|
npc_skin: "<dark_gray>› <gray>Syntax: {primaryColor}/npc skin {secondaryColor}(npc) (@none | @mirror | name | uuid | placeholder | url | file name) [--slim]"
|
||||||
npc_teleport: "<dark_gray>› <gray>Syntax: {primaryColor}/npc teleport {secondaryColor}(npc)"
|
npc_teleport: "<dark_gray>› <gray>Syntax: {primaryColor}/npc teleport {secondaryColor}(npc)"
|
||||||
@@ -176,6 +177,7 @@ messages:
|
|||||||
- "<dark_gray>› <hover:show_text:'<gray>Teleports NPC to specified location.'>{primaryColor}/npc move_to {secondaryColor}(npc) (x) (y) (z) [world]"
|
- "<dark_gray>› <hover:show_text:'<gray>Teleports NPC to specified location.'>{primaryColor}/npc move_to {secondaryColor}(npc) (x) (y) (z) [world]"
|
||||||
- "<dark_gray>› <hover:show_text:'<gray>Lists all NPCs in your world. Can be filtered and sorted.'>{primaryColor}/npc nearby {secondaryColor}[--radius] [--type] [--sort]"
|
- "<dark_gray>› <hover:show_text:'<gray>Lists all NPCs in your world. Can be filtered and sorted.'>{primaryColor}/npc nearby {secondaryColor}[--radius] [--type] [--sort]"
|
||||||
- "<dark_gray>› <hover:show_text:'<gray>Removes (deletes) specified NPC.'>{primaryColor}/npc remove {secondaryColor}(npc)"
|
- "<dark_gray>› <hover:show_text:'<gray>Removes (deletes) specified NPC.'>{primaryColor}/npc remove {secondaryColor}(npc)"
|
||||||
|
- "<dark_gray>› <hover:show_text:'<gray>Changes the rotation (yaw and pitch) of the NPC.'>{primaryColor}/npc rotate {secondaryColor}(npc) (yaw) (pitch)"
|
||||||
- "<dark_gray>› <hover:show_text:'<gray>Changes the scale of the size of the NPC.'>{primaryColor}/npc scale {secondaryColor}(npc) (factor)"
|
- "<dark_gray>› <hover:show_text:'<gray>Changes the scale of the size of the NPC.'>{primaryColor}/npc scale {secondaryColor}(npc) (factor)"
|
||||||
- "<dark_gray>› <hover:show_text:'<gray>Changes whether the NPC is shown in the player-list. This works only on NPCs of PLAYER type.<newline><newline>{errorColor}Re-connecting to the server might be required for changes to take effect.'>{primaryColor}/npc show_in_tab {secondaryColor}(npc) (state)"
|
- "<dark_gray>› <hover:show_text:'<gray>Changes whether the NPC is shown in the player-list. This works only on NPCs of PLAYER type.<newline><newline>{errorColor}Re-connecting to the server might be required for changes to take effect.'>{primaryColor}/npc show_in_tab {secondaryColor}(npc) (state)"
|
||||||
- "<dark_gray>› <hover:show_text:'<gray>Changes skin of the NPC.<newline><gray>Supports PlaceholderAPI and MiniPlaceholders.<newline><newline>{warningColor}@none <dark_gray>- <gray>removes the skin<newline>{warningColor}@mirror <dark_gray>- <gray>mirrors player skin<newline>{warningColor}(name) <dark_gray>- <gray>name of any player<newline>{warningColor}(url) <dark_gray>- <gray>url of the skin texture'>{primaryColor}/npc skin {secondaryColor}(npc) (@none | @mirror | name | url) [--slim]"
|
- "<dark_gray>› <hover:show_text:'<gray>Changes skin of the NPC.<newline><gray>Supports PlaceholderAPI and MiniPlaceholders.<newline><newline>{warningColor}@none <dark_gray>- <gray>removes the skin<newline>{warningColor}@mirror <dark_gray>- <gray>mirrors player skin<newline>{warningColor}(name) <dark_gray>- <gray>name of any player<newline>{warningColor}(url) <dark_gray>- <gray>url of the skin texture'>{primaryColor}/npc skin {secondaryColor}(npc) (@none | @mirror | name | url) [--slim]"
|
||||||
@@ -302,6 +304,9 @@ messages:
|
|||||||
# Commands (npc remove)
|
# Commands (npc remove)
|
||||||
npc_remove_success: "<dark_gray>› <gray>NPC {warningColor}{npc}<gray> has been removed."
|
npc_remove_success: "<dark_gray>› <gray>NPC {warningColor}{npc}<gray> has been removed."
|
||||||
|
|
||||||
|
# Commands (npc rotate)
|
||||||
|
npc_rotate_set_success: "<dark_gray>› <gray>NPC {warningColor}{npc}<gray> has been rotated to yaw {warningColor}{yaw}<gray> and pitch {warningColor}{pitch}<gray>."
|
||||||
|
|
||||||
# Commands (scale)
|
# Commands (scale)
|
||||||
npc_scale_set_success: "<dark_gray>› <gray>NPC {warningColor}{npc}<gray> has been scaled to {warningColor}{scale}<gray>."
|
npc_scale_set_success: "<dark_gray>› <gray>NPC {warningColor}{npc}<gray> has been scaled to {warningColor}{scale}<gray>."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user