diff --git a/gradle.properties b/gradle.properties index 5ca89d8..5c5f7a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.13.3 # Mod Properties - mod_version = 1.2.7 + mod_version = 1.3.0 maven_group = me.emafire003.dev archives_base_name = coloredglowlib diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/command/SetTypeGlowingColor.java b/src/main/java/me/emafire003/dev/coloredglowlib/command/SetTypeGlowingColor.java new file mode 100644 index 0000000..a14750f --- /dev/null +++ b/src/main/java/me/emafire003/dev/coloredglowlib/command/SetTypeGlowingColor.java @@ -0,0 +1,65 @@ +package me.emafire003.dev.coloredglowlib.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import me.emafire003.dev.coloredglowlib.ColoredGlowLib; +import me.emafire003.dev.coloredglowlib.util.Color; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.command.argument.EntitySummonArgumentType; +import net.minecraft.command.suggestion.SuggestionProviders; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.command.SummonCommand; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Identifier; + +import java.util.Collection; + +import static me.emafire003.dev.coloredglowlib.ColoredGlowLib.updateData; + +public class SetTypeGlowingColor { + + @SuppressWarnings("all") + public static void register(CommandDispatcher dispatcher, boolean b) { + dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)CommandManager.literal("setglowcolor").requires((source) -> { + return source.hasPermissionLevel(2); + })).then(CommandManager.argument("entity", EntitySummonArgumentType.entitySummon()).suggests(SuggestionProviders.SUMMONABLE_ENTITIES).then(((RequiredArgumentBuilder)CommandManager.argument("color", StringArgumentType.string()).executes((context) -> { + return execute((ServerCommandSource)context.getSource(), StringArgumentType.getString(context, "color"), EntitySummonArgumentType.getEntitySummon(context, "entity")); + }))))); + } + + + private static int execute(ServerCommandSource source, String color, Identifier id) throws CommandSyntaxException { + color = "#"+color; + + if(Color.isHexColor(color) || color.equalsIgnoreCase("#rainbow")){ + EntityType type = EntityType.get(id.toString()).get(); + ColoredGlowLib.removeColor(type); + if(color.equalsIgnoreCase("#rainbow")){ + ColoredGlowLib.setRainbowColorToEntityType(type, true); + }else{ + ColoredGlowLib.setColorToEntityType(type, Color.translateFromHEX(color)); + } + + if(!source.getWorld().isClient){ + updateData(source.getServer()); + } + + //source.sendFeedback(new TranslatableText("commands.setglowcolor.success1").append(color).append(new TranslatableText("commands.setglowcolor.success2")), true); + source.sendFeedback(new LiteralText("Setted color '" + color + "' to the selected entity/entities!"), false); + return 1; + }else{ + //source.sendError(new TranslatableText("commands.setglowcolor.notcolor")); + source.sendError(new LiteralText("Error! The value you have specified is not valid! It should be RRGGBB (without '#') or 'rainbow'")); + return 0; + } + } + + + +} diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/util/CGLCommandRegister.java b/src/main/java/me/emafire003/dev/coloredglowlib/util/CGLCommandRegister.java index d4ef06d..ffaccb4 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/util/CGLCommandRegister.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/util/CGLCommandRegister.java @@ -1,6 +1,7 @@ package me.emafire003.dev.coloredglowlib.util; import me.emafire003.dev.coloredglowlib.command.SetGlowingColor; +import me.emafire003.dev.coloredglowlib.command.SetTypeGlowingColor; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import static me.emafire003.dev.coloredglowlib.ColoredGlowLib.LOGGER; @@ -9,6 +10,7 @@ public class CGLCommandRegister { public static void registerCommands() { LOGGER.info("Registering commands..."); CommandRegistrationCallback.EVENT.register(SetGlowingColor::register); + CommandRegistrationCallback.EVENT.register(SetTypeGlowingColor::register); LOGGER.info("Done!"); } }