chore: pre-commit changes [skip ci]

This commit is contained in:
github-actions[bot] 2024-12-08 12:13:39 +00:00
parent 0550a4dba4
commit d8c8aa408a
8 changed files with 186 additions and 170 deletions

View File

@ -16,7 +16,6 @@ import com.sekwah.advancedportals.core.services.PlayerDataServices;
import com.sekwah.advancedportals.core.util.GameScheduler;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.Matrix;
import java.awt.*;
import java.util.List;
import java.util.Objects;
@ -106,21 +105,26 @@ public class ShowDestiSubCommand
&& pos.distanceTo(player.getLoc())
< config.getShowVisibleRange()) {
drawArrow(player, pos, new Color(255, 221, 0));
} }
}
}
}
}, 1, 5);
}
// The arrow will be rotated around the player at 0 0 0 facing forwards in the positive Z direction
// The arrow will be rotated around the player at 0 0 0 facing forwards in
// the positive Z direction
Vector BASE = new Vector(0, 0, -1);
Vector TIP = new Vector(0, 0, 1);
Vector LEFT = new Vector(0.7, 0, 0.2);
Vector RIGHT = new Vector(-0.7, 0, 0.2);
public void drawArrow(PlayerContainer player, PlayerLocation playerLocation, Color color) {
public void drawArrow(PlayerContainer player, PlayerLocation playerLocation,
Color color) {
// Draw three lines to create an arrow, applying the yaw and pitch
// to the direction of the arrow
Matrix rotation = Matrix.identity().rotY(-playerLocation.getYaw()).rotX(playerLocation.getPitch());
Matrix rotation = Matrix.identity()
.rotY(-playerLocation.getYaw())
.rotX(playerLocation.getPitch());
Vector location = playerLocation.add(new Vector(0, 1.5, 0));

View File

@ -25,7 +25,6 @@ import java.util.Objects;
*/
public class ShowPortalSubCommand
implements SubCommand, SubCommand.SubCommandOnInit {
boolean alternate_show_trigger = true;
@Inject
@ -115,38 +114,32 @@ public class ShowPortalSubCommand
var pos2 = tempData.getPos2();
if (pos1 != null && pos2 != null
&& pos1.getWorldName().equals(
player.getWorldName())
&& pos2.getWorldName().equals(
player.getWorldName())) {
int widthX = Math.abs(pos1.getPosX()
- pos2.getPosX());
int widthY = Math.abs(pos1.getPosY()
- pos2.getPosY());
int widthZ = Math.abs(pos1.getPosZ()
- pos2.getPosZ());
&& pos1.getWorldName().equals(player.getWorldName())
&& pos2.getWorldName().equals(player.getWorldName())) {
int widthX = Math.abs(pos1.getPosX() - pos2.getPosX());
int widthY = Math.abs(pos1.getPosY() - pos2.getPosY());
int widthZ = Math.abs(pos1.getPosZ() - pos2.getPosZ());
int totalBlocks = widthX * widthY * widthZ;
if (totalBlocks <= config.maxPortalVisualisationSize())
debugVisuals(player, pos1,
pos2, SELECTION_COLOR);
debugVisuals(player, pos1, pos2, SELECTION_COLOR);
}
if (pos1 != null
&& pos1.getWorldName().equals(
player.getWorldName())) {
&& pos1.getWorldName().equals(player.getWorldName())) {
drawBox(player, pos1, pos1, POS1_COLOR, 0.25f);
}
if (pos2 != null
&& pos2.getWorldName().equals(
player.getWorldName())) {
&& pos2.getWorldName().equals(player.getWorldName())) {
drawBox(player, pos2, pos2, POS2_COLOR, 0.25f);
}
// If both are selected and both worlds are the same as the player
if(pos1 != null && pos2 != null &&
pos1.getWorldName().equals(player.getWorldName()) &&
pos2.getWorldName().equals(player.getWorldName())) {
if(pos1.distanceTo(pos2) <= config.maxSelectionVisualisationSize()) {
// If both are selected and both worlds are the same as the
// player
if (pos1 != null && pos2 != null
&& pos1.getWorldName().equals(player.getWorldName())
&& pos2.getWorldName().equals(player.getWorldName())) {
if (pos1.distanceTo(pos2)
<= config.maxSelectionVisualisationSize()) {
drawBox(player, pos1, pos2, SELECTION_COLOR, 1f);
}
}
@ -161,7 +154,7 @@ public class ShowPortalSubCommand
}
}
}
}, 1,5);
}, 1, 5);
}
private void debugVisuals(PlayerContainer player, BlockLocation pos1,
@ -171,11 +164,13 @@ public class ShowPortalSubCommand
private void debugVisuals(PlayerContainer player, AdvancedPortal portal,
Color color, Color triggerColor) {
debugVisuals(player, portal.getMinLoc(), portal.getMaxLoc(), color, triggerColor, portal);
debugVisuals(player, portal.getMinLoc(), portal.getMaxLoc(), color,
triggerColor, portal);
}
private void drawBox(PlayerContainer player, BlockLocation pos1,
BlockLocation pos2, Color color, float particleDensity) {
BlockLocation pos2, Color color,
float particleDensity) {
int minX = Math.min(pos1.getPosX(), pos2.getPosX());
int minY = Math.min(pos1.getPosY(), pos2.getPosY());
int minZ = Math.min(pos1.getPosZ(), pos2.getPosZ());
@ -184,19 +179,30 @@ public class ShowPortalSubCommand
int maxY = Math.max(pos1.getPosY(), pos2.getPosY()) + 1;
int maxZ = Math.max(pos1.getPosZ(), pos2.getPosZ()) + 1;
player.drawLine(new Vector(minX, maxY, maxZ), new Vector(maxX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, minZ), new Vector(maxX, minY, minZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, minZ), new Vector(minX, maxY, minZ), color, particleDensity);
player.drawLine(new Vector(maxX, minY, maxZ), new Vector(maxX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(maxX, maxY, minZ), new Vector(maxX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, minZ), new Vector(minX, minY, maxZ), color, particleDensity);
player.drawLine(new Vector(maxX, minY, minZ), new Vector(maxX, maxY, minZ), color, particleDensity);
player.drawLine(new Vector(maxX, minY, minZ), new Vector(maxX, minY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, maxY, minZ), new Vector(maxX, maxY, minZ), color, particleDensity);
player.drawLine(new Vector(minX, maxY, minZ), new Vector(minX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, maxZ), new Vector(maxX, minY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, maxZ), new Vector(minX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, maxY, maxZ),
new Vector(maxX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, minZ),
new Vector(maxX, minY, minZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, minZ),
new Vector(minX, maxY, minZ), color, particleDensity);
player.drawLine(new Vector(maxX, minY, maxZ),
new Vector(maxX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(maxX, maxY, minZ),
new Vector(maxX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, minZ),
new Vector(minX, minY, maxZ), color, particleDensity);
player.drawLine(new Vector(maxX, minY, minZ),
new Vector(maxX, maxY, minZ), color, particleDensity);
player.drawLine(new Vector(maxX, minY, minZ),
new Vector(maxX, minY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, maxY, minZ),
new Vector(maxX, maxY, minZ), color, particleDensity);
player.drawLine(new Vector(minX, maxY, minZ),
new Vector(minX, maxY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, maxZ),
new Vector(maxX, minY, maxZ), color, particleDensity);
player.drawLine(new Vector(minX, minY, maxZ),
new Vector(minX, maxY, maxZ), color, particleDensity);
}
private void debugVisuals(PlayerContainer player, BlockLocation pos1,
@ -225,9 +231,9 @@ public class ShowPortalSubCommand
boolean isTrigger = portal != null
&& portal.isTriggerBlock(world.getBlock(pos));
if (isTrigger && alternate_show_trigger)
player.spawnColoredDust(pos.toVector().add(OFFSET), 0.2, 0.2, 0.2, 1,
triggerColor);
player.spawnColoredDust(pos.toVector().add(OFFSET),
0.2, 0.2, 0.2, 1,
triggerColor);
}
}
}

View File

@ -2,7 +2,6 @@ package com.sekwah.advancedportals.core.connector.containers;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.Vector;
import java.awt.*;
import java.util.UUID;
@ -39,10 +38,11 @@ public interface PlayerContainer extends EntityContainer, HasPermission {
GameMode getGameMode();
default void drawLine(Vector start, Vector end, Color color, float particleDensity) {
default void drawLine(Vector start, Vector end, Color color,
float particleDensity) {
Vector direction = end.subtract(start);
double length = direction.length();
if(length == 0) {
if (length == 0) {
return;
}
direction = direction.normalize();
@ -56,5 +56,6 @@ public interface PlayerContainer extends EntityContainer, HasPermission {
spawnColoredDust(pos, 0, 0, 0, count, color);
}
void spawnColoredDust(Vector pos, double xSpread, double ySpread, double zSpread, int count, Color color);
void spawnColoredDust(Vector pos, double xSpread, double ySpread,
double zSpread, int count, Color color);
}

View File

@ -97,7 +97,8 @@ public class BlockLocation {
}
public WorldLocation toWorldLocation() {
return new WorldLocation(this.worldName, this.posX, this.posY, this.posZ);
return new WorldLocation(this.worldName, this.posX, this.posY,
this.posZ);
}
public BlockLocation add(int x, int y, int z) {

View File

@ -140,14 +140,16 @@ public class DestinationServices {
player.teleport(this.destinationRepository.get(name).getLoc());
if (doEffect && configRepository.getWarpEffectEnabled()) {
var warpEffectVisual = warpEffectRegistry.getVisualEffect(
configRepository.getWarpVisual());
configRepository.getWarpVisual());
if (warpEffectVisual != null) {
warpEffectVisual.onWarpVisual(player, WarpEffect.Action.ENTER);
warpEffectVisual.onWarpVisual(player,
WarpEffect.Action.ENTER);
}
var warpEffectSound = warpEffectRegistry.getSoundEffect(
configRepository.getWarpSound());
configRepository.getWarpSound());
if (warpEffectSound != null) {
warpEffectSound.onWarpSound(player, WarpEffect.Action.ENTER);
warpEffectSound.onWarpSound(player,
WarpEffect.Action.ENTER);
}
}
return true;

View File

@ -1,103 +1,101 @@
package com.sekwah.advancedportals.core.util;
import com.sekwah.advancedportals.core.serializeddata.Vector;
public class Matrix {
public double m00, m01, m02;
public double m10, m11, m12;
public double m20, m21, m22;
public Matrix() {
}
public Matrix(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) {
setMatrix(m00, m01, m02, m10, m11, m12, m20, m21, m22);
}
public static Matrix identity() {
return new Matrix( 1,0,0,
0,1,0,
0,0,1);
}
public Matrix clone() {
return new Matrix(this.m00, this.m01, this.m02, this.m10, this.m11, this.m12, this.m20, this.m21, this.m22);
}
public void setMatrix(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) {
this.m00 = m00; this.m01 = m01; this.m02 = m02;
this.m10 = m10; this.m11 = m11; this.m12 = m12;
this.m20 = m20; this.m21 = m21; this.m22 = m22;
}
public Matrix rotX(double x) {
x = Math.toRadians(x);
double sin = Math.sin(x);
double cos = Math.cos(x);
this.mul( 1, 0, 0,
0, cos, -sin,
0, sin, cos);
return this;
}
public Matrix rotY(double y) {
y = Math.toRadians(y);
double sin = Math.sin(y);
double cos = Math.cos(y);
this.mul( cos, 0, sin,
0, 1, 0,
-sin, 0, cos);
return this;
}
public Matrix rotZ(double z) {
z = Math.toRadians(z);
double sin = Math.sin(z);
double cos = Math.cos(z);
this.mul( cos, -sin, 0,
sin, cos, 0,
0, 0, 1);
return this;
}
public void mul(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) {
double t00, t01, t02,
t10, t11, t12,
t20, t21, t22;
t00 = this.m00 * m00 + this.m01 * m10 + this.m02 * m20;
t01 = this.m00 * m01 + this.m01 * m11 + this.m02 * m21;
t02 = this.m00 * m02 + this.m01 * m12 + this.m02 * m22;
t10 = this.m10 * m00 + this.m11 * m10 + this.m12 * m20;
t11 = this.m10 * m01 + this.m11 * m11 + this.m12 * m21;
t12 = this.m10 * m02 + this.m11 * m12 + this.m12 * m22;
t20 = this.m20 * m00 + this.m21 * m10 + this.m22 * m20;
t21 = this.m20 * m01 + this.m21 * m11 + this.m22 * m21;
t22 = this.m20 * m02 + this.m21 * m12 + this.m22 * m22;
this.setMatrix( t00, t01, t02,
t10, t11, t12,
t20, t21, t22);
}
public void mul(Matrix mat) {
this.mul(mat.m00, mat.m01, mat.m02, mat.m10, mat.m11, mat.m12, mat.m20, mat.m21, mat.m22);
}
public Vector transform(Vector vec) {
return transform(vec.getX(), vec.getY(), vec.getZ());
}
public Vector transform(double x, double y, double z) {
return new Vector(
m00 * x + m01 * y + m02 * z,
m10 * x + m11 * y + m12 * z,
m20 * x + m21 * y + m22 * z);
}
}
package com.sekwah.advancedportals.core.util;
import com.sekwah.advancedportals.core.serializeddata.Vector;
public class Matrix {
public double m00, m01, m02;
public double m10, m11, m12;
public double m20, m21, m22;
public Matrix() {
}
public Matrix(double m00, double m01, double m02, double m10, double m11,
double m12, double m20, double m21, double m22) {
setMatrix(m00, m01, m02, m10, m11, m12, m20, m21, m22);
}
public static Matrix identity() {
return new Matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
}
public Matrix clone() {
return new Matrix(this.m00, this.m01, this.m02, this.m10, this.m11,
this.m12, this.m20, this.m21, this.m22);
}
public void setMatrix(double m00, double m01, double m02, double m10,
double m11, double m12, double m20, double m21,
double m22) {
this.m00 = m00;
this.m01 = m01;
this.m02 = m02;
this.m10 = m10;
this.m11 = m11;
this.m12 = m12;
this.m20 = m20;
this.m21 = m21;
this.m22 = m22;
}
public Matrix rotX(double x) {
x = Math.toRadians(x);
double sin = Math.sin(x);
double cos = Math.cos(x);
this.mul(1, 0, 0, 0, cos, -sin, 0, sin, cos);
return this;
}
public Matrix rotY(double y) {
y = Math.toRadians(y);
double sin = Math.sin(y);
double cos = Math.cos(y);
this.mul(cos, 0, sin, 0, 1, 0, -sin, 0, cos);
return this;
}
public Matrix rotZ(double z) {
z = Math.toRadians(z);
double sin = Math.sin(z);
double cos = Math.cos(z);
this.mul(cos, -sin, 0, sin, cos, 0, 0, 0, 1);
return this;
}
public void mul(double m00, double m01, double m02, double m10, double m11,
double m12, double m20, double m21, double m22) {
double t00, t01, t02, t10, t11, t12, t20, t21, t22;
t00 = this.m00 * m00 + this.m01 * m10 + this.m02 * m20;
t01 = this.m00 * m01 + this.m01 * m11 + this.m02 * m21;
t02 = this.m00 * m02 + this.m01 * m12 + this.m02 * m22;
t10 = this.m10 * m00 + this.m11 * m10 + this.m12 * m20;
t11 = this.m10 * m01 + this.m11 * m11 + this.m12 * m21;
t12 = this.m10 * m02 + this.m11 * m12 + this.m12 * m22;
t20 = this.m20 * m00 + this.m21 * m10 + this.m22 * m20;
t21 = this.m20 * m01 + this.m21 * m11 + this.m22 * m21;
t22 = this.m20 * m02 + this.m21 * m12 + this.m22 * m22;
this.setMatrix(t00, t01, t02, t10, t11, t12, t20, t21, t22);
}
public void mul(Matrix mat) {
this.mul(mat.m00, mat.m01, mat.m02, mat.m10, mat.m11, mat.m12, mat.m20,
mat.m21, mat.m22);
}
public Vector transform(Vector vec) {
return transform(vec.getX(), vec.getY(), vec.getZ());
}
public Vector transform(double x, double y, double z) {
return new Vector(m00 * x + m01 * y + m02 * z,
m10 * x + m11 * y + m12 * z,
m20 * x + m21 * y + m22 * z);
}
}

View File

@ -9,7 +9,6 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.Vector;
import com.sekwah.advancedportals.shadowed.inject.Inject;
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
import java.awt.*;
import java.util.Arrays;
import java.util.UUID;
@ -95,8 +94,8 @@ public class SpigotPlayerContainer
@Override
public boolean sendPacket(String channel, byte[] bytes) {
player.sendPluginMessage(AdvancedPortalsPlugin.getInstance(),
channel, bytes);
player.sendPluginMessage(AdvancedPortalsPlugin.getInstance(), channel,
bytes);
return true;
}
@ -123,19 +122,25 @@ public class SpigotPlayerContainer
return new SpigotServerContainer(this.player.getServer());
}
@Override
public void spawnColoredDust(Vector position, double xSpread, double ySpread, double zSpread, int count, Color color) {
public void spawnColoredDust(Vector position, double xSpread,
double ySpread, double zSpread, int count,
Color color) {
// Check distance to player
if(this.player.getLocation().distance(new Location(this.player.getWorld(), position.getX(), position.getY(), position.getZ())) > 180) {
if (this.player.getLocation().distance(
new Location(this.player.getWorld(), position.getX(),
position.getY(), position.getZ()))
> 180) {
return;
}
Particle.DustOptions dustOptions = new Particle.DustOptions(
org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(),
color.getBlue()), 1.5f);
org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(),
color.getBlue()),
1.5f);
this.player.spawnParticle(Particle.REDSTONE, position.getX(),
position.getY(), position.getZ(), count,
xSpread, ySpread, zSpread, count, dustOptions);
position.getY(), position.getZ(), count,
xSpread, ySpread, zSpread, count,
dustOptions);
}
}

View File

@ -4,6 +4,7 @@ import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
import com.sekwah.advancedportals.core.data.BlockAxis;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import java.awt.*;
import org.bukkit.Axis;
import org.bukkit.Material;
import org.bukkit.Particle;
@ -12,8 +13,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.EndGateway;
import org.bukkit.block.data.Orientable;
import java.awt.*;
public class SpigotWorldContainer implements WorldContainer {
private final World world;