Skip to content

Commit

Permalink
Adaptation to the latest version of FacilisCommon
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev7ex committed Mar 4, 2024
1 parent fcdc7bb commit 6ae3fba
Show file tree
Hide file tree
Showing 29 changed files with 270 additions and 269 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dev7ex.multiperms.api.bukkit;

import com.dev7ex.common.bukkit.plugin.configuration.DefaultPluginConfiguration;
import com.dev7ex.common.io.file.configuration.ConfigurationHolder;
import com.dev7ex.multiperms.api.MultiPermsApiConfiguration;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -13,14 +14,14 @@
*/
public abstract class MultiPermsBukkitApiConfiguration extends DefaultPluginConfiguration implements MultiPermsApiConfiguration {

public MultiPermsBukkitApiConfiguration(@NotNull final Plugin plugin) {
super(plugin);
public MultiPermsBukkitApiConfiguration(@NotNull final ConfigurationHolder configurationHolder) {
super(configurationHolder);
}

@Getter(AccessLevel.PUBLIC)
public enum Entry {

PREFIX("prefix", "§8[§bMultiWorld§8]§r", false),
PREFIX("prefix", "§8[§aMultiPerms§8]§r", false),
NO_PERMISSION("no-permission",
"§cIm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that is in error.", false),
NO_CONSOLE_COMMAND("no-console-command", "%prefix% §cThis command can only performed by the console", false),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dev7ex.multiperms.api.group;

import com.dev7ex.common.map.ParsedMap;
import com.dev7ex.common.collect.map.ParsedMap;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dev7ex.multiperms.api.user;

import com.dev7ex.common.map.ParsedMap;
import com.dev7ex.common.collect.map.ParsedMap;
import org.jetbrains.annotations.NotNull;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.dev7ex.multiperms;

import com.dev7ex.common.bukkit.configuration.ConfigurationProperties;
import com.dev7ex.common.io.file.configuration.ConfigurationHolder;
import com.dev7ex.common.io.file.configuration.ConfigurationProperties;
import com.dev7ex.common.io.file.configuration.YamlConfiguration;
import com.dev7ex.multiperms.api.bukkit.MultiPermsBukkitApiConfiguration;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

/**
* @author Dev7ex
* @since 03.07.2023
*/
@ConfigurationProperties(fileName = "config.yml")
@ConfigurationProperties(fileName = "config.yml", provider = YamlConfiguration.class)
public class MultiPermsConfiguration extends MultiPermsBukkitApiConfiguration {

public MultiPermsConfiguration(@NotNull final Plugin plugin) {
super(plugin);
public MultiPermsConfiguration(@NotNull final ConfigurationHolder configurationHolder) {
super(configurationHolder);
}

@Override
Expand All @@ -23,14 +24,14 @@ public void load() {
for (final MultiPermsBukkitApiConfiguration.Entry entry : MultiPermsBukkitApiConfiguration.Entry.values()) {
if ((entry.isRemoved()) && (super.getFileConfiguration().contains(entry.getPath()))) {
super.getFileConfiguration().set(entry.getPath(), null);
super.getPlugin().getLogger().info("Remove unnecessary config entry: " + entry.getPath());
MultiPermsPlugin.getInstance().getLogger().info("Remove unnecessary config entry: " + entry.getPath());
}

if ((entry.isRemoved()) || (super.getFileConfiguration().contains(entry.getPath()))) {
continue;
}

super.getPlugin().getLogger().info("Adding missing config entry: " + entry.getPath());
MultiPermsPlugin.getInstance().getLogger().info("Adding missing config entry: " + entry.getPath());
super.getFileConfiguration().set(entry.getPath(), entry.getDefaultValue());
}
super.saveFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dev7ex.multiperms;

import com.dev7ex.common.bukkit.plugin.BukkitPlugin;
import com.dev7ex.common.bukkit.plugin.PluginProperties;
import com.dev7ex.common.bukkit.plugin.ConfigurablePlugin;
import com.dev7ex.common.bukkit.plugin.PluginIdentification;
import com.dev7ex.common.bukkit.plugin.statistic.PluginStatisticProperties;
import com.dev7ex.multiperms.api.MultiPermsApiProvider;
import com.dev7ex.multiperms.api.bukkit.MultiPermsBukkitApi;
import com.dev7ex.multiperms.command.PermissionCommand;
Expand All @@ -16,6 +18,7 @@
import com.dev7ex.multiperms.user.UserService;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand All @@ -25,8 +28,9 @@
* @since 03.07.2023
*/
@Getter(AccessLevel.PUBLIC)
@PluginProperties(metrics = true, metricsId = 19393)
public class MultiPermsPlugin extends BukkitPlugin implements MultiPermsBukkitApi {
@PluginIdentification(spigotResourceId = 111992)
@PluginStatisticProperties(enabled = true, identification = 19393)
public class MultiPermsPlugin extends BukkitPlugin implements MultiPermsBukkitApi, ConfigurablePlugin {

private MultiPermsConfiguration configuration;
private GroupConfiguration groupConfiguration;
Expand All @@ -52,6 +56,7 @@ public void onLoad() {
@Override
public void onEnable() {
MultiPermsApiProvider.registerApi(this);
super.getServer().getServicesManager().register(MultiPermsBukkitApi.class, this, this, ServicePriority.Normal);
}

@Override
Expand All @@ -73,11 +78,11 @@ public void registerListeners() {
}

@Override
public void registerServices() {
super.registerService(this.groupProvider = new GroupService(this.groupConfiguration));
super.registerService(this.userProvider = new UserService(this.groupProvider));
super.registerService(this.scoreboardProvider = new ScoreboardService(this.groupProvider));
super.registerService(this.permissionHookProvider = new DefaultPermissionHookProvider());
public void registerModules() {
super.registerModule(this.groupProvider = new GroupService(this.groupConfiguration));
super.registerModule(this.userProvider = new UserService(this.groupProvider));
super.registerModule(this.scoreboardProvider = new ScoreboardService(this.groupProvider));
super.registerModule(this.permissionHookProvider = new DefaultPermissionHookProvider());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package com.dev7ex.multiperms.command;

import com.dev7ex.common.bukkit.command.BukkitCommand;
import com.dev7ex.common.bukkit.command.CommandProperties;
import com.dev7ex.common.bukkit.command.BukkitCommandProperties;
import com.dev7ex.common.bukkit.command.completer.BukkitTabCompleter;
import com.dev7ex.common.bukkit.plugin.BukkitPlugin;
import com.dev7ex.multiperms.command.permission.GroupCommand;
import com.dev7ex.multiperms.command.permission.HelpCommand;
import com.dev7ex.multiperms.command.permission.ReloadCommand;
import com.dev7ex.multiperms.command.permission.UserCommand;
import com.google.common.collect.Lists;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* @author Dev7ex
* @since 03.07.2023
*/
@CommandProperties(name = "permission", permission = "multiperms.command.permission", aliases = {"mp", "perms"})
public class PermissionCommand extends BukkitCommand implements TabCompleter {
@BukkitCommandProperties(name = "permission", permission = "multiperms.command.permission", aliases = {"mp", "perms"})
public class PermissionCommand extends BukkitCommand implements BukkitTabCompleter {

public PermissionCommand(@NotNull final BukkitPlugin plugin) {
super(plugin);
Expand All @@ -33,30 +33,31 @@ public PermissionCommand(@NotNull final BukkitPlugin plugin) {
}

@Override
public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
public void execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
if ((arguments.length == 0) || (arguments.length > 6)) {
return super.getSubCommand("help").orElseThrow().execute(commandSender, arguments);
Objects.requireNonNull(super.getSubCommand(HelpCommand.class)).execute(commandSender, arguments);
return;
}
final Optional<BukkitCommand> commandOptional = super.getSubCommand(arguments[0].toLowerCase());

if (commandOptional.isEmpty()) {
return super.getSubCommand("help").orElseThrow().execute(commandSender, arguments);
if (super.getSubCommand(arguments[0].toLowerCase()).isEmpty()) {
Objects.requireNonNull(super.getSubCommand(HelpCommand.class)).execute(commandSender, arguments);
return;
}
return commandOptional.get().execute(commandOptional.get(), commandSender, arguments);
super.getSubCommand(arguments[0].toLowerCase()).get().execute(commandSender, arguments);
}

@Override
public List<String> onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command,
@NotNull final String commandLabel, @NotNull final String[] arguments) {
public List<String> onTabComplete(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
if (arguments.length == 1) {
return Lists.newArrayList(super.getSubCommands().keySet());
}
final Optional<BukkitCommand> commandOptional = super.getSubCommand(arguments[0].toLowerCase());

if ((commandOptional.isEmpty()) || (!(commandOptional.get() instanceof TabCompleter))) {
if ((commandOptional.isEmpty()) || (!(commandOptional.get() instanceof BukkitTabCompleter))) {
return null;
}
return ((TabCompleter) commandOptional.get()).onTabComplete(commandSender, command, commandLabel, arguments);
return ((BukkitTabCompleter) commandOptional.get()).onTabComplete(commandSender, arguments);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.dev7ex.multiperms.command.permission;

import com.dev7ex.common.bukkit.command.BukkitCommand;
import com.dev7ex.common.bukkit.command.CommandProperties;
import com.dev7ex.common.bukkit.command.BukkitCommandProperties;
import com.dev7ex.common.bukkit.command.completer.BukkitTabCompleter;
import com.dev7ex.common.bukkit.plugin.BukkitPlugin;
import com.dev7ex.multiperms.command.permission.group.*;
import com.google.common.collect.Lists;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* @author Dev7ex
* @since 03.07.2023
*/
@CommandProperties(name = "group", permission = "multiperms.command.permission.group")
public class GroupCommand extends BukkitCommand implements TabCompleter {
@BukkitCommandProperties(name = "group", permission = "multiperms.command.permission.group")
public class GroupCommand extends BukkitCommand implements BukkitTabCompleter {

public GroupCommand(@NotNull final BukkitPlugin plugin) {
super(plugin);
Expand All @@ -33,21 +33,21 @@ public GroupCommand(@NotNull final BukkitPlugin plugin) {
}

@Override
public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
public void execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
if ((arguments.length == 1) || (arguments.length > 6)) {
return super.getSubCommand("help").orElseThrow().execute(commandSender, arguments);
Objects.requireNonNull(super.getSubCommand(HelpCommand.class)).execute(commandSender, arguments);
return;
}

if (super.getSubCommand(arguments[1].toLowerCase()).isEmpty()) {
super.getSubCommand("help").orElseThrow().execute(commandSender, arguments);
return true;
Objects.requireNonNull(super.getSubCommand(HelpCommand.class)).execute(commandSender, arguments);
return;
}
return super.getSubCommand(arguments[1].toLowerCase()).get().execute(commandSender, arguments);
super.getSubCommand(arguments[1].toLowerCase()).get().execute(commandSender, arguments);
}

@Override
public final List<String> onTabComplete(@NotNull final CommandSender commandSender, @NotNull final Command command,
@NotNull final String commandLabel, @NotNull final String[] arguments) {
public final List<String> onTabComplete(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
if (arguments.length == 2) {
return Lists.newArrayList(super.getSubCommands().keySet());
}
Expand All @@ -57,10 +57,10 @@ public final List<String> onTabComplete(@NotNull final CommandSender commandSend
}
final BukkitCommand subCommand = super.getSubCommand(arguments[1].toLowerCase()).get();

if (!(subCommand instanceof TabCompleter)) {
if (!(subCommand instanceof BukkitTabCompleter)) {
return Collections.emptyList();
}
return ((TabCompleter) subCommand).onTabComplete(commandSender, command, commandLabel, arguments);
return ((BukkitTabCompleter) subCommand).onTabComplete(commandSender, arguments);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dev7ex.multiperms.command.permission;

import com.dev7ex.common.bukkit.command.BukkitCommand;
import com.dev7ex.common.bukkit.command.CommandProperties;
import com.dev7ex.common.bukkit.command.BukkitCommandProperties;
import com.dev7ex.common.bukkit.plugin.BukkitPlugin;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
Expand All @@ -10,19 +10,19 @@
* @author Dev7ex
* @since 03.07.2023
*/
@CommandProperties(name = "help", permission = "multiperms.command.permission")
@BukkitCommandProperties(name = "help", permission = "multiperms.command.permission")
public class HelpCommand extends BukkitCommand {

public HelpCommand(@NotNull final BukkitPlugin plugin) {
super(plugin);
}

@Override
public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
public void execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
super.getConfiguration().getStringList("messages.commands.permission.help.message").forEach(message -> {
commandSender.sendMessage(message.replaceAll("%prefix%", super.getPrefix()));
commandSender.sendMessage(message.replaceAll("%prefix%", super.getConfiguration().getPrefix()));
});
return true;
return;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dev7ex.multiperms.command.permission;

import com.dev7ex.common.bukkit.command.BukkitCommand;
import com.dev7ex.common.bukkit.command.CommandProperties;
import com.dev7ex.common.bukkit.command.BukkitCommandProperties;
import com.dev7ex.common.bukkit.plugin.BukkitPlugin;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
Expand All @@ -10,24 +10,24 @@
* @author Dev7ex
* @since 08.08.2023
*/
@CommandProperties(name = "reload", permission = "multiperms.command.permission.reload")
@BukkitCommandProperties(name = "reload", permission = "multiperms.command.permission.reload")
public class ReloadCommand extends BukkitCommand {

public ReloadCommand(@NotNull final BukkitPlugin plugin) {
super(plugin);
}

@Override
public boolean execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
public void execute(@NotNull final CommandSender commandSender, @NotNull final String[] arguments) {
if (arguments.length != 1) {
commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.reload.usage")
.replaceAll("%prefix%", super.getPrefix()));
return true;
.replaceAll("%prefix%", super.getConfiguration().getPrefix()));
return;
}
super.getConfiguration().load();
commandSender.sendMessage(super.getConfiguration().getString("messages.commands.permission.reload.message")
.replaceAll("%prefix%", super.getPrefix()));
return true;
.replaceAll("%prefix%", super.getConfiguration().getPrefix()));
return;
}

}
Loading

0 comments on commit 6ae3fba

Please sign in to comment.