Skip to content

Commit

Permalink
Merge pull request #8 from NonSwag/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
NonSwag authored Jun 15, 2024
2 parents d6b6f21 + bcb238c commit 5727af4
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 306 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ paper {
provides = listOf("goPaint")

permissions {
register("bettergopaint.command.admin.reload") {
register("gopaint.command.admin.reload") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("bettergopaint.use") {
register("gopaint.use") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("bettergopaint.admin") {
register("gopaint.admin") {
default = BukkitPluginDescription.Permission.Default.FALSE
}
register("bettergopaint.world.bypass") {
register("gopaint.world.bypass") {
default = BukkitPluginDescription.Permission.Default.FALSE
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public class GoPaintPlugin extends JavaPlugin implements Listener {

public static final String PAPER_DOCS = "https://jd.papermc.io/paper/1.20.6/org/bukkit/Material.html#enum-constant-summary";

public static final String USE_PERMISSION = "bettergopaint.use";
public static final String ADMIN_PERMISSION = "bettergopaint.admin";
public static final String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
public static final String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";
public static final String USE_PERMISSION = "gopaint.use";
public static final String ADMIN_PERMISSION = "gopaint.admin";
public static final String RELOAD_PERMISSION = "gopaint.command.admin.reload";
public static final String WORLD_BYPASS_PERMISSION = "gopaint.world.bypass";

private final File translations = new File(getDataFolder(), "translations");
private final ComponentBundle bundle = new ComponentBundle(translations, audience ->
Expand All @@ -86,9 +86,9 @@ public void onLoad() {

@Override
public void onEnable() {
// disable if goPaint and BetterGoPaint are installed simultaneously
// disable if goPaint and goPaintAdvanced are installed simultaneously
if (hasOriginalGoPaint()) {
getComponentLogger().error("BetterGoPaint is a replacement for goPaint. Please use one instead of both");
getComponentLogger().error("goPaintAdvanced is a replacement for goPaint. Please use one instead of both");
getComponentLogger().error("This plugin is now disabling to prevent future errors");
getServer().getPluginManager().disablePlugin(this);
return;
Expand All @@ -103,11 +103,6 @@ public void onEnable() {
getServer().getPluginManager().disablePlugin(this);
}

//noinspection UnnecessaryUnicodeEscape
getComponentLogger().info(MiniMessage.miniMessage().deserialize(
"<white>Made with <red>\u2665</red> <white>in <gradient:black:red:gold>Germany</gradient>"
));

registerListeners();
registerCommands();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ public void onClick(PlayerInteractEvent event) {
return;
}

final boolean hasNotWorldBaypassPermission = !player.hasPermission(GoPaintPlugin.WORLD_BYPASS_PERMISSION);

if (hasNotWorldBaypassPermission && Settings.settings().GENERIC.DISABLED_WORLDS
.contains(location.getWorld().getName())) {
if (!player.hasPermission(GoPaintPlugin.WORLD_BYPASS_PERMISSION)
&& Settings.settings().GENERIC.DISABLED_WORLDS.contains(location.getWorld().getName())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ public static class GENERIC {
public int DEFAULT_FALLOFF_STRENGTH = 50;
@Comment("Default paint mixing strength")
public int DEFAULT_MIXING_STRENGTH = 50;
@Comment("Prefix of the plugin")
public String PREFIX = "<aqua>BetterGoPaint > </aqua>";
@Comment("World there are disabled to used brushes")
public List<String> DISABLED_WORLDS = new ArrayList<>();

Expand Down
231 changes: 29 additions & 202 deletions src/main/java/net/thenextlvl/gopaint/utils/curve/BezierSpline.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
*/
package net.thenextlvl.gopaint.utils.curve;


import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;

import java.util.LinkedList;

Expand All @@ -32,12 +28,6 @@ public class BezierSpline {
private Location[] knots;
private BezierSplineSegment[] segments;
private double length = 0;
private Location anchorPoint;

public BezierSpline() {
knotsList = new LinkedList<>();
segments = new BezierSplineSegment[0];
}

public BezierSpline(LinkedList<Location> knotsList) {
this.knotsList = knotsList;
Expand All @@ -54,18 +44,6 @@ private void recalculate() {
calculateLength();
}

public void addKnot(Location location) {
knotsList.add(location);
recalculate();
}

public void removeKnot(int n) {
if (n < knots.length) {
knotsList.remove(n);
recalculate();
}
}

public double getCurveLength() {
return length;
}
Expand All @@ -78,44 +56,6 @@ public void calculateLength() {
}
}

public int getSegmentsCount() {
return segments.length;
}

public BezierSplineSegment getCurveSegment(int n) {
assert (n < segments.length);
return segments[n];
}

public double getT(double blocks) {
if (length == 0) {
calculateLength();
}

assert (blocks >= 0);
assert (blocks <= length);
if (blocks == 0) {
return 0;
}
if (blocks == length) {
return segments.length;
}
double current = 0;
int i = 0;

for (i = 0; i < segments.length; ++i) {
current += segments[i].getCurveLength();
if (current > blocks) {
current -= segments[i].getCurveLength();
break;
}
}
if (i >= segments.length) {
return segments.length;
}
return i + segments[i].getT(blocks - current);
}

public Location getPoint(double point) {
if (point >= segments.length) {
return getPoint(segments.length - 1, 1);
Expand All @@ -131,34 +71,9 @@ public Location getPoint(int n, double f) {
return segment.getPoint(f);
}

public double getdTdS(double f) {
if (f >= segments.length) {
return segments[segments.length - 1].getdTdS(1);
} else {
return segments[(int) Math.floor(f)].getdTdS(f - Math.floor(f));
}
}

public double getHAngle(double f) {
assert (f <= segments.length);
if (f >= segments.length) {
return segments[segments.length - 1].getHAngle(1);
} else {
return segments[(int) Math.floor(f)].getHAngle(f - Math.floor(f));
}
}

public void calculateControlPoints() {
/*
* Do not touch.
*/
if (segments == null) {
return;
}

if (segments.length == 0) {
return;
}
if (segments == null) return;
if (segments.length == 0) return;

Double xflat, yflat, zflat;
xflat = knots[0].getX();
Expand All @@ -185,12 +100,9 @@ public void calculateControlPoints() {

if (segments.length == 1) {
Location midpoint = new Location(segments[0].getP0().getWorld(), 0, 0, 0);
midpoint
.setX((segments[0].getP0().getX() + segments[0].getP3().getX()) / 2);
midpoint
.setY((segments[0].getP0().getY() + segments[0].getP3().getY()) / 2);
midpoint
.setZ((segments[0].getP0().getZ() + segments[0].getP3().getZ()) / 2);
midpoint.setX((segments[0].getP0().getX() + segments[0].getP3().getX()) / 2);
midpoint.setY((segments[0].getP0().getY() + segments[0].getP3().getY()) / 2);
midpoint.setZ((segments[0].getP0().getZ() + segments[0].getP3().getZ()) / 2);
segments[0].setP1(midpoint);
segments[0].setP2(midpoint.clone());
} else {
Expand All @@ -200,11 +112,11 @@ public void calculateControlPoints() {
segments[0].getR().setX(knots[0].getX() + 2 * knots[1].getX());
segments[0].getR().setY(knots[0].getY() + 2 * knots[1].getY());
segments[0].getR().setZ(knots[0].getZ() + 2 * knots[1].getZ());

int n = knots.length - 1;
int i;
float m;

for (i = 1; i < n - 1; i++) {
for (int i = 1; i < n - 1; i++) {
segments[i].setA(1);
segments[i].setB(4);
segments[i].setC(1);
Expand All @@ -220,126 +132,41 @@ public void calculateControlPoints() {
segments[n - 1].getR().setY(8 * knots[n - 1].getY() + knots[n].getY());
segments[n - 1].getR().setZ(8 * knots[n - 1].getZ() + knots[n].getZ());

for (i = 1; i < n; i++) {
for (int i = 1; i < n; i++) {
m = segments[i].getA() / segments[i - 1].getB();
segments[i].setB(segments[i].getB() - m * segments[i - 1].getC());
segments[i].getR().setX(
segments[i].getR().getX() - m * segments[i - 1].getR().getX());
segments[i].getR().setY(
segments[i].getR().getY() - m * segments[i - 1].getR().getY());
segments[i].getR().setZ(
segments[i].getR().getZ() - m * segments[i - 1].getR().getZ());
segments[i].getR().setX(segments[i].getR().getX() - m * segments[i - 1].getR().getX());
segments[i].getR().setY(segments[i].getR().getY() - m * segments[i - 1].getR().getY());
segments[i].getR().setZ(segments[i].getR().getZ() - m * segments[i - 1].getR().getZ());
}
segments[n - 1].getP1().setX(
segments[n - 1].getR().getX() / segments[n - 1].getB());
segments[n - 1].getP1().setY(
segments[n - 1].getR().getY() / segments[n - 1].getB());
segments[n - 1].getP1().setZ(
segments[n - 1].getR().getZ() / segments[n - 1].getB());

for (i = n - 2; i >= 0; i--) {
segments[i].getP1().setX(
(segments[i].getR().getX() - segments[i].getC()
* segments[i + 1].getP1().getX())
/ segments[i].getB());
segments[i].getP1().setY(
(segments[i].getR().getY() - segments[i].getC()
* segments[i + 1].getP1().getY())
/ segments[i].getB());
segments[i].getP1().setZ(
(segments[i].getR().getZ() - segments[i].getC()
* segments[i + 1].getP1().getZ())
/ segments[i].getB());
}
segments[n - 1].getP1().setX(segments[n - 1].getR().getX() / segments[n - 1].getB());
segments[n - 1].getP1().setY(segments[n - 1].getR().getY() / segments[n - 1].getB());
segments[n - 1].getP1().setZ(segments[n - 1].getR().getZ() / segments[n - 1].getB());

for (i = 0; i < n - 1; i++) {
segments[i].getP2().setX(
2 * knots[i + 1].getX() - segments[i + 1].getP1().getX());
segments[i].getP2().setY(
2 * knots[i + 1].getY() - segments[i + 1].getP1().getY());
segments[i].getP2().setZ(
2 * knots[i + 1].getZ() - segments[i + 1].getP1().getZ());
for (int i = n - 2; i >= 0; i--) {
segments[i].getP1().setX((segments[i].getR().getX() - segments[i].getC() * segments[i + 1].getP1().getX()) / segments[i].getB());
segments[i].getP1().setY((segments[i].getR().getY() - segments[i].getC() * segments[i + 1].getP1().getY()) / segments[i].getB());
segments[i].getP1().setZ((segments[i].getR().getZ() - segments[i].getC() * segments[i + 1].getP1().getZ()) / segments[i].getB());
}
segments[n - 1].getP2().setX(
0.5 * (knots[n].getX() + segments[n - 1].getP1().getX()));
segments[n - 1].getP2().setY(
0.5 * (knots[n].getY() + segments[n - 1].getP1().getY()));
segments[n - 1].getP2().setZ(
0.5 * (knots[n].getZ() + segments[n - 1].getP1().getZ()));
}

if (xflat != null) {
for (BezierSplineSegment cs : segments) {
cs.setX(xflat);
}
}
if (yflat != null) {
for (BezierSplineSegment cs : segments) {
cs.setY(yflat);
for (int i = 0; i < n - 1; i++) {
segments[i].getP2().setX(2 * knots[i + 1].getX() - segments[i + 1].getP1().getX());
segments[i].getP2().setY(2 * knots[i + 1].getY() - segments[i + 1].getP1().getY());
segments[i].getP2().setZ(2 * knots[i + 1].getZ() - segments[i + 1].getP1().getZ());
}
segments[n - 1].getP2().setX(0.5 * (knots[n].getX() + segments[n - 1].getP1().getX()));
segments[n - 1].getP2().setY(0.5 * (knots[n].getY() + segments[n - 1].getP1().getY()));
segments[n - 1].getP2().setZ(0.5 * (knots[n].getZ() + segments[n - 1].getP1().getZ()));
}
if (zflat != null) {
for (BezierSplineSegment cs : segments) {
cs.setZ(zflat);
}
}
}

public void shift(Vector vector) {
for (Location location : knotsList) {
location.add(vector);
}
recalculate();
}

public void scale(double d) {
for (Location l : knotsList) {
l.subtract(anchorPoint);
l.multiply(d);
l.add(anchorPoint);
}
recalculate();
}

public void scale(Vector vector) {
for (Location l : knotsList) {
l.subtract(anchorPoint);
l.setX(l.getX() * vector.getX());
l.setY(l.getY() * vector.getY());
l.setZ(l.getZ() * vector.getZ());
l.add(anchorPoint);
}
recalculate();
}

public @Nullable World getWorld() {
if (knots == null) {
return null;
}
if (knots.length == 0) {
return null;
}
return knots[0].getWorld();
if (xflat != null) for (BezierSplineSegment cs : segments) cs.setX(xflat);
if (yflat != null) for (BezierSplineSegment cs : segments) cs.setY(yflat);
if (zflat != null) for (BezierSplineSegment cs : segments) cs.setZ(zflat);
}

@Override
public String toString() {
if (knots == null) {
return "0 points.";
}
return knots.length + " points.";
}

public String toName() {
return "Curve";
}

public BezierSpline emptySystem() {
return new BezierSpline();
}

public String toShorthand() {
return "curve";
return (knots != null ? knots.length : 0) + " points.";
}

}
Loading

0 comments on commit 5727af4

Please sign in to comment.