Browse Source

1.5.3

master
Nazar Kalinowski 8 months ago
parent
commit
0e19316375
15 changed files with 138 additions and 71 deletions
  1. +3
    -0
      CHANGELOG
  2. +1
    -1
      pom.xml
  3. +2
    -2
      src/main/java/dev/gwm/spongeplugin/cosmetics/Cosmetics.java
  4. +8
    -5
      src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/BlockHighlightCosmeticEffect.java
  5. +8
    -7
      src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/CircleCosmeticEffect.java
  6. +9
    -6
      src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/GlobeCosmeticEffect.java
  7. +9
    -6
      src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/HelixCosmeticEffect.java
  8. +8
    -5
      src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/base/Abstract2dCosmeticEffect.java
  9. +10
    -8
      src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/base/AbstractCosmeticEffect.java
  10. +6
    -31
      src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/base/CosmeticEffect.java
  11. +22
    -0
      src/main/java/dev/gwm/spongeplugin/cosmetics/util/LocatableWorldViewerable.java
  12. +17
    -0
      src/main/java/dev/gwm/spongeplugin/cosmetics/util/Vector3dVector3dable.java
  13. +9
    -0
      src/main/java/dev/gwm/spongeplugin/cosmetics/util/Vector3dable.java
  14. +17
    -0
      src/main/java/dev/gwm/spongeplugin/cosmetics/util/ViewerViewerable.java
  15. +9
    -0
      src/main/java/dev/gwm/spongeplugin/cosmetics/util/Viewerable.java

+ 3
- 0
CHANGELOG View File

@@ -1,3 +1,6 @@
VERSION 1.5.3
* Code refactoring

VERSION 1.5.2
* Update to GWMLibrary 2.5.3
* Remove '/cosmetics save' command


+ 1
- 1
pom.xml View File

@@ -6,7 +6,7 @@

<groupId>dev.gwm.spongeplugin</groupId>
<artifactId>cosmetics</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>
<name>Cosmetics</name>
<packaging>jar</packaging>



+ 2
- 2
src/main/java/dev/gwm/spongeplugin/cosmetics/Cosmetics.java View File

