Skip to content
This repository was archived by the owner on Apr 25, 2021. It is now read-only.

Commit 01552f8

Browse files
Initial commit
0 parents  commit 01552f8

26 files changed

Lines changed: 746 additions & 0 deletions

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>MagicLib</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=10
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=10
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.release=enabled
12+
org.eclipse.jdt.core.compiler.source=10

MagicLib.iml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>SPIGOT</platformType>
8+
</autoDetectTypes>
9+
</configuration>
10+
</facet>
11+
</component>
12+
<component name="NewModuleRootManager" inherit-compiler-output="true">
13+
<exclude-output />
14+
<content url="file://$MODULE_DIR$">
15+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
16+
</content>
17+
<orderEntry type="inheritedJdk" />
18+
<orderEntry type="sourceFolder" forTests="false" />
19+
<orderEntry type="library" name="Maven: minecraft:Spigot:1.16.4" level="project" />
20+
</component>
21+
</module>

bin/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/com/

bin/plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: MagicLib
2+
version: 1.0.6.4
3+
main: com.magicsweet.bukkitminecraftadditions.Main.Main
4+
api-version: 1.13
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package com.magicsweet.bukkitminecraftadditions.Color;
2+
3+
import java.awt.Color;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.regex.Matcher;
7+
import java.util.regex.Pattern;
8+
import java.util.stream.Collectors;
9+
10+
import net.md_5.bungee.api.ChatColor;
11+
12+
public class Colorizer {
13+
14+
public static List<String> format(List<String> stringList) {
15+
return stringList.stream().map(string -> {
16+
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
17+
18+
Matcher match = pattern.matcher(string);
19+
while (match.find()) {
20+
String color = string.substring(match.start(), match.end());
21+
22+
string = string.replace(color, ChatColor.of(color).toString());
23+
match = pattern.matcher(string);
24+
}
25+
26+
return ChatColor.translateAlternateColorCodes('&', string);
27+
}).collect(Collectors.toList());
28+
}
29+
30+
public static String format(String string) {
31+
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
32+
33+
Matcher match = pattern.matcher(string);
34+
while (match.find()) {
35+
String color = string.substring(match.start(), match.end());
36+
37+
string = string.replace(color, ChatColor.of(color).toString());
38+
39+
match = pattern.matcher(string);
40+
}
41+
42+
return ChatColor.translateAlternateColorCodes('&', string);
43+
}
44+
45+
@Deprecated
46+
public static List<String> formatLegacy(List<String> stringList) {
47+
return stringList.stream().map(string -> {
48+
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
49+
50+
Matcher match = pattern.matcher(string);
51+
while (match.find()) {
52+
String color = string.substring(match.start(), match.end());
53+
54+
string = string.replace(color, convertHexColorToNearestMinecraftColor(color));
55+
match = pattern.matcher(string);
56+
}
57+
58+
return ChatColor.translateAlternateColorCodes('&', string);
59+
}).collect(Collectors.toList());
60+
}
61+
62+
@Deprecated
63+
public static String formatLegacy(String string) {
64+
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
65+
66+
Matcher match = pattern.matcher(string);
67+
while (match.find()) {
68+
String color = string.substring(match.start(), match.end());
69+
70+
string = string.replace(color, convertHexColorToNearestMinecraftColor(color));
71+
72+
match = pattern.matcher(string);
73+
}
74+
75+
return ChatColor.translateAlternateColorCodes('&', string);
76+
}
77+
78+
79+
private static String convertHexColorToNearestMinecraftColor(String hex) {
80+
81+
HashMap<Color, String> mcColors = new HashMap<>();
82+
83+
mcColors.put(Color.decode("#000000"), "0");
84+
mcColors.put(Color.decode("#0000AA"), "1");
85+
mcColors.put(Color.decode("#00AA00"), "2");
86+
mcColors.put(Color.decode("#00AAAA"), "3");
87+
mcColors.put(Color.decode("#AA0000"), "4");
88+
mcColors.put(Color.decode("#AA00AA"), "5");
89+
mcColors.put(Color.decode("#FFAA00"), "6");
90+
mcColors.put(Color.decode("#AAAAAA"), "7");
91+
mcColors.put(Color.decode("#555555"), "8");
92+
mcColors.put(Color.decode("#5555FF"), "9");
93+
mcColors.put(Color.decode("#55FF55"), "a");
94+
mcColors.put(Color.decode("#55FFFF"), "b");
95+
mcColors.put(Color.decode("#FF5555"), "c");
96+
mcColors.put(Color.decode("#FF5555"), "d");
97+
mcColors.put(Color.decode("#FFFF55"), "e");
98+
mcColors.put(Color.decode("#FFFFFF"), "f");
99+
100+
var initial = Color.decode(hex);
101+
102+
var differences = new HashMap<Color, Integer>();
103+
104+
mcColors.keySet().forEach(key -> {
105+
int r, g, b;
106+
r = initial.getRed() - key.getRed(); if (r < 0) r = r*-1;
107+
g = initial.getGreen() - key.getGreen(); if (g < 0) g = g*-1;
108+
b = initial.getBlue() - key.getBlue(); if (b < 0) b = b*-1;
109+
110+
differences.put(key, r + g + b);
111+
112+
});
113+
114+
int c = Integer.MAX_VALUE;
115+
Color color = null;
116+
117+
for (var col: differences.keySet()) {
118+
var val = differences.get(col);
119+
if (val < c) {
120+
c = val;
121+
color = col;
122+
}
123+
}
124+
125+
if (color != null) {
126+
return "&" + mcColors.get(color);
127+
} else {
128+
return null;
129+
}
130+
}
131+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.magicsweet.bukkitminecraftadditions.EventManager;
2+
3+
import org.bukkit.event.Listener;
4+
5+
import com.magicsweet.bukkitminecraftadditions.Main.Main;
6+
7+
public abstract class ExtendableEvent implements Listener {
8+
9+
public ExtendableEvent() {
10+
Main.getPlugin(Main.class).getServer().getPluginManager().registerEvents(this, Main.getPlugin(Main.class));
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.magicsweet.bukkitminecraftadditions.Expression;
2+
3+
public class LambdaExpression<T0> {
4+
5+
public T0 run(LambdaExpressionConsumer<T0> consumer) {
6+
return consumer.run();
7+
}
8+
}

0 commit comments

Comments
 (0)