Skip to content

Commit

Permalink
Merge pull request #46 from PXAV/development
Browse files Browse the repository at this point in the history
Add all changes for v0.3.0 - "The world update"
  • Loading branch information
PXAV committed Feb 27, 2021
2 parents 76a9981 + 1a41cc0 commit 2ac280b
Show file tree
Hide file tree
Showing 54 changed files with 4,505 additions and 268 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG/kelp-v0.3.0.md
@@ -0,0 +1,37 @@
# v0.3.0
> Release date: 27.02.2021
**The world update**:
* Add custom library to for world and location management:
* Add `KelpWorld` class replacing the normal `World` class by bukkit. It still does not offer all methods of a default bukkit world, but offers integration with other kelp world classes.
* Add `KelpLocation` offering a replacement for the normal bukkit `Location`. It offers some more methods for vector calculation for example.
* Add `KelpChunk`, which is a replacement for the normal bukkit `Chunk`. On top of the normal bukkit methods, it offers methods to work with neighbouring chunks.
* Add `KelpBlock`
* All the mentioned classes port methods from newer versions to older versions for example bone meal application for `KelpBlock` or checking whether a `KelpChunk` is a slime chunk. More method ports will follow.
* Add some util methods used by the kelp world classes:
* `WorldType` expresses whether a world is overworld, nether or the end
* `CardinalDirection` expresses in which direction a player or relative block is facing. It simplifies the work wit `yaw`
* `ExplosionPower` is basically just a wrapper for a float, but it contains some default values for default minecraft explosion types, which makes the code more readable. Instead of `4F`, you would write `ExplosionPower.TNT`
* Add functionality to force load chunks
* The `KelpPlayer`, `KelpEntity`, `KelpNpc` class as well as the particle library are now using the new location system instead of the normal bukkit system.
* Add `KelpDummyPlugin` which can be used to emulate a plugin (`KelpApplication`) when developing core features where providing a plugin instance is needed.
* Fix some material sub ids of the above mentioned ones.
* Add `MathUtils` class providing some useful mathematical functions
* When tagging an item of type `AIR`, the method does not return `null` anymore but the original item stack without a tag. This should avoid unexpected NPEs in the future.
* Documentation improvements
* Fix #45: Item description of `KelpItem` was not rendered.















