Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api/api bukkit #10

Closed
wants to merge 97 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
e5f9f57
Move stuff out to main api and start creating api-bukkit
Intybyte Dec 8, 2024
385fc69
Move enums to api-internal
Intybyte Dec 8, 2024
87fff67
Move main bukkit classes to api-bukkit
Intybyte Dec 8, 2024
176a6ef
Get this somewhere else
Intybyte Dec 8, 2024
b4e2e28
Complete interfaces
Intybyte Dec 8, 2024
dfdd85e
Complete interfaces x2
Intybyte Dec 8, 2024
98d89f4
Add/Fix poms
Intybyte Dec 8, 2024
9a58ad7
Fix imports
Intybyte Dec 8, 2024
79f3ed1
Fix CannonDesign dataclass
Intybyte Dec 8, 2024
9fb3719
Fix CannonDesign docs and stuff
Intybyte Dec 8, 2024
23fa7bb
Update lombok
Intybyte Dec 8, 2024
57f51e5
Turn Projectile into a dataclass
Intybyte Dec 8, 2024
0a312d5
Apply changes
Intybyte Dec 8, 2024
f8691be
Adapt FlyingProjectile
Intybyte Dec 8, 2024
cc1cd92
Move enum + fix
Intybyte Dec 8, 2024
f6d02e2
Unused remove constructor
Intybyte Dec 9, 2024
4d86604
Beautify Projectile
Intybyte Dec 9, 2024
906a49c
Centralize lombok dependency
Intybyte Dec 9, 2024
5336dd4
Remove removal designated methods
Intybyte Dec 9, 2024
9d1f784
Turn SpawnMaterialHolder into data class
Intybyte Dec 9, 2024
67666f2
Use firework builder
Intybyte Dec 9, 2024
c26616a
Beautify + turn SpawnEntityHolder into a Dataclass
Intybyte Dec 9, 2024
dd8ef8a
fix wait time
Intybyte Dec 9, 2024
afdcba7
this is impossible to use
Intybyte Dec 9, 2024
c50e59f
better item stack parsing
Intybyte Dec 9, 2024
2468809
Remove unnecessary stuff
Intybyte Dec 9, 2024
2d9f8e4
Add logger holder
Intybyte Dec 9, 2024
4c845ef
Rename equals to check
Intybyte Dec 9, 2024
3acbf65
Import cannon logger
Intybyte Dec 9, 2024
3a71dcb
CannonBlocks dataclass
Intybyte Dec 9, 2024
fc33b69
Turn SoundHolder to dataclass
Intybyte Dec 9, 2024
dc8ebf6
Relocate Hooks and create BukkitSoundHolder
Intybyte Dec 9, 2024
9303561
Remove unused + beautify
Intybyte Dec 9, 2024
44ff794
Remove unused method call
Intybyte Dec 9, 2024
ef5d3f3
ItemHolder abstracted
Intybyte Dec 9, 2024
0941bd5
Abstract SimpleBlock and make BukkitBlock
Intybyte Dec 10, 2024
e7f50a8
Small fixes + documentation
Intybyte Dec 10, 2024
2e319e3
Abstract SpawnEntityHolder and make BukkitEntityHolder
Intybyte Dec 11, 2024
2616c1d
Add lookup table
Intybyte Dec 13, 2024
a46fea7
Move some methods to SpawnEntityHolder
Intybyte Dec 13, 2024
af8a7ef
Abstract SpawnMaterialHolder and make BukkitSpawnMaterialHolder
Intybyte Dec 13, 2024
78d048c
Fix java 17 warning
Intybyte Dec 13, 2024
b765eca
Abstract CannonBlocks and make BukkitCannonBlocks
Intybyte Dec 13, 2024
72ba448
Abstract CannonBlocks
Intybyte Dec 13, 2024
570f19a
Add custom implementation of location and vector
Intybyte Dec 13, 2024
8c2bdc1
Add documentation
Intybyte Dec 13, 2024
6e53976
Make CannonVector similar to bukkit vector + remove Coordinate.java
Intybyte Dec 13, 2024
a9cc751
Apply changes
Intybyte Dec 13, 2024
d0800f8
Remove unused imports
Intybyte Dec 13, 2024
92a79dd
Fix implementation of BukkitItemHolder
Intybyte Dec 13, 2024
f3989f0
Fix enums
Intybyte Dec 13, 2024
45fd66a
Better error handling
Intybyte Dec 13, 2024
9b4ce8d
Cleanup container package
Intybyte Dec 14, 2024
7da5155
Abstract away Projectile
Intybyte Dec 14, 2024
4820122
Make BukkitProjectile
Intybyte Dec 14, 2024
68067d1
Fix Projectile
Intybyte Dec 14, 2024
4f999c6
Fix projectile (again)
Intybyte Dec 14, 2024
013c533
Run optimize imports
Intybyte Dec 14, 2024
6319d36
Cleanup FakeBlockEntry
Intybyte Dec 14, 2024
59b4e2f
FileUtils and DesignFileName cleanup
Intybyte Dec 14, 2024
c5be70f
Use FileUtils and remove methods from CannonsUtil
Intybyte Dec 14, 2024
228383d
Move NumberTricks
Intybyte Dec 14, 2024
28205ea
Projectile Manager & Storage cleanup
Intybyte Dec 14, 2024
23eddb5
Cleanup FlyingProjectile
Intybyte Dec 14, 2024
3628fb8
Abstract and fix MovingObject, and make BukkitMovingObject
Intybyte Dec 15, 2024
1027046
Move BukkitMovingObject
Intybyte Dec 15, 2024
4a609d4
Abstract FakeBlockEntry and make BukkitFakeBlockEntry
Intybyte Dec 15, 2024
f8aab9a
Add platform independent location
Intybyte Dec 15, 2024
2d50e55
Abstract Target and make BukkitTarget
Intybyte Dec 15, 2024
f2fed94
Fix stuff
Intybyte Dec 15, 2024
7212006
Abstract DeathCause and make BukkitDeathCause
Intybyte Dec 15, 2024
7214d90
Abstract CannonDesign
Intybyte Dec 16, 2024
5437e37
Rename BukkitCannonDesign
Intybyte Dec 16, 2024
20c5995
Add Bukkit specific implementation
Intybyte Dec 16, 2024
3ea24c4
Add null checks
Intybyte Dec 17, 2024
771decc
Fix errors
Intybyte Dec 17, 2024
8cf23e6
Use CannonDataHolder
Intybyte Dec 17, 2024
6ad9844
Data class GunAngles
Intybyte Dec 18, 2024
38c6ac9
Remove commented code
Intybyte Dec 19, 2024
3c88252
Relocate abstract holders
Intybyte Dec 19, 2024
066101b
Abstract FlyingProjectile and make BukkitFlyingProjectile
Intybyte Dec 19, 2024
5433eed
Optimize imports
Intybyte Dec 19, 2024
3d65202
Move BukkitFlyingProjectile
Intybyte Dec 21, 2024
555f737
Move dependency
Intybyte Dec 21, 2024
621fd43
Cleanup dao
Intybyte Dec 21, 2024
a6157bc
Beautify
Intybyte Dec 21, 2024
5c41b9e
Refactor DelayedTask
Intybyte Dec 21, 2024
c079c77
Refactor CreateTableTask
Intybyte Dec 21, 2024
2e317c3
Remove DelayedTask after all it is useless, just currying up runnable…
Intybyte Dec 21, 2024
85adf74
Separate MainTaskManager from AsyncTaskManager
Intybyte Dec 21, 2024
15b9363
Relocate AsyncTaskManager and RunnableAsync
Intybyte Dec 21, 2024
eb8df52
Create CannonDatabase singleton
Intybyte Dec 22, 2024
6bef8fc
Extract to API some dao components
Intybyte Dec 22, 2024
4df578e
Fix
Intybyte Dec 22, 2024
b5a1f8a
Fix CannonManager
Intybyte Dec 22, 2024
6b1d802
Make all method in CannonManager not static
Intybyte Dec 22, 2024
580e131
Api/bukkit/listeners (#11)
Intybyte Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions api-bukkit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.pavlov</groupId>
<artifactId>cannons</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>api-bukkit</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>at.pavlov</groupId>
<artifactId>api-internal</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.7</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${java.source}</source>
<target>${java.target}</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.pavlov.cannons.builders;
package at.pavlov.bukkit.builders;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package at.pavlov.bukkit.cannons;

import at.pavlov.internal.cannons.functionalities.InventoryObject;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;

public interface CannonBukkit extends CannonDataHolderBukkit, InventoryObject<Inventory> {
boolean sameType(CannonBukkit cannonBukkit);

default boolean isAccessLinkingAllowed(CannonBukkit fcannon, Player player) {
return !this.getCannonDesign().isAccessForOwnerOnly() || fcannon.getOwner() == player.getUniqueId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package at.pavlov.bukkit.cannons;

import at.pavlov.bukkit.cannons.holders.CannonDesignHBukkit;
import at.pavlov.bukkit.cannons.holders.CannonPositionHBukkit;
import at.pavlov.bukkit.projectile.BukkitProjectile;
import at.pavlov.internal.cannons.functionalities.CannonDataHolder;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;

public interface CannonDataHolderBukkit extends
CannonDataHolder<BlockFace, BukkitProjectile, Player>,
CannonPositionHBukkit,
CannonDesignHBukkit
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package at.pavlov.bukkit.cannons;

import at.pavlov.bukkit.cannons.data.BukkitCannonDesign;
import at.pavlov.internal.cannons.functionalities.Updatable;

public interface CannonDesignHolder extends Updatable {
void setCannonDesign(BukkitCannonDesign design);

BukkitCannonDesign getCannonDesign();

default boolean sameDesign(CannonBukkit cannon) {
return sameDesign(cannon.getCannonDesign());
}

default boolean sameDesign(BukkitCannonDesign cannonDesign) {
return getCannonDesign().equals(cannonDesign);
}

default String getDesignID() {
return getCannonDesign().getDesignID();
}

void setDesignID(String designID);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package at.pavlov.bukkit.cannons.data;

import at.pavlov.bukkit.cannons.CannonBukkit;
import at.pavlov.bukkit.container.BukkitCannonBlocks;
import at.pavlov.bukkit.container.holders.BukkitBlock;
import at.pavlov.bukkit.container.holders.BukkitItemHolder;
import at.pavlov.bukkit.container.holders.BukkitSoundHolder;
import at.pavlov.bukkit.factory.VectorUtils;
import at.pavlov.internal.CannonLogger;
import at.pavlov.internal.cannons.data.CannonDesign;
import at.pavlov.internal.container.location.CannonVector;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.inventory.ItemStack;

public class BukkitCannonDesign extends CannonDesign<
BlockData,
BlockFace,
Material,
BukkitItemHolder,
BukkitSoundHolder,
BukkitBlock,
BukkitCannonBlocks
> {

/**
* returns the rotation center of a cannon design
*/
public Location getRotationCenter(CannonBukkit cannon)
{
BukkitCannonBlocks cannonBlocks = cannonBlockMap.get(cannon.getCannonDirection());
if (cannonBlocks != null)
{
CannonVector vector = cannonBlocks.getRotationCenter().clone().add(cannon.getOffset());
return VectorUtils.toLoc(cannon.getWorldBukkit(), vector);
}

CannonLogger.getLogger().info("missing rotation center for cannon design " + cannon.getCannonName());
return VectorUtils.toLoc(cannon.getWorldBukkit(), cannon.getOffset());
}


/**
* returns the muzzle location
*/
public Location getMuzzle(CannonBukkit cannon)
{
BukkitCannonBlocks cannonBlocks = cannonBlockMap.get(cannon.getCannonDirection());
if (cannonBlocks != null)
{
CannonVector vector = cannonBlocks.getMuzzle().clone().add(cannon.getOffset());
return VectorUtils.toLoc(cannon.getWorldBukkit(), vector);
}

CannonLogger.getLogger().info("missing muzzle location for cannon design " + cannon.getCannonName());
return VectorUtils.toLoc(cannon.getWorldBukkit(), cannon.getOffset());
}

/**
* is this Item a cooling tool to cool down a cannon
* @param item - item to check
* @return - true if this item is in the list of cooling items
*/
public boolean isCoolingTool(ItemStack item)
{
//todo rework tool properties
for (BukkitItemHolder mat : itemCooling)
{
if (mat.equalsFuzzy(item))
return true;
}
return false;
}

/**
* returns the used used item. E.g. a water bucket will be an empty bucket.
* @param item - the item used for the event
* @return the new item which replaces the old one
*/
public ItemStack getCoolingToolUsed(ItemStack item)
{
for (int i=0; i < itemCooling.size(); i++)
{
//todo rework tool properties
if (itemCooling.get(i).equalsFuzzy(item))
{
return itemCoolingUsed.get(i).toItemStack(item.getAmount());
}
}
return null;
}

@Override
public void putCannonBlockMap(BlockFace cannonDirection, BukkitCannonBlocks blocks) {
for (var block : blocks.getAllCannonBlocks()) {
allowedMaterials.add(block.getBlockData().getMaterial());
}

cannonBlockMap.put(cannonDirection, blocks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package at.pavlov.bukkit.cannons.holders;

import at.pavlov.bukkit.cannons.data.BukkitCannonDesign;
import at.pavlov.internal.cannons.holders.CannonDesignHolder;

public interface CannonDesignHBukkit extends CannonDesignHolder<BukkitCannonDesign> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package at.pavlov.bukkit.cannons.holders;

import at.pavlov.internal.cannons.holders.CannonPositionHolder;
import at.pavlov.internal.container.location.CannonVector;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlockFace;

public interface CannonPositionHBukkit extends CannonPositionHolder<BlockFace> {

/**
* @return bukkit world from saved UUID
*/
default World getWorldBukkit() {
if (this.getWorld() == null) {
return null;
}
World bukkitWorld = Bukkit.getWorld(this.getWorld());
//if (bukkitWorld == null)
// Cannons.logger().info("Can't find world: " + getWorld());
return Bukkit.getWorld(this.getWorld());
// return new Location(bukkitWorld, )
}

default void move(CannonVector moved) {
getOffset().add(moved);
this.hasUpdated();
}

Location getLocation();

Location getMuzzle();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package at.pavlov.bukkit.container;

import at.pavlov.bukkit.container.holders.BukkitBlock;
import at.pavlov.internal.container.CannonBlocks;

/**
* This class is used internally to keep track of some blocks,
* it is not suggested to create new instances of it but instead
* use it to get the positions of the various stuff
*/
public class BukkitCannonBlocks extends CannonBlocks<BukkitBlock> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package at.pavlov.bukkit.container;

import at.pavlov.bukkit.projectile.BukkitProjectile;
import at.pavlov.internal.container.DeathCause;

import java.util.UUID;

public final class BukkitDeathCause extends DeathCause<BukkitProjectile> {
public BukkitDeathCause(BukkitProjectile projectile, UUID cannonUID, UUID shooterUID) {
super(projectile, cannonUID, shooterUID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package at.pavlov.bukkit.container;

import at.pavlov.bukkit.factory.VectorUtils;
import at.pavlov.internal.container.FakeBlockEntry;
import at.pavlov.internal.enums.FakeBlockType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

public class BukkitFakeBlockEntry extends FakeBlockEntry {

public BukkitFakeBlockEntry(Location loc, Player player, FakeBlockType type, long duration) {
super(VectorUtils.fromLoc(loc), loc.getWorld().getUID(), player.getUniqueId(), type, duration);
}

public World getWorldBukkit() {
return Bukkit.getWorld(getWorld());
}

public Location getLocation() {
World world = getWorldBukkit();
if (world == null) {
return null;
}

return new Location(world, getLocX(), getLocY(), getLocZ());
}

public Player getPlayerBukkit() {
return Bukkit.getPlayer(getPlayer());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package at.pavlov.bukkit.container;

import at.pavlov.bukkit.factory.VectorUtils;
import at.pavlov.internal.container.MovingObject;
import at.pavlov.internal.container.location.CannonVector;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.util.Vector;

import java.util.List;
import java.util.UUID;

public class BukkitMovingObject extends MovingObject<EntityType> {

public BukkitMovingObject(UUID world, CannonVector loc, CannonVector vel, EntityType entityType) {
super(world, loc, vel, entityType);
}

public BukkitMovingObject(Location newLoc, Vector velocity, EntityType projectileEntity) {
super(newLoc.getWorld().getUID(), VectorUtils.fromLoc(newLoc), VectorUtils.fromBaseVector(velocity), projectileEntity);
}

/**
* teleports the projectile to this location
* @param loc the projectile will be teleported to this location
* @param vel velocity of the object
*/
public void teleport(Location loc, Vector vel)
{
this.loc = VectorUtils.fromBaseVector(loc.toVector());
this.vel = VectorUtils.fromBaseVector(vel);
this.world = loc.getWorld().getUID();
}

/**
* returns the calculated location of the projectile
* @return the location where the projectile should be
*/
public Location getLocation()
{
return VectorUtils.toLoc(Bukkit.getWorld(world), loc);
}

public void setLocation(Location loc)
{
this.loc = VectorUtils.fromBaseVector(loc.toVector());
this.world = loc.getWorld().getUID();
}


@Override
public EntityType arrow() {
return EntityType.ARROW;
}

static private final List<EntityType> fireballs = List.of(EntityType.FIREBALL, EntityType.SMALL_FIREBALL);
@Override
public List<EntityType> fireballs() {
return fireballs;
}
}

Loading