9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00

add back api + add new; optimize Connection.flushQueue

This commit is contained in:
NONPLAYT
2025-03-03 01:42:23 +03:00
parent 9386e465a9
commit 31a1a929ee
11 changed files with 683 additions and 5 deletions

View File

@@ -0,0 +1,75 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 3 Mar 2025 01:14:19 +0300
Subject: [PATCH] Expanded Adventure support
diff --git a/src/main/java/org/bukkit/Color.java b/src/main/java/org/bukkit/Color.java
index f8edb964c4af597b03a2de06c464cc06a96b791c..596e2e09c6a64fa5861221789185d2fd7b004248 100644
--- a/src/main/java/org/bukkit/Color.java
+++ b/src/main/java/org/bukkit/Color.java
@@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
* but subject to change.
*/
@SerializableAs("Color")
-public final class Color implements ConfigurationSerializable {
+public final class Color implements ConfigurationSerializable, net.kyori.adventure.text.format.TextColor { // DivineMC - Expanded Adventure support
private static final int BIT_MASK = 0xff;
private static final int DEFAULT_ALPHA = 255;
@@ -310,6 +310,13 @@ public final class Color implements ConfigurationSerializable {
return getAlpha() << 24 | getRed() << 16 | getGreen() << 8 | getBlue();
}
+ // DivineMC start - Expanded Adventure support
+ @Override
+ public int value() {
+ return asRGB();
+ }
+ // DivineMC end - Expanded Adventure support
+
/**
* Gets the color as an BGR integer.
*
diff --git a/src/main/java/org/bukkit/DyeColor.java b/src/main/java/org/bukkit/DyeColor.java
index 2f038f233afd4210687586800070d5f61e40562a..24068f23f45a0d3b837b04565d143a5cd8cd8869 100644
--- a/src/main/java/org/bukkit/DyeColor.java
+++ b/src/main/java/org/bukkit/DyeColor.java
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable;
/**
* All supported color values for dyes and cloth
*/
-public enum DyeColor {
+public enum DyeColor implements net.kyori.adventure.util.RGBLike, net.kyori.adventure.text.format.StyleBuilderApplicable { // DivineMC - Expanded Adventure support
/**
* Represents white dye.
@@ -135,6 +135,28 @@ public enum DyeColor {
return firework;
}
+ // DivineMC start - Expanded Adventure support
+ @Override
+ public @org.jetbrains.annotations.Range(from = 0L, to = 255L) int red() {
+ return color.getRed();
+ }
+
+ @Override
+ public @org.jetbrains.annotations.Range(from = 0L, to = 255L) int green() {
+ return color.getGreen();
+ }
+
+ @Override
+ public @org.jetbrains.annotations.Range(from = 0L, to = 255L) int blue() {
+ return color.getBlue();
+ }
+
+ @Override
+ public void styleApply(net.kyori.adventure.text.format.Style.@org.jetbrains.annotations.NotNull Builder style) {
+ style.color(net.kyori.adventure.text.format.TextColor.color(color));
+ }
+ // DivineMC end - Expanded Adventure support
+
/**
* Gets the DyeColor with the given wool data value.
*

View File

@@ -0,0 +1,181 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 3 Mar 2025 01:15:10 +0300
Subject: [PATCH] Extend Location API
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
index 20e30fa5a33c68a4dec12e51a6b81f4afbda35b5..8b71277d3cab283eeab43df3e4dc4fb4fbad2388 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -1253,4 +1253,170 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
public @NotNull Location toLocation(@NotNull World world) {
return new Location(world, this.x(), this.y(), this.z(), this.getYaw(), this.getPitch());
}
+
+ // DivineMC start - Extend Location API
+ /**
+ * Sets the x-coordinate of this location.
+ *
+ * @param x The x-coordinate
+ * @return this location
+ */
+ public @NotNull Location x(double x) {
+ this.x = x;
+ return this;
+ }
+
+ /**
+ * Sets the y-coordinate of this location.
+ *
+ * @param y The y-coordinate
+ * @return this location
+ */
+ public @NotNull Location y(double y) {
+ this.y = y;
+ return this;
+ }
+
+ /**
+ * Sets the z-coordinate of this location.
+ *
+ * @param z The z-coordinate
+ * @return this location
+ */
+ public @NotNull Location z(double z) {
+ this.z = z;
+ return this;
+ }
+
+ /**
+ * Sets the yaw of this location, measured in degrees.
+ * <ul>
+ * <li>A yaw of 0 or 360 represents the positive z direction.
+ * <li>A yaw of 180 represents the negative z direction.
+ * <li>A yaw of 90 represents the negative x direction.
+ * <li>A yaw of 270 represents the positive x direction.
+ * </ul>
+ * Increasing yaw values are the equivalent of turning to your
+ * right-facing, increasing the scale of the next respective axis, and
+ * decreasing the scale of the previous axis.
+ *
+ * @param yaw new rotation's yaw
+ * @return this location
+ */
+ public @NotNull Location yaw(float yaw) {
+ this.yaw = yaw;
+ return this;
+ }
+
+ /**
+ * Sets the pitch of this location, measured in degrees.
+ * <ul>
+ * <li>A pitch of 0 represents level forward facing.
+ * <li>A pitch of 90 represents downward facing, or negative y
+ * direction.
+ * <li>A pitch of -90 represents upward facing, or positive y direction.
+ * </ul>
+ * Increasing pitch values the equivalent of looking down.
+ *
+ * @param pitch new incline's pitch
+ * @return this location
+ */
+ public @NotNull Location pitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ /**
+ * Sets the world that this location resides in
+ *
+ * @param world New world that this location resides in
+ * @return this location
+ */
+ public @NotNull Location world(@Nullable World world) {
+ this.world = (world == null) ? null : new WeakReference<>(world);
+ return this;
+ }
+
+ /**
+ * Increments the x-coordinate by the given value.
+ *
+ * @param x Amount to increment the x-coordinate by
+ * @return this location
+ */
+ public @NotNull Location addX(double x) {
+ this.x += x;
+ return this;
+ }
+
+ /**
+ * Increments the y-coordinate by the given value.
+ *
+ * @param y Amount to increment the y-coordinate by
+ * @return this location
+ */
+ public @NotNull Location addY(double y) {
+ this.y += y;
+ return this;
+ }
+
+ /**
+ * Increments the z-coordinate by the given value.
+ *
+ * @param z Amount to increment the z-coordinate by
+ * @return this location
+ */
+ public @NotNull Location addZ(double z) {
+ this.z += z;
+ return this;
+ }
+
+ /**
+ * Returns location with centered X, Y and Z values.
+ *
+ * @return this location
+ */
+ public @NotNull Location center() {
+ return center(0.5);
+ }
+
+ /**
+ * Returns location with centered X and Z values.
+ * Y will be set to provided.
+ *
+ * @param y Y adding value
+ * @return this location
+ */
+ public @NotNull Location center(double y) {
+ return set(getBlockX() + 0.5, getBlockY() + y, getBlockZ() + 0.5);
+ }
+
+ /**
+ * Checks if locations have the same X, Y and Z values.
+ *
+ * @param loc Location to check
+ * @return true if locations have same coordinates
+ * @apiNote Ignores world
+ */
+ public boolean isSame(@NotNull Location loc) {
+ return getY() == loc.getY() && getX() == loc.getX() && getZ() == loc.getZ();
+ }
+
+ /**
+ * Shifts this location by one block up
+ *
+ * @return this location
+ */
+ public @NotNull Location above() {
+ return addY(1);
+ }
+
+ /**
+ * Shifts this location by one block down
+ *
+ * @return this location
+ */
+ public @NotNull Location below() {
+ return addY(-1);
+ }
+ // DivineMC end - Extend Location API
}

View File

@@ -0,0 +1,80 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 3 Mar 2025 01:16:29 +0300
Subject: [PATCH] Extend Sound API
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
index b703ad820ff873097dadff9e55b53fcc6b1b8698..b35c3852a3b8e62c7d2f67fc3ff651c8e0a4d5f2 100644
--- a/src/main/java/org/bukkit/block/Block.java
+++ b/src/main/java/org/bukkit/block/Block.java
@@ -817,4 +817,29 @@ public interface Block extends Metadatable, Translatable, net.kyori.adventure.tr
return this.getBlockData().getDestroySpeed(itemStack, considerEnchants);
}
// Paper end - destroy speed API
+
+ // DivineMC start - Extend Sound API
+ /**
+ * Plays a sound at the location of the block
+ *
+ * @param sound sound to play
+ * @param volume volume of the sound
+ * @param pitch pitch of the sound
+ */
+ default void emitSound(@NotNull org.bukkit.Sound sound, float volume, float pitch) {
+ emitSound(sound, org.bukkit.SoundCategory.BLOCKS, volume, pitch);
+ }
+
+ /**
+ * Plays a sound at the location of the block
+ *
+ * @param sound sound to play
+ * @param category category of the sound
+ * @param volume volume of the sound
+ * @param pitch pitch of the sound
+ */
+ default void emitSound(@NotNull org.bukkit.Sound sound, @NotNull org.bukkit.SoundCategory category, float volume, float pitch) {
+ getWorld().playSound(getLocation().toCenterLocation(), sound, category, volume, pitch);
+ }
+ // DivineMC end - Extend Sound API
}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index be56f0f42d4ec23397f9974e158b49fcc7ed44f3..82117a1b258d43f68ff803c4c1af0a33c99065a8 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -1251,4 +1251,35 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
void setImmuneToFire(@Nullable Boolean fireImmune);
// Purpur end - Fire Immunity API
+
+ // DivineMC start - Extend Sound API
+ /**
+ * Plays a sound at the location of the entity
+ *
+ * @param sound sound to play
+ * @param volume volume of the sound
+ * @param pitch pitch of the sound
+ */
+ default void emitSound(@NotNull org.bukkit.Sound sound, float volume, float pitch) {
+ org.bukkit.SoundCategory soundGroup = switch (this) {
+ case HumanEntity humanEntity -> org.bukkit.SoundCategory.PLAYERS;
+ case Ambient ambient -> org.bukkit.SoundCategory.AMBIENT;
+ case Monster monster -> org.bukkit.SoundCategory.HOSTILE;
+ default -> org.bukkit.SoundCategory.NEUTRAL;
+ };
+ emitSound(sound, soundGroup, volume, pitch);
+ }
+
+ /**
+ * Plays a sound at the location of the block
+ *
+ * @param sound sound to play
+ * @param category category of the sound
+ * @param volume volume of the sound
+ * @param pitch pitch of the sound
+ */
+ default void emitSound(@NotNull org.bukkit.Sound sound, @NotNull org.bukkit.SoundCategory category, float volume, float pitch) {
+ getWorld().playSound(this, sound, category, volume, pitch);
+ }
+ // DivineMC end - Extend Sound API
}

