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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicSweet-dev committed Feb 7, 2021
0 parents commit 01552f8
Show file tree
Hide file tree
Showing 26 changed files with 746 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
23 changes: 23 additions & 0 deletions .gitignore
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*
17 changes: 17 additions & 0 deletions .project
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>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
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
21 changes: 21 additions & 0 deletions MagicLib.iml
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>
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/com/
4 changes: 4 additions & 0 deletions bin/plugin.yml
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 src/com/magicsweet/bukkitminecraftadditions/Color/Colorizer.java
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;
}
}
}
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));
}
}
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();
}
}
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();
}
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");

}
}
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);
}
}
Loading

0 comments on commit 01552f8

Please sign in to comment.