Skip to content

Commit

Permalink
Merge pull request #67 from KelpFramework/development
Browse files Browse the repository at this point in the history
Changes for release 0.4.0 - The entity update
  • Loading branch information
PXAV committed May 24, 2021
2 parents 64d4428 + 7680535 commit 1b7a876
Show file tree
Hide file tree
Showing 373 changed files with 18,686 additions and 5,542 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG/kelp-v0.4.0.md
@@ -0,0 +1,25 @@
# v0.4.0
> Release date: 24.05.2021
**The entity update**:

* Make methods of `StringUtils` and `ReflectionUtil` static.
* You can now invoke methods using `ReflectionUtils.invokeMethod(Object, String, Object...)` and `ReflectionUtils.invokeStaticMethod(Class<?>, String name, Object... parameters)`
* Move `isInWater` and `isInCobweb` method from `KelpPlayer` to `KelpEntity` as this is a more general method that can be applied to all entities.
* `KelpPlayer` is now an interface instead of a class for better integration into the entity system
* Although it has ever been a sub-type of `LivingKelpEntity`, it was not handled as such. The `EntityTypeVersionTemplate` could not convert it. Now it is exactly handled as an entity with the only logical exceptions that you cannot create/spawn new ones (use `KelpNpc`), and you cannot remove players from the server (kick them instead).
* Complete rework of the entity library:
* Old entity classes and methods are not supported anymore. They have been removed from the code.
* Entities are now represented as interfaces in the core module instead of classes.
* Those interfaces are implemented by the version modules - similar to bukkit. All entity types for MC1.8 have been implemented
* Add new entity types to `KelpEntityType` enum that have been added in 1.15 and 1.16.
* With the entity rework, other features that entities depend on had to be implemented as well:
* Add potion API allowing you to add potion effects
* Add `@MinecraftPotion` annotation, and a class for each potion effect type. The Kelp-Binder can now check for custom implementations of a potion effect type: If you run a 1.8 server, but want to use the levitation effect, this is no problem because the levitation effect can be reproduced by Kelp (just as you would create a version template and implementation). However, no effect has been emulated yet - only the mechanics exist and have been tested.
* Add entity constants for all entities that exist in 1.8. You can now convert horse types, villager professions, etc. across different versions
* Add `StorageInventory` interface, which represents a general inventory just like bukkit's `Inventory` interface.
* Add `HorseInventory` and `AbstractHorseInventory` allowing you to easily access a horse's saddle or armor.
* `PlayerInventory` now also is a subtype of `StorageInventory` and has been converted to an interface as well.
* Add 1.16-1.16.5 versions to `KelpVersion` enum
* Add `getEntities()` method to `KelpWorld` returning a list of all entities in the given world.
* Fix bug that entities could not be damaged by left click interaction when Kelp was installed. This was due to a bug that when an interaction packet was intercepted, it was not passed on to the server afterwards.
13 changes: 12 additions & 1 deletion core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.pxav.kelp</groupId>
<artifactId>parent</artifactId>
<version>0.3.4</version>
<version>0.4.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -141,6 +141,17 @@
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
</build>

<dependencies>
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/de/pxav/kelp/core/KelpPlugin.java
Expand Up @@ -36,9 +36,6 @@
*
* @author pxav
*/
@Plugin(name = "Kelp", version = "0.3.3")
@Author("pxav")
@Description("A cross version spigot framework.")
@Singleton
public class KelpPlugin extends JavaPlugin {

Expand Down
@@ -1,19 +1,23 @@
package de.pxav.kelp.core.application.inject;

import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.inject.AbstractModule;
import de.pxav.kelp.core.KelpPlugin;
import de.pxav.kelp.core.application.KelpApplication;
import de.pxav.kelp.core.application.KelpApplicationRepository;
import de.pxav.kelp.core.application.KelpVersionTemplate;
import de.pxav.kelp.core.entity.util.potion.MinecraftPotion;
import de.pxav.kelp.core.version.KelpVersion;
import de.pxav.kelp.core.version.VersionImplementation;
import de.pxav.kelp.core.version.Versioned;
import io.github.classgraph.*;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ClassFile;
import javassist.bytecode.annotation.*;
import org.bukkit.Bukkit;

import java.io.DataInputStream;
import java.io.File;
Expand Down Expand Up @@ -125,7 +129,9 @@ protected void configure() {
* @see KelpVersionTemplate
*/
private Collection<Class> detectVersionTemplates(String... packages) {
KelpVersion serverVersion = KelpVersion.withBukkitVersion(Bukkit.getBukkitVersion());
Collection<Class> output = Lists.newArrayList();

try (ScanResult scanResult =
new ClassGraph()
.enableAnnotationInfo()
Expand All @@ -140,6 +146,27 @@ private Collection<Class> detectVersionTemplates(String... packages) {
if (annotationInfo.getName().equalsIgnoreCase(KelpVersionTemplate.class.getName())) {
output.add(current.loadClass());
}

// next to normal version templates, search for potion templates that - unlike general
// version templates - don't have to be implemented in every server version. On an 1.8
// server, the Levitation effect has to be implemented, while on an 1.14 server not.
if (annotationInfo.getName().equalsIgnoreCase(MinecraftPotion.class.getName())) {

// the annotation only has a single parameter: The version since when it existed.
for (AnnotationParameterValue parameter : annotationInfo.getParameterValues()) {
// fetch the version since when the potion exists in the game
AnnotationEnumValue enumValue = (AnnotationEnumValue) parameter.getValue();
KelpVersion potionVersion = KelpVersion.valueOf(enumValue.getValueName());

// check if the current server version is lower than the version since when the
// potion existed, because in that case it has to be implemented and therefore
// be added to the template list.
if (potionVersion.isHigherThan(serverVersion)) {
output.add(current.loadClass());
}
}
}

}
}

Expand Down
Expand Up @@ -2,7 +2,6 @@

import de.pxav.kelp.core.KelpPlugin;
import de.pxav.kelp.core.command.version.KelpConsoleSenderVersionTemplate;
import de.pxav.kelp.core.player.KelpPlayer;
import org.bukkit.command.CommandSender;

/**
Expand Down
18 changes: 11 additions & 7 deletions core/src/main/java/de/pxav/kelp/core/common/MathUtils.java
Expand Up @@ -10,7 +10,7 @@
*/
public class MathUtils {

private static final int[] values = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
private static final int[] values = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
private static final String[] romanLiterals = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };

/**
Expand All @@ -37,23 +37,27 @@ public static boolean isOdd(int number) {

/**
* Randomly calculates whether a certain chance has been
* fulfilled. If your {@code chance} is set to {@code 50},
* fulfilled. If your {@code chance} is set to {@code 0.5},
* there will be a 50% chance that this method will return
* {@code true}. If it is {@code 5}, then there will be a
* {@code true}. If it is {@code 0.05}, then there will be a
* {@code 5} per cent chance that this method will return
* {@code true}.
*
* @param chance The chance to use for random calculation.
* This number may range from 0.0 (always false, 0% change)
* and 1.0 (always true, 100% chance), where 0.01 is equal to
* 1%.
* @return Either true or false depending on your luck and the provided chance.
*/
public static boolean perCentChance(int chance) {
if (chance == 100) {
public static boolean perCentChance(double chance) {
if (chance >= 1.0d) {
return true;
}
if (chance == 0) {
if (chance <= 0.0d) {
return false;
}
return ThreadLocalRandom.current().nextInt(0, 101) < chance;

return Math.random() < chance;
}

public static String getRomanNumber(int number) {
Expand Down
57 changes: 28 additions & 29 deletions core/src/main/java/de/pxav/kelp/core/common/StringUtils.java
Expand Up @@ -14,17 +14,16 @@
*
* @author pxav
*/
@Singleton
public class StringUtils {

// an array containing all color codes in alphabetical order.
private char[] colorCodes = new char[] {
private static char[] colorCodes = new char[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'
};

// an array containing all style codes in alphabetical order.
private char[] styleCodes = new char[] {
private static char[] styleCodes = new char[] {
'k', 'l', 'm', 'n', 'o', 'r'
};

Expand All @@ -34,7 +33,7 @@ public class StringUtils {
* @param text The text you want to remove the char of.
* @return The given text without the last char.
*/
public String removeLastChar(String text) {
public static String removeLastChar(String text) {
// build a substring excluding the last char.
return text.substring(0, text.length() - 1);
}
Expand All @@ -47,7 +46,7 @@ public String removeLastChar(String text) {
* @param text The text you want to remove the color codes of.
* @return The final string without color codes.
*/
public String removeFormattingCodes(String text) {
public static String removeFormattingCodes(String text) {
List<String> codes = extractFormattingCodes(text);
for (String current : codes) {
text = text.replace(current, "");
Expand All @@ -62,10 +61,10 @@ public String removeFormattingCodes(String text) {
* @param text The text you want to get the color codes of.
* @return The color codes in chronological order.
*/
public List<String> extractColorCodes(String text) {
public static List<String> extractColorCodes(String text) {
List<String> output = Lists.newArrayList();
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '§' && this.isColorCode(text.charAt(i + 1))) {
if (text.charAt(i) == '§' && isColorCode(text.charAt(i + 1))) {
output.add("§" + text.charAt(i + 1));
}
}
Expand All @@ -79,10 +78,10 @@ public List<String> extractColorCodes(String text) {
* @param text The text you want to get the style codes of.
* @return The style codes in chronological order.
*/
public List<String> extractStyleCodes(String text) {
public static List<String> extractStyleCodes(String text) {
List<String> output = Lists.newArrayList();
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '§' && this.isStyleCode(text.charAt(i + 1))) {
if (text.charAt(i) == '§' && isStyleCode(text.charAt(i + 1))) {
output.add("§" + text.charAt(i + 1));
}
}
Expand All @@ -96,7 +95,7 @@ public List<String> extractStyleCodes(String text) {
* @param text The text you want to get the codes of.
* @return The formatting codes in chronological order.
*/
public List<String> extractFormattingCodes(String text) {
public static List<String> extractFormattingCodes(String text) {
List<String> output = Lists.newArrayList();
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) != '§') {
Expand All @@ -107,8 +106,8 @@ public List<String> extractFormattingCodes(String text) {
break;
}

if (this.isStyleCode(text.charAt(i + 1))
|| this.isColorCode(text.charAt(i + 1))) {
if (isStyleCode(text.charAt(i + 1))
|| isColorCode(text.charAt(i + 1))) {
output.add("§" + text.charAt(i + 1));
}
}
Expand Down Expand Up @@ -136,7 +135,7 @@ public List<String> extractFormattingCodes(String text) {
* @param text The text you want to check.
* @return The last color and style codes.
*/
public String lastFormattingCodesOf(String text) {
public static String lastFormattingCodesOf(String text) {
// get all formatting codes of the text and reverse their order.
List<String> reversed = extractFormattingCodes(text);
Collections.reverse(reversed);
Expand Down Expand Up @@ -193,13 +192,13 @@ public String lastFormattingCodesOf(String text) {
* @param text The text you want to check.
* @return The last color and style codes.
*/
public String lastFullFormattingCodesOf(String text) {
public static String lastFullFormattingCodesOf(String text) {
// check if the color codes have a single '§' at the end.
// this has to be removed as we only want to have full
// color codes.
if (this.lastFormattingCodesOf(text).endsWith("§")) {
String colorCodes = this.lastFormattingCodesOf(text);
return this.removeLastChar(colorCodes);
if (lastFormattingCodesOf(text).endsWith("§")) {
String colorCodes = lastFormattingCodesOf(text);
return removeLastChar(colorCodes);
}
return lastFormattingCodesOf(text);
}
Expand All @@ -215,7 +214,7 @@ public String lastFullFormattingCodesOf(String text) {
* e. g. '1' for dark blue
* @return {@code true} if the given indicator is
*/
public boolean isColorCode(char indicator) {
public static boolean isColorCode(char indicator) {
for (char current : colorCodes) {
if (current == indicator) {
return true;
Expand All @@ -234,7 +233,7 @@ public boolean isColorCode(char indicator) {
* e. g. 'l' for bold
* @return {@code true} if the given indicator is a style code.
*/
public boolean isStyleCode(char indicator) {
public static boolean isStyleCode(char indicator) {
for (char current : styleCodes) {
if (current == indicator) {
return true;
Expand All @@ -252,7 +251,7 @@ public boolean isStyleCode(char indicator) {
* @param formattingCode The formatting code to be converted.
* @return The corresponding md_5 chat color.
*/
public ChatColor getChatColor(char formattingCode) {
public static ChatColor getChatColor(char formattingCode) {
return isFormattingCode(formattingCode)
? ChatColor.getByChar(formattingCode)
: ChatColor.WHITE;
Expand All @@ -267,7 +266,7 @@ public ChatColor getChatColor(char formattingCode) {
* @param formattingCode The formatting code to be converted.
* @return The corresponding bukkit chat color.
*/
public org.bukkit.ChatColor getBukkitChatColor(char formattingCode) {
public static org.bukkit.ChatColor getBukkitChatColor(char formattingCode) {
return isFormattingCode(formattingCode)
? org.bukkit.ChatColor.getByChar(formattingCode)
: org.bukkit.ChatColor.WHITE;
Expand All @@ -283,7 +282,7 @@ public org.bukkit.ChatColor getBukkitChatColor(char formattingCode) {
* @return The final {@link ChatColor} to be returned. {@code null} if the
* color was not found.
*/
public ChatColor getChatColor(String formattingCode) {
public static ChatColor getChatColor(String formattingCode) {
char code = formattingCode.charAt(1);
return isFormattingCode(code) && formattingCode.charAt(0) == '§'
? ChatColor.getByChar(code)
Expand All @@ -299,7 +298,7 @@ public ChatColor getChatColor(String formattingCode) {
* @param formattingCode The formatting code to be converted.
* @return The final {@link org.bukkit.ChatColor} to be returned.
*/
public org.bukkit.ChatColor getBukkitChatColor(String formattingCode) {
public static org.bukkit.ChatColor getBukkitChatColor(String formattingCode) {
char code = formattingCode.charAt(1);
return isFormattingCode(code) && formattingCode.charAt(0) == '§'
? org.bukkit.ChatColor.getByChar(code)
Expand All @@ -314,7 +313,7 @@ public org.bukkit.ChatColor getBukkitChatColor(String formattingCode) {
* @return The last color code of the text. {@code null} if there
* was no color code to be detected.
*/
public String endsWithColorCode(String text) {
public static String endsWithColorCode(String text) {
if (text.length() < 2) {
return null;
}
Expand All @@ -335,7 +334,7 @@ public String endsWithColorCode(String text) {
* @return The last formatting code of the text. {@code null} if there
* was no color code to be detected.
*/
public String endsWithFormattingCode(String text) {
public static String endsWithFormattingCode(String text) {
// if the text is less than 2 chars long there can
// be no formatting code, so return immediately.
if (text.length() < 2) {
Expand All @@ -356,7 +355,7 @@ public String endsWithFormattingCode(String text) {
*
* @return Any random bukkit color code.
*/
public char randomColorCode() {
public static char randomColorCode() {
return colorCodes[ThreadLocalRandom.current().nextInt(colorCodes.length - 1)];
}

Expand All @@ -366,7 +365,7 @@ public char randomColorCode() {
*
* @return
*/
public char randomStyleCode() {
public static char randomStyleCode() {
return styleCodes[ThreadLocalRandom.current().nextInt(colorCodes.length - 1)];
}

Expand All @@ -376,15 +375,15 @@ public char randomStyleCode() {
*
* @return Any random foramtting code without {@code '§'} in front.
*/
public char randomFormattingCode() {
public static char randomFormattingCode() {
return ThreadLocalRandom.current().nextBoolean() ? randomColorCode() : randomStyleCode();
}

/**
* @param indicator The indicator of the code you want to check.
* @return {@code true} if the either a color code or a style code.
*/
public boolean isFormattingCode(char indicator) {
public static boolean isFormattingCode(char indicator) {
return isColorCode(indicator) || isStyleCode(indicator);
}

Expand Down

0 comments on commit 1b7a876

Please sign in to comment.