diff --git a/nucleus-api/src/main/java/io/github/nucleuspowered/nucleus/api/NucleusAPI.java b/nucleus-api/src/main/java/io/github/nucleuspowered/nucleus/api/NucleusAPI.java index ce4f49f78..4fb6c1e81 100644 --- a/nucleus-api/src/main/java/io/github/nucleuspowered/nucleus/api/NucleusAPI.java +++ b/nucleus-api/src/main/java/io/github/nucleuspowered/nucleus/api/NucleusAPI.java @@ -7,6 +7,7 @@ import io.github.nucleuspowered.nucleus.api.service.NucleusAFKService; import io.github.nucleuspowered.nucleus.api.service.NucleusAPIMetaService; import io.github.nucleuspowered.nucleus.api.service.NucleusBackService; +import io.github.nucleuspowered.nucleus.api.service.NucleusBlacklistMigrationService; import io.github.nucleuspowered.nucleus.api.service.NucleusHomeService; import io.github.nucleuspowered.nucleus.api.service.NucleusJailService; import io.github.nucleuspowered.nucleus.api.service.NucleusKitService; @@ -94,7 +95,7 @@ public static Optional getAFKService() { } /** - * Gets the {@link NucleusAFKService}, if it exists. + * Gets the {@link NucleusBackService}, if it exists. * *

* Requires the "back" module. @@ -106,6 +107,19 @@ public static Optional getBackService() { return getService(NucleusBackService.class); } + /** + * Gets the {@link NucleusBlacklistMigrationService}, if it exists. + * + *

+ * Requires the "blacklist" module. + *

+ * + * @return The {@link NucleusBlacklistMigrationService} + */ + public static Optional getBlacklistMigrationService() { + return getService(NucleusBlacklistMigrationService.class); + } + /** * Gets the {@link NucleusHomeService}, if it exists. * diff --git a/nucleus-api/src/main/java/io/github/nucleuspowered/nucleus/api/service/NucleusBlacklistMigrationService.java b/nucleus-api/src/main/java/io/github/nucleuspowered/nucleus/api/service/NucleusBlacklistMigrationService.java new file mode 100644 index 000000000..b16efe853 --- /dev/null +++ b/nucleus-api/src/main/java/io/github/nucleuspowered/nucleus/api/service/NucleusBlacklistMigrationService.java @@ -0,0 +1,55 @@ +/* + * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file + * at the root of this project for more details. + */ +package io.github.nucleuspowered.nucleus.api.service; + +import org.spongepowered.api.block.BlockState; +import org.spongepowered.api.item.ItemType; + +import java.util.Map; + +/** + * This service provides methods to support obtaining Nucleus' blacklist entries + * for use by another plugin. + */ +public interface NucleusBlacklistMigrationService { + + /** + * Gets all the {@link BlockState}s that had a restriction on them. + * + * @return The {@link BlockState} and the results. + */ + Map getBlacklistedBlockstates(); + + /** + * Gets all the {@link ItemType}s that had a restriction on them. + * + * @return The {@link ItemType}s and the results. + */ + Map getBlacklistedItemtypes(); + + interface Result { + + /** + * If true, Nucleus blocked this type from being placed/broken. + * + * @return true if blacklisted + */ + boolean environment(); + + /** + * If true, Nucleus blocked this item type from being used. + * + * @return true if blacklisted + */ + boolean use(); + + /** + * If true, Nucleus blocked this item type from being possessed. + * + * @return true if blacklisted + */ + boolean possession(); + } +} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/configurate/datatypes/item/BlacklistNode.java b/src/main/java/io/github/nucleuspowered/nucleus/configurate/datatypes/item/BlacklistNode.java index d77f77f49..985b1f3f5 100644 --- a/src/main/java/io/github/nucleuspowered/nucleus/configurate/datatypes/item/BlacklistNode.java +++ b/src/main/java/io/github/nucleuspowered/nucleus/configurate/datatypes/item/BlacklistNode.java @@ -10,13 +10,13 @@ @ConfigSerializable public class BlacklistNode { - @Setting(value = "block-environment", comment = "loc:config.itemdatanode.blacklist.environment") + @Setting(value = "block-environment") private boolean environment = false; - @Setting(value = "block-possesion", comment = "loc:config.itemdatanode.blacklist.possesion") + @Setting(value = "block-possesion") private boolean inventory = false; - @Setting(value = "block-use", comment = "loc:config.itemdatanode.blacklist.block-use") + @Setting(value = "block-use") private boolean use = false; public boolean isEnvironment() { diff --git a/src/main/java/io/github/nucleuspowered/nucleus/internal/command/CommandBuilder.java b/src/main/java/io/github/nucleuspowered/nucleus/internal/command/CommandBuilder.java index 45e0db076..f4831f27c 100644 --- a/src/main/java/io/github/nucleuspowered/nucleus/internal/command/CommandBuilder.java +++ b/src/main/java/io/github/nucleuspowered/nucleus/internal/command/CommandBuilder.java @@ -76,24 +76,29 @@ > Optional buildCommand(Class command cn.removeChild("aliases"); } - // Register the commands. - if (rootCmd) { - // This will return true for the first anyway - String first = c.getAliases()[0]; - String[] aliases = Arrays.stream(c.getAliases()).filter(x -> x.equals(first) || node.getNode(x).getBoolean(true)) - .toArray(String[]::new); - Sponge.getCommandManager().register(plugin, c, aliases); - } + try { + // Register the commands. + if (rootCmd) { + // This will return true for the first anyway + String first = c.getAliases()[0]; + String[] aliases = Arrays.stream(c.getAliases()).filter(x -> x.equals(first) || node.getNode(x).getBoolean(true)) + .toArray(String[]::new); + Sponge.getCommandManager().register(plugin, c, aliases); + } - // Register as another full blown command. - for (String s : c.getRootCommandAliases()) { - if (plugin.getCommandsConfig().getCommandNode(c.getCommandConfigAlias()).getNode("aliases", s).getBoolean(true)) { - Sponge.getCommandManager().register(plugin, c, s); + // Register as another full blown command. + for (String s : c.getRootCommandAliases()) { + if (plugin.getCommandsConfig().getCommandNode(c.getCommandConfigAlias()).getNode("aliases", s).getBoolean(true)) { + Sponge.getCommandManager().register(plugin, c, s); + } } - } - if (c instanceof StandardAbstractCommand.Reloadable) { - plugin.registerReloadable(((StandardAbstractCommand.Reloadable) c)::onReload); + if (c instanceof StandardAbstractCommand.Reloadable) { + plugin.registerReloadable(((StandardAbstractCommand.Reloadable) c)::onReload); + } + } catch (Exception e) { + throw new IllegalStateException(plugin.getMessageProvider().getMessageWithFormat("startup.commandfailiure", c.getAliases()[0], + commandClass.getName())); } registeredCommands.add(c.getClass()); diff --git a/src/main/java/io/github/nucleuspowered/nucleus/internal/migrators/EssCmdsMigrator.java b/src/main/java/io/github/nucleuspowered/nucleus/internal/migrators/EssCmdsMigrator.java index e23d1b601..af32f4500 100644 --- a/src/main/java/io/github/nucleuspowered/nucleus/internal/migrators/EssCmdsMigrator.java +++ b/src/main/java/io/github/nucleuspowered/nucleus/internal/migrators/EssCmdsMigrator.java @@ -16,8 +16,6 @@ import io.github.hsyyid.essentialcmds.utils.Utils; import io.github.nucleuspowered.nucleus.Nucleus; import io.github.nucleuspowered.nucleus.api.service.NucleusWarpService; -import io.github.nucleuspowered.nucleus.configurate.datatypes.item.BlacklistNode; -import io.github.nucleuspowered.nucleus.dataservices.ItemDataService; import io.github.nucleuspowered.nucleus.modules.environment.datamodule.EnvironmentWorldDataModule; import io.github.nucleuspowered.nucleus.modules.home.datamodules.HomeUserDataModule; import io.github.nucleuspowered.nucleus.modules.jail.data.JailData; @@ -32,8 +30,6 @@ import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.Transform; import org.spongepowered.api.entity.living.player.User; -import org.spongepowered.api.item.ItemType; -import org.spongepowered.api.item.ItemTypes; import org.spongepowered.api.service.user.UserStorageService; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; @@ -71,22 +67,6 @@ public void migrate(CommandSource src) throws Exception { src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.nucleus.migrate.warps")); } - // Blacklisted items - ItemDataService ids = this.plugin.getItemDataService(); - for (String item : Utils.getBlacklistItems()) { - ItemType itemType = Sponge.getRegistry().getType(ItemType.class, item).orElse(ItemTypes.NONE); - - if (itemType != ItemTypes.NONE) { - BlacklistNode bn = ids.getDataForItem(itemType.getId()).getBlacklist(); - bn.setUse(true); - bn.setEnvironment(true); - bn.setInventory(true); - ids.save(); - } - } - - src.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.nucleus.migrate.blacklist")); - // Homes Configurable homesConfig = HomeConfig.getConfig(); diff --git a/src/main/java/io/github/nucleuspowered/nucleus/internal/qsml/module/StandardModule.java b/src/main/java/io/github/nucleuspowered/nucleus/internal/qsml/module/StandardModule.java index b965d794c..2c6cc0ca7 100644 --- a/src/main/java/io/github/nucleuspowered/nucleus/internal/qsml/module/StandardModule.java +++ b/src/main/java/io/github/nucleuspowered/nucleus/internal/qsml/module/StandardModule.java @@ -107,6 +107,7 @@ private void loadCommands() { // Find all commands that are also scannable. performFilter(plugin.getModuleContainer().getLoadedClasses().stream() + .filter(x -> x.getPackage().getName().startsWith(packageName)) .filter(x -> x.isAnnotationPresent(Scan.class)) .flatMap(x -> Arrays.stream(x.getDeclaredClasses())) .filter(StandardAbstractCommand.class::isAssignableFrom) diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/BlacklistModule.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/BlacklistModule.java index 394a955a5..088b23da8 100644 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/BlacklistModule.java +++ b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/BlacklistModule.java @@ -4,17 +4,30 @@ */ package io.github.nucleuspowered.nucleus.modules.blacklist; -import io.github.nucleuspowered.nucleus.internal.qsml.module.ConfigurableModule; -import io.github.nucleuspowered.nucleus.modules.blacklist.config.BlacklistConfigAdapter; +import io.github.nucleuspowered.nucleus.api.service.NucleusBlacklistMigrationService; +import io.github.nucleuspowered.nucleus.internal.qsml.module.StandardModule; +import io.github.nucleuspowered.nucleus.modules.blacklist.handler.BlacklistMigrationHandler; +import org.spongepowered.api.Sponge; import uk.co.drnaylor.quickstart.annotations.ModuleData; -@ModuleData(id = BlacklistModule.ID, name = "Blacklist") -public class BlacklistModule extends ConfigurableModule { +@ModuleData(id = "blacklist", name = "Blacklist") +public class BlacklistModule extends StandardModule { - public final static String ID = "blacklist"; + @Override public void onEnable() { + super.onEnable(); - @Override - public BlacklistConfigAdapter createAdapter() { - return new BlacklistConfigAdapter(); + plugin.getLogger().warn("-----------------------------------"); + plugin.getLogger().warn("NOTICE OF REMOVAL: BLACKLIST MODULE"); + plugin.getLogger().warn("-----------------------------------"); + plugin.getLogger().warn("The item blacklist module has been removed from Nucleus. Please use some other protection plugin, such as " + + "GriefPrevention that can block these items."); + plugin.getLogger().warn("A migrator for those of you that use ProtectionPerms has been provided, run `/blacklist migrate pp` to " + + "attempt to migrate."); + plugin.getLogger().warn("A migrator for those of you that use GriefPrevention will be provided soon."); + plugin.getLogger().warn("-----------------------------------"); + + BlacklistMigrationHandler bmh = new BlacklistMigrationHandler(); + plugin.getInternalServiceManager().registerService(BlacklistMigrationHandler.class, bmh); + Sponge.getServiceManager().setProvider(plugin, NucleusBlacklistMigrationService.class, bmh); } } diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistCommand.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistCommand.java deleted file mode 100644 index 0ceff2096..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.commands; - -import io.github.nucleuspowered.nucleus.internal.annotations.Permissions; -import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand; -import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand; -import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.command.args.CommandContext; - -@Permissions(suggestedLevel = SuggestedLevel.ADMIN) -@RegisterCommand(value = "blacklist", hasExecutor = false) -public class BlacklistCommand extends AbstractCommand { - - @Override - public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception { - return CommandResult.empty(); - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistListCommand.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistListCommand.java deleted file mode 100644 index 5ab4e0806..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistListCommand.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.commands; - -import io.github.nucleuspowered.nucleus.Util; -import io.github.nucleuspowered.nucleus.configurate.datatypes.item.BlacklistNode; -import io.github.nucleuspowered.nucleus.dataservices.ItemDataService; -import io.github.nucleuspowered.nucleus.internal.annotations.Permissions; -import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand; -import io.github.nucleuspowered.nucleus.internal.annotations.RunAsync; -import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand; -import io.github.nucleuspowered.nucleus.internal.messages.MessageProvider; -import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.command.args.CommandContext; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.action.TextActions; -import org.spongepowered.api.text.format.TextColors; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@RunAsync -@Permissions(prefix = "blacklist", suggestedLevel = SuggestedLevel.ADMIN) -@RegisterCommand(value = {"list", "ls"}, subcommandOf = BlacklistCommand.class) -public class BlacklistListCommand extends AbstractCommand { - - @Override - public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception { - ItemDataService itemDataService = this.plugin.getItemDataService(); - Map itemsToNodes = itemDataService.getAllBlacklistedItems().entrySet().stream() - .collect(Collectors.toMap(x -> Util.getTranslatedStringFromItemId(x.getKey()).orElse(x.getKey()), Map.Entry::getValue)); - - if (itemsToNodes.isEmpty()) { - src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.blacklist.list.none")); - return CommandResult.empty(); - } - - MessageProvider mp = plugin.getMessageProvider(); - Text header = mp.getTextMessageWithFormat("blacklist.title"); - - List lt = new ArrayList<>(); - itemsToNodes.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).forEach(e -> { - String types = String.join(", ", new ArrayList() {{ - if (e.getValue().isEnvironment()) { - add(mp.getMessageWithFormat("command.blacklist.list.environment")); - } - - if (e.getValue().isInventory()) { - add(mp.getMessageWithFormat("command.blacklist.list.possess")); - } - - if (e.getValue().isUse()) { - add(mp.getMessageWithFormat("command.blacklist.list.use")); - } - }}); - - lt.add(Text.builder(e.getKey()).color(TextColors.GREEN) - .onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("blacklist.hover", e.getKey()))) - .append(Text.of(TextColors.YELLOW, " - " + types)) - .build()); - }); - - Util.getPaginationBuilder(src).title(Text.of(TextColors.YELLOW, header)).padding(Text.of(TextColors.GREEN, "-")).contents(lt).sendTo(src); - return CommandResult.success(); - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistSetCommand.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistSetCommand.java deleted file mode 100644 index 91c0260aa..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/BlacklistSetCommand.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.commands; - -import com.google.common.collect.Lists; -import io.github.nucleuspowered.nucleus.Util; -import io.github.nucleuspowered.nucleus.argumentparsers.ItemAliasArgument; -import io.github.nucleuspowered.nucleus.configurate.datatypes.ItemDataNode; -import io.github.nucleuspowered.nucleus.dataservices.ItemDataService; -import io.github.nucleuspowered.nucleus.internal.annotations.Permissions; -import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand; -import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand; -import io.github.nucleuspowered.nucleus.internal.messages.MessageProvider; -import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel; -import org.spongepowered.api.CatalogType; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.command.args.CommandContext; -import org.spongepowered.api.command.args.CommandElement; -import org.spongepowered.api.command.args.GenericArguments; -import org.spongepowered.api.text.Text; - -import java.util.Collection; -import java.util.function.BiConsumer; -import java.util.stream.Collectors; - -import javax.inject.Inject; - -@SuppressWarnings("ALL") -@Permissions(prefix = "blacklist", suggestedLevel = SuggestedLevel.ADMIN) -@RegisterCommand(value = {"set"}, subcommandOf = BlacklistCommand.class) -public class BlacklistSetCommand extends AbstractCommand { - - @Inject private ItemDataService itemDataService; - private final String typeKey = "action to block"; - private final String itemKey = "item"; - private final String blacklistKey = "blacklist"; - - @Override public CommandElement[] getArguments() { - return new CommandElement[] { - GenericArguments.flags().valueFlag(GenericArguments.enumValue(Text.of(typeKey), Type.class), "t", "-type") - .buildWith( - GenericArguments.seq( - GenericArguments.optionalWeak(GenericArguments.onlyOne(new ItemAliasArgument(Text.of(itemKey)))), - GenericArguments.onlyOne(GenericArguments.bool(Text.of(blacklistKey))))) - }; - } - - @Override public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception { - CatalogType type = getCatalogTypeFromHandOrArgs(src, itemKey, args); - Collection typesToUpdate = args.hasAny(typeKey) ? args.getAll(typeKey) : Lists.newArrayList(Type.values()); - boolean blacklist = args.getOne(blacklistKey).get(); - ItemDataService dataStore = this.plugin.getItemDataService(); - ItemDataNode dataNode = dataStore.getDataForItem(type.getId()); - - typesToUpdate.forEach(x -> x.consumer.accept(dataNode, blacklist)); - dataStore.setDataForItem(type.getId(), dataNode); - dataStore.save(); - - MessageProvider mp = plugin.getMessageProvider(); - src.sendMessage(mp.getTextMessageWithFormat("command.blacklist.set.success", - Util.getTranslatedStringFromItemId(type.getId()).orElse(Util.getTranslatableIfPresentOnCatalogType(type)), - String.join(", ", typesToUpdate.stream().map(x -> x.toString().toLowerCase()).collect(Collectors.toList())), - blacklist ? mp.getMessageWithFormat("command.blacklist.set.added") : mp.getMessageWithFormat("command.blacklist.set.removed") - )); - - return CommandResult.success(); - } - - private enum Type { - ENVIRONMENT((i, b) -> i.getBlacklist().setEnvironment(b)), - POSSESSION((i, b) -> i.getBlacklist().setInventory(b)), - USE((i, b) -> i.getBlacklist().setUse(b)); - - private final BiConsumer consumer; - - Type(BiConsumer consumer) { - this.consumer = consumer; - } - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/DummyCommands.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/DummyCommands.java new file mode 100644 index 000000000..91290255d --- /dev/null +++ b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/DummyCommands.java @@ -0,0 +1,35 @@ +/* + * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file + * at the root of this project for more details. + */ +package io.github.nucleuspowered.nucleus.modules.blacklist.commands; + +import io.github.nucleuspowered.nucleus.internal.annotations.Permissions; +import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand; +import io.github.nucleuspowered.nucleus.internal.annotations.Scan; +import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.command.args.CommandContext; + +@Scan +public class DummyCommands { + + @Permissions + @RegisterCommand(value = "blacklist", hasExecutor = false) + public static class BlacklistCommand extends AbstractCommand { + + @Override protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception { + return null; + } + } + + @Permissions(prefix = "blacklist") + @RegisterCommand(value = "migrate", subcommandOf = DummyCommands.BlacklistCommand.class, hasExecutor = false) + public static class MigrateCommand extends AbstractCommand { + + @Override protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception { + return null; + } + } +} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/GPMigrateCommand.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/GPMigrateCommand.java new file mode 100644 index 000000000..8dc422bdb --- /dev/null +++ b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/GPMigrateCommand.java @@ -0,0 +1,44 @@ +/* + * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file + * at the root of this project for more details. + */ +package io.github.nucleuspowered.nucleus.modules.blacklist.commands; + +import com.google.inject.Inject; +import io.github.nucleuspowered.nucleus.internal.annotations.Permissions; +import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand; +import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand; +import io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException; +import io.github.nucleuspowered.nucleus.modules.blacklist.handler.BlacklistMigrationHandler; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.command.args.CommandContext; +import org.spongepowered.api.service.permission.PermissionService; +import org.spongepowered.api.service.permission.SubjectData; +import org.spongepowered.api.util.annotation.NonnullByDefault; + +@NonnullByDefault +@Permissions(prefix = "blacklist", mainOverride = "migrate") +@RegisterCommand(value = { "griefprevention", "gp" }, subcommandOf = DummyCommands.MigrateCommand.class) +public class GPMigrateCommand extends AbstractCommand { + + private final BlacklistMigrationHandler blacklistMigrationHandler; + + @Inject + public GPMigrateCommand(BlacklistMigrationHandler blacklistMigrationHandler) { + this.blacklistMigrationHandler = blacklistMigrationHandler; + } + + @Override protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception { + // Get the item types. + PermissionService service = Sponge.getServiceManager().provide(PermissionService.class) + .orElseThrow(() -> ReturnMessageException.fromKey("command.blacklist.migrate.permissionabs")); + SubjectData defaults = service.getDefaults().getSubjectData(); + + throw ReturnMessageException.fromKey("command.blacklist.migrate.gp.soon"); + +// return CommandResult.success(); + } + +} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/ProtectionPermsMigrate.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/ProtectionPermsMigrate.java new file mode 100644 index 000000000..d2d33da0b --- /dev/null +++ b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/commands/ProtectionPermsMigrate.java @@ -0,0 +1,68 @@ +/* + * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file + * at the root of this project for more details. + */ +package io.github.nucleuspowered.nucleus.modules.blacklist.commands; + +import com.google.inject.Inject; +import io.github.nucleuspowered.nucleus.api.service.NucleusBlacklistMigrationService; +import io.github.nucleuspowered.nucleus.internal.annotations.Permissions; +import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand; +import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand; +import io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException; +import io.github.nucleuspowered.nucleus.modules.blacklist.handler.BlacklistMigrationHandler; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.command.args.CommandContext; +import org.spongepowered.api.service.permission.PermissionService; +import org.spongepowered.api.service.permission.SubjectData; +import org.spongepowered.api.util.Tristate; +import org.spongepowered.api.util.annotation.NonnullByDefault; + +import java.util.HashSet; + +@NonnullByDefault +@Permissions(prefix = "blacklist", mainOverride = "migrate") +@RegisterCommand(value = { "protectionperms", "pp" }, subcommandOf = DummyCommands.MigrateCommand.class) +public class ProtectionPermsMigrate extends AbstractCommand { + + private final BlacklistMigrationHandler blacklistMigrationHandler; + + @Inject + public ProtectionPermsMigrate(BlacklistMigrationHandler blacklistMigrationHandler) { + this.blacklistMigrationHandler = blacklistMigrationHandler; + } + + @Override protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception { + // Get the item types. + PermissionService service = Sponge.getServiceManager().provide(PermissionService.class) + .orElseThrow(() -> ReturnMessageException.fromKey("command.blacklist.migrate.permissionabs")); + SubjectData defaults = service.getDefaults().getSubjectData(); + + src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.blacklist.migrate.protectionperms.start")); + + blacklistMigrationHandler.getBlacklistedBlockstates().forEach((k, v) -> applyPermissions(defaults, k.getType().getId(), v)); + blacklistMigrationHandler.getBlacklistedItemtypes().forEach((k, v) -> applyPermissions(defaults, k.getType().getId(), v)); + + src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.blacklist.migrate.protectionperms.done")); + + return CommandResult.success(); + } + + private void applyPermissions(SubjectData defaults, String id, NucleusBlacklistMigrationService.Result v) { + if (v.use()) { + defaults.setPermission(new HashSet<>(), "protectionperms.item.use." + id, Tristate.FALSE); + } + + if (v.environment()) { + defaults.setPermission(new HashSet<>(), "protectionperms.block.interact" + id, Tristate.FALSE); + defaults.setPermission(new HashSet<>(), "protectionperms.block.break" + id, Tristate.FALSE); + defaults.setPermission(new HashSet<>(), "protectionperms.block.place" + id, Tristate.FALSE); + } + + if (v.possession()) { + defaults.setPermission(new HashSet<>(), "protectionperms.item.craft." + id, Tristate.FALSE); + } + } +} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/config/BlacklistConfig.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/config/BlacklistConfig.java deleted file mode 100644 index 003304c21..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/config/BlacklistConfig.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.config; - -import io.github.nucleuspowered.nucleus.Util; -import ninja.leaping.configurate.objectmapping.Setting; -import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.api.CatalogType; -import org.spongepowered.api.block.BlockState; -import org.spongepowered.api.item.ItemType; -import org.spongepowered.api.item.ItemTypes; -import org.spongepowered.api.item.inventory.ItemStack; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; - -import java.util.Optional; - -@ConfigSerializable -public class BlacklistConfig { - - @Setting(value = "use-replacement", comment = "config.blacklist.use-replacement") - private boolean useReplacement = false; - - @Setting(comment = "config.blacklist.replacement") - private String replacement = ItemTypes.DIRT.getId(); - - @Setting(value = "blocked-actions", comment = "config.blacklist.blockedactions") - private Types blockedActions = new Types(); - - @ConfigSerializable - public static class Types { - - @Setting(value = "possession", comment = "config.blacklist.possession") - private boolean possession = true; - - @Setting(value = "environment", comment = "config.blacklist.environment") - private boolean environment = true; - - @Setting(value = "use", comment = "config.blacklist.use") - private boolean use = true; - } - - public boolean shouldUseReplacement() { - return useReplacement; - } - - public CatalogType getReplacement() { - return Util.getCatalogTypeForItemFromId(replacement).orElse(ItemTypes.DIRT); - } - - public ItemStack getReplacementItemStack() { - CatalogType type = getReplacement(); - if (type instanceof ItemType) { - return ItemStack.of((ItemType)type, 1); - } - - // Assume Block State - try { - BlockState bs = (BlockState) type; - return ItemStack.builder().fromBlockState(bs).quantity(1).build(); - } catch (Exception e) { - return ItemStack.of(ItemTypes.DIRT, 1); - } - } - - public Optional getItemStackIfShouldUseReplacement() { - if (shouldUseReplacement()) { - return Optional.of(getReplacementItemStack().createSnapshot()); - } - - return Optional.empty(); - } - - public boolean getPossession() { - return blockedActions.possession; - } - - public boolean getEnvironment() { - return blockedActions.environment; - } - - public boolean getUse() { - return blockedActions.use; - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/config/BlacklistConfigAdapter.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/config/BlacklistConfigAdapter.java deleted file mode 100644 index 419109cdf..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/config/BlacklistConfigAdapter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.config; - -import com.google.common.collect.Lists; -import io.github.nucleuspowered.nucleus.internal.qsml.NucleusConfigAdapter; - -import java.util.List; - -public class BlacklistConfigAdapter extends NucleusConfigAdapter.StandardWithSimpleDefault { - - @Override protected List getTransformations() { - return Lists.newArrayList( - new Transformation(new Object[]{"environment"}, (inputPath, valueAtPath) -> { - valueAtPath.setValue(null); - return null; - }), - new Transformation(new Object[]{"inventory"}, (inputPath, valueAtPath) -> { - valueAtPath.setValue(null); - return null; - }), - new Transformation(new Object[]{"useReplacement"}, (inputPath, valueAtPath) -> new Object[] { "use-replacement" }) - ); - } - - public BlacklistConfigAdapter() { - super(BlacklistConfig.class); - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/handler/BlacklistMigrationHandler.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/handler/BlacklistMigrationHandler.java new file mode 100644 index 000000000..11647f29e --- /dev/null +++ b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/handler/BlacklistMigrationHandler.java @@ -0,0 +1,60 @@ +/* + * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file + * at the root of this project for more details. + */ +package io.github.nucleuspowered.nucleus.modules.blacklist.handler; + +import io.github.nucleuspowered.nucleus.Nucleus; +import io.github.nucleuspowered.nucleus.api.service.NucleusBlacklistMigrationService; +import io.github.nucleuspowered.nucleus.configurate.datatypes.item.BlacklistNode; +import io.github.nucleuspowered.nucleus.dataservices.ItemDataService; +import org.spongepowered.api.block.BlockState; +import org.spongepowered.api.item.ItemType; +import org.spongepowered.api.util.Tuple; + +import java.util.Map; +import java.util.stream.Collectors; + +public class BlacklistMigrationHandler implements NucleusBlacklistMigrationService { + + @Override public Map getBlacklistedBlockstates() { + ItemDataService service = Nucleus.getNucleus().getItemDataService(); + return service.getAllBlacklistedItemsByCatalogType().entrySet().stream() + .filter(x -> x.getKey() instanceof BlockState) + .map(x -> Tuple.of((BlockState) x.getKey(), new BlacklistResult(x.getValue()))) + .collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)); + } + + @Override public Map getBlacklistedItemtypes() { + ItemDataService service = Nucleus.getNucleus().getItemDataService(); + return service.getAllBlacklistedItemsByCatalogType().entrySet().stream() + .filter(x -> x.getKey() instanceof ItemType) + .map(x -> Tuple.of((ItemType) x.getKey(), new BlacklistResult(x.getValue()))) + .collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)); + } + + private static class BlacklistResult implements Result { + + private final boolean env; + private final boolean use; + private final boolean pos; + + private BlacklistResult(BlacklistNode node) { + this.env = node.isEnvironment(); + this.use = node.isUse(); + this.pos = node.isInventory(); + } + + @Override public boolean environment() { + return this.env; + } + + @Override public boolean use() { + return this.use; + } + + @Override public boolean possession() { + return this.pos; + } + } +} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/BlacklistListener.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/BlacklistListener.java deleted file mode 100644 index 35f8c7a1d..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/BlacklistListener.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.listeners; - -import com.google.common.collect.Maps; -import com.google.inject.Inject; -import io.github.nucleuspowered.nucleus.Nucleus; -import io.github.nucleuspowered.nucleus.configurate.datatypes.item.BlacklistNode; -import io.github.nucleuspowered.nucleus.dataservices.ItemDataService; -import io.github.nucleuspowered.nucleus.internal.ListenerBase; -import io.github.nucleuspowered.nucleus.internal.PermissionRegistry; -import io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation; -import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel; -import io.github.nucleuspowered.nucleus.modules.blacklist.BlacklistModule; -import io.github.nucleuspowered.nucleus.modules.blacklist.config.BlacklistConfig; -import io.github.nucleuspowered.nucleus.modules.blacklist.config.BlacklistConfigAdapter; -import org.spongepowered.api.GameState; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.block.BlockSnapshot; -import org.spongepowered.api.entity.living.player.Player; -import uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException; -import uk.co.drnaylor.quickstart.exceptions.NoModuleException; - -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import javax.annotation.Nullable; - -/** - * Common listener methods for the listeners. - */ -public abstract class BlacklistListener extends ListenerBase.Reloadable { - - @Inject private ItemDataService itemDataService; - @Inject BlacklistConfigAdapter bca; - private boolean isRegisteredInIDS = false; - private Set ids = null; - - private final String bypass = PermissionRegistry.PERMISSIONS_PREFIX + "blacklist.bypass"; - - private final Map messageCache = Maps.newHashMap(); - - void sendMessage(Player target, String descRoot, String item, boolean single) { - - UUID u = target.getUniqueId(); - if (!messageCache.containsKey(u) || messageCache.get(u).isAfter(Instant.now())) { - // Alert the user, but only once a second. - if (single) { - target.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat(descRoot + ".single", item)); - } else { - target.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat(descRoot + ".multiple", item)); - } - - messageCache.put(u, Instant.now().plus(1, ChronoUnit.SECONDS)); - - // Cleanup stale entries. - messageCache.entrySet().removeIf(x -> x.getValue().isAfter(Instant.now())); - } - } - - @Override - public Map getPermissions() { - Map mp = Maps.newHashMap(); - mp.put(bypass, PermissionInformation.getWithTranslation("permission.blacklist.bypass", SuggestedLevel.ADMIN)); - return mp; - } - - final boolean hasBypass(Player player, String permissionToCheck) { - return (player.hasPermission(bypass) || player.hasPermission(permissionToCheck)); - } - - Set getIds(Predicate> predicate) { - if (ids == null) { - ids = itemDataService.getAllBlacklistedItems().entrySet() - .stream().filter(predicate) - .map(Map.Entry::getKey) - .collect(Collectors.toSet()); - } - - return ids; - } - - boolean checkBlock(@Nullable BlockSnapshot bs, Set ids) { - return bs != null && (ids.contains(bs.getState().getId()) || ids.contains(bs.getExtendedState().getId()) || ids.contains(bs.getState().getType().getId())); - } - - @Override public void onReload() throws Exception { - if (!isRegisteredInIDS) { - isRegisteredInIDS = true; - itemDataService.addOnItemUpdate(() -> ids = null); - ids = null; - } - } - - public abstract static class Condition implements Predicate { - - public abstract boolean configPredicate(BlacklistConfig config); - - @Override public boolean test(Nucleus nucleus) { - if (Sponge.getGame().getState().ordinal() < GameState.SERVER_STARTING.ordinal()) { - return false; - } - - try { - return configPredicate(nucleus.getModuleContainer().getConfigAdapterForModule(BlacklistModule.ID, BlacklistConfigAdapter.class) - .getNodeOrDefault()); - } catch (NoModuleException | IncorrectAdapterTypeException e) { - if (nucleus.isDebugMode()) { - e.printStackTrace(); - } - - return false; - } - } - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/EnvironmentListener.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/EnvironmentListener.java deleted file mode 100644 index bf5f30b1d..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/EnvironmentListener.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.listeners; - -import com.google.common.collect.Maps; -import io.github.nucleuspowered.nucleus.Util; -import io.github.nucleuspowered.nucleus.internal.PermissionRegistry; -import io.github.nucleuspowered.nucleus.internal.annotations.ConditionalListener; -import io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation; -import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel; -import io.github.nucleuspowered.nucleus.modules.blacklist.config.BlacklistConfig; -import org.spongepowered.api.block.BlockSnapshot; -import org.spongepowered.api.data.Transaction; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.block.ChangeBlockEvent; -import org.spongepowered.api.event.filter.cause.Root; -import org.spongepowered.api.event.filter.type.Include; - -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import javax.annotation.Nullable; - -@ConditionalListener(EnvironmentListener.Condition.class) -public class EnvironmentListener extends BlacklistListener { - - private final String environmentRoot = "blacklist.environment"; - private final String environment = PermissionRegistry.PERMISSIONS_PREFIX + "blacklist.bypass.environment"; - - @Listener - @Include({ChangeBlockEvent.Break.class, ChangeBlockEvent.Modify.class, ChangeBlockEvent.Place.class}) - public void onPlayerChangeBlock(ChangeBlockEvent event, @Root Player player) { - if (hasBypass(player, environment)) { - return; - } - - Set ids = getIds(x -> x.getValue().isEnvironment()); - List> list = event.getTransactions().stream().filter(Transaction::isValid) - .filter(x -> checkTransactions(x.getOriginal(), x.getFinal(), ids)) - .collect(Collectors.toList()); - - if (!list.isEmpty()) { - list.forEach(x -> x.setValid(false)); - if (checkBlock(list.get(0).getOriginal(), ids)) { - sendMessage(player, environmentRoot, Util.getTranslatableIfPresentOnCatalogType(list.get(0).getOriginal().getExtendedState()), list.size() == 1); - } else { - sendMessage(player, environmentRoot, Util.getTranslatableIfPresentOnCatalogType(list.get(0).getFinal().getExtendedState()), list.size() == 1); - } - } - } - - private boolean checkTransactions(@Nullable BlockSnapshot original, @Nullable BlockSnapshot fin, Set ids) { - return checkBlock(original, ids) || checkBlock(fin, ids); - } - - @Override - public Map getPermissions() { - Map mp = Maps.newHashMap(); - mp.put(environment, PermissionInformation.getWithTranslation("permission.blacklist.bypassenvironment", SuggestedLevel.ADMIN)); - return mp; - } - - public static class Condition extends BlacklistListener.Condition { - - @Override public boolean configPredicate(BlacklistConfig config) { - return config.getEnvironment(); - } - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/PossessionListener.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/PossessionListener.java deleted file mode 100644 index aaac96090..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/PossessionListener.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.listeners; - -import com.google.common.collect.Maps; -import io.github.nucleuspowered.nucleus.Nucleus; -import io.github.nucleuspowered.nucleus.Util; -import io.github.nucleuspowered.nucleus.internal.PermissionRegistry; -import io.github.nucleuspowered.nucleus.internal.annotations.ConditionalListener; -import io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation; -import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel; -import io.github.nucleuspowered.nucleus.modules.blacklist.config.BlacklistConfig; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.filter.cause.Root; -import org.spongepowered.api.event.filter.type.Exclude; -import org.spongepowered.api.event.item.inventory.ChangeInventoryEvent; -import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; -import org.spongepowered.api.event.item.inventory.InteractInventoryEvent; -import org.spongepowered.api.item.inventory.Inventory; -import org.spongepowered.api.item.inventory.ItemStack; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; -import org.spongepowered.api.item.inventory.type.CarriedInventory; -import org.spongepowered.api.scheduler.Task; - -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -@ConditionalListener(PossessionListener.Condition.class) -public class PossessionListener extends BlacklistListener { - - private final String possess = PermissionRegistry.PERMISSIONS_PREFIX + "blacklist.bypass.possesion"; - private final String confiscateRoot = "blacklist.confiscate"; - - @Nullable private ItemStackSnapshot replacementItem = null; - - @Listener - public void onOpenInventory(InteractInventoryEvent.Open event, @Root Player player) { - Inventory inventory; - if (isPlayerInventory(event.getTargetInventory(), player)) { - inventory = event.getTargetInventory(); - } else { - inventory = player.getInventory(); - } - - testInventory(inventory, player); - } - - @Listener - public void onCloseInventory(InteractInventoryEvent.Close event, @Root Player player) { - testInventory(player.getInventory(), player); - } - - private boolean testInventory(Inventory inventory, @Root Player player) { - if (hasBypass(player, possess)) { - return false; - } - - // Scan inventory. - final Set ids = getIds(x -> x.getValue().isInventory()); - - int replaced = 0; - String item = null; - - for (Inventory x : inventory.slots()) { - Optional itemStackOptional = x.peek(); - if (itemStackOptional.isPresent()) { - ItemStack y = itemStackOptional.get(); - if (ids.contains(Util.getTypeFromItem(y).getId())) { - if (replacementItem == null) { - x.clear(); - } else { - x.set(replacementItem.createStack()); - } - - replaced++; - if (item == null) { - item = Util.getTranslatableIfPresentOnCatalogType(y.getItem().getType()); - } - } - } - } - - if (replaced > 0) { - sendMessage(player, confiscateRoot, item, true); - return true; - } - - return false; - } - - @Listener - public void onChangeItem(ChangeInventoryEvent event, @Root Player player) { - if (hasBypass(player, possess)) { - return; - } - - if (isPlayerInventory(event.getTargetInventory(), player)) { - final Set ids = getIds(x -> x.getValue().isInventory()); - event.getTransactions().forEach(x -> { - if (ids.contains(Util.getTypeFromItem(x.getFinal()).getId())) { - x.setValid(false); - } - }); - - Task.builder().execute(() -> testInventory(event.getTargetInventory(), player)).submit(plugin); - } - } - - @Listener - @Exclude({ClickInventoryEvent.Close.class, ClickInventoryEvent.Open.class}) - public void onClick(ClickInventoryEvent event, @Root Player player) { - if (hasBypass(player, possess)) { - return; - } - - if (isPlayerInventory(event.getTargetInventory(), player)) { - final Set ids = getIds(x -> x.getValue().isInventory()); - if (ids.contains(Util.getTypeFromItem(event.getCursorTransaction().getOriginal()).getId())) { - event.setCancelled(true); - sendMessage(player, confiscateRoot, Util.getTranslatableIfPresentOnCatalogType(event.getCursorTransaction().getOriginal().getType()), true); - } else if (ids.contains(Util.getTypeFromItem(event.getCursorTransaction().getFinal()).getId())) { - event.setCancelled(true); - sendMessage(player, confiscateRoot, Util.getTranslatableIfPresentOnCatalogType(event.getCursorTransaction().getFinal().getType()), true); - } - - testInventory(event.getTargetInventory(), player); - } - } - - @SuppressWarnings("unchecked") - private boolean isPlayerInventory(Inventory container, Player player) { - try { - return container instanceof CarriedInventory && (boolean) ((CarriedInventory) container).getCarrier() - .map(x -> x instanceof Player && ((Player) x).getUniqueId().equals(player.getUniqueId())).orElse(false); - } catch (Exception e) { - if (Nucleus.getNucleus().isDebugMode()) { - e.printStackTrace(); - } - - return false; - } - } - - @Override public void onReload() throws Exception { - super.onReload(); - replacementItem = bca.getNodeOrDefault().getItemStackIfShouldUseReplacement().orElse(null); - } - - @Override - public Map getPermissions() { - Map mp = Maps.newHashMap(); - mp.put(possess, PermissionInformation.getWithTranslation("permission.blacklist.bypasspossess", SuggestedLevel.ADMIN)); - return mp; - } - - public static class Condition extends BlacklistListener.Condition { - - @Override public boolean configPredicate(BlacklistConfig config) { - return config.getPossession(); - } - } -} diff --git a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/UseListener.java b/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/UseListener.java deleted file mode 100644 index 129c74224..000000000 --- a/src/main/java/io/github/nucleuspowered/nucleus/modules/blacklist/listeners/UseListener.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file - * at the root of this project for more details. - */ -package io.github.nucleuspowered.nucleus.modules.blacklist.listeners; - -import io.github.nucleuspowered.nucleus.Util; -import io.github.nucleuspowered.nucleus.internal.PermissionRegistry; -import io.github.nucleuspowered.nucleus.internal.annotations.ConditionalListener; -import io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation; -import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel; -import io.github.nucleuspowered.nucleus.modules.blacklist.config.BlacklistConfig; -import org.spongepowered.api.block.BlockSnapshot; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.block.InteractBlockEvent; -import org.spongepowered.api.event.filter.Getter; -import org.spongepowered.api.event.filter.cause.Root; -import org.spongepowered.api.event.item.inventory.UseItemStackEvent; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; - -import java.util.Map; - -@ConditionalListener(UseListener.Condition.class) -public class UseListener extends BlacklistListener { - - private final String use = PermissionRegistry.PERMISSIONS_PREFIX + "blacklist.bypass.use"; - private final String useRoot = "blacklist.use"; - - @Listener - public void onPlayerUseItem(UseItemStackEvent.Start event, @Root Player player, @Getter("getItemStackInUse")ItemStackSnapshot itemStackSnapshot) { - if (hasBypass(player, use)) { - return; - } - - if (getIds(x -> x.getValue().isUse()).contains(Util.getTypeFromItem(itemStackSnapshot).getId())) { - event.setCancelled(true); - sendMessage(player, useRoot, Util.getTranslatableIfPresentOnCatalogType(itemStackSnapshot.getType()), true); - } - } - - @Listener - public void onPlayerInteractBlock(InteractBlockEvent.Secondary event, @Root Player player, @Getter("getTargetBlock") BlockSnapshot blockSnapshot) { - if (hasBypass(player, use)) { - return; - } - - if (this.checkBlock(blockSnapshot, getIds(x -> x.getValue().isUse()))) { - event.setCancelled(true); - sendMessage(player, useRoot, Util.getTranslatableIfPresentOnCatalogType(blockSnapshot.getState().getType()), true); - } - } - - @Override public void onReload() throws Exception {} - - @Override - public Map getPermissions() { - Map mp = super.getPermissions(); - mp.put(use, PermissionInformation.getWithTranslation("permission.blacklist.bypassuse", SuggestedLevel.ADMIN)); - return mp; - } - - public static class Condition extends BlacklistListener.Condition { - - @Override public boolean configPredicate(BlacklistConfig config) { - return config.getUse(); - } - } -} diff --git a/src/main/resources/assets/nucleus/commands.properties b/src/main/resources/assets/nucleus/commands.properties index 0c32680ba..cd8c7b9fb 100644 --- a/src/main/resources/assets/nucleus/commands.properties +++ b/src/main/resources/assets/nucleus/commands.properties @@ -368,18 +368,13 @@ world.setkeepspawnloaded.desc=Sets whether a world will keep the chunks around i world.info.desc=Displays information about one world. world.info.extended=This is otherwise identical to "/world list". -blacklist.desc=Parent command for all other blacklist commands. -blacklist.list.desc=Lists all blacklisted items. - -blacklist.set.desc=Sets an item''s blacklist status. -blacklist.set.extended=This command allows you to specify if an item should be "blacklisted", and if so how. Blacklisting an item prevents items from \ -being used in certain ways. By default, this command will globally set or unset the blacklist options, but by using the -t flag (potentially multiple \ -times), the following types of blacklist behaviour can be set independently:\n\n\ -* "environment": breaking or placing blocks.\n\ -* "possess": whether the item is allowed in a player''s inventory.\n\ -* "use": whether the item can be consumed by a player.\ -\n\n\ -This command replaces /blacklist add and /blacklist remove from previous releases. +blacklist.desc=The blacklist module has been removed. +blacklist.extended=If you wish to migrate your data to another protection plugin:\n\n\ +\n * ProtectionPerms migration can be run using "/blacklist migrate pp"\ +\n * GriefPrevention migration will be available in a later update to Nucleus and GP.\ +\n\n Other migration will need to be done manually or by the plugin in question. + +blacklist.migrate.desc=Available migrations are subcommands to this command. back.desc=Allows a user to return to their last place before death or warp. diff --git a/src/main/resources/assets/nucleus/messages.properties b/src/main/resources/assets/nucleus/messages.properties index 3f80d240d..88c3ebec0 100644 --- a/src/main/resources/assets/nucleus/messages.properties +++ b/src/main/resources/assets/nucleus/messages.properties @@ -53,6 +53,7 @@ startup.moduleloading={0} is now loading and enabling modules. This may take a f startup.modulenotloaded={0} was unable to load modules and has aborted loading. startup.moduleloaded={0} has completed loading modules. startup.injectablenotloaded=The {0} was not loaded because of an injection error, but loading will continue. +startup.commandfailiure=The {0} command ({1}) was not registed due to an error. Nucleus will stop loading. startup.started={0} has started. startup.stopped={0} is performing server shutdown tasks. @@ -113,13 +114,6 @@ freeze.cancelmove=&cYou cannot move while frozen. freeze.cancelinteract=&cYou cannot interact with entities while frozen. freeze.cancelinteractblock=&cYou cannot interact with block while frozen. -blacklist.confiscate.single=&c{0} is blacklisted. You may not hold this item. -blacklist.confiscate.multiple=&cSome of the blocks/items are blacklisted and cannot be held, including the {0}. -blacklist.environment.single=&c{0} is blacklisted. You may not interact with, mine or place this item. -blacklist.environment.multiple=&cSome of the blocks/items are blacklisted and cannot be interacted with, including the {0}. -blacklist.use.single=&c{0} is blacklisted. You may not use or consume this item. -blacklist.use.multiple=&cSome of the blocks/items are blacklisted and cannot be used or consumed, including the {0}. - globalmute.novoice=&cYou cannot speak as the server is globally muted. chat.url.click=Click here to open the URL &b&o{0} &rin your web browser. @@ -286,13 +280,6 @@ config.back.ondeath=Log player''s location on death. config.back.onteleport=Log player''s last location on warp. config.back.onportal=Log player''s last location after travelling through a portal. -config.blacklist.environment=If true, blacklisted items and blocks cannot be interacted with, mined, or placed. -config.blacklist.possession=If true, blacklisted items cannot exist in a player''s inventory, be dropped, or picked up. -config.blacklist.use=If true, blacklisted items and blocks cannot be used or interacted with. -config.blacklist.use-replacement=If true, blacklisted items will be replaced with the ItemType specified. -config.blacklist.replacement=If use-replacement is set to true, this ItemType will replace any blacklisted item taken from a player. -config.blacklist.blockedactions=These are global toggles, if any are false, the related listeners will be turned off. - config.rules.title=The rules page title. config.serverlist.modify=If true, when a prospective player pings the server on the multiplayer server list, one of the messages in the list below \ @@ -403,9 +390,6 @@ config.misc.speed.max=Sets the maximum speed that a player can set via the /spee config.servershop.maxpurchasable=The maximum amount a player can buy in one transaction. config.itemdatanode.aliases=A set of aliases that Nucleus recognises for this item. They all must be lowercase, and contain only letters, numbers, hyphens or underscores. -config.itemdatanode.blacklist.environment=Prevents the mining or placing of an item in the world. -config.itemdatanode.blacklist.possesion=Prevents the item being possessed. -config.itemdatanode.blacklist.block-use=Prevents the item being used. config.item.skullcompat=If true, Nucleus will simply treat /skull as an alias to '"/give [player] skull [number] 3 {SkullOwner:[skullplayer]}"' @@ -839,17 +823,13 @@ command.world.gamerule.header=&aGamerules for world &e{0} command.world.gamerule.key=&b{0} &f= {1} command.world.gamerule.set.success=&aSet the gamerule "&e{0}&a" to "&e{1}&a" for the world "&e{2}&a" successfully. -command.blacklist.add.success=&a{0} has been added to the blacklist. -command.blacklist.add.alreadyadded=&c{0} is already blacklisted. -command.blacklist.set.success=&aThe item &e{0}&a has the actions &e{1} &a{2} -command.blacklist.set.added=added to the blacklist. -command.blacklist.set.removed=removed from the blacklist. -command.blacklist.remove.success=&a{0} has been removed from the blacklist. -command.blacklist.remove.notadded=&c{0} is not on the blacklist. -command.blacklist.list.none=&cThere are no blacklisted items. -command.blacklist.list.possess=possession -command.blacklist.list.use=use -command.blacklist.list.environment=environment +command.blacklist.migrate.permissionabs=&cA permissions plugin is required to perform this migration. +command.blacklist.migrate.protectionperms.start=&aAttempting to migrate to ProtectionPerms. Note that permissions for actions will be set to FALSE \ + on the default user. +command.blacklist.migrate.protectionperms.done=&aMigration is complete. +command.blacklist.migrate.gp.soon=&cThe GP migrator will be available in a later release of Nucleus and GriefPrevention. +command.blacklist.migrate.gp.start=&aAttempting to migrate to GriefPrevention. +command.blacklist.migrate.gp.done=&aMigration is complete. command.kit.create.notcreated=&cCould not open a GUI to create your kit. command.kit.create.title=Create Kit: {0} @@ -1598,10 +1578,6 @@ home.location=: [world: {0}, location: {1}, {2}, {3}] home.warphover=Click here to warp to {0}. home.warphoverinvalid=&cThis home is pointing to an invalid location and cannot be used. -# Blacklist -blacklist.title=&aBlacklist -blacklist.hover={0} is blacklisted. - # Broadcast broadcast.tag=&a[Broadcast] @@ -1748,11 +1724,6 @@ permission.message.style=Allows user to use styles into messages. permission.message.magic=Allows user to use magic characters into messages. permission.message.urls=Allows user to type clickable URLs into messages. -permission.blacklist.bypass=Allows user to bypass all restrictions on blacklisted items. -permission.blacklist.bypassuse=Allows user to bypass use restrictions on blacklisted items. -permission.blacklist.bypasspossess=Allows user to bypass use restrictions on possessing items. -permission.blacklist.bypassenvironment=Allows user to bypass use restrictions on mining or placing items. - permission.warn.showonlogin=Allows user to see other users warnings when they login. permission.note.showonlogin=Allows user to see other users notes when they login.