@@ -32,7 +32,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Plugin(id = "cosmetics",
name = "Cosmetics",
version = "1.5.2",
version = "1.5.3",
description = "Fancy cosmetic effects",
authors = {"GWM"/* My contacts:
* E-Mail(nazark@tutanota.com),
@@ -43,7 +43,7 @@ import java.util.concurrent.atomic.AtomicInteger;
})
public class Cosmetics extends SpongePlugin {
public static final Version VERSION = new Version(1, 5, 2);
public static final Version VERSION = new Version(1, 5, 3);
private static Cosmetics instance = null;


+ 8
- 5
src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/BlockHighlightCosmeticEffect.java View File

@@ -3,6 +3,8 @@ package dev.gwm.spongeplugin.cosmetics.superobject.effect;
import com.flowpowered.math.vector.Vector3d;
import dev.gwm.spongeplugin.cosmetics.superobject.effect.base.BaseCosmeticEffect;
import dev.gwm.spongeplugin.cosmetics.util.CosmeticsUtils;
import dev.gwm.spongeplugin.cosmetics.util.Vector3dable;
import dev.gwm.spongeplugin.cosmetics.util.Viewerable;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.effect.Viewer;
import org.spongepowered.api.effect.particle.ParticleEffect;
@@ -31,18 +33,19 @@ public final class BlockHighlightCosmeticEffect extends BaseCosmeticEffect {
}

@Override
public Runnable createTask(Viewer viewer, Locatable locatable, Vector3d offset) {
return new EffectRunnable(viewer, locatable, offset);
public Runnable createTask(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
return new EffectRunnable(viewerable, locatable, offset);
}

private final class EffectRunnable extends AbstractEffectRunnable {

private EffectRunnable(Viewer viewer, Locatable locatable, Vector3d offset) {
super(viewer, locatable, offset);
private EffectRunnable(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
super(viewerable, locatable, offset);
}

@Override
public void run() {
Viewer viewer = getViewerable().getViewer();
Vector3d position = getPosition();
ParticleEffect particleEffect = isPerAnimationColor() ?
ParticleEffect.builder().
@@ -60,7 +63,7 @@ public final class BlockHighlightCosmeticEffect extends BaseCosmeticEffect {
option(ParticleOptions.COLOR, CosmeticsUtils.getRandomColor()).
build();
}
getViewer().spawnParticles(particleEffect, position.add(x, y, z));
viewer.spawnParticles(particleEffect, position.add(x, y, z));
}
}
}


+ 8
- 7
src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/CircleCosmeticEffect.java View File

@@ -3,6 +3,8 @@ package dev.gwm.spongeplugin.cosmetics.superobject.effect;
import com.flowpowered.math.vector.Vector3d;
import dev.gwm.spongeplugin.cosmetics.superobject.effect.base.BaseCosmeticEffect;
import dev.gwm.spongeplugin.cosmetics.util.CosmeticsUtils;
import dev.gwm.spongeplugin.cosmetics.util.Vector3dable;
import dev.gwm.spongeplugin.cosmetics.util.Viewerable;
import dev.gwm.spongeplugin.library.exception.SuperObjectConstructionException;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.effect.Viewer;
@@ -80,8 +82,8 @@ public final class CircleCosmeticEffect extends BaseCosmeticEffect {
}

@Override
public Runnable createTask(Viewer viewer, Locatable locatable, Vector3d offset) {
return new EffectRunnable(viewer, locatable, offset);
public Runnable createTask(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
return new EffectRunnable(viewerable, locatable, offset);
}

public double getRadius() {
@@ -102,12 +104,13 @@ public final class CircleCosmeticEffect extends BaseCosmeticEffect {
private final double l = (2 * Math.PI) / d;
private int i = 0;

private EffectRunnable(Viewer viewer, Locatable locatable, Vector3d offset) {
super(viewer, locatable, offset);
private EffectRunnable(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
super(viewerable, locatable, offset);
}

@Override
public void run() {
Viewer viewer = getViewerable().getViewer();
Vector3d position = getPosition();
ParticleEffect effect = isPerAnimationColor() ?
ParticleEffect.builder().
@@ -125,11 +128,9 @@ public final class CircleCosmeticEffect extends BaseCosmeticEffect {
if (i > l) {
i = 0;
}
final double x = position.getX();
final double z = position.getZ();
double xOffset = radius * Math.cos(i * d);
double zOffset = radius * Math.sin(i * d);
getViewer().spawnParticles(effect, position.add(new Vector3d(xOffset, 0, zOffset)));
viewer.spawnParticles(effect, position.add(new Vector3d(xOffset, 0, zOffset)));
i++;
}
}


+ 9
- 6
src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/GlobeCosmeticEffect.java View File

@@ -3,6 +3,8 @@ package dev.gwm.spongeplugin.cosmetics.superobject.effect;
import com.flowpowered.math.vector.Vector3d;
import dev.gwm.spongeplugin.cosmetics.superobject.effect.base.BaseCosmeticEffect;
import dev.gwm.spongeplugin.cosmetics.util.CosmeticsUtils;
import dev.gwm.spongeplugin.cosmetics.util.Vector3dable;
import dev.gwm.spongeplugin.cosmetics.util.Viewerable;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.effect.Viewer;
import org.spongepowered.api.effect.particle.ParticleEffect;
@@ -31,26 +33,27 @@ public final class GlobeCosmeticEffect extends BaseCosmeticEffect {
}

@Override
public Runnable createTask(Viewer viewer, Locatable locatable, Vector3d offset) {
return new EffectRunnable(viewer, locatable, offset);
public Runnable createTask(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
return new EffectRunnable(viewerable, locatable, offset);
}

private final class EffectRunnable extends AbstractEffectRunnable {

private double phi = 0;

private EffectRunnable(Viewer viewer, Locatable locatable, Vector3d offset) {
super(viewer, locatable, offset);
private EffectRunnable(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
super(viewerable, locatable, offset);
}

/* Original code have been copied from "CrazyFeet-Sponge" developed by runescapejon */
@Override
public void run() {
Viewer viewer = getViewerable().getViewer();
Vector3d position = getPosition();
phi += Math.PI / 10;
if (phi >= Math.PI) {
phi = 0;
}
Vector3d position = getPosition();
ParticleEffect effect = isPerAnimationColor() ?
ParticleEffect.builder().
from(getParticleEffect()).
@@ -68,7 +71,7 @@ public final class GlobeCosmeticEffect extends BaseCosmeticEffect {
double x = r * Math.cos(theta) * Math.sin(phi);
double y = r * Math.cos(phi) + 1.5;
double z = r * Math.sin(theta) * Math.sin(phi);
getViewer().spawnParticles(effect, position.add(x, y, z));
viewer.spawnParticles(effect, position.add(x, y, z));
}
}
}


+ 9
- 6
src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/HelixCosmeticEffect.java View File

@@ -3,6 +3,8 @@ package dev.gwm.spongeplugin.cosmetics.superobject.effect;
import com.flowpowered.math.vector.Vector3d;
import dev.gwm.spongeplugin.cosmetics.superobject.effect.base.BaseCosmeticEffect;
import dev.gwm.spongeplugin.cosmetics.util.CosmeticsUtils;
import dev.gwm.spongeplugin.cosmetics.util.Vector3dable;
import dev.gwm.spongeplugin.cosmetics.util.Viewerable;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.effect.Viewer;
import org.spongepowered.api.effect.particle.ParticleEffect;
@@ -31,26 +33,27 @@ public final class HelixCosmeticEffect extends BaseCosmeticEffect {
}

@Override
public Runnable createTask(Viewer viewer, Locatable locatable, Vector3d offset) {
return new EffectRunnable(viewer, locatable, offset);
public Runnable createTask(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
return new EffectRunnable(viewerable, locatable, offset);
}

private final class EffectRunnable extends AbstractEffectRunnable {

private double phi = 0;

private EffectRunnable(Viewer viewer, Locatable locatable, Vector3d offset) {
super(viewer, locatable, offset);
private EffectRunnable(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
super(viewerable, locatable, offset);
}

/* Original code have been copied from "CrazyFeet-Sponge" developed by runescapejon */
@Override
public void run() {
Viewer viewer = getViewerable().getViewer();
Vector3d position = getPosition();
phi = phi + Math.PI / 16;
if (phi >= Math.PI) {
phi = 0;
}
Vector3d position = getPosition();
double x, y, z;
ParticleEffect effect = isPerAnimationColor() ?
ParticleEffect.builder().
@@ -69,7 +72,7 @@ public final class HelixCosmeticEffect extends BaseCosmeticEffect {
x = 0.15 * (2 * Math.PI - t) * Math.cos(t + phi + i * Math.PI);
y = 0.5 * t;
z = 0.15 * (2 * Math.PI - t) * Math.sin(t + phi + i * Math.PI);
getViewer().spawnParticles(effect, position.add(x, y, z));
viewer.spawnParticles(effect, position.add(x, y, z));
}
}
}


+ 8
- 5
src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/base/Abstract2dCosmeticEffect.java View File

@@ -1,6 +1,8 @@
package dev.gwm.spongeplugin.cosmetics.superobject.effect.base;

import com.flowpowered.math.vector.Vector3d;
import dev.gwm.spongeplugin.cosmetics.util.Vector3dable;
import dev.gwm.spongeplugin.cosmetics.util.Viewerable;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.effect.Viewer;
import org.spongepowered.api.effect.particle.ParticleEffect;
@@ -23,8 +25,8 @@ public abstract class Abstract2dCosmeticEffect extends BaseCosmeticEffect {
}

@Override
public Runnable createTask(Viewer viewer, Locatable locatable, Vector3d offset) {
return new DotsEffectRunnable(viewer, locatable, offset);
public Runnable createTask(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
return new DotsEffectRunnable(viewerable, locatable, offset);
}

protected Map<Vector3d, ParticleEffect> colorDots(Map<Vector3d, ParticleEffect> dots) {
@@ -68,19 +70,20 @@ public abstract class Abstract2dCosmeticEffect extends BaseCosmeticEffect {
return new Vector3d(x, y, z);
}

public DotsEffectRunnable(Viewer viewer, Locatable locatable, Vector3d offset) {
super(viewer, locatable, offset);
public DotsEffectRunnable(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
super(viewerable, locatable, offset);
}

@Override
public void run() {
Viewer viewer = getViewerable().getViewer();
Vector3d rotationAngles = getRotation();
Vector3d center = getPosition();
for (Map.Entry<Vector3d, ParticleEffect> entry : getDots().entrySet()) {
Vector3d dot = entry.getKey();
ParticleEffect particleEffect = entry.getValue();
Vector3d point = center.add(rotate(dot, rotationAngles.getX(), rotationAngles.getY(), rotationAngles.getZ()));
getViewer().spawnParticles(particleEffect, point);
viewer.spawnParticles(particleEffect, point);
}
}
}

+ 10
- 8
src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/base/AbstractCosmeticEffect.java View File

@@ -2,6 +2,8 @@ package dev.gwm.spongeplugin.cosmetics.superobject.effect.base;

import com.flowpowered.math.vector.Vector3d;
import dev.gwm.spongeplugin.cosmetics.util.CosmeticsSuperObjectCategories;
import dev.gwm.spongeplugin.cosmetics.util.Vector3dable;
import dev.gwm.spongeplugin.cosmetics.util.Viewerable;
import dev.gwm.spongeplugin.library.exception.SuperObjectConstructionException;
import dev.gwm.spongeplugin.library.superobject.AbstractSuperObject;
import dev.gwm.spongeplugin.library.util.GWMLibraryUtils;
@@ -67,29 +69,29 @@ public abstract class AbstractCosmeticEffect extends AbstractSuperObject impleme

protected static abstract class AbstractEffectRunnable implements Runnable {

private final Viewer viewer;
private final Viewerable viewerable;
private final Locatable locatable;
private final Vector3d offset;
private final Vector3dable offset;

public AbstractEffectRunnable(Viewer viewer, Locatable locatable, Vector3d offset) {
this.viewer = viewer;
public AbstractEffectRunnable(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
this.viewerable = viewerable;
this.locatable = locatable;
this.offset = offset;
}

public Vector3d getPosition() {
return locatable.getLocation().getPosition().add(offset);
return locatable.getLocation().getPosition().add(offset.getVector3d());
}

public Viewer getViewer() {
return viewer;
public Viewerable getViewerable() {
return viewerable;
}

public Locatable getLocatable() {
return locatable;
}

public Vector3d getOffset() {
public Vector3dable getOffset() {
return offset;
}
}


+ 6
- 31
src/main/java/dev/gwm/spongeplugin/cosmetics/superobject/effect/base/CosmeticEffect.java View File

@@ -2,8 +2,7 @@ package dev.gwm.spongeplugin.cosmetics.superobject.effect.base;

import com.flowpowered.math.vector.Vector3d;
import dev.gwm.spongeplugin.cosmetics.Cosmetics;
import dev.gwm.spongeplugin.cosmetics.util.CosmeticsSuperObjectCategories;
import dev.gwm.spongeplugin.cosmetics.util.LocationLocatable;
import dev.gwm.spongeplugin.cosmetics.util.*;
import dev.gwm.spongeplugin.library.superobject.SuperObject;
import dev.gwm.spongeplugin.library.util.SuperObjectCategory;
import org.spongepowered.api.Sponge;
@@ -20,42 +19,18 @@ public interface CosmeticEffect extends SuperObject {
return CosmeticsSuperObjectCategories.COSMETIC_EFFECT;
}

default void play(Viewer viewer, Locatable locatable, Vector3d offset) {
createTask(viewer, locatable, offset).run();
default void play(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
createTask(viewerable, locatable, offset).run();
}

default void play(Viewer viewer, Locatable locatable) {
play(viewer, locatable, getOffset());
}

default void play(Viewer viewer, Location<World> location, Vector3d offset) {
play(viewer, new LocationLocatable(location), offset);
}

default void play(Viewer viewer, Location<World> location) {
play(viewer, location, getOffset());
}

default Task activate(Viewer viewer, Locatable locatable, Vector3d offset) {
default Task activate(Viewerable viewerable, Locatable locatable, Vector3dable offset) {
return Sponge.getScheduler().createTaskBuilder().
execute(createTask(viewer, locatable, offset)).
execute(createTask(viewerable, locatable, offset)).
intervalTicks(getDelay()).
submit(Cosmetics.getInstance());
}

default Task activate(Viewer viewer, Locatable locatable) {
return activate(viewer, locatable, getOffset());
}

default Task activate(Viewer viewer, Location<World> location, Vector3d offset) {
return activate(viewer, new LocationLocatable(location), offset);
}

default Task activate(Viewer viewer, Location<World> location) {
return activate(viewer, location, getOffset());
}

Runnable createTask(Viewer viewer, Locatable locatable, Vector3d offset);
Runnable createTask(Viewerable viewerable, Locatable locatable, Vector3dable offset);

default long getDelay() {
return defaultDelay();


+ 22
- 0
src/main/java/dev/gwm/spongeplugin/cosmetics/util/LocatableWorldViewerable.java View File

@@ -0,0 +1,22 @@
package dev.gwm.spongeplugin.cosmetics.util;

import org.spongepowered.api.effect.Viewer;
import org.spongepowered.api.world.Locatable;

public class LocatableWorldViewerable implements Viewerable {

private final Locatable locatable;

public LocatableWorldViewerable(Locatable locatable) {
this.locatable = locatable;
}

@Override
public Viewer getViewer() {
return locatable.getWorld();
}

public Locatable getLocatable() {
return locatable;
}
}

+ 17
- 0
src/main/java/dev/gwm/spongeplugin/cosmetics/util/Vector3dVector3dable.java View File

@@ -0,0 +1,17 @@
package dev.gwm.spongeplugin.cosmetics.util;

import com.flowpowered.math.vector.Vector3d;

public class Vector3dVector3dable implements Vector3dable {

private final Vector3d vector3d;

public Vector3dVector3dable(Vector3d vector3d) {
this.vector3d = vector3d;
}

@Override
public Vector3d getVector3d() {
return vector3d;
}
}

+ 9
- 0
src/main/java/dev/gwm/spongeplugin/cosmetics/util/Vector3dable.java View File

@@ -0,0 +1,9 @@
package dev.gwm.spongeplugin.cosmetics.util;

import com.flowpowered.math.vector.Vector3d;

@FunctionalInterface
public interface Vector3dable {

Vector3d getVector3d();
}

+ 17
- 0
src/main/java/dev/gwm/spongeplugin/cosmetics/util/ViewerViewerable.java View File

@@ -0,0 +1,17 @@
package dev.gwm.spongeplugin.cosmetics.util;

import org.spongepowered.api.effect.Viewer;

public class ViewerViewerable implements Viewerable {

private final Viewer viewer;

public ViewerViewerable(Viewer viewer) {
this.viewer = viewer;
}

@Override
public Viewer getViewer() {
return viewer;
}
}

+ 9
- 0
src/main/java/dev/gwm/spongeplugin/cosmetics/util/Viewerable.java View File

@@ -0,0 +1,9 @@
package dev.gwm.spongeplugin.cosmetics.util;

import org.spongepowered.api.effect.Viewer;

@FunctionalInterface
public interface Viewerable {

Viewer getViewer();
}

Loading…
Cancel
Save