diff --git a/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java b/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java index 272d03ba..56cd0033 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java +++ b/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java @@ -29,10 +29,12 @@ import net.william278.huskhomes.teleport.TeleportManager; import net.william278.huskhomes.util.BukkitLogger; import net.william278.huskhomes.util.BukkitResourceReader; import net.william278.huskhomes.util.Logger; +import net.william278.huskhomes.util.Permission; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.PluginCommand; +import org.bukkit.permissions.PermissionDefault; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -163,6 +165,15 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes { // Prepare the home and warp position manager this.savedPositionManager = new SavedPositionManager(database, cache); + // Register permissions + Arrays.stream(Permission.values()).forEach(permission -> getServer().getPluginManager().addPermission( + new org.bukkit.permissions.Permission(permission.node, + switch (permission.defaultAccess) { + case EVERYONE -> PermissionDefault.TRUE; + case NOBODY -> PermissionDefault.FALSE; + case OPERATORS -> PermissionDefault.OP; + }))); + // Register commands - todo add all here getLogger().log(Level.INFO, "Registering commands..."); final CommandBase[] commands = new CommandBase[]{ diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java index 5d250513..2693ff6a 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java @@ -38,6 +38,7 @@ public class BukkitCommand implements CommandExecutor, TabExecutor { public void register(@NotNull PluginCommand pluginCommand) { pluginCommand.setExecutor(this); pluginCommand.setTabCompleter(this); + pluginCommand.setPermission(command.permission); pluginCommand.setDescription(command.getDescription()); } diff --git a/common/src/main/java/net/william278/huskhomes/command/BackCommand.java b/common/src/main/java/net/william278/huskhomes/command/BackCommand.java index a9b35ab3..1e3582c0 100644 --- a/common/src/main/java/net/william278/huskhomes/command/BackCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/BackCommand.java @@ -3,14 +3,13 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.player.Player; import net.william278.huskhomes.player.User; +import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; public class BackCommand extends CommandBase { - private final static String PERMISSION = "huskhomes.command.back"; - public BackCommand(@NotNull HuskHomes implementor) { - super("back", PERMISSION, implementor); + super("back", Permission.COMMAND_BACK, implementor); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/command/CommandBase.java b/common/src/main/java/net/william278/huskhomes/command/CommandBase.java index 8edff400..6d7fd206 100644 --- a/common/src/main/java/net/william278/huskhomes/command/CommandBase.java +++ b/common/src/main/java/net/william278/huskhomes/command/CommandBase.java @@ -2,6 +2,7 @@ package net.william278.huskhomes.command; import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.player.Player; +import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; /** @@ -30,9 +31,9 @@ public abstract class CommandBase { public final HuskHomes plugin; - public CommandBase(@NotNull String command, @NotNull String permission, @NotNull HuskHomes implementor, String... aliases) { + public CommandBase(@NotNull String command, @NotNull Permission permission, @NotNull HuskHomes implementor, String... aliases) { this.command = command; - this.permission = permission; + this.permission = permission.node; this.plugin = implementor; this.aliases = aliases; } diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java index 5963bc11..11b853a1 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java @@ -4,6 +4,7 @@ import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.list.PrivateHomeList; import net.william278.huskhomes.player.Player; import net.william278.huskhomes.player.User; +import net.william278.huskhomes.util.Permission; import net.william278.huskhomes.util.RegexUtil; import org.jetbrains.annotations.NotNull; @@ -12,10 +13,8 @@ import java.util.stream.Collectors; public class HomeCommand extends CommandBase implements TabCompletable, ConsoleExecutable { - private final static String PERMISSION = "huskhomes.command.home"; - public HomeCommand(@NotNull HuskHomes implementor) { - super("home", PERMISSION, implementor); + super("home", Permission.COMMAND_HOME, implementor); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java index 1b4a99a6..728bb5f8 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java @@ -4,14 +4,13 @@ import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.list.PrivateHomeList; import net.william278.huskhomes.player.Player; import net.william278.huskhomes.player.User; +import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; public class HomeListCommand extends CommandBase implements ConsoleExecutable { - private final static String PERMISSION = "huskhomes.command.home"; - public HomeListCommand(@NotNull HuskHomes implementor) { - super("homelist", PERMISSION, implementor); + super("homelist", Permission.COMMAND_HOME, implementor); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java index e06e9675..ccfa1356 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java @@ -5,14 +5,13 @@ import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.player.Player; import net.william278.huskhomes.player.User; import net.william278.huskhomes.position.PositionMeta; +import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; public class SetHomeCommand extends CommandBase { - private final static String PERMISSION = "huskhomes.command.sethome"; - public SetHomeCommand(@NotNull HuskHomes implementor) { - super("sethome", PERMISSION, implementor); + super("sethome", Permission.COMMAND_SET_HOME, implementor); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/listener/EventProcessor.java b/common/src/main/java/net/william278/huskhomes/listener/EventProcessor.java index 2d0ead85..8f8091aa 100644 --- a/common/src/main/java/net/william278/huskhomes/listener/EventProcessor.java +++ b/common/src/main/java/net/william278/huskhomes/listener/EventProcessor.java @@ -83,4 +83,22 @@ public class EventProcessor { new User(player.getUuid(), player.getName()), position)); } + /** + * Handle when a {@link Player} dies + * + * @param player the {@link Player} who died + */ + public void onPlayerDeath(@NotNull Player player) { + + } + + /** + * Handle when a {@link Player} respawns after dying + * + * @param player the respawning {@link Player} + */ + public void onPlayerRespawn(@NotNull Player player) { + + } + } \ No newline at end of file diff --git a/common/src/main/java/net/william278/huskhomes/util/Permission.java b/common/src/main/java/net/william278/huskhomes/util/Permission.java new file mode 100644 index 00000000..2433ef54 --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/util/Permission.java @@ -0,0 +1,173 @@ +package net.william278.huskhomes.util; + +import org.jetbrains.annotations.NotNull; + +/** + * Static plugin permission nodes required to perform actions or execute commands + */ +public enum Permission { + + /* + * Bypass permission nodes + */ + + /** + * Lets the user bypass the warmup time when a player must stand still before teleportation + */ + BYPASS_TELEPORT_WARMUP("huskhomes.bypass.teleport_warmup", DefaultAccess.NOBODY), + /** + * Lets the user bypass the cooldown on the {@code /rtp} command + */ + BYPASS_RTP_COOLDOWN("huskhomes.bypass.rtp_cooldown", DefaultAccess.NOBODY), + + /* + * Command permission nodes + */ + + /** + * Lets the user teleport to their homes ({@code /home [home_name]}) + */ + COMMAND_HOME("huskhomes.command.home", DefaultAccess.EVERYONE), + /** + * Lets the user teleport to other users' homes ({@code /home [player_name.home_name]}) + */ + COMMAND_HOME_OTHER("huskhomes.command.home.other", DefaultAccess.OPERATORS), + /** + * Lets the user set a home ({@code /sethome [home_name]}) + */ + COMMAND_SET_HOME("huskhomes.command.sethome", DefaultAccess.EVERYONE), + /** + * Lets the user delete a home ({@code /delhome [home_name]}) + */ + COMMAND_DELETE_HOME("huskhomes.command.delhome", DefaultAccess.EVERYONE), + /** + * Lets the user delete other users' homes ({@code /delhome [player_name.home_name]}) + */ + COMMAND_DELETE_HOME_OTHER("huskhomes.command.delhome.other", DefaultAccess.OPERATORS), + /** + * Lets the user edit their homes ({@code /edithome [home_name]}) + */ + COMMAND_EDIT_HOME("huskhomes.command.edithome", DefaultAccess.EVERYONE), + /** + * Lets the user edit other users' homes ({@code /edithome [player_name.home_name]}) + */ + COMMAND_EDIT_HOME_OTHER("huskhomes.command.edithome.other", DefaultAccess.OPERATORS), + /** + * Lets the user edit the privacy of their home ({@code /edithome [home_name] [public/private]}) + */ + COMMAND_EDIT_HOME_PRIVACY("huskhomes.command.edithome.privacy", DefaultAccess.EVERYONE), + /** + * Lets the user teleport to a public home ({@code /phome [player_name.home_name]}) + */ + COMMAND_PUBLIC_HOME("huskhomes.command.phome", DefaultAccess.EVERYONE), + /** + * Lets the user teleport to a warp ({@code /warp [warp_name]}) + */ + COMMAND_WARP("huskhomes.command.warp", DefaultAccess.EVERYONE), + /** + * Lets the user set a warp ({@code /setwarp [warp_name]}) + */ + COMMAND_SET_WARP("huskhomes.command.setwarp", DefaultAccess.OPERATORS), + /** + * Lets the user delete a warp ({@code /delwarp [warp_name]}) + */ + COMMAND_DELETE_WARP("huskhomes.command.delwarp", DefaultAccess.OPERATORS), + /** + * Lets the user edit a warp ({@code /editwarp [warp_name]}) + */ + COMMAND_EDIT_WARP("huskhomes.command.editwarp", DefaultAccess.OPERATORS), + /** + * Lets the user instantly tp to another player ({@code /tp [player_name]}) + */ + COMMAND_TP("huskhomes.command.tp", DefaultAccess.OPERATORS), + /** + * Lets the user instantly tp to a set of coordinates ({@code /tp [x] [y] [z] [yaw] [pitch] [world] [server]}) + */ + COMMAND_TP_TO_COORDINATES("huskhomes.command.tp.coordinates", DefaultAccess.OPERATORS), + /** + * Lets the user instantly tp another player to them ({@code /tphere [player_name]}) + */ + COMMAND_TPHERE("huskhomes.command.tphere", DefaultAccess.OPERATORS), + /** + * Lets the user request to tp to another player ({@code /tpa [player_name]}) + */ + COMMAND_TPA("huskhomes.command.tpa", DefaultAccess.EVERYONE), + /** + * Lets the user request another player to tp to them ({@code /tpahere [player_name]}) + */ + COMMAND_TPAHERE("huskhomes.command.tpahere", DefaultAccess.EVERYONE), + /** + * Lets the user accept a tp request ({@code /tpaccept}) + */ + COMMAND_TPACCEPT("huskhomes.command.tpaccept", DefaultAccess.EVERYONE), + /** + * Lets the user deny a tp request ({@code /tpdeny}) + */ + COMMAND_TPDENY("huskhomes.command.tpdeny", DefaultAccess.EVERYONE), + /** + * Lets the user ignore incoming tp requests ({@code /tpignore}) + */ + COMMAND_TPIGNORE("huskhomes.command.tpignore", DefaultAccess.EVERYONE), + /** + * Lets the user tp to where a user logged out ({@code /tpoffline [player_name]}) + */ + COMMAND_TPOFFLINE("huskhomes.command.tpoffline", DefaultAccess.OPERATORS), + /** + * Lets the user randomly teleport in the world they are in ({@code /rtp}) + */ + COMMAND_RTP("huskhomes.command.rtp", DefaultAccess.EVERYONE), + /** + * Lets the user teleport to the defined spawn position ({@code /spawn}) + */ + COMMAND_SPAWN("huskhomes.command.spawn", DefaultAccess.EVERYONE), + /** + * Lets the user set the spawn position ({@code /setspawn}) + */ + COMMAND_SETSPAWN("huskhomes.command.setspawn", DefaultAccess.OPERATORS), + /** + * Lets the user return to where they last teleported from ({@code /back}) + */ + COMMAND_BACK("huskhomes.command.back", DefaultAccess.EVERYONE), + /** + * Lets the user use {@code /back} to return to where they died + */ + COMMAND_BACK_ON_DEATH("huskhomes.command.back.death", DefaultAccess.EVERYONE), + /** + * Lets the user view plugin information + */ + COMMAND_HUSKHOMES_ABOUT("huskhomes.command.huskhomes.about", DefaultAccess.EVERYONE), + /** + * Lets the user reload the plugin config and message files + */ + COMMAND_HUSKHOMES_RELOAD("huskhomes.command.huskhomes.reload", DefaultAccess.OPERATORS), + /** + * Lets the user check for plugin updates + */ + COMMAND_HUSKHOMES_UPDATE("huskhomes.command.huskhomes.update", DefaultAccess.OPERATORS); + + public final String node; + public final DefaultAccess defaultAccess; + + Permission(@NotNull String node, @NotNull DefaultAccess defaultAccess) { + this.node = node; + this.defaultAccess = defaultAccess; + } + + /** + * Identifies who gets what permissions by default + */ + public enum DefaultAccess { + /** + * Everyone gets this permission node by default + */ + EVERYONE, + /** + * Nobody gets this permission node by default + */ + NOBODY, + /** + * Server operators ({@code /op}) get this permission node by default + */ + OPERATORS + } +}