Adds some utils for UtilColor
Small changes in Wind Up suit
This commit is contained in:
parent
491c509317
commit
28de514d1a
@ -2,6 +2,9 @@ package mineplex.core.common.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
@ -15,6 +18,8 @@ public class UtilColor
|
||||
public static final RGBData RgbLightRed = hexToRgb(0xeb1c1c);
|
||||
public static final RGBData RgbPurple = hexToRgb(0x9c17a3);
|
||||
|
||||
public static final Color defaultLeatherColor = Color.fromRGB(160, 101, 64);
|
||||
|
||||
public static byte chatColorToClayData(ChatColor chatColor)
|
||||
{
|
||||
//TODO
|
||||
@ -73,6 +78,47 @@ public class UtilColor
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static ChatColor woolDataToChatColor(byte data)
|
||||
{
|
||||
switch (data)
|
||||
{
|
||||
case 0:
|
||||
return ChatColor.WHITE;
|
||||
case 1:
|
||||
return ChatColor.GOLD;
|
||||
case 2:
|
||||
return ChatColor.DARK_PURPLE;
|
||||
case 3:
|
||||
return ChatColor.BLUE;
|
||||
case 4:
|
||||
return ChatColor.YELLOW;
|
||||
case 5:
|
||||
return ChatColor.GREEN;
|
||||
case 6:
|
||||
return ChatColor.LIGHT_PURPLE;
|
||||
case 7:
|
||||
return ChatColor.DARK_GRAY;
|
||||
case 8:
|
||||
return ChatColor.GRAY;
|
||||
case 9:
|
||||
return ChatColor.DARK_AQUA;
|
||||
case 10:
|
||||
return ChatColor.DARK_PURPLE;
|
||||
case 11:
|
||||
return ChatColor.DARK_BLUE;
|
||||
case 12:
|
||||
return ChatColor.DARK_RED;
|
||||
case 13:
|
||||
return ChatColor.DARK_GREEN;
|
||||
case 14:
|
||||
return ChatColor.RED;
|
||||
case 15:
|
||||
return ChatColor.BLACK;
|
||||
default:
|
||||
return ChatColor.WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector colorToVector(Color color)
|
||||
{
|
||||
@ -98,4 +144,52 @@ public class UtilColor
|
||||
{
|
||||
return new RGBData(r, g, b);
|
||||
}
|
||||
|
||||
public static Color getNextColor(Color original, Color finalColor, int increment)
|
||||
{
|
||||
int red = original.getRed(), green = original.getGreen(), blue = original.getBlue();
|
||||
|
||||
if (red > finalColor.getRed())
|
||||
red -= increment;
|
||||
else if (red < finalColor.getRed())
|
||||
red += increment;
|
||||
else if (green > finalColor.getGreen())
|
||||
green -= increment;
|
||||
else if (green < finalColor.getGreen())
|
||||
green += increment;
|
||||
else if (blue > finalColor.getBlue())
|
||||
blue -= increment;
|
||||
else if (blue < finalColor.getBlue())
|
||||
blue += increment;
|
||||
|
||||
red = UtilMath.clamp(red, 0, 255);
|
||||
green = UtilMath.clamp(green, 0, 255);
|
||||
blue = UtilMath.clamp(blue, 0, 255);
|
||||
|
||||
return Color.fromRGB(red, green, blue);
|
||||
}
|
||||
|
||||
public static ItemStack applyColor(ItemStack itemStack, Color color)
|
||||
{
|
||||
if (!UtilGear.isMat(itemStack, Material.LEATHER_HELMET) && !UtilGear.isMat(itemStack, Material.LEATHER_CHESTPLATE)
|
||||
&& !UtilGear.isMat(itemStack, Material.LEATHER_LEGGINGS) && !UtilGear.isMat(itemStack, Material.LEATHER_BOOTS))
|
||||
return itemStack;
|
||||
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemStack.getItemMeta();
|
||||
|
||||
leatherArmorMeta.setColor(color);
|
||||
itemStack.setItemMeta(leatherArmorMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static Color getItemColor(ItemStack itemStack)
|
||||
{
|
||||
if (!UtilGear.isMat(itemStack, Material.LEATHER_HELMET) && !UtilGear.isMat(itemStack, Material.LEATHER_CHESTPLATE)
|
||||
&& !UtilGear.isMat(itemStack, Material.LEATHER_LEGGINGS) && !UtilGear.isMat(itemStack, Material.LEATHER_BOOTS))
|
||||
return Color.fromRGB(0, 0, 0);
|
||||
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemStack.getItemMeta();
|
||||
|
||||
return leatherArmorMeta.getColor();
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ public class UtilPlayer
|
||||
|
||||
// A mapping of player names (Keys) to the system time when they last changed active Hotbar Slot
|
||||
private static Map<String, Long> _hotbarUpdates = new HashMap<String, Long>();
|
||||
|
||||
// A mapping of player names (Keys) to the world border they are using (if they are using)
|
||||
private static Map<String, WorldBorder> _worldBorders = new HashMap<String, WorldBorder>();
|
||||
|
||||
// The amount of time (in milliseconds) after changin hotbars that you can block
|
||||
public static final long BLOCKING_HOTBAR_DELAY = 100;
|
||||
@ -854,13 +857,36 @@ public class UtilPlayer
|
||||
*/
|
||||
public static void sendRedScreen(Player player, int warningDistance)
|
||||
{
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
WorldBorder worldBorder = craftPlayer.getHandle().getWorld().getWorldBorder();
|
||||
WorldBorder worldBorder = (_worldBorders.containsKey(player.getName())) ? _worldBorders.get(player.getName()) : new WorldBorder();
|
||||
worldBorder.setCenter(player.getLocation().getX(), player.getLocation().getZ());
|
||||
worldBorder.setSize(10000);
|
||||
worldBorder.setWarningDistance(warningDistance);
|
||||
PacketPlayOutWorldBorder packet = new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE);
|
||||
sendPacket(player, packet);
|
||||
_worldBorders.put(player.getName(), worldBorder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has a WorldBorder object stored
|
||||
* @param player
|
||||
* @return true if WorldBorder object is stored for that player
|
||||
*/
|
||||
public static boolean hasWorldBorder(Player player)
|
||||
{
|
||||
return _worldBorders.containsKey(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes player from world border map
|
||||
* @param player
|
||||
*/
|
||||
public static void removeWorldBorder(Player player)
|
||||
{
|
||||
if (hasWorldBorder(player))
|
||||
{
|
||||
sendRedScreen(player, 0);
|
||||
_worldBorders.remove(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static MinecraftVersion getVersion(Player player)
|
||||
|
@ -11,7 +11,6 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
@ -48,6 +47,9 @@ public class OutfitWindUpSuit extends OutfitGadget
|
||||
if (_booster.contains(player))
|
||||
_booster.remove(player);
|
||||
|
||||
if (UtilPlayer.hasWorldBorder(player))
|
||||
UtilPlayer.removeWorldBorder(player);
|
||||
|
||||
player.removePotionEffect(PotionEffectType.SPEED);
|
||||
player.removePotionEffect(PotionEffectType.JUMP);
|
||||
}
|
||||
@ -77,19 +79,19 @@ public class OutfitWindUpSuit extends OutfitGadget
|
||||
if (color == null)
|
||||
return;
|
||||
|
||||
int r = color.getRed(), g = color.getGreen(), b = color.getBlue();
|
||||
Color[] colors = new Color[] {Color.fromRGB(0, 255, 0), Color.fromRGB(255, 255, 0), Color.fromRGB(255, 0, 0)};
|
||||
|
||||
if (phase == 0)
|
||||
{
|
||||
updateNextColor(r, 0, g, 255, b, 0, player, phase);
|
||||
updateNextColor(color, colors[phase], player, phase);
|
||||
}
|
||||
else if (phase == 1)
|
||||
{
|
||||
updateNextColor(r, 255, g, 255, b, 0, player, phase);
|
||||
updateNextColor(color, colors[phase], player, phase);
|
||||
}
|
||||
else if (phase == 2)
|
||||
{
|
||||
updateNextColor(r, 255, g, 0, b, 0, player, phase);
|
||||
updateNextColor(color, colors[phase], player, phase);
|
||||
}
|
||||
else if (phase == 3)
|
||||
{
|
||||
@ -116,7 +118,7 @@ public class OutfitWindUpSuit extends OutfitGadget
|
||||
return;
|
||||
|
||||
_colorPhase.put(player.getName(), 0);
|
||||
updateColor(player, Color.fromRGB(160, 101, 64));
|
||||
updateColor(player, UtilColor.defaultLeatherColor);
|
||||
_booster.remove(player);
|
||||
UtilPlayer.sendRedScreen(player, 0);
|
||||
|
||||
@ -144,53 +146,20 @@ public class OutfitWindUpSuit extends OutfitGadget
|
||||
|
||||
private Color getColor(Player player)
|
||||
{
|
||||
ItemStack stack;
|
||||
ItemStack stack = getStack(player);
|
||||
|
||||
if(GetSlot() == ArmorSlot.Helmet)
|
||||
{
|
||||
stack = player.getInventory().getHelmet();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Chest)
|
||||
{
|
||||
stack = player.getInventory().getChestplate();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Legs)
|
||||
{
|
||||
stack = player.getInventory().getLeggings();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Boots)
|
||||
{
|
||||
stack = player.getInventory().getBoots();
|
||||
}
|
||||
else
|
||||
return null;
|
||||
if (stack == null)
|
||||
return UtilColor.defaultLeatherColor;
|
||||
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
|
||||
|
||||
return meta.getColor();
|
||||
return UtilColor.getItemColor(stack);
|
||||
}
|
||||
|
||||
private void updateColor(Player player, Color color)
|
||||
{
|
||||
ItemStack stack;
|
||||
|
||||
if(GetSlot() == ArmorSlot.Helmet)
|
||||
{
|
||||
stack = player.getInventory().getHelmet();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Chest)
|
||||
{
|
||||
stack = player.getInventory().getChestplate();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Legs)
|
||||
{
|
||||
stack = player.getInventory().getLeggings();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Boots)
|
||||
{
|
||||
stack = player.getInventory().getBoots();
|
||||
}
|
||||
else
|
||||
ItemStack stack = getStack(player);
|
||||
|
||||
if (stack == null)
|
||||
return;
|
||||
|
||||
// Checks if material is the same
|
||||
@ -200,49 +169,50 @@ public class OutfitWindUpSuit extends OutfitGadget
|
||||
return;
|
||||
}
|
||||
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
|
||||
UtilColor.applyColor(stack, color);
|
||||
|
||||
/*LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
|
||||
|
||||
meta.setColor(color);
|
||||
|
||||
stack.setItemMeta(meta);
|
||||
stack.setItemMeta(meta);*/
|
||||
}
|
||||
|
||||
private void updateNextColor(int actualRed, int requiredRed, int actualGreen, int requiredGreen, int actualBlue, int requiredBlue, Player player, int phase)
|
||||
private void updateNextColor(Color original, Color finalColor, Player player, int phase)
|
||||
{
|
||||
if (actualRed > requiredRed)
|
||||
actualRed -= 5;
|
||||
else if (actualRed < requiredRed)
|
||||
actualRed += 5;
|
||||
// Makes a really smooth transition between colors
|
||||
Color nextColor = UtilColor.getNextColor(original, finalColor, 5);
|
||||
|
||||
if (actualGreen > requiredGreen)
|
||||
actualGreen -= 5;
|
||||
else if (actualGreen < requiredGreen)
|
||||
actualGreen += 5;
|
||||
|
||||
if (actualBlue > requiredBlue)
|
||||
actualBlue -= 5;
|
||||
else if (actualBlue < requiredBlue)
|
||||
actualBlue += 5;
|
||||
|
||||
if (actualRed > 255)
|
||||
actualRed = 255;
|
||||
else if (actualRed < 0)
|
||||
actualRed = 0;
|
||||
|
||||
if (actualGreen > 255)
|
||||
actualGreen = 255;
|
||||
else if (actualGreen < 0)
|
||||
actualGreen = 0;
|
||||
|
||||
if (actualBlue > 255)
|
||||
actualBlue = 255;
|
||||
else if (actualBlue < 0)
|
||||
actualBlue = 0;
|
||||
|
||||
if (actualRed == requiredRed && actualGreen == requiredGreen && actualBlue == requiredBlue)
|
||||
if (nextColor.getRed() == finalColor.getRed() && nextColor.getGreen() == finalColor.getGreen() && nextColor.getBlue() == finalColor.getBlue())
|
||||
_colorPhase.put(player.getName(), phase + 1);
|
||||
|
||||
updateColor(player, Color.fromRGB(actualRed, actualGreen, actualBlue));
|
||||
updateColor(player, nextColor);
|
||||
}
|
||||
|
||||
private ItemStack getStack(Player player)
|
||||
{
|
||||
ItemStack stack;
|
||||
|
||||
if(GetSlot() == ArmorSlot.Helmet)
|
||||
{
|
||||
stack = player.getInventory().getHelmet();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Chest)
|
||||
{
|
||||
stack = player.getInventory().getChestplate();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Legs)
|
||||
{
|
||||
stack = player.getInventory().getLeggings();
|
||||
}
|
||||
else if (GetSlot() == ArmorSlot.Boots)
|
||||
{
|
||||
stack = player.getInventory().getBoots();
|
||||
}
|
||||
else
|
||||
stack = null;
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user