Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent legacy material initialization, update cloud, fix a few bugs related to 1.19.4 #119

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ paper {
foliaSupported = true
version = rootProject.version.toString()
description = "Simple, lightweight and fast NPC plugin using packets"
apiVersion = "1.20"
apiVersion = "1.19"
serverDependencies {
register("PlaceholderAPI") {
required = false
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ fancyLibVersion=1.0.24
fancyAnalyticsVersion=0.0.4
plotsquaredVersion=7.2.0
chatcolorhandlerVersion=v2.5.3
cloudCoreVersion=2.0.0-rc.1
cloudPaperVersion=2.0.0-beta.7
cloudAnnotationsVersion=2.0.0-rc.1
cloudCoreVersion=2.0.0-rc.2
cloudPaperVersion=2.0.0-beta.8
cloudAnnotationsVersion=2.0.0-rc.2
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
import net.minecraft.world.entity.Display;
import net.minecraft.world.level.block.Block;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.entity.EntityType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.StreamSupport;

public class BlockDisplayAttributes {

private static final List<String> BLOCKS = StreamSupport.stream(Registry.MATERIAL.spliterator(), false).filter(Material::isBlock).map(it -> it.key().value()).toList();

public static List<NpcAttribute> getAllAttributes() {
List<NpcAttribute> attributes = new ArrayList<>();

attributes.add(new NpcAttribute(
"block",
Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Enum::name)
.map(String::toLowerCase)
.toList(),
BLOCKS,
List.of(EntityType.BLOCK_DISPLAY),
BlockDisplayAttributes::setBlock
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@
import net.minecraft.world.entity.Display;
import net.minecraft.world.level.block.Block;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.entity.EntityType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class BlockDisplayAttributes {

private static final List<String> BLOCKS = Registry.MATERIAL.stream().filter(Material::isBlock).map(it -> it.key().value()).toList();

public static List<NpcAttribute> getAllAttributes() {
List<NpcAttribute> attributes = new ArrayList<>();

attributes.add(new NpcAttribute(
"block",
Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Enum::name)
.map(String::toLowerCase)
.toList(),
BLOCKS,
List.of(EntityType.BLOCK_DISPLAY),
BlockDisplayAttributes::setBlock
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@
import net.minecraft.world.entity.Display;
import net.minecraft.world.level.block.Block;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.entity.EntityType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class BlockDisplayAttributes {

private static final List<String> BLOCKS = Registry.MATERIAL.stream().filter(Material::isBlock).map(it -> it.key().value()).toList();

public static List<NpcAttribute> getAllAttributes() {
List<NpcAttribute> attributes = new ArrayList<>();

attributes.add(new NpcAttribute(
"block",
Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Enum::name)
.map(String::toLowerCase)
.toList(),
BLOCKS,
List.of(EntityType.BLOCK_DISPLAY),
BlockDisplayAttributes::setBlock
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@
import net.minecraft.world.entity.Display;
import net.minecraft.world.level.block.Block;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.entity.EntityType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class BlockDisplayAttributes {

private static final List<String> BLOCKS = Registry.MATERIAL.stream().filter(Material::isBlock).map(it -> it.key().value()).toList();

public static List<NpcAttribute> getAllAttributes() {
List<NpcAttribute> attributes = new ArrayList<>();

attributes.add(new NpcAttribute(
"block",
Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Enum::name)
.map(String::toLowerCase)
.toList(),
BLOCKS,
List.of(EntityType.BLOCK_DISPLAY),
BlockDisplayAttributes::setBlock
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.RemoteChatSession;
import net.minecraft.network.protocol.game.*;
import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@
import net.minecraft.world.entity.Display;
import net.minecraft.world.level.block.Block;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.entity.EntityType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class BlockDisplayAttributes {

private static final List<String> BLOCKS = Registry.MATERIAL.stream().filter(Material::isBlock).map(it -> it.key().value()).toList();

public static List<NpcAttribute> getAllAttributes() {
List<NpcAttribute> attributes = new ArrayList<>();

attributes.add(new NpcAttribute(
"block",
Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Enum::name)
.map(String::toLowerCase)
.toList(),
BLOCKS,
List.of(EntityType.BLOCK_DISPLAY),
BlockDisplayAttributes::setBlock
));
Expand Down
51 changes: 38 additions & 13 deletions src/main/java/de/oliver/fancynpcs/commands/CloudCommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,31 @@
import de.oliver.fancynpcs.commands.arguments.LocationArgument;
import de.oliver.fancynpcs.commands.arguments.NpcArgument;
import de.oliver.fancynpcs.commands.exceptions.ReplyingParseException;
import de.oliver.fancynpcs.commands.npc.*;
import de.oliver.fancynpcs.commands.npc.AttributeCMD;
import de.oliver.fancynpcs.commands.npc.CollidableCMD;
import de.oliver.fancynpcs.commands.npc.CopyCMD;
import de.oliver.fancynpcs.commands.npc.CreateCMD;
import de.oliver.fancynpcs.commands.npc.DisplayNameCMD;
import de.oliver.fancynpcs.commands.npc.EquipmentCMD;
import de.oliver.fancynpcs.commands.npc.FixCMD;
import de.oliver.fancynpcs.commands.npc.GlowingCMD;
import de.oliver.fancynpcs.commands.npc.HelpCMD;
import de.oliver.fancynpcs.commands.npc.InfoCMD;
import de.oliver.fancynpcs.commands.npc.InteractionCooldownCMD;
import de.oliver.fancynpcs.commands.npc.ListCMD;
import de.oliver.fancynpcs.commands.npc.MessageCMD;
import de.oliver.fancynpcs.commands.npc.MoveHereCMD;
import de.oliver.fancynpcs.commands.npc.MoveToCMD;
import de.oliver.fancynpcs.commands.npc.NearbyCMD;
import de.oliver.fancynpcs.commands.npc.PlayerCommandCMD;
import de.oliver.fancynpcs.commands.npc.RemoveCMD;
import de.oliver.fancynpcs.commands.npc.ScaleCMD;
import de.oliver.fancynpcs.commands.npc.ServerCommandCMD;
import de.oliver.fancynpcs.commands.npc.ShowInTabCMD;
import de.oliver.fancynpcs.commands.npc.SkinCMD;
import de.oliver.fancynpcs.commands.npc.TeleportCMD;
import de.oliver.fancynpcs.commands.npc.TurnToPlayerCMD;
import de.oliver.fancynpcs.commands.npc.TypeCMD;
import de.oliver.fancynpcs.utils.GlowingColor;
import io.leangen.geantyref.TypeToken;
import org.bukkit.Bukkit;
Expand All @@ -25,14 +49,15 @@
import org.incendo.cloud.exception.parsing.NumberParseException;
import org.incendo.cloud.exception.parsing.ParserException;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.PaperCommandManager;
import org.incendo.cloud.paper.LegacyPaperCommandManager;
import org.incendo.cloud.parser.standard.BooleanParser;
import org.incendo.cloud.parser.standard.EnumParser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.incendo.cloud.exception.handling.ExceptionHandler.unwrappingHandler;

// DEV NOTES:
Expand All @@ -43,13 +68,13 @@ public final class CloudCommandManager {

private final @NotNull FancyNpcs plugin;

private final @NotNull PaperCommandManager<CommandSender> commandManager;
private final @NotNull LegacyPaperCommandManager<CommandSender> commandManager;
private final @NotNull AnnotationParser<CommandSender> annotationParser;

public CloudCommandManager(final @NotNull FancyNpcs plugin, final boolean isBrigadier) {
this.plugin = plugin;
// Creating instance of Cloud's PaperCommandManager, which is used for anything command-related.
this.commandManager = PaperCommandManager.createNative(plugin, ExecutionCoordinator.simpleCoordinator());
// Creating instance of Cloud's LegacyPaperCommandManager, which is used for anything command-related.
this.commandManager = LegacyPaperCommandManager.createNative(plugin, ExecutionCoordinator.simpleCoordinator());
// Registering Brigadier, if available.
if (isBrigadier && commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER))
commandManager.registerBrigadier();
Expand All @@ -58,7 +83,7 @@ public CloudCommandManager(final @NotNull FancyNpcs plugin, final boolean isBrig
}

/**
* Registers arguments (parsers and suggestion providers) to the {@link PaperCommandManager}.
* Registers arguments (parsers and suggestion providers) to the {@link LegacyPaperCommandManager}.
*/
public @NotNull CloudCommandManager registerArguments() {
annotationParser.parse(NpcArgument.INSTANCE);
Expand All @@ -68,7 +93,7 @@ public CloudCommandManager(final @NotNull FancyNpcs plugin, final boolean isBrig
}

/**
* Registers exception handlers to the {@link PaperCommandManager}.
* Registers exception handlers to the {@link LegacyPaperCommandManager}.
*/
public @NotNull CloudCommandManager registerExceptionHandlers() {
final Translator translator = plugin.getTranslator();
Expand Down Expand Up @@ -103,7 +128,7 @@ public CloudCommandManager(final @NotNull FancyNpcs plugin, final boolean isBrig
.replaceStripped("input", exceptionContext.exception().input())
.send(exceptionContext.context().sender());
});
// DEV NOTE: Temporary solution util https://github.com/Incendo/cloud-minecraft/pull/70 is merged.
// DEV NOTE: Temporary solution until https://github.com/Incendo/cloud-minecraft/pull/70 is merged.
commandManager.exceptionController().register(ExceptionHandlerRegistration.<CommandSender, ArgumentParseException>builder(TypeToken.get(ArgumentParseException.class))
.exceptionFilter(exception -> exception.getCause() instanceof ParserException parserException && parserException.argumentParserClass() == LocationParser.class)
.exceptionHandler(exceptionContext -> {
Expand Down Expand Up @@ -160,7 +185,7 @@ else if (exceptionContext.exception().enumClass() == GlowingColor.class)
}

/**
* Registers plugin commands to the {@link PaperCommandManager}.
* Registers plugin commands to the {@link LegacyPaperCommandManager}.
*/
public @NotNull CloudCommandManager registerCommands() {
annotationParser.parse(AttributeCMD.INSTANCE);
Expand Down Expand Up @@ -199,9 +224,9 @@ else if (exceptionContext.exception().enumClass() == GlowingColor.class)
}

/**
* Returns the internal {@link PaperCommandManager} associated with this instance of {@link CloudCommandManager}.
* Returns the internal {@link LegacyPaperCommandManager} associated with this instance of {@link CloudCommandManager}.
*/
public @NotNull PaperCommandManager<CommandSender> getCommandManager() {
public @NotNull LegacyPaperCommandManager<CommandSender> getCommandManager() {
return commandManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.StreamSupport;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -37,7 +38,8 @@ public enum EquipmentCMD {

// Storing in a static variable to avoid re-creating the array each time suggestion is requested.
private static final List<String> SLOT_SUGGESTIONS = Arrays.stream(NpcEquipmentSlot.values()).map(slot -> slot.name().toLowerCase()).toList();
private static final List<String> MATERIAL_SUGGESTIONS = Registry.MATERIAL.stream().map(material -> material.key().asString()).toList();
// Replace with Registry#stream after dropping 1.19.4 support.
private static final List<String> MATERIAL_SUGGESTIONS = StreamSupport.stream(Registry.MATERIAL.spliterator(), false).filter(Material::isItem).map(material -> material.key().asString()).toList();

@Command("npc equipment <npc> set <slot> <item>")
@Permission("fancynpcs.command.npc.equipment.set")
Expand Down Expand Up @@ -136,7 +138,7 @@ else if (value.equals("@hand") && context.sender() instanceof Player player)
// Getting material from the registry.
final @Nullable Material material = Registry.MATERIAL.get(key);
// Sending error message if no material was found.
if (material == null)
if (material == null || !material.isItem())
throw ReplyingParseException.replying(() -> translator.translate("command_invalid_material").replaceStripped("input", value).send(context.sender()));
// Returning new ItemStack object from the specified Material.
return new ItemStack(material);
Expand Down