This repository was archived by the owner on Apr 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 01552f8
Showing
26 changed files
with
746 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
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,23 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>MagicLib</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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,12 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=10 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=10 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=10 |
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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="FacetManager"> | ||
<facet type="minecraft" name="Minecraft"> | ||
<configuration> | ||
<autoDetectTypes> | ||
<platformType>SPIGOT</platformType> | ||
</autoDetectTypes> | ||
</configuration> | ||
</facet> | ||
</component> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: minecraft:Spigot:1.16.4" level="project" /> | ||
</component> | ||
</module> |
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 @@ | ||
/com/ |
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,4 @@ | ||
name: MagicLib | ||
version: 1.0.6.4 | ||
main: com.magicsweet.bukkitminecraftadditions.Main.Main | ||
api-version: 1.13 |
131 changes: 131 additions & 0 deletions
131
src/com/magicsweet/bukkitminecraftadditions/Color/Colorizer.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,131 @@ | ||
package com.magicsweet.bukkitminecraftadditions.Color; | ||
|
||
import java.awt.Color; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import net.md_5.bungee.api.ChatColor; | ||
|
||
public class Colorizer { | ||
|
||
public static List<String> format(List<String> stringList) { | ||
return stringList.stream().map(string -> { | ||
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}"); | ||
|
||
Matcher match = pattern.matcher(string); | ||
while (match.find()) { | ||
String color = string.substring(match.start(), match.end()); | ||
|
||
string = string.replace(color, ChatColor.of(color).toString()); | ||
match = pattern.matcher(string); | ||
} | ||
|
||
return ChatColor.translateAlternateColorCodes('&', string); | ||
}).collect(Collectors.toList()); | ||
} | ||
|
||
public static String format(String string) { | ||
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}"); | ||
|
||
Matcher match = pattern.matcher(string); | ||
while (match.find()) { | ||
String color = string.substring(match.start(), match.end()); | ||
|
||
string = string.replace(color, ChatColor.of(color).toString()); | ||
|
||
match = pattern.matcher(string); | ||
} | ||
|
||
return ChatColor.translateAlternateColorCodes('&', string); | ||
} | ||
|
||
@Deprecated | ||
public static List<String> formatLegacy(List<String> stringList) { | ||
return stringList.stream().map(string -> { | ||
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}"); | ||
|
||
Matcher match = pattern.matcher(string); | ||
while (match.find()) { | ||
String color = string.substring(match.start(), match.end()); | ||
|
||
string = string.replace(color, convertHexColorToNearestMinecraftColor(color)); | ||
match = pattern.matcher(string); | ||
} | ||
|
||
return ChatColor.translateAlternateColorCodes('&', string); | ||
}).collect(Collectors.toList()); | ||
} | ||
|
||
@Deprecated | ||
public static String formatLegacy(String string) { | ||
final Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}"); | ||
|
||
Matcher match = pattern.matcher(string); | ||
while (match.find()) { | ||
String color = string.substring(match.start(), match.end()); | ||
|
||
string = string.replace(color, convertHexColorToNearestMinecraftColor(color)); | ||
|
||
match = pattern.matcher(string); | ||
} | ||
|
||
return ChatColor.translateAlternateColorCodes('&', string); | ||
} | ||
|
||
|
||
private static String convertHexColorToNearestMinecraftColor(String hex) { | ||
|
||
HashMap<Color, String> mcColors = new HashMap<>(); | ||
|
||
mcColors.put(Color.decode("#000000"), "0"); | ||
mcColors.put(Color.decode("#0000AA"), "1"); | ||
mcColors.put(Color.decode("#00AA00"), "2"); | ||
mcColors.put(Color.decode("#00AAAA"), "3"); | ||
mcColors.put(Color.decode("#AA0000"), "4"); | ||
mcColors.put(Color.decode("#AA00AA"), "5"); | ||
mcColors.put(Color.decode("#FFAA00"), "6"); | ||
mcColors.put(Color.decode("#AAAAAA"), "7"); | ||
mcColors.put(Color.decode("#555555"), "8"); | ||
mcColors.put(Color.decode("#5555FF"), "9"); | ||
mcColors.put(Color.decode("#55FF55"), "a"); | ||
mcColors.put(Color.decode("#55FFFF"), "b"); | ||
mcColors.put(Color.decode("#FF5555"), "c"); | ||
mcColors.put(Color.decode("#FF5555"), "d"); | ||
mcColors.put(Color.decode("#FFFF55"), "e"); | ||
mcColors.put(Color.decode("#FFFFFF"), "f"); | ||
|
||
var initial = Color.decode(hex); | ||
|
||
var differences = new HashMap<Color, Integer>(); | ||
|
||
mcColors.keySet().forEach(key -> { | ||
int r, g, b; | ||
r = initial.getRed() - key.getRed(); if (r < 0) r = r*-1; | ||
g = initial.getGreen() - key.getGreen(); if (g < 0) g = g*-1; | ||
b = initial.getBlue() - key.getBlue(); if (b < 0) b = b*-1; | ||
|
||
differences.put(key, r + g + b); | ||
|
||
}); | ||
|
||
int c = Integer.MAX_VALUE; | ||
Color color = null; | ||
|
||
for (var col: differences.keySet()) { | ||
var val = differences.get(col); | ||
if (val < c) { | ||
c = val; | ||
color = col; | ||
} | ||
} | ||
|
||
if (color != null) { | ||
return "&" + mcColors.get(color); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/com/magicsweet/bukkitminecraftadditions/EventManager/ExtendableEvent.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,12 @@ | ||
package com.magicsweet.bukkitminecraftadditions.EventManager; | ||
|
||
import org.bukkit.event.Listener; | ||
|
||
import com.magicsweet.bukkitminecraftadditions.Main.Main; | ||
|
||
public abstract class ExtendableEvent implements Listener { | ||
|
||
public ExtendableEvent() { | ||
Main.getPlugin(Main.class).getServer().getPluginManager().registerEvents(this, Main.getPlugin(Main.class)); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/com/magicsweet/bukkitminecraftadditions/Expression/LambdaExpression.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,8 @@ | ||
package com.magicsweet.bukkitminecraftadditions.Expression; | ||
|
||
public class LambdaExpression<T0> { | ||
|
||
public T0 run(LambdaExpressionConsumer<T0> consumer) { | ||
return consumer.run(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/com/magicsweet/bukkitminecraftadditions/Expression/LambdaExpressionConsumer.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,6 @@ | ||
package com.magicsweet.bukkitminecraftadditions.Expression; | ||
|
||
@FunctionalInterface | ||
public interface LambdaExpressionConsumer<T0> { | ||
public T0 run(); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/com/magicsweet/bukkitminecraftadditions/Key/ColorConverter.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,35 @@ | ||
package com.magicsweet.bukkitminecraftadditions.Key; | ||
|
||
|
||
//Still exists here because of legacy features | ||
@Deprecated | ||
public class ColorConverter { | ||
public static String convert(String toConvert) { | ||
|
||
return toConvert | ||
.replace("&0", "§0") | ||
.replace("&1", "§1") | ||
.replace("&2", "§2") | ||
.replace("&3", "§3") | ||
.replace("&4", "§4") | ||
.replace("&5", "§5") | ||
.replace("&6", "§6") | ||
.replace("&7", "§7") | ||
.replace("&8", "§8") | ||
.replace("&9", "§9") | ||
.replace("&a", "§a") | ||
.replace("&b", "§b") | ||
.replace("&c", "§c") | ||
.replace("&d", "§d") | ||
.replace("&e", "§e") | ||
.replace("&f", "§f") | ||
.replace("&g", "§g") | ||
.replace("&k", "§k") | ||
.replace("&l", "§l") | ||
.replace("&m", "§m") | ||
.replace("&n", "§n") | ||
.replace("&o", "§o") | ||
.replace("&r", "§r"); | ||
|
||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/com/magicsweet/bukkitminecraftadditions/Key/Exception/IllegalItemException.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,9 @@ | ||
package com.magicsweet.bukkitminecraftadditions.Key.Exception; | ||
|
||
public class IllegalItemException extends Exception { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public IllegalItemException(String message) { | ||
super("\n" + message); | ||
} | ||
} |
Oops, something went wrong.