cleanup code

This commit is contained in:
Freddie 2023-04-30 22:05:11 +01:00
parent b839298eae
commit f4d77f7d95
5 changed files with 51 additions and 35 deletions

View File

@ -1,6 +1,7 @@
package lol.vera.spigot;
import lol.vera.spigot.implementation.ApiImplementation;
import lol.vera.spigot.implementation.PacketHandlerImplementation;
import lol.vera.spigot.implementation.KnockbackImplementation;
import lombok.Data;
@ -9,6 +10,10 @@ public class VeraSpigotAPI {
public static VeraSpigotAPI INSTANCE = new VeraSpigotAPI();
private ApiImplementation implementation = new ApiImplementation.DEFAULT();
private KnockbackImplementation knockback
= new KnockbackImplementation.DEFAULT();
private PacketHandlerImplementation packetHandler
= new PacketHandlerImplementation.DEFAULT();
}

View File

@ -8,16 +8,8 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.CreatureSpawnEvent;
/**
* WARNING: This event only fires for a limited number of cases, and not for every case that CreatureSpawnEvent does.
*
* You should still listen to CreatureSpawnEvent as a backup, and only use this event as an "enhancement".
* The intent of this event is to improve server performance, so limited use cases.
*
* Currently: NATURAL and SPAWNER based reasons. Please submit a Pull Request for future additions.
* Also, Plugins that replace Entity Registrations with their own custom entities might not fire this event.
*/
public class PreCreatureSpawnEvent extends Event implements Cancellable {
private final Location location;
private final EntityType type;
private final CreatureSpawnEvent.SpawnReason reason;
@ -95,4 +87,5 @@ public class PreCreatureSpawnEvent extends Event implements Cancellable {
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View File

@ -14,20 +14,27 @@ public class PrePlayerDeathEvent extends PlayerEvent implements Cancellable {
super(who);
}
/**
* @return If the death of this player is cancelled or not
*/
public boolean isCancelled() {
return this.cancelled;
}
/**
* Set whether the event should be cancelled
* @param cancel true if you wish to cancel this event
*/
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -1,16 +1,9 @@
package lol.vera.spigot.implementation;
import lol.vera.spigot.handler.IMovementHandler;
import lol.vera.spigot.handler.IPacketHandler;
import lol.vera.spigot.knockback.KnockbackProfile;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public interface ApiImplementation {
void registerMovementHandlers(JavaPlugin plugin, IMovementHandler... movementHandlers);
void registerPacketHandlers(JavaPlugin plugin, IPacketHandler... packetHandlers);
public interface KnockbackImplementation {
KnockbackProfile getActiveKnockbackProfile();
@ -20,17 +13,7 @@ public interface ApiImplementation {
void setActiveKnockbackProfile(Player player, KnockbackProfile knockbackProfile);
class DEFAULT implements ApiImplementation {
@Override
public void registerMovementHandlers(JavaPlugin plugin, IMovementHandler... movementHandlers) {
}
@Override
public void registerPacketHandlers(JavaPlugin plugin, IPacketHandler... packetHandlers) {
}
class DEFAULT implements KnockbackImplementation {
@Override
public KnockbackProfile getActiveKnockbackProfile() {

View File

@ -0,0 +1,28 @@
package lol.vera.spigot.implementation;
import lol.vera.spigot.handler.IMovementHandler;
import lol.vera.spigot.handler.IPacketHandler;
import org.bukkit.plugin.java.JavaPlugin;
public interface PacketHandlerImplementation {
void registerMovementHandlers(JavaPlugin plugin, IMovementHandler... movementHandlers);
void registerPacketHandlers(JavaPlugin plugin, IPacketHandler... packetHandlers);
class DEFAULT implements PacketHandlerImplementation {
@Override
public void registerMovementHandlers(JavaPlugin plugin, IMovementHandler... movementHandlers) {
}
@Override
public void registerPacketHandlers(JavaPlugin plugin, IPacketHandler... packetHandlers) {
}
}
}