Nick gradient, and some other thing

This commit is contained in:
Seth 2020-07-13 23:00:08 -07:00 committed by GitHub
commit 2ca57c9b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 175 additions and 10 deletions

View File

@ -35,6 +35,7 @@ public class GameRuleHandler extends FreedomService
setGameRule(GameRule.KEEP_INVENTORY, true, false);
setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false, false);
setGameRule(GameRule.SHOW_DEATH_MESSAGES, false, false);
setGameRule(GameRule.SEND_COMMAND_FEEDBACK, false, false);
commitGameRules();
}
@ -95,7 +96,8 @@ public class GameRuleHandler extends FreedomService
NATURAL_REGENERATION("naturalRegeneration", true),
DO_DAYLIGHT_CYCLE("doDaylightCycle", true),
ANNOUNCE_ADVANCEMENTS("announceAdvancements", false),
SHOW_DEATH_MESSAGES("showDeathMessages", false);
SHOW_DEATH_MESSAGES("showDeathMessages", false),
SEND_COMMAND_FEEDBACK("sendCommandFeedback", false);
//
private final String gameRuleName;
private final boolean defaultValue;

View File

@ -0,0 +1,76 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
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.ONLY_IN_GAME)
@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/<command> <hex> <hex> <nick>")
public class Command_nickgradient extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 3)
{
return false;
}
String nick = args[2].trim();
if (nick.length() < 3 || nick.length() > 30)
{
msg("Your nickname must be between 3 and 30 characters long.");
return true;
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (player == playerSender)
{
continue;
}
if (player.getName().equalsIgnoreCase(nick) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nick))
{
msg("That nickname is already in use.");
return true;
}
}
java.awt.Color awt1, awt2;
try
{
awt1 = java.awt.Color.decode(args[0]);
awt2 = java.awt.Color.decode(args[1]);
}
catch (NumberFormatException ex)
{
msg("Invalid hex values.");
return true;
}
Color c1 = FUtil.fromAWT(awt1);
Color c2 = FUtil.fromAWT(awt2);
List<Color> gradient = FUtil.createColorGradient(c1, c2, nick.length());
String[] splitNick = nick.split("");
for (int i = 0; i < splitNick.length; i++)
{
splitNick[i] = net.md_5.bungee.api.ChatColor.of(FUtil.toAWT(gradient.get(i))) + splitNick[i];
}
nick = StringUtils.join(splitNick, "");
final String outputNick = FUtil.colorize(nick);
plugin.esb.setNickname(sender.getName(), outputNick);
msg("Your nickname is now: " + outputNick);
return true;
}
}

View File

@ -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;

View File

@ -58,20 +58,17 @@ public class Command_tempban extends FreedomCommand
final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName());
Date expires = FUtil.parseDateOffset("30m");
message.append(" until ").append(date_format.format(expires));
String reason = null;
if (args.length >= 2)
{
Date parsed_offset = FUtil.parseDateOffset(args[1]);
reason = StringUtils.join(ArrayUtils.subarray(args, parsed_offset == null ? 1 : 2, args.length), " ") + " (" + sender.getName() + ")";
if (parsed_offset != null)
{
expires = parsed_offset;
}
}
message.append(" until ").append(date_format.format(expires));
String reason = null;
if (args.length >= 3)
{
reason = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ") + " (" + sender.getName() + ")";
message.append(", Reason: \"").append(reason).append("\"");
}

View File

@ -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()