From 9778c813ce8aac426d2db1f39f8922ce372217b4 Mon Sep 17 00:00:00 2001
From: Emafire003 <29462910+Emafire003@users.noreply.github.com>
Date: Thu, 7 Apr 2022 10:25:55 +0200
Subject: [PATCH] Added /setglowcolor for EntityTypes

---
 gradle.properties                             |  2 +-
 .../command/SetTypeGlowingColor.java          | 65 +++++++++++++++++++
 .../util/CGLCommandRegister.java              |  2 +
 3 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 src/main/java/me/emafire003/dev/coloredglowlib/command/SetTypeGlowingColor.java

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<ServerCommandSource> 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!");
     }
 }