more stuff
This commit is contained in:
parent
ae21d85740
commit
5130a65a0f
7 changed files with 150 additions and 12 deletions
|
@ -5,17 +5,13 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment="">
|
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/Color.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/utils/Check.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/DyeColor.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/ExtraConversionUtil.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/Rotation.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/APIConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/APIConfig.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/SpigotWorld.java" beforeDir="false" afterPath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/SpigotWorld.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/test-plugin/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/test-plugin/build.gradle" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -299,6 +295,7 @@
|
||||||
<workItem from="1706696719616" duration="4783000" />
|
<workItem from="1706696719616" duration="4783000" />
|
||||||
<workItem from="1706784821835" duration="7882000" />
|
<workItem from="1706784821835" duration="7882000" />
|
||||||
<workItem from="1706858181164" duration="925000" />
|
<workItem from="1706858181164" duration="925000" />
|
||||||
|
<workItem from="1707159905372" duration="3391000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -2,6 +2,7 @@ package me.tofaa.entitylib;
|
||||||
|
|
||||||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||||
import me.tofaa.entitylib.tick.TickContainer;
|
import me.tofaa.entitylib.tick.TickContainer;
|
||||||
|
import me.tofaa.entitylib.wrapper.WrapperEntity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -25,6 +26,7 @@ public interface EntityLibAPI<W, T> {
|
||||||
|
|
||||||
void onEnable();
|
void onEnable();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a wrapped world for the platform specific world.
|
* Creates a wrapped world for the platform specific world.
|
||||||
* @param world The platform specific world handle.
|
* @param world The platform specific world handle.
|
||||||
|
|
64
api/src/main/java/me/tofaa/entitylib/utils/Check.java
Normal file
64
api/src/main/java/me/tofaa/entitylib/utils/Check.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package me.tofaa.entitylib.utils;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenient class to check for common exceptions. Taken from <a href="https://minestom.net/">Minestom</a>
|
||||||
|
*/
|
||||||
|
public final class Check {
|
||||||
|
|
||||||
|
private Check() {}
|
||||||
|
|
||||||
|
@Contract("null, _ -> fail")
|
||||||
|
public static void notNull(@Nullable Object object, @NotNull String reason) {
|
||||||
|
if (Objects.isNull(object)) {
|
||||||
|
throw new NullPointerException(reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("null, _, _ -> fail")
|
||||||
|
public static void notNull(@Nullable Object object, @NotNull String reason, Object... arguments) {
|
||||||
|
if (Objects.isNull(object)) {
|
||||||
|
throw new NullPointerException(MessageFormat.format(reason, arguments));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("true, _ -> fail")
|
||||||
|
public static void argCondition(boolean condition, @NotNull String reason) {
|
||||||
|
if (condition) {
|
||||||
|
throw new IllegalArgumentException(reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("true, _, _ -> fail")
|
||||||
|
public static void argCondition(boolean condition, @NotNull String reason, Object... arguments) {
|
||||||
|
if (condition) {
|
||||||
|
throw new IllegalArgumentException(MessageFormat.format(reason, arguments));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_ -> fail")
|
||||||
|
public static void fail(@NotNull String reason) {
|
||||||
|
throw new IllegalArgumentException(reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("true, _ -> fail")
|
||||||
|
public static void stateCondition(boolean condition, @NotNull String reason) {
|
||||||
|
if (condition) {
|
||||||
|
throw new IllegalStateException(reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("true, _, _ -> fail")
|
||||||
|
public static void stateCondition(boolean condition, @NotNull String reason, Object... arguments) {
|
||||||
|
if (condition) {
|
||||||
|
throw new IllegalStateException(MessageFormat.format(reason, arguments));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -45,6 +45,10 @@ public class WrapperEntity implements Tickable {
|
||||||
this.viewers = new HashSet<>();
|
this.viewers = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean spawn(Location location) {
|
||||||
|
return spawn(null, location);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean spawn(WorldWrapper<?> world, Location location) {
|
public boolean spawn(WorldWrapper<?> world, Location location) {
|
||||||
if (spawned) return false;
|
if (spawned) return false;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
@ -117,6 +121,14 @@ public class WrapperEntity implements Tickable {
|
||||||
teleport(world, location, onGround);
|
teleport(world, location, onGround);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void teleport(@NotNull Location location, boolean onGround) {
|
||||||
|
teleport(null, location, onGround);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void teleport(@NotNull Location location) {
|
||||||
|
teleport(null, location, onGround);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a viewer to the viewers set. The viewer will receive all packets and be informed of this addition
|
* Adds a viewer to the viewers set. The viewer will receive all packets and be informed of this addition
|
||||||
* @param uuid the uuid of the user to add
|
* @param uuid the uuid of the user to add
|
||||||
|
@ -160,6 +172,10 @@ public class WrapperEntity implements Tickable {
|
||||||
addViewerSilently(user.getUUID());
|
addViewerSilently(user.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a viewer from the viewers set of this entity. The viewer will be informed of this removal and will no longer receive any packets
|
||||||
|
* @param UUID the uuid of the user to remove
|
||||||
|
*/
|
||||||
public void removeViewer(UUID uuid) {
|
public void removeViewer(UUID uuid) {
|
||||||
if (!viewers.remove(uuid)) {
|
if (!viewers.remove(uuid)) {
|
||||||
return;
|
return;
|
||||||
|
@ -167,6 +183,10 @@ public class WrapperEntity implements Tickable {
|
||||||
sendPacket(uuid, new WrapperPlayServerDestroyEntities(entityId));
|
sendPacket(uuid, new WrapperPlayServerDestroyEntities(entityId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a viewer from the viewers set of this entity. The viewer will be informed of this removal and will no longer receive any packets
|
||||||
|
* @param user the user to remove
|
||||||
|
*/
|
||||||
public void removeViewer(User user) {
|
public void removeViewer(User user) {
|
||||||
removeViewer(user.getUUID());
|
removeViewer(user.getUUID());
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ public interface Hologram<W> {
|
||||||
return new LegacyHologram<>(world, location, lines);
|
return new LegacyHologram<>(world, location, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull Location getLocation();
|
@NotNull Location getLocation();
|
||||||
|
|
||||||
@NotNull WorldWrapper<W> getWorld();
|
@NotNull WorldWrapper<W> getWorld();
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package me.tofaa.entitylib.spigot;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||||
|
import com.github.retrooper.packetevents.protocol.player.HumanoidArm;
|
||||||
|
import org.bukkit.entity.Pose;
|
||||||
|
import org.bukkit.inventory.MainHand;
|
||||||
|
|
||||||
|
public final class ExtraConversionUtil {
|
||||||
|
|
||||||
|
private ExtraConversionUtil() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityPose fromBukkitPose(Pose pose) {
|
||||||
|
return EntityPose.values()[pose.ordinal()];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HumanoidArm fromBukkitHand(MainHand hand) {
|
||||||
|
if (hand == MainHand.RIGHT) return HumanoidArm.RIGHT;
|
||||||
|
return HumanoidArm.LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,8 +4,17 @@ import com.github.retrooper.packetevents.protocol.world.Location;
|
||||||
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
|
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
|
||||||
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||||
import me.tofaa.entitylib.common.AbstractWorldWrapper;
|
import me.tofaa.entitylib.common.AbstractWorldWrapper;
|
||||||
|
import me.tofaa.entitylib.meta.EntityMeta;
|
||||||
|
import me.tofaa.entitylib.meta.types.LivingEntityMeta;
|
||||||
|
import me.tofaa.entitylib.meta.types.PlayerMeta;
|
||||||
|
import me.tofaa.entitylib.utils.Check;
|
||||||
import me.tofaa.entitylib.wrapper.WrapperEntity;
|
import me.tofaa.entitylib.wrapper.WrapperEntity;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class SpigotWorld extends AbstractWorldWrapper<World> {
|
public class SpigotWorld extends AbstractWorldWrapper<World> {
|
||||||
|
@ -18,7 +27,31 @@ public class SpigotWorld extends AbstractWorldWrapper<World> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends WrapperEntity> @NotNull T cloneEntity(@NotNull Object platformEntity, @NotNull Location location) {
|
public <T extends WrapperEntity> @NotNull T cloneEntity(@NotNull Object platformEntity, @NotNull Location location) {
|
||||||
return null;
|
Check.stateCondition(!(platformEntity instanceof Entity), "Entity must be a Bukkit entity");
|
||||||
|
Entity e = (Entity) platformEntity;
|
||||||
|
EntityMeta meta = EntityMeta.createMeta(e.getEntityId(), SpigotConversionUtil.fromBukkitEntityType(e.getType()));
|
||||||
|
meta.setHasNoGravity(!e.hasGravity());
|
||||||
|
meta.setCustomNameVisible(e.isCustomNameVisible());
|
||||||
|
meta.setCustomName(LegacyComponentSerializer.legacyAmpersand().deserialize(e.getCustomName()));
|
||||||
|
meta.setPose(ExtraConversionUtil.fromBukkitPose(e.getPose()));
|
||||||
|
meta.setOnFire(e.getFireTicks() > 0);
|
||||||
|
meta.setSilent(e.isSilent());
|
||||||
|
meta.setHasGlowingEffect(e.isGlowing());
|
||||||
|
if (e instanceof LivingEntity) {
|
||||||
|
LivingEntity le = (LivingEntity) e;
|
||||||
|
LivingEntityMeta lm = (LivingEntityMeta) meta;
|
||||||
|
lm.setHealth((float) le.getHealth());
|
||||||
|
lm.setFlyingWithElytra(le.isGliding());
|
||||||
|
}
|
||||||
|
if (e instanceof Player) {
|
||||||
|
Player p = (Player) e;
|
||||||
|
PlayerMeta pm = (PlayerMeta) meta;
|
||||||
|
pm.setSneaking(p.isSneaking());
|
||||||
|
pm.setSprinting(p.isSprinting());
|
||||||
|
pm.setSwimming(p.isSwimming());
|
||||||
|
pm.setActiveHand(ExtraConversionUtil.fromBukkitHand(p.getMainHand()));
|
||||||
|
}
|
||||||
|
return null; // TODO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue