mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 20:39:10 +00:00
Merge remote-tracking branch 'refs/remotes/upstream/dev' into dev
# Conflicts: # bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.api.event;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.api.event;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.api.event;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -293,7 +293,7 @@ public class ItemEventListener implements Listener {
|
||||
Cancellable dummy = Cancellable.dummy();
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
PlayerOptionalContext context = PlayerOptionalContext.of(this.plugin.adapt(event.getPlayer()), ContextHolder.builder()
|
||||
.withParameter(DirectContextParameters.CONSUMED_ITEM, wrapped)
|
||||
.withParameter(DirectContextParameters.ITEM_IN_HAND, wrapped)
|
||||
.withParameter(DirectContextParameters.EVENT, dummy)
|
||||
.withParameter(DirectContextParameters.HAND, event.getHand() == EquipmentSlot.HAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND)
|
||||
);
|
||||
|
||||
@@ -38,6 +38,8 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -903,4 +905,18 @@ public class BukkitServerPlayer extends Player {
|
||||
public void setSaturation(float saturation) {
|
||||
this.platformPlayer().setSaturation(saturation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPotionEffect(Key potionEffectType, int duration, int amplifier, boolean ambient, boolean particles) {
|
||||
PotionEffectType type = Registry.POTION_EFFECT_TYPE.get(KeyUtils.toNamespacedKey(potionEffectType));
|
||||
if (type == null) return;
|
||||
this.platformPlayer().addPotionEffect(new PotionEffect(type, duration, amplifier, ambient, particles));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePotionEffect(Key potionEffectType) {
|
||||
PotionEffectType type = Registry.POTION_EFFECT_TYPE.get(KeyUtils.toNamespacedKey(potionEffectType));
|
||||
if (type == null) return;
|
||||
this.platformPlayer().removePotionEffect(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
|
||||
public final class ColorUtils {
|
||||
private ColorUtils() {}
|
||||
|
||||
public static Color toBukkit(net.momirealms.craftengine.core.util.Color color) {
|
||||
return Color.fromARGB(color.a(), color.r(), color.g(), color.b());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.particle.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Vibration;
|
||||
import org.bukkit.World;
|
||||
|
||||
public final class ParticleUtils {
|
||||
private ParticleUtils() {}
|
||||
@@ -21,4 +26,18 @@ public final class ParticleUtils {
|
||||
|
||||
public static final Particle HAPPY_VILLAGER = getParticle("HAPPY_VILLAGER");
|
||||
public static final Particle BUBBLE = getParticle("BUBBLE");
|
||||
|
||||
public static Object toBukkitParticleData(ParticleData particleData, Context context, World world, double x, double y, double z) {
|
||||
return switch (particleData) {
|
||||
case BlockStateData data -> BlockStateUtils.fromBlockData(data.blockState().handle());
|
||||
case ColorData data -> ColorUtils.toBukkit(data.color());
|
||||
case DustData data -> new Particle.DustOptions(ColorUtils.toBukkit(data.color()), data.size());
|
||||
case DustTransitionData data -> new Particle.DustTransition(ColorUtils.toBukkit(data.from()), ColorUtils.toBukkit(data.to()), data.size());
|
||||
case ItemStackData data -> data.item().getItem();
|
||||
case JavaTypeData data -> data.data();
|
||||
case VibrationData data -> new Vibration(new Vibration.Destination.BlockDestination(new Location(world, x + data.destinationX().getDouble(context), y + data.destinationY().getDouble(context), y + data.destinationZ().getDouble(context))), data.arrivalTime().getInt(context));
|
||||
case TrailData data -> new Particle.Trail(new Location(world, x + data.targetX().getDouble(context), y + data.targetZ().getDouble(context), z + data.targetZ().getDouble(context)), ColorUtils.toBukkit(data.color()), data.duration().getInt(context));
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package net.momirealms.craftengine.bukkit.world;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.EntityUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.SoundUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.*;
|
||||
import net.momirealms.craftengine.core.block.BlockStateWrapper;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.sound.SoundSource;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
@@ -13,12 +12,17 @@ import net.momirealms.craftengine.core.world.BlockInWorld;
|
||||
import net.momirealms.craftengine.core.world.Position;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import net.momirealms.craftengine.core.world.WorldHeight;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
@@ -99,6 +103,14 @@ public class BukkitWorld implements World {
|
||||
platformWorld().playSound(new Location(null, location.x(), location.y(), location.z()), sound.toString(), SoundCategory.BLOCKS, volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Position location, Key particle, int count, double xOffset, double yOffset, double zOffset, double speed, @Nullable ParticleData extraData, @NotNull Context context) {
|
||||
Particle particleType = Registry.PARTICLE_TYPE.get(KeyUtils.toNamespacedKey(particle));
|
||||
if (particleType == null) return;
|
||||
org.bukkit.World platformWorld = platformWorld();
|
||||
platformWorld.spawnParticle(particleType, location.x(), location.y(), location.z(), count, xOffset, yOffset, zOffset, speed, extraData == null ? null : ParticleUtils.toBukkitParticleData(extraData, context, platformWorld, location.x(), location.y(), location.z()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long time() {
|
||||
return platformWorld().getTime();
|
||||
|
||||
Reference in New Issue
Block a user