4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -125,13 +125,13 @@ There are version implementations for the following version implementations avai
<dependency>
<groupId>com.github.pxav.kelp</groupId>
<artifactId>core</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
```

### Gradle
```shell script
compile group: 'com.github.pxav.kelp', name: 'core', version: '0.2.0'
compile group: 'com.github.pxav.kelp', name: 'core', version: '0.3.0'
```

### Other build tools
Expand Down
6 changes: 3 additions & 3 deletions core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.pxav.kelp</groupId>
<artifactId>parent</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -158,7 +158,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/java/de/pxav/kelp/core/KelpDummyPlugin.java
@@ -0,0 +1,18 @@
package de.pxav.kelp.core;

import de.pxav.kelp.core.application.KelpApplication;

/**
* This class is used to pass a dummy plugin instance when developing
* inside the core module.
*
* For some things like {@link de.pxav.kelp.core.world.KelpChunk#addForceLoadFlag(Class)} you
* need to pass a {@link KelpApplication} class representing your plugin, but the kelp core
* obviously is no Kelp plugin, but a spigot plugin ({@link org.bukkit.plugin.java.JavaPlugin}).
*
* So if you ever run into such scenarios as a KelpCore developer, use this
* class.
*
* @author pxav
*/
public class KelpDummyPlugin extends KelpApplication {}
2 changes: 1 addition & 1 deletion core/src/main/java/de/pxav/kelp/core/KelpPlugin.java
Expand Up @@ -35,7 +35,7 @@
*
* @author pxav
*/
@Plugin(name = "Kelp", version = "0.2.0")
@Plugin(name = "Kelp", version = "0.3.0")
@Author("pxav")
@Description("A cross version spigot framework.")
@Singleton
Expand Down
56 changes: 56 additions & 0 deletions core/src/main/java/de/pxav/kelp/core/common/MathUtils.java
@@ -0,0 +1,56 @@
package de.pxav.kelp.core.common;

import java.util.concurrent.ThreadLocalRandom;

/**
* A small collection of some mathematical utils for Kelp.
* This class is functional, so all methods can be accessed statically.
*
* @author pxav
*/
public class MathUtils {

/**
* Checks if the given number x is even, which is
* equal to {@code x % 2 == 0}
*
* @param number The number to check.
* @return {@code true} if the number is even.
*/
public static boolean isEven(int number) {
return number % 2 == 0;
}

/**
* Checks if the given number x is odd, which is
* equal to {@code x % 2 == 1}
*
* @param number The number to check.
* @return {@code true} if the number is odd.
*/
public static boolean isOdd(int number) {
return number % 2 != 0;
}

/**
* Randomly calculates whether a certain chance has been
* fulfilled. If your {@code chance} is set to {@code 50},
* there will be a 50% chance that this method will return
* {@code true}. If it is {@code 5}, 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.
* @return Either true or false depending on your luck and the provided chance.
*/
public static boolean perCentChance(int chance) {
if (chance == 100) {
return true;
}
if (chance == 0) {
return false;
}
return ThreadLocalRandom.current().nextInt(0, 101) < chance;
}

}
143 changes: 26 additions & 117 deletions core/src/main/java/de/pxav/kelp/core/entity/KelpEntity.java
@@ -1,10 +1,10 @@
package de.pxav.kelp.core.entity;

import de.pxav.kelp.core.entity.version.EntityVersionTemplate;
import org.bukkit.Bukkit;
import de.pxav.kelp.core.world.KelpLocation;
import de.pxav.kelp.core.world.KelpWorld;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -61,12 +61,21 @@ public KelpEntity entityType(KelpEntityType entityType) {
return this;
}

public Location getInitialLocation() {
public Location getInitialBukkitLocation() {
return initialLocation;
}

public KelpEntity initialLocation(Location currentLocation) {
this.initialLocation = currentLocation;
public KelpLocation getInitialLocation() {
return KelpLocation.from(initialLocation);
}

public KelpEntity initialLocation(KelpLocation currentLocation) {
this.initialLocation = currentLocation.getBukkitLocation();
return this;
}

public KelpEntity initialLocation(Location location) {
this.initialLocation = location;
return this;
}

Expand Down Expand Up @@ -104,7 +113,7 @@ public Entity toBukkitEntity() {
*
* @return The current location of the current entity.
*/
public Location getLocation() {
public KelpLocation getLocation() {
return entityVersionTemplate.getLocation(toBukkitEntity());
}

Expand Down Expand Up @@ -162,8 +171,8 @@ public boolean isOnGround() {
*
* @return The world where the entity is currently located.
*/
public World getWorld() {
return entityVersionTemplate.getWorld(toBukkitEntity());
public KelpWorld getWorld() {
return KelpWorld.from(getLocation().getWorldName());
}

/**
Expand All @@ -183,7 +192,7 @@ public KelpEntity setRotation(float yaw, float pitch) {
*
* @param to The location you want the entity to be teleported to.
*/
public KelpEntity teleport(Location to) {
public KelpEntity teleport(KelpLocation to) {
entityVersionTemplate.teleport(toBukkitEntity(), to, PlayerTeleportEvent.TeleportCause.PLUGIN);
return this;
}
Expand All @@ -198,42 +207,7 @@ public KelpEntity teleport(Location to) {
* @param z The exact value of the location's z axis.
*/
public KelpEntity teleport(double x, double y, double z) {
World world = entityVersionTemplate.getWorld(toBukkitEntity());
Location to = new Location(world, x, y, z);
teleport(to);
return this;
}

/**
* Teleports the entity to the location at the given
* coordinates. As there is no world passed, this method
* will use the current world of the entity.
*
* @param x The block value of the location's x axis.
* @param y The block value of the location's y axis.
* @param z The block value of the location's z axis.
*/
public KelpEntity teleport(int x, int y, int z) {
World world = entityVersionTemplate.getWorld(toBukkitEntity());
Location to = new Location(world, x, y, z);
teleport(to);
return this;
}

/**
* Teleports the entity to the location at the given
* coordinates. As there is no world passed, this method
* will use the current world of the entity.
*
* @param x The block value of the location's x axis.
* @param y The block value of the location's y axis.
* @param z The block value of the location's z axis.
* @param yaw The yaw rotation of the entity.
* @param pitch The location's pitch
*/
public KelpEntity teleport(int x, int y, int z, float yaw, float pitch) {
World world = entityVersionTemplate.getWorld(toBukkitEntity());
Location to = new Location(world, x, y, z, yaw, pitch);
KelpLocation to = KelpLocation.from(getWorld(), x, y, z);
teleport(to);
return this;
}
Expand All @@ -250,8 +224,7 @@ public KelpEntity teleport(int x, int y, int z, float yaw, float pitch) {
* @param pitch The location's pitch
*/
public KelpEntity teleport(double x, double y, double z, float yaw, float pitch) {
World world = entityVersionTemplate.getWorld(toBukkitEntity());
Location to = new Location(world, x, y, z, yaw, pitch);
KelpLocation to = KelpLocation.from(getWorld(), x, y, z, yaw, pitch);
teleport(to);
return this;
}
Expand All @@ -267,40 +240,8 @@ public KelpEntity teleport(double x, double y, double z, float yaw, float pitch)
* @param yaw The yaw rotation of the entity.
* @param pitch The location's pitch
*/
public KelpEntity teleport(World world, double x, double y, double z, float yaw, float pitch) {
Location to = new Location(world, x, y, z, yaw, pitch);
teleport(to);
return this;
}

/**
* Teleports the entity to the location at the given
* coordinates.
*
* @param world The world where the entity should be teleported to.
* @param x The block value of the location's x axis.
* @param y The block value of the location's y axis.
* @param z The block value of the location's z axis.
* @param yaw The yaw rotation of the entity.
* @param pitch The location's pitch
*/
public KelpEntity teleport(World world, int x, int y, int z, float yaw, float pitch) {
Location to = new Location(world, x, y, z, yaw, pitch);
teleport(to);
return this;
}

/**
* Teleports the entity to the location at the given
* coordinates.
*
* @param world The world where the entity should be teleported to.
* @param x The block value of the location's x axis.
* @param y The block value of the location's y axis.
* @param z The block value of the location's z axis.
*/
public KelpEntity teleport(World world, int x, int y, int z) {
Location to = new Location(world, x, y, z);
public KelpEntity teleport(KelpWorld world, double x, double y, double z, float yaw, float pitch) {
KelpLocation to = KelpLocation.from(world, x, y, z, yaw, pitch);
teleport(to);
return this;
}
Expand All @@ -314,8 +255,8 @@ public KelpEntity teleport(World world, int x, int y, int z) {
* @param y The exact value of the location's y axis.
* @param z The exact value of the location's z axis.
*/
public KelpEntity teleport(World world, double x, double y, double z) {
Location to = new Location(world, x, y, z);
public KelpEntity teleport(KelpWorld world, double x, double y, double z) {
KelpLocation to = KelpLocation.from(world, x, y, z);
teleport(to);
return this;
}
Expand All @@ -332,39 +273,7 @@ public KelpEntity teleport(World world, double x, double y, double z) {
* @param pitch The location's pitch
*/
public KelpEntity teleport(String worldName, double x, double y, double z, float yaw, float pitch) {
Location to = new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
teleport(to);
return this;
}

/**
* Teleports the entity to the location at the given
* coordinates.
*
* @param worldName The name of the world where the entity should be teleported to.
* @param x The block value of the location's x axis.
* @param y The block value of the location's y axis.
* @param z The block value of the location's z axis.
* @param yaw The yaw rotation of the entity.
* @param pitch The location's pitch
*/
public KelpEntity teleport(String worldName, int x, int y, int z, float yaw, float pitch) {
Location to = new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
teleport(to);
return this;
}

/**
* Teleports the entity to the location at the given
* coordinates.
*
* @param worldName The name of the world where the entity should be teleported to.
* @param x The block value of the location's x axis.
* @param y The block value of the location's y axis.
* @param z The block value of the location's z axis.
*/
public KelpEntity teleport(String worldName, int x, int y, int z) {
Location to = new Location(Bukkit.getWorld(worldName), x, y, z);
KelpLocation to = KelpLocation.from(worldName, x, y, z, yaw, pitch);
teleport(to);
return this;
}
Expand All @@ -379,7 +288,7 @@ public KelpEntity teleport(String worldName, int x, int y, int z) {
* @param z The exact value of the location's z axis.
*/
public KelpEntity teleport(String worldName, double x, double y, double z) {
Location to = new Location(Bukkit.getWorld(worldName), x, y, z);
KelpLocation to = KelpLocation.from(worldName, x, y, z);
teleport(to);
return this;
}
Expand Down

0 comments on commit 2ac280b

Please sign in to comment.