Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Make fireworks use configuration color
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Mar 6, 2021
1 parent 6c5e5f3 commit bd494b0
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hm.achievement.listener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -40,6 +42,7 @@
import com.hm.achievement.domain.Achievement;
import com.hm.achievement.domain.Reward;
import com.hm.achievement.lifecycle.Reloadable;
import com.hm.achievement.utils.ColorHelper;
import com.hm.achievement.utils.FancyMessageSender;
import com.hm.achievement.utils.PlayerAdvancedAchievementEvent;
import com.hm.achievement.utils.SoundPlayer;
Expand All @@ -55,6 +58,26 @@ public class PlayerAdvancedAchievementListener implements Listener, Reloadable {

private static final Random RANDOM = new Random();

private static final Map<ChatColor, ChatColor> FIREWORK_COLOR_MIX = new HashMap<>();
static {
FIREWORK_COLOR_MIX.put(ChatColor.AQUA, ChatColor.DARK_AQUA);
FIREWORK_COLOR_MIX.put(ChatColor.BLACK, ChatColor.GRAY);
FIREWORK_COLOR_MIX.put(ChatColor.BLUE, ChatColor.DARK_BLUE);
FIREWORK_COLOR_MIX.put(ChatColor.GRAY, ChatColor.DARK_GRAY);
FIREWORK_COLOR_MIX.put(ChatColor.DARK_AQUA, ChatColor.AQUA);
FIREWORK_COLOR_MIX.put(ChatColor.DARK_BLUE, ChatColor.BLUE);
FIREWORK_COLOR_MIX.put(ChatColor.DARK_GRAY, ChatColor.GRAY);
FIREWORK_COLOR_MIX.put(ChatColor.DARK_GREEN, ChatColor.GREEN);
FIREWORK_COLOR_MIX.put(ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE);
FIREWORK_COLOR_MIX.put(ChatColor.DARK_RED, ChatColor.RED);
FIREWORK_COLOR_MIX.put(ChatColor.GOLD, ChatColor.YELLOW);
FIREWORK_COLOR_MIX.put(ChatColor.GREEN, ChatColor.DARK_GREEN);
FIREWORK_COLOR_MIX.put(ChatColor.LIGHT_PURPLE, ChatColor.DARK_PURPLE);
FIREWORK_COLOR_MIX.put(ChatColor.RED, ChatColor.DARK_RED);
FIREWORK_COLOR_MIX.put(ChatColor.WHITE, ChatColor.GRAY);
FIREWORK_COLOR_MIX.put(ChatColor.YELLOW, ChatColor.GOLD);
}

private final YamlConfiguration mainConfig;
private final YamlConfiguration langConfig;
private final int serverVersion;
Expand All @@ -71,6 +94,8 @@ public class PlayerAdvancedAchievementListener implements Listener, Reloadable {

private String configFireworkStyle;
private boolean configFirework;
private Color configColor;
private Color mixColor;
private boolean configSimplifiedReception;
private boolean configTitleScreen;
private boolean configNotifyOtherPlayers;
Expand Down Expand Up @@ -130,6 +155,9 @@ public void extractConfigurationParameters() {
configHoverableReceiverChatText = false;
}
configReceiverChatMessages = mainConfig.getBoolean("ReceiverChatMessages");
ChatColor chatColor = ChatColor.getByChar(mainConfig.getString("Color"));
configColor = ColorHelper.convertChatColorToColor(chatColor);
mixColor = Color.WHITE.mixColors(ColorHelper.convertChatColorToColor(FIREWORK_COLOR_MIX.get(chatColor)));

langAchievementReceived = langConfig.getString("achievement-received") + " " + ChatColor.WHITE;
langAchievementNew = pluginHeader + langConfig.getString("achievement-new") + " " + ChatColor.WHITE;
Expand Down Expand Up @@ -282,8 +310,8 @@ private void displayFirework(Player player) {
Firework firework = player.getWorld().spawn(location, Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
FireworkEffect fireworkEffect = FireworkEffect.builder()
.withColor(Color.WHITE.mixColors(Color.BLUE.mixColors(Color.NAVY)))
.withFade(Color.PURPLE)
.withColor(configColor)
.withFade(mixColor)
.with(getFireworkType())
.build();
fireworkMeta.addEffects(fireworkEffect);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.hm.achievement.utils;

import org.bukkit.ChatColor;
import org.bukkit.Color;

public class ColorHelper {

public static Color convertChatColorToColor(ChatColor chatColor) {
switch (chatColor) {
case AQUA:
return Color.fromRGB(0x55, 0xFF, 0xFF);
case BLACK:
return Color.BLACK;
case BLUE:
return Color.fromRGB(0x55, 0x55, 0xFF);
case GRAY:
return Color.fromRGB(0xAA, 0xAA, 0xAA);
case DARK_AQUA:
return Color.fromRGB(0x00, 0xAA, 0xAA);
case DARK_BLUE:
return Color.fromRGB(0x00, 0x00, 0xAA);
case DARK_GRAY:
return Color.fromRGB(0x55, 0x55, 0x55);
case DARK_GREEN:
return Color.fromRGB(0x00, 0xAA, 0x00);
case DARK_PURPLE:
return Color.fromRGB(0xAA, 0x00, 0xAA);
case DARK_RED:
return Color.fromRGB(0xAA, 0x00, 0x00);
case GOLD:
return Color.fromRGB(0xFF, 0xAA, 0x00);
case GREEN:
return Color.fromRGB(0x55, 0xFF, 0x55);
case LIGHT_PURPLE:
return Color.fromRGB(0xFF, 0x55, 0xFF);
case RED:
return Color.fromRGB(0xFF, 0x55, 0x55);
case WHITE:
return Color.WHITE;
case YELLOW:
return Color.fromRGB(0xFF, 0xFF, 0x55);
default:
return Color.WHITE;
}
}

private ColorHelper() {
// Not called.
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hm.achievement.utils;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.EnumSource.Mode;

class ColorHelperTest {

@ParameterizedTest
@EnumSource(value = ChatColor.class, mode = Mode.EXCLUDE, names = { "MAGIC", "BOLD", "STRIKETHROUGH", "UNDERLINE",
"ITALIC", "RESET" })
void shouldConvertChatColorsToColor(ChatColor chatColor) {
Color color = ColorHelper.convertChatColorToColor(chatColor);

java.awt.Color javaColor = chatColor.asBungee().getColor();
assertEquals(Color.fromRGB(javaColor.getRed(), javaColor.getGreen(), javaColor.getBlue()), color);
}

@ParameterizedTest
@EnumSource(value = ChatColor.class, mode = Mode.INCLUDE, names = { "MAGIC", "BOLD", "STRIKETHROUGH", "UNDERLINE",
"ITALIC", "RESET" })
void shouldConvertChatFormatsToWhite(ChatColor chatColor) {
Color color = ColorHelper.convertChatColorToColor(chatColor);

assertEquals(Color.WHITE, color);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ HoverableReceiverChatText: false

# Display achievement Name and Message as screen titles. No effect if using Minecraft 1.7.9 or 1.7.10.
TitleScreen: false

# Main color of the plugin (default: 5, dark purple).
Color: 5

0 comments on commit bd494b0

Please sign in to comment.