mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
i'm gonna cry this is amazing
This commit is contained in:
parent
cdb385dd20
commit
7d6370da23
@ -9,12 +9,13 @@ import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Allows you to set your own prefix.", usage = "/<command> [-s[ave]] <set <tag..> | list | off | clear <player> | clearall>")
|
||||
@CommandParameters(description = "Allows you to set your own prefix.", usage = "/<command> [-s[ave]] <set <tag..> | list | gradient <hex> <hex> <tag..> | off | clear <player> | clearall>")
|
||||
public class Command_tag extends FreedomCommand
|
||||
{
|
||||
|
||||
@ -155,7 +156,7 @@ public class Command_tag extends FreedomCommand
|
||||
|
||||
if (rawTag.length() > tagLimit)
|
||||
{
|
||||
msg("That tag is too long (Max is " + String.valueOf(tagLimit) + " characters).");
|
||||
msg("That tag is too long (Max is " + tagLimit + " characters).");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -180,6 +181,62 @@ public class Command_tag extends FreedomCommand
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("gradient"))
|
||||
{
|
||||
java.awt.Color awt1, awt2;
|
||||
try
|
||||
{
|
||||
awt1 = java.awt.Color.decode(args[1]);
|
||||
awt2 = java.awt.Color.decode(args[2]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
msg("Invalid hex values.");
|
||||
return true;
|
||||
}
|
||||
Color c1 = FUtil.fromAWT(awt1);
|
||||
Color c2 = FUtil.fromAWT(awt2);
|
||||
String tag = StringUtils.join(args, " ", 3, args.length);
|
||||
List<Color> gradient = FUtil.createColorGradient(c1, c2, tag.length());
|
||||
String[] splitTag = tag.split("");
|
||||
for (int i = 0; i < splitTag.length; i++)
|
||||
{
|
||||
splitTag[i] = net.md_5.bungee.api.ChatColor.of(FUtil.toAWT(gradient.get(i))) + splitTag[i];
|
||||
}
|
||||
tag = StringUtils.join(splitTag, "");
|
||||
final String outputTag = FUtil.colorize(tag);
|
||||
|
||||
int tagLimit = (plugin.al.isAdmin(sender) ? 30 : 20);
|
||||
|
||||
final String rawTag = ChatColor.stripColor(outputTag).toLowerCase();
|
||||
|
||||
if (rawTag.length() > tagLimit)
|
||||
{
|
||||
msg("That tag is too long (Max is " + tagLimit + " characters).");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
for (String word : FORBIDDEN_WORDS)
|
||||
{
|
||||
if (rawTag.contains(word))
|
||||
{
|
||||
msg("That tag contains a forbidden word.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin.pl.getPlayer(playerSender).setTag(outputTag);
|
||||
if (save)
|
||||
{
|
||||
save(playerSender, tag);
|
||||
}
|
||||
msg("Tag set to '" + outputTag + ChatColor.GRAY + "'." + (save ? " (Saved)" : ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
|
@ -34,6 +34,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -715,6 +716,38 @@ public class FUtil
|
||||
return event.getAddress().getHostAddress().trim();
|
||||
}
|
||||
|
||||
private static Color interpolateColor(Color c1, Color c2, double factor)
|
||||
{
|
||||
long[] c1values = {c1.getRed(), c1.getGreen(), c1.getBlue()};
|
||||
long[] c2values = {c2.getRed(), c2.getGreen(), c2.getBlue()};
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
c1values[i] = Math.round(c1values[i] + factor * (c2values[i] - c1values[i]));
|
||||
}
|
||||
return Color.fromRGB((int) c1values[0], (int) c1values[1], (int) c1values[2]);
|
||||
}
|
||||
|
||||
public static List<Color> createColorGradient(Color c1, Color c2, int steps)
|
||||
{
|
||||
double factor = 1.0 / (steps - 1.0);
|
||||
List<Color> colors = new ArrayList<>();
|
||||
for (int i = 0; i < steps; i++)
|
||||
{
|
||||
colors.add(interpolateColor(c1, c2, factor * i));
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
public static Color fromAWT(java.awt.Color color)
|
||||
{
|
||||
return Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
public static java.awt.Color toAWT(Color color)
|
||||
{
|
||||
return new java.awt.Color(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
public static void createExplosionOnDelay(Location location, float power, int delay)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
|
Loading…
Reference in New Issue
Block a user