View File

@@ -0,0 +1,87 @@
package org.bxteam.divinemc.event.entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Predicate;
/**
* Called when some item needs a projectile for further actions
*/
@NullMarked
public class EntityLoadsProjectileEvent extends EntityEvent {
private static final HandlerList handlers = new HandlerList();
private final ItemStack weapon;
private final Predicate<ItemStack> projectileValidator;
private ItemStack projectile;
public EntityLoadsProjectileEvent(LivingEntity entity, ItemStack weapon, @Nullable ItemStack projectile, Predicate<ItemStack> projectileValidator) {
super(entity);
this.weapon = weapon;
this.projectile = projectile == null ? ItemStack.empty() : projectile;
this.projectileValidator = projectileValidator;
}
/**
* Returns the entity firing the weapon
*
* @return the entity firing the weapon
*/
@Override
public LivingEntity getEntity() {
return (LivingEntity) this.entity;
}
/**
* Returns the weapon requesting the projectile
*
* @return weapon
*/
public ItemStack getWeapon() {
return weapon;
}
/**
* Returns the projectile that will be submitted to the weapon.
* {@link ItemStack#isEmpty()} items mean no projectile.
*
* @return projectile
*/
public ItemStack getProjectile() {
return projectile;
}
/**
* Sets the projectile that will be used by the weapon
*
* @param projectile projectile
*/
public void setProjectile(@Nullable ItemStack projectile) {
this.projectile = projectile == null ? ItemStack.empty() : projectile;
}
/**
* Checks whether the provided item can be fired from the weapon.
* <br>
* You may still provide a non-fireable projectile to it.
*
* @param item projectile item
* @return whether the provided item can be fired from the weapon
*/
public boolean canBeFired(@Nullable ItemStack item) {
return item != null && this.projectileValidator.test(item);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,84 @@
package org.bxteam.divinemc.event.entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jspecify.annotations.NullMarked;
@NullMarked
public class EntityStartUsingItemEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final ItemStack item;
private int useDuration;
private boolean cancelled;
public EntityStartUsingItemEvent(LivingEntity entity, ItemStack item, int useDuration) {
super(entity);
this.item = item;
this.useDuration = useDuration;
}
@Override
public LivingEntity getEntity() {
return (LivingEntity) this.entity;
}
/**
* Gets the item that's being used
*
* @return the item that's being used
*/
public ItemStack getItem() {
return this.item;
}
/**
* Gets for how long in ticks the item should be used until it's ready
*
* @return item use duration
*/
public int getUseDuration() {
return this.useDuration;
}
/**
* Sets for how long in ticks the item should be used until it's ready
*
* @param useDuration item use duration in ticks
*/
public void setUseDuration(int useDuration) {
this.useDuration = useDuration;
}
/**
* {@inheritDoc}
*
* @return if cancelled, the item will stop being in use
*/
@Override
public boolean isCancelled() {
return this.cancelled;
}
/**
* Set whether to cancel item use. If canceled,
* the item will stop being in use.
*
* @param cancel whether you wish to cancel this event
*/
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}