This repository has been archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make fireworks use configuration color
- Loading branch information
Showing
4 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
advanced-achievements-plugin/src/main/java/com/hm/achievement/utils/ColorHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
advanced-achievements-plugin/src/test/java/com/hm/achievement/utils/ColorHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters