mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-27 19:19:07 +00:00
Cleanup SRC
This commit is contained in:
@@ -1,27 +1,22 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public abstract class AR implements Runnable, CancellableTask
|
||||
{
|
||||
private int id = 0;
|
||||
public abstract class AR implements Runnable, CancellableTask {
|
||||
private int id = 0;
|
||||
|
||||
public AR()
|
||||
{
|
||||
this(0);
|
||||
}
|
||||
public AR() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public AR(int interval)
|
||||
{
|
||||
id = J.ar(this, interval);
|
||||
}
|
||||
public AR(int interval) {
|
||||
id = J.ar(this, interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel()
|
||||
{
|
||||
J.car(id);
|
||||
}
|
||||
@Override
|
||||
public void cancel() {
|
||||
J.car(id);
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,38 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public class AlignedPoint
|
||||
{
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
public class AlignedPoint {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public AlignedPoint(double x, double y, double z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public AlignedPoint(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public double getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(double x)
|
||||
{
|
||||
this.x = x;
|
||||
}
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public double getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(double y)
|
||||
{
|
||||
this.y = y;
|
||||
}
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getZ()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(double z)
|
||||
{
|
||||
this.z = z;
|
||||
}
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({PARAMETER, TYPE, FIELD})
|
||||
public @interface ArrayType
|
||||
{
|
||||
Class<?> type();
|
||||
public @interface ArrayType {
|
||||
Class<?> type();
|
||||
|
||||
int min() default 0;
|
||||
int min() default 0;
|
||||
}
|
||||
|
||||
@@ -6,90 +6,82 @@ import com.google.common.util.concurrent.AtomicDoubleArray;
|
||||
* Provides an incredibly fast averaging object. It swaps values from a sum
|
||||
* using an array. Averages do not use any form of looping. An average of 10,000
|
||||
* entries is the same speed as an average with 5 entries.
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class AtomicAverage {
|
||||
protected AtomicDoubleArray values;
|
||||
private double average;
|
||||
private double lastSum;
|
||||
private boolean dirty;
|
||||
protected int cursor;
|
||||
private boolean brandNew;
|
||||
protected AtomicDoubleArray values;
|
||||
private double average;
|
||||
private double lastSum;
|
||||
private boolean dirty;
|
||||
protected int cursor;
|
||||
private boolean brandNew;
|
||||
|
||||
/**
|
||||
* Create an average holder
|
||||
*
|
||||
* @param size the size of entries to keep
|
||||
*/
|
||||
public AtomicAverage(int size) {
|
||||
values = new AtomicDoubleArray(size);
|
||||
DoubleArrayUtils.fill(values, 0);
|
||||
brandNew = true;
|
||||
average = 0;
|
||||
cursor = 0;
|
||||
lastSum = 0;
|
||||
dirty = false;
|
||||
}
|
||||
/**
|
||||
* Create an average holder
|
||||
*
|
||||
* @param size the size of entries to keep
|
||||
*/
|
||||
public AtomicAverage(int size) {
|
||||
values = new AtomicDoubleArray(size);
|
||||
DoubleArrayUtils.fill(values, 0);
|
||||
brandNew = true;
|
||||
average = 0;
|
||||
cursor = 0;
|
||||
lastSum = 0;
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value into the average (rolls over if full)
|
||||
*
|
||||
* @param i the value
|
||||
*/
|
||||
public void put(double i) {
|
||||
/**
|
||||
* Put a value into the average (rolls over if full)
|
||||
*
|
||||
* @param i the value
|
||||
*/
|
||||
public void put(double i) {
|
||||
|
||||
try
|
||||
{
|
||||
dirty = true;
|
||||
try {
|
||||
dirty = true;
|
||||
|
||||
if(brandNew)
|
||||
{
|
||||
DoubleArrayUtils.fill(values, i);
|
||||
lastSum = size() * i;
|
||||
brandNew = false;
|
||||
return;
|
||||
}
|
||||
if (brandNew) {
|
||||
DoubleArrayUtils.fill(values, i);
|
||||
lastSum = size() * i;
|
||||
brandNew = false;
|
||||
return;
|
||||
}
|
||||
|
||||
double current = values.get(cursor);
|
||||
lastSum = (lastSum - current) + i;
|
||||
values.set(cursor, i);
|
||||
cursor = cursor + 1 < size() ? cursor + 1 : 0;
|
||||
}
|
||||
double current = values.get(cursor);
|
||||
lastSum = (lastSum - current) + i;
|
||||
values.set(cursor, i);
|
||||
cursor = cursor + 1 < size() ? cursor + 1 : 0;
|
||||
} catch (Throwable e) {
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the current average
|
||||
*
|
||||
* @return the average
|
||||
*/
|
||||
public double getAverage() {
|
||||
if (dirty) {
|
||||
calculateAverage();
|
||||
return getAverage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current average
|
||||
*
|
||||
* @return the average
|
||||
*/
|
||||
public double getAverage() {
|
||||
if (dirty) {
|
||||
calculateAverage();
|
||||
return getAverage();
|
||||
}
|
||||
return average;
|
||||
}
|
||||
|
||||
return average;
|
||||
}
|
||||
private void calculateAverage() {
|
||||
average = lastSum / (double) size();
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
private void calculateAverage() {
|
||||
average = lastSum / (double) size();
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return values.length();
|
||||
}
|
||||
|
||||
public boolean isDirty()
|
||||
{
|
||||
return dirty;
|
||||
}
|
||||
public int size() {
|
||||
return values.length();
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return dirty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,102 +1,86 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public class AtomicRollingSequence extends AtomicAverage
|
||||
{
|
||||
private double median;
|
||||
private double max;
|
||||
private double min;
|
||||
private boolean dirtyMedian;
|
||||
private int dirtyExtremes;
|
||||
private boolean precision;
|
||||
public class AtomicRollingSequence extends AtomicAverage {
|
||||
private double median;
|
||||
private double max;
|
||||
private double min;
|
||||
private boolean dirtyMedian;
|
||||
private int dirtyExtremes;
|
||||
private boolean precision;
|
||||
|
||||
public AtomicRollingSequence(int size)
|
||||
{
|
||||
super(size);
|
||||
median = 0;
|
||||
min = 0;
|
||||
max = 0;
|
||||
setPrecision(false);
|
||||
}
|
||||
public AtomicRollingSequence(int size) {
|
||||
super(size);
|
||||
median = 0;
|
||||
min = 0;
|
||||
max = 0;
|
||||
setPrecision(false);
|
||||
}
|
||||
|
||||
public double addLast(int amt)
|
||||
{
|
||||
double f = 0;
|
||||
public double addLast(int amt) {
|
||||
double f = 0;
|
||||
|
||||
for(int i = 0; i < Math.min(values.length(), amt); i++)
|
||||
{
|
||||
f += values.get(i);
|
||||
}
|
||||
for (int i = 0; i < Math.min(values.length(), amt); i++) {
|
||||
f += values.get(i);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
public void setPrecision(boolean p)
|
||||
{
|
||||
this.precision = p;
|
||||
}
|
||||
public void setPrecision(boolean p) {
|
||||
this.precision = p;
|
||||
}
|
||||
|
||||
public boolean isPrecision()
|
||||
{
|
||||
return precision;
|
||||
}
|
||||
public boolean isPrecision() {
|
||||
return precision;
|
||||
}
|
||||
|
||||
public double getMin()
|
||||
{
|
||||
if(dirtyExtremes > (isPrecision() ? 0 : values.length()))
|
||||
{
|
||||
resetExtremes();
|
||||
}
|
||||
public double getMin() {
|
||||
if (dirtyExtremes > (isPrecision() ? 0 : values.length())) {
|
||||
resetExtremes();
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
public double getMax()
|
||||
{
|
||||
if(dirtyExtremes > (isPrecision() ? 0 : values.length()))
|
||||
{
|
||||
resetExtremes();
|
||||
}
|
||||
public double getMax() {
|
||||
if (dirtyExtremes > (isPrecision() ? 0 : values.length())) {
|
||||
resetExtremes();
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public double getMedian()
|
||||
{
|
||||
if(dirtyMedian)
|
||||
{
|
||||
recalculateMedian();
|
||||
}
|
||||
public double getMedian() {
|
||||
if (dirtyMedian) {
|
||||
recalculateMedian();
|
||||
}
|
||||
|
||||
return median;
|
||||
}
|
||||
return median;
|
||||
}
|
||||
|
||||
private void recalculateMedian()
|
||||
{
|
||||
median = new KList<Double>().forceAdd(values).sort().middleValue();
|
||||
dirtyMedian = false;
|
||||
}
|
||||
private void recalculateMedian() {
|
||||
median = new KList<Double>().forceAdd(values).sort().middleValue();
|
||||
dirtyMedian = false;
|
||||
}
|
||||
|
||||
public void resetExtremes()
|
||||
{
|
||||
max = Integer.MIN_VALUE;
|
||||
min = Integer.MAX_VALUE;
|
||||
public void resetExtremes() {
|
||||
max = Integer.MIN_VALUE;
|
||||
min = Integer.MAX_VALUE;
|
||||
|
||||
for(int i = 0; i < values.length(); i++)
|
||||
{
|
||||
double v = values.get(i);
|
||||
max = M.max(max, v);
|
||||
min = M.min(min, v);
|
||||
}
|
||||
for (int i = 0; i < values.length(); i++) {
|
||||
double v = values.get(i);
|
||||
max = M.max(max, v);
|
||||
min = M.min(min, v);
|
||||
}
|
||||
|
||||
dirtyExtremes = 0;
|
||||
}
|
||||
dirtyExtremes = 0;
|
||||
}
|
||||
|
||||
public void put(double i)
|
||||
{
|
||||
super.put(i);
|
||||
dirtyMedian = true;
|
||||
dirtyExtremes++;
|
||||
max = M.max(max, i);
|
||||
min = M.min(min, i);
|
||||
}
|
||||
public void put(double i) {
|
||||
super.put(i);
|
||||
dirtyMedian = true;
|
||||
dirtyExtremes++;
|
||||
max = M.max(max, i);
|
||||
min = M.min(min, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,82 +4,78 @@ package com.volmit.iris.util;
|
||||
* Provides an incredibly fast averaging object. It swaps values from a sum
|
||||
* using an array. Averages do not use any form of looping. An average of 10,000
|
||||
* entries is the same speed as an average with 5 entries.
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class Average {
|
||||
protected double[] values;
|
||||
private double average;
|
||||
private double lastSum;
|
||||
private boolean dirty;
|
||||
protected int cursor;
|
||||
private boolean brandNew;
|
||||
protected double[] values;
|
||||
private double average;
|
||||
private double lastSum;
|
||||
private boolean dirty;
|
||||
protected int cursor;
|
||||
private boolean brandNew;
|
||||
|
||||
/**
|
||||
* Create an average holder
|
||||
*
|
||||
* @param size the size of entries to keep
|
||||
*/
|
||||
public Average(int size) {
|
||||
values = new double[size];
|
||||
DoubleArrayUtils.fill(values, 0);
|
||||
brandNew = true;
|
||||
average = 0;
|
||||
cursor = 0;
|
||||
lastSum = 0;
|
||||
dirty = false;
|
||||
}
|
||||
/**
|
||||
* Create an average holder
|
||||
*
|
||||
* @param size the size of entries to keep
|
||||
*/
|
||||
public Average(int size) {
|
||||
values = new double[size];
|
||||
DoubleArrayUtils.fill(values, 0);
|
||||
brandNew = true;
|
||||
average = 0;
|
||||
cursor = 0;
|
||||
lastSum = 0;
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value into the average (rolls over if full)
|
||||
*
|
||||
* @param i the value
|
||||
*/
|
||||
public void put(double i) {
|
||||
/**
|
||||
* Put a value into the average (rolls over if full)
|
||||
*
|
||||
* @param i the value
|
||||
*/
|
||||
public void put(double i) {
|
||||
|
||||
dirty = true;
|
||||
|
||||
if(brandNew)
|
||||
{
|
||||
DoubleArrayUtils.fill(values, i);
|
||||
lastSum = size() * i;
|
||||
brandNew = false;
|
||||
return;
|
||||
}
|
||||
|
||||
double current = values[cursor];
|
||||
lastSum = (lastSum - current) + i;
|
||||
values[cursor] = i;
|
||||
cursor = cursor + 1 < size() ? cursor + 1 : 0;
|
||||
}
|
||||
dirty = true;
|
||||
|
||||
/**
|
||||
* Get the current average
|
||||
*
|
||||
* @return the average
|
||||
*/
|
||||
public double getAverage() {
|
||||
if (dirty) {
|
||||
calculateAverage();
|
||||
return getAverage();
|
||||
}
|
||||
if (brandNew) {
|
||||
DoubleArrayUtils.fill(values, i);
|
||||
lastSum = size() * i;
|
||||
brandNew = false;
|
||||
return;
|
||||
}
|
||||
|
||||
return average;
|
||||
}
|
||||
double current = values[cursor];
|
||||
lastSum = (lastSum - current) + i;
|
||||
values[cursor] = i;
|
||||
cursor = cursor + 1 < size() ? cursor + 1 : 0;
|
||||
}
|
||||
|
||||
private void calculateAverage() {
|
||||
average = lastSum / (double) size();
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return values.length;
|
||||
}
|
||||
|
||||
public boolean isDirty()
|
||||
{
|
||||
return dirty;
|
||||
}
|
||||
/**
|
||||
* Get the current average
|
||||
*
|
||||
* @return the average
|
||||
*/
|
||||
public double getAverage() {
|
||||
if (dirty) {
|
||||
calculateAverage();
|
||||
return getAverage();
|
||||
}
|
||||
|
||||
return average;
|
||||
}
|
||||
|
||||
private void calculateAverage() {
|
||||
average = lastSum / (double) size();
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return values.length;
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return dirty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,82 +4,69 @@ import com.volmit.iris.object.IrisPosition;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
public class AxisAlignedBB
|
||||
{
|
||||
private double xa;
|
||||
private double xb;
|
||||
private double ya;
|
||||
private double yb;
|
||||
private double za;
|
||||
private double zb;
|
||||
public class AxisAlignedBB {
|
||||
private final double xa;
|
||||
private final double xb;
|
||||
private final double ya;
|
||||
private final double yb;
|
||||
private final double za;
|
||||
private final double zb;
|
||||
|
||||
public AxisAlignedBB(double xa, double xb, double ya, double yb, double za, double zb)
|
||||
{
|
||||
this.xa = xa;
|
||||
this.xb = xb;
|
||||
this.ya = ya;
|
||||
this.yb = yb;
|
||||
this.za = za;
|
||||
this.zb = zb;
|
||||
}
|
||||
public AxisAlignedBB(double xa, double xb, double ya, double yb, double za, double zb) {
|
||||
this.xa = xa;
|
||||
this.xb = xb;
|
||||
this.ya = ya;
|
||||
this.yb = yb;
|
||||
this.za = za;
|
||||
this.zb = zb;
|
||||
}
|
||||
|
||||
public AxisAlignedBB shifted(IrisPosition p)
|
||||
{
|
||||
return shifted(p.getX(), p.getY(), p.getZ());
|
||||
}
|
||||
public AxisAlignedBB shifted(IrisPosition p) {
|
||||
return shifted(p.getX(), p.getY(), p.getZ());
|
||||
}
|
||||
|
||||
public AxisAlignedBB shifted(double x, double y, double z)
|
||||
{
|
||||
return new AxisAlignedBB(min().add(new IrisPosition((int)x,(int)y,(int)z)), max().add(new IrisPosition((int)x,(int)y,(int)z)));
|
||||
}
|
||||
public AxisAlignedBB shifted(double x, double y, double z) {
|
||||
return new AxisAlignedBB(min().add(new IrisPosition((int) x, (int) y, (int) z)), max().add(new IrisPosition((int) x, (int) y, (int) z)));
|
||||
}
|
||||
|
||||
public AxisAlignedBB(AlignedPoint a, AlignedPoint b)
|
||||
{
|
||||
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
|
||||
}
|
||||
public AxisAlignedBB(AlignedPoint a, AlignedPoint b) {
|
||||
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
|
||||
}
|
||||
|
||||
public AxisAlignedBB(IrisPosition a, IrisPosition b)
|
||||
{
|
||||
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
|
||||
}
|
||||
public AxisAlignedBB(IrisPosition a, IrisPosition b) {
|
||||
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
|
||||
}
|
||||
|
||||
public boolean contains(AlignedPoint p)
|
||||
{
|
||||
return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb;
|
||||
}
|
||||
public boolean contains(AlignedPoint p) {
|
||||
return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb;
|
||||
}
|
||||
|
||||
public boolean contains(IrisPosition p)
|
||||
{
|
||||
return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb;
|
||||
}
|
||||
public boolean contains(IrisPosition p) {
|
||||
return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb;
|
||||
}
|
||||
|
||||
public boolean intersects(AxisAlignedBB s)
|
||||
{
|
||||
return this.xb >= s.xa && this.yb >= s.ya && this.zb >= s.za && s.xb >= this.xa && s.yb >= this.ya && s.zb >= this.za;
|
||||
}
|
||||
public boolean intersects(AxisAlignedBB s) {
|
||||
return this.xb >= s.xa && this.yb >= s.ya && this.zb >= s.za && s.xb >= this.xa && s.yb >= this.ya && s.zb >= this.za;
|
||||
}
|
||||
|
||||
public IrisPosition max()
|
||||
{
|
||||
return new IrisPosition((int)xb, (int)yb, (int)zb);
|
||||
}
|
||||
public IrisPosition max() {
|
||||
return new IrisPosition((int) xb, (int) yb, (int) zb);
|
||||
}
|
||||
|
||||
|
||||
public BlockVector maxbv()
|
||||
{
|
||||
return new BlockVector((int)xb, (int)yb, (int)zb);
|
||||
}
|
||||
public BlockVector maxbv() {
|
||||
return new BlockVector((int) xb, (int) yb, (int) zb);
|
||||
}
|
||||
|
||||
public IrisPosition min()
|
||||
{
|
||||
return new IrisPosition((int)xa, (int)ya, (int)za);
|
||||
}
|
||||
public IrisPosition min() {
|
||||
return new IrisPosition((int) xa, (int) ya, (int) za);
|
||||
}
|
||||
|
||||
public BlockVector minbv()
|
||||
{
|
||||
return new BlockVector((int)xa, (int)ya, (int)za);
|
||||
}
|
||||
public BlockVector minbv() {
|
||||
return new BlockVector((int) xa, (int) ya, (int) za);
|
||||
}
|
||||
|
||||
public Cuboid toCuboid(World world) {
|
||||
return new Cuboid(min().toLocation(world), max().toLocation(world));
|
||||
}
|
||||
public Cuboid toCuboid(World world) {
|
||||
return new Cuboid(min().toLocation(world), max().toLocation(world));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,22 +2,18 @@ package com.volmit.iris.util;
|
||||
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
|
||||
public class BiomeMap
|
||||
{
|
||||
private final IrisBiome[] height;
|
||||
public class BiomeMap {
|
||||
private final IrisBiome[] height;
|
||||
|
||||
public BiomeMap()
|
||||
{
|
||||
height = new IrisBiome[256];
|
||||
}
|
||||
public BiomeMap() {
|
||||
height = new IrisBiome[256];
|
||||
}
|
||||
|
||||
public void setBiome(int x, int z, IrisBiome h)
|
||||
{
|
||||
height[x * 16 + z] = h;
|
||||
}
|
||||
public void setBiome(int x, int z, IrisBiome h) {
|
||||
height[x * 16 + z] = h;
|
||||
}
|
||||
|
||||
public IrisBiome getBiome(int x, int z)
|
||||
{
|
||||
return height[x * 16 + z];
|
||||
}
|
||||
public IrisBiome getBiome(int x, int z) {
|
||||
return height[x * 16 + z];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,79 +5,70 @@ import lombok.Data;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
public class BlockPosition
|
||||
{
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
public class BlockPosition {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
//Magic numbers
|
||||
private static final int m1 = 1 + MathHelper.f(MathHelper.c(30000000));
|
||||
private static final int m2 = 64 - (m1 * 2);
|
||||
private static final long m3 = m1 + m2;
|
||||
private static final long m4 = (1L << m1) - 1L;
|
||||
private static final long m5 = (1L << m2) - 1L;
|
||||
private static final long m6 = (1L << m1) - 1L;
|
||||
//Magic numbers
|
||||
private static final int m1 = 1 + MathHelper.f(MathHelper.c(30000000));
|
||||
private static final int m2 = 64 - (m1 * 2);
|
||||
private static final long m3 = m1 + m2;
|
||||
private static final long m4 = (1L << m1) - 1L;
|
||||
private static final long m5 = (1L << m2) - 1L;
|
||||
private static final long m6 = (1L << m1) - 1L;
|
||||
|
||||
|
||||
public BlockPosition(int x, int y, int z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public BlockPosition(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if(o == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(o instanceof BlockPosition)
|
||||
{
|
||||
BlockPosition ot = (BlockPosition) o;
|
||||
if (o instanceof BlockPosition) {
|
||||
BlockPosition ot = (BlockPosition) o;
|
||||
|
||||
return ot.x == x && ot.y == y && ot.z == z;
|
||||
}
|
||||
return ot.x == x && ot.y == y && ot.z == z;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getChunkX()
|
||||
{
|
||||
return x >> 4;
|
||||
}
|
||||
public int getChunkX() {
|
||||
return x >> 4;
|
||||
}
|
||||
|
||||
public int getChunkZ()
|
||||
{
|
||||
return z >> 4;
|
||||
}
|
||||
public int getChunkZ() {
|
||||
return z >> 4;
|
||||
}
|
||||
|
||||
public boolean is(int x, int z)
|
||||
{
|
||||
return this.x == x && this.z == z;
|
||||
}
|
||||
public boolean is(int x, int z) {
|
||||
return this.x == x && this.z == z;
|
||||
}
|
||||
|
||||
public boolean is(int x, int y, int z)
|
||||
{
|
||||
return this.x == x && this.y == y && this.z == z;
|
||||
}
|
||||
public boolean is(int x, int y, int z) {
|
||||
return this.x == x && this.y == y && this.z == z;
|
||||
}
|
||||
|
||||
public long asLong() {
|
||||
return toLong(getX(), getY(), getZ());
|
||||
}
|
||||
public long asLong() {
|
||||
return toLong(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public static long toLong(int x, int y, int z) {
|
||||
long var3 = 0L;
|
||||
var3 |= (x & m4) << m3;
|
||||
var3 |= (y & m5) << 0L;
|
||||
var3 |= (z & m6) << m2;
|
||||
return var3;
|
||||
}
|
||||
public static long toLong(int x, int y, int z) {
|
||||
long var3 = 0L;
|
||||
var3 |= (x & m4) << m3;
|
||||
var3 |= (y & m5) << 0L;
|
||||
var3 |= (z & m6) << m2;
|
||||
return var3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
@@ -13,135 +9,122 @@ import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 3/23/2018
|
||||
*/
|
||||
public class Board
|
||||
{
|
||||
public class Board {
|
||||
|
||||
private static final String[] CACHED_ENTRIES = new String[C.values().length];
|
||||
private static final String[] CACHED_ENTRIES = new String[C.values().length];
|
||||
|
||||
private static final Function<String, String> APPLY_COLOR_TRANSLATION = s -> C.translateAlternateColorCodes('&', s);
|
||||
private static final Function<String, String> APPLY_COLOR_TRANSLATION = s -> C.translateAlternateColorCodes('&', s);
|
||||
|
||||
static
|
||||
{
|
||||
IntStream.range(0, 15).forEach(i -> CACHED_ENTRIES[i] = C.values()[i].toString() + C.RESET);
|
||||
}
|
||||
static {
|
||||
IntStream.range(0, 15).forEach(i -> CACHED_ENTRIES[i] = C.values()[i].toString() + C.RESET);
|
||||
}
|
||||
|
||||
private final Player player;
|
||||
private final Objective objective;
|
||||
private final Team team;
|
||||
@Setter
|
||||
private BoardSettings boardSettings;
|
||||
private boolean ready;
|
||||
private final Player player;
|
||||
private final Objective objective;
|
||||
private final Team team;
|
||||
@Setter
|
||||
private BoardSettings boardSettings;
|
||||
private boolean ready;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Board(@NonNull final Player player, final BoardSettings boardSettings)
|
||||
{
|
||||
this.player = player;
|
||||
this.boardSettings = boardSettings;
|
||||
this.objective = this.getScoreboard().getObjective("board") == null ? this.getScoreboard().registerNewObjective("board", "dummy") : this.getScoreboard().getObjective("board");
|
||||
this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
this.team = this.getScoreboard().getTeam("board") == null ? this.getScoreboard().registerNewTeam("board") : this.getScoreboard().getTeam("board");
|
||||
this.team.setAllowFriendlyFire(true);
|
||||
this.team.setCanSeeFriendlyInvisibles(false);
|
||||
this.team.setPrefix("");
|
||||
this.team.setSuffix("");
|
||||
this.ready = true;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public Board(@NonNull final Player player, final BoardSettings boardSettings) {
|
||||
this.player = player;
|
||||
this.boardSettings = boardSettings;
|
||||
this.objective = this.getScoreboard().getObjective("board") == null ? this.getScoreboard().registerNewObjective("board", "dummy") : this.getScoreboard().getObjective("board");
|
||||
this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
this.team = this.getScoreboard().getTeam("board") == null ? this.getScoreboard().registerNewTeam("board") : this.getScoreboard().getTeam("board");
|
||||
this.team.setAllowFriendlyFire(true);
|
||||
this.team.setCanSeeFriendlyInvisibles(false);
|
||||
this.team.setPrefix("");
|
||||
this.team.setSuffix("");
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
public Scoreboard getScoreboard()
|
||||
{
|
||||
return (player != null) ? player.getScoreboard() : null;
|
||||
}
|
||||
public Scoreboard getScoreboard() {
|
||||
return (player != null) ? player.getScoreboard() : null;
|
||||
}
|
||||
|
||||
public void remove()
|
||||
{
|
||||
this.resetScoreboard();
|
||||
}
|
||||
public void remove() {
|
||||
this.resetScoreboard();
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
// Checking if we are ready to start updating the Scoreboard.
|
||||
if(!ready)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void update() {
|
||||
// Checking if we are ready to start updating the Scoreboard.
|
||||
if (!ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Making sure the player is connected.
|
||||
if(!player.isOnline())
|
||||
{
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
// Making sure the player is connected.
|
||||
if (!player.isOnline()) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// Making sure the Scoreboard Provider is set.
|
||||
if(boardSettings == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Making sure the Scoreboard Provider is set.
|
||||
if (boardSettings == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Getting their Scoreboard display from the Scoreboard Provider.
|
||||
final List<String> entries = boardSettings.getBoardProvider().getLines(player).stream().map(APPLY_COLOR_TRANSLATION).collect(Collectors.toList());
|
||||
// Getting their Scoreboard display from the Scoreboard Provider.
|
||||
final List<String> entries = boardSettings.getBoardProvider().getLines(player).stream().map(APPLY_COLOR_TRANSLATION).collect(Collectors.toList());
|
||||
|
||||
if(boardSettings.getScoreDirection() == ScoreDirection.UP)
|
||||
{
|
||||
Collections.reverse(entries);
|
||||
}
|
||||
if (boardSettings.getScoreDirection() == ScoreDirection.UP) {
|
||||
Collections.reverse(entries);
|
||||
}
|
||||
|
||||
// Setting the Scoreboard title
|
||||
String title = boardSettings.getBoardProvider().getTitle(player);
|
||||
if(title.length() > 32)
|
||||
{
|
||||
Bukkit.getLogger().warning("The title " + title + " is over 32 characters in length, substringing to prevent errors.");
|
||||
title = title.substring(0, 32);
|
||||
}
|
||||
objective.setDisplayName(C.translateAlternateColorCodes('&', title));
|
||||
// Setting the Scoreboard title
|
||||
String title = boardSettings.getBoardProvider().getTitle(player);
|
||||
if (title.length() > 32) {
|
||||
Bukkit.getLogger().warning("The title " + title + " is over 32 characters in length, substringing to prevent errors.");
|
||||
title = title.substring(0, 32);
|
||||
}
|
||||
objective.setDisplayName(C.translateAlternateColorCodes('&', title));
|
||||
|
||||
// Clearing previous Scoreboard values if entry sizes don't match.
|
||||
if(this.getScoreboard().getEntries().size() != entries.size())
|
||||
this.getScoreboard().getEntries().forEach(this::removeEntry);
|
||||
// Clearing previous Scoreboard values if entry sizes don't match.
|
||||
if (this.getScoreboard().getEntries().size() != entries.size())
|
||||
this.getScoreboard().getEntries().forEach(this::removeEntry);
|
||||
|
||||
// Setting Scoreboard lines.
|
||||
for(int i = 0; i < entries.size(); i++)
|
||||
{
|
||||
String str = entries.get(i);
|
||||
BoardEntry entry = BoardEntry.translateToEntry(str);
|
||||
Team team = getScoreboard().getTeam(CACHED_ENTRIES[i]);
|
||||
// Setting Scoreboard lines.
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
String str = entries.get(i);
|
||||
BoardEntry entry = BoardEntry.translateToEntry(str);
|
||||
Team team = getScoreboard().getTeam(CACHED_ENTRIES[i]);
|
||||
|
||||
if(team == null)
|
||||
{
|
||||
team = this.getScoreboard().registerNewTeam(CACHED_ENTRIES[i]);
|
||||
team.addEntry(team.getName());
|
||||
}
|
||||
if (team == null) {
|
||||
team = this.getScoreboard().registerNewTeam(CACHED_ENTRIES[i]);
|
||||
team.addEntry(team.getName());
|
||||
}
|
||||
|
||||
team.setPrefix(entry.getPrefix());
|
||||
team.setSuffix(entry.getSuffix());
|
||||
team.setPrefix(entry.getPrefix());
|
||||
team.setSuffix(entry.getSuffix());
|
||||
|
||||
switch(boardSettings.getScoreDirection())
|
||||
{
|
||||
case UP:
|
||||
objective.getScore(team.getName()).setScore(1 + i);
|
||||
break;
|
||||
case DOWN:
|
||||
objective.getScore(team.getName()).setScore(15 - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (boardSettings.getScoreDirection()) {
|
||||
case UP:
|
||||
objective.getScore(team.getName()).setScore(1 + i);
|
||||
break;
|
||||
case DOWN:
|
||||
objective.getScore(team.getName()).setScore(15 - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEntry(String id)
|
||||
{
|
||||
this.getScoreboard().resetScores(id);
|
||||
}
|
||||
public void removeEntry(String id) {
|
||||
this.getScoreboard().resetScores(id);
|
||||
}
|
||||
|
||||
public void resetScoreboard()
|
||||
{
|
||||
ready = false;
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
}
|
||||
public void resetScoreboard() {
|
||||
ready = false;
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,39 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 3/29/2018
|
||||
*/
|
||||
public class BoardEntry
|
||||
{
|
||||
public class BoardEntry {
|
||||
|
||||
@Getter
|
||||
private final String prefix, suffix;
|
||||
@Getter
|
||||
private final String prefix, suffix;
|
||||
|
||||
private BoardEntry(final String prefix, final String suffix)
|
||||
{
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
}
|
||||
private BoardEntry(final String prefix, final String suffix) {
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public static BoardEntry translateToEntry(String input)
|
||||
{
|
||||
if(input.isEmpty())
|
||||
{
|
||||
return new BoardEntry("", "");
|
||||
}
|
||||
if(input.length() <= 16)
|
||||
{
|
||||
return new BoardEntry(input, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
String prefix = input.substring(0, 16);
|
||||
String suffix = "";
|
||||
public static BoardEntry translateToEntry(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return new BoardEntry("", "");
|
||||
}
|
||||
if (input.length() <= 16) {
|
||||
return new BoardEntry(input, "");
|
||||
} else {
|
||||
String prefix = input.substring(0, 16);
|
||||
String suffix = "";
|
||||
|
||||
if(prefix.endsWith("\u00a7"))
|
||||
{
|
||||
prefix = prefix.substring(0, prefix.length() - 1);
|
||||
suffix = "\u00a7" + suffix;
|
||||
}
|
||||
if (prefix.endsWith("\u00a7")) {
|
||||
prefix = prefix.substring(0, prefix.length() - 1);
|
||||
suffix = "\u00a7" + suffix;
|
||||
}
|
||||
|
||||
suffix = StringUtils.left(C.getLastColors(prefix) + suffix + input.substring(16), 16);
|
||||
return new BoardEntry(prefix, suffix);
|
||||
}
|
||||
}
|
||||
suffix = StringUtils.left(C.getLastColors(prefix) + suffix + input.substring(16), 16);
|
||||
return new BoardEntry(prefix, suffix);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +1,78 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@DontObfuscate
|
||||
public class BoardManager
|
||||
{
|
||||
@DontObfuscate
|
||||
private final JavaPlugin plugin;
|
||||
public class BoardManager {
|
||||
@DontObfuscate
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
@DontObfuscate
|
||||
private BoardSettings boardSettings;
|
||||
@DontObfuscate
|
||||
private BoardSettings boardSettings;
|
||||
|
||||
@DontObfuscate
|
||||
private Map<UUID, Board> scoreboards;
|
||||
@DontObfuscate
|
||||
private final Map<UUID, Board> scoreboards;
|
||||
|
||||
@DontObfuscate
|
||||
private BukkitTask updateTask;
|
||||
@DontObfuscate
|
||||
private final BukkitTask updateTask;
|
||||
|
||||
@DontObfuscate
|
||||
public BoardManager(JavaPlugin plugin, BoardSettings boardSettings)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.boardSettings = boardSettings;
|
||||
this.scoreboards = new ConcurrentHashMap<>();
|
||||
this.updateTask = new BoardUpdateTask(this).runTaskTimer(plugin, 2L, 2L);
|
||||
plugin.getServer().getOnlinePlayers().forEach(this::setup);
|
||||
}
|
||||
@DontObfuscate
|
||||
public BoardManager(JavaPlugin plugin, BoardSettings boardSettings) {
|
||||
this.plugin = plugin;
|
||||
this.boardSettings = boardSettings;
|
||||
this.scoreboards = new ConcurrentHashMap<>();
|
||||
this.updateTask = new BoardUpdateTask(this).runTaskTimer(plugin, 2L, 2L);
|
||||
plugin.getServer().getOnlinePlayers().forEach(this::setup);
|
||||
}
|
||||
|
||||
@DontObfuscate
|
||||
public void setBoardSettings(BoardSettings boardSettings)
|
||||
{
|
||||
this.boardSettings = boardSettings;
|
||||
scoreboards.values().forEach(board -> board.setBoardSettings(boardSettings));
|
||||
}
|
||||
@DontObfuscate
|
||||
public void setBoardSettings(BoardSettings boardSettings) {
|
||||
this.boardSettings = boardSettings;
|
||||
scoreboards.values().forEach(board -> board.setBoardSettings(boardSettings));
|
||||
}
|
||||
|
||||
@DontObfuscate
|
||||
public boolean hasBoard(Player player)
|
||||
{
|
||||
return scoreboards.containsKey(player.getUniqueId());
|
||||
}
|
||||
@DontObfuscate
|
||||
public boolean hasBoard(Player player) {
|
||||
return scoreboards.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
@DontObfuscate
|
||||
public Optional<Board> getBoard(Player player)
|
||||
{
|
||||
return Optional.ofNullable(scoreboards.get(player.getUniqueId()));
|
||||
}
|
||||
@DontObfuscate
|
||||
public Optional<Board> getBoard(Player player) {
|
||||
return Optional.ofNullable(scoreboards.get(player.getUniqueId()));
|
||||
}
|
||||
|
||||
@DontObfuscate
|
||||
public void setup(Player player)
|
||||
{
|
||||
Optional.ofNullable(scoreboards.remove(player.getUniqueId())).ifPresent(Board::resetScoreboard);
|
||||
if(player.getScoreboard().equals(Bukkit.getScoreboardManager().getMainScoreboard()))
|
||||
{
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
}
|
||||
scoreboards.put(player.getUniqueId(), new Board(player, boardSettings));
|
||||
}
|
||||
@DontObfuscate
|
||||
public void setup(Player player) {
|
||||
Optional.ofNullable(scoreboards.remove(player.getUniqueId())).ifPresent(Board::resetScoreboard);
|
||||
if (player.getScoreboard().equals(Bukkit.getScoreboardManager().getMainScoreboard())) {
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
}
|
||||
scoreboards.put(player.getUniqueId(), new Board(player, boardSettings));
|
||||
}
|
||||
|
||||
@DontObfuscate
|
||||
public void remove(Player player)
|
||||
{
|
||||
Optional.ofNullable(scoreboards.remove(player.getUniqueId())).ifPresent(Board::remove);
|
||||
}
|
||||
@DontObfuscate
|
||||
public void remove(Player player) {
|
||||
Optional.ofNullable(scoreboards.remove(player.getUniqueId())).ifPresent(Board::remove);
|
||||
}
|
||||
|
||||
@DontObfuscate
|
||||
public Map<UUID, Board> getScoreboards()
|
||||
{
|
||||
return Collections.unmodifiableMap(scoreboards);
|
||||
}
|
||||
@DontObfuscate
|
||||
public Map<UUID, Board> getScoreboards() {
|
||||
return Collections.unmodifiableMap(scoreboards);
|
||||
}
|
||||
|
||||
@DontObfuscate
|
||||
public void onDisable()
|
||||
{
|
||||
updateTask.cancel();
|
||||
plugin.getServer().getOnlinePlayers().forEach(this::remove);
|
||||
scoreboards.clear();
|
||||
}
|
||||
@DontObfuscate
|
||||
public void onDisable() {
|
||||
updateTask.cancel();
|
||||
plugin.getServer().getOnlinePlayers().forEach(this::remove);
|
||||
scoreboards.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@DontObfuscate
|
||||
public interface BoardProvider
|
||||
{
|
||||
@DontObfuscate
|
||||
String getTitle(Player player);
|
||||
import java.util.List;
|
||||
|
||||
@DontObfuscate
|
||||
List<String> getLines(Player player);
|
||||
@DontObfuscate
|
||||
public interface BoardProvider {
|
||||
@DontObfuscate
|
||||
String getTitle(Player player);
|
||||
|
||||
@DontObfuscate
|
||||
List<String> getLines(Player player);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,10 @@ import lombok.Getter;
|
||||
@DontObfuscate
|
||||
@Getter
|
||||
@Builder
|
||||
public class BoardSettings
|
||||
{
|
||||
@DontObfuscate
|
||||
private BoardProvider boardProvider;
|
||||
public class BoardSettings {
|
||||
@DontObfuscate
|
||||
private final BoardProvider boardProvider;
|
||||
|
||||
@DontObfuscate
|
||||
private ScoreDirection scoreDirection;
|
||||
@DontObfuscate
|
||||
private final ScoreDirection scoreDirection;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
|
||||
@@ -2,24 +2,24 @@ package com.volmit.iris.util;
|
||||
|
||||
/*
|
||||
* JNBT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2010 Graham Edgecombe
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the JNBT team nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -30,13 +30,13 @@ package com.volmit.iris.util;
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>TAG_Byte_Array</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
*/
|
||||
public final class ByteArrayTag extends Tag {
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class ByteArrayTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name The name.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
*/
|
||||
public ByteArrayTag(String name, byte[] value) {
|
||||
@@ -76,7 +76,7 @@ public final class ByteArrayTag extends Tag {
|
||||
if (name != null && !name.equals("")) {
|
||||
append = "(\"" + this.getName() + "\")";
|
||||
}
|
||||
return "TAG_Byte_Array" + append + ": " + hex.toString();
|
||||
return "TAG_Byte_Array" + append + ": " + hex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,24 +2,24 @@ package com.volmit.iris.util;
|
||||
|
||||
/*
|
||||
* JNBT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2010 Graham Edgecombe
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the JNBT team nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -30,13 +30,13 @@ package com.volmit.iris.util;
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>TAG_Byte</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
*/
|
||||
public final class ByteTag extends Tag {
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class ByteTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name The name.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
*/
|
||||
public ByteTag(String name, byte value) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,49 +1,41 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public class CDou
|
||||
{
|
||||
private double number;
|
||||
private double max;
|
||||
|
||||
public CDou(double max)
|
||||
{
|
||||
number = 0;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public CDou set(double n)
|
||||
{
|
||||
number = n;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CDou add(double a)
|
||||
{
|
||||
number += a;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CDou sub(double a)
|
||||
{
|
||||
number -= a;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public double get()
|
||||
{
|
||||
return number;
|
||||
}
|
||||
|
||||
public void circ()
|
||||
{
|
||||
if(number < 0)
|
||||
{
|
||||
number = max - (Math.abs(number) > max ? max : Math.abs(number));
|
||||
}
|
||||
|
||||
number = number % (max);
|
||||
}
|
||||
public class CDou {
|
||||
private double number;
|
||||
private final double max;
|
||||
|
||||
public CDou(double max) {
|
||||
number = 0;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public CDou set(double n) {
|
||||
number = n;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CDou add(double a) {
|
||||
number += a;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CDou sub(double a) {
|
||||
number -= a;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public double get() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void circ() {
|
||||
if (number < 0) {
|
||||
number = max - (Math.abs(number) > max ? max : Math.abs(number));
|
||||
}
|
||||
|
||||
number = number % (max);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,15 @@ package com.volmit.iris.util;
|
||||
/**
|
||||
* Callback for async workers
|
||||
*
|
||||
* @param <T> the type of object to be returned in the runnable
|
||||
* @author cyberpwn
|
||||
*
|
||||
* @param <T>
|
||||
* the type of object to be returned in the runnable
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Callback<T>
|
||||
{
|
||||
/**
|
||||
* Called when the callback calls back...
|
||||
*
|
||||
* @param t
|
||||
* the object to be called back
|
||||
*/
|
||||
public void run(T t);
|
||||
public interface Callback<T> {
|
||||
/**
|
||||
* Called when the callback calls back...
|
||||
*
|
||||
* @param t the object to be called back
|
||||
*/
|
||||
void run(T t);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public interface CallbackCV<T>
|
||||
{
|
||||
public void run(T t);
|
||||
public interface CallbackCV<T> {
|
||||
void run(T t);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public interface CancellableTask
|
||||
{
|
||||
public void cancel();
|
||||
public interface CancellableTask {
|
||||
void cancel();
|
||||
}
|
||||
|
||||
@@ -3,13 +3,11 @@ package com.volmit.iris.util;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class CarveResult
|
||||
{
|
||||
private final int surface;
|
||||
private final int ceiling;
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return ceiling - surface;
|
||||
}
|
||||
public class CarveResult {
|
||||
private final int surface;
|
||||
private final int ceiling;
|
||||
|
||||
public int getHeight() {
|
||||
return ceiling - surface;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,16 @@ package com.volmit.iris.util;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CaveResult
|
||||
{
|
||||
private int floor;
|
||||
private int ceiling;
|
||||
public class CaveResult {
|
||||
private int floor;
|
||||
private int ceiling;
|
||||
|
||||
public CaveResult(int floor, int ceiling)
|
||||
{
|
||||
this.floor = floor;
|
||||
this.ceiling = ceiling;
|
||||
}
|
||||
public CaveResult(int floor, int ceiling) {
|
||||
this.floor = floor;
|
||||
this.ceiling = ceiling;
|
||||
}
|
||||
|
||||
public boolean isWithin(int v)
|
||||
{
|
||||
return v > floor || v < ceiling;
|
||||
}
|
||||
public boolean isWithin(int v) {
|
||||
return v > floor || v < ceiling;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,32 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public class ChronoLatch
|
||||
{
|
||||
private long interval;
|
||||
private long since;
|
||||
public class ChronoLatch {
|
||||
private final long interval;
|
||||
private long since;
|
||||
|
||||
public ChronoLatch(long interval, boolean openedAtStart)
|
||||
{
|
||||
this.interval = interval;
|
||||
since = System.currentTimeMillis() - (openedAtStart ? interval * 2 : 0);
|
||||
}
|
||||
public ChronoLatch(long interval, boolean openedAtStart) {
|
||||
this.interval = interval;
|
||||
since = System.currentTimeMillis() - (openedAtStart ? interval * 2 : 0);
|
||||
}
|
||||
|
||||
public ChronoLatch(long interval)
|
||||
{
|
||||
this(interval, true);
|
||||
}
|
||||
public ChronoLatch(long interval) {
|
||||
this(interval, true);
|
||||
}
|
||||
|
||||
public void flipDown()
|
||||
{
|
||||
since = System.currentTimeMillis();
|
||||
}
|
||||
public void flipDown() {
|
||||
since = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean couldFlip()
|
||||
{
|
||||
return System.currentTimeMillis() - since > interval;
|
||||
}
|
||||
public boolean couldFlip() {
|
||||
return System.currentTimeMillis() - since > interval;
|
||||
}
|
||||
|
||||
public boolean flip()
|
||||
{
|
||||
if(System.currentTimeMillis() - since > interval)
|
||||
{
|
||||
since = System.currentTimeMillis();
|
||||
return true;
|
||||
}
|
||||
public boolean flip() {
|
||||
if (System.currentTimeMillis() - since > interval) {
|
||||
since = System.currentTimeMillis();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,52 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public class ChunkPosition
|
||||
{
|
||||
private int x;
|
||||
private int z;
|
||||
public class ChunkPosition {
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
public ChunkPosition(int x, int z)
|
||||
{
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
public ChunkPosition(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public int getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x)
|
||||
{
|
||||
this.x = x;
|
||||
}
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getZ()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(int z)
|
||||
{
|
||||
this.z = z;
|
||||
}
|
||||
public void setZ(int z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + x;
|
||||
result = prime * result + z;
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + x;
|
||||
result = prime * result + z;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!(obj instanceof ChunkPosition))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ChunkPosition other = (ChunkPosition) obj;
|
||||
return x == other.x && z == other.z;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof ChunkPosition)) {
|
||||
return false;
|
||||
}
|
||||
ChunkPosition other = (ChunkPosition) obj;
|
||||
return x == other.x && z == other.z;
|
||||
}
|
||||
|
||||
public double distance(ChunkPosition center)
|
||||
{
|
||||
return Math.pow(center.getX() - x, 2) + Math.pow(center.getZ() - z, 2);
|
||||
public double distance(ChunkPosition center) {
|
||||
return Math.pow(center.getX() - x, 2) + Math.pow(center.getZ() - z, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,53 +5,47 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Chunker<T>
|
||||
{
|
||||
private ExecutorService executor;
|
||||
private int threads;
|
||||
private int workload;
|
||||
private KList<T> q;
|
||||
public class Chunker<T> {
|
||||
private ExecutorService executor;
|
||||
private int threads;
|
||||
private int workload;
|
||||
private final KList<T> q;
|
||||
|
||||
public Chunker(KList<T> q)
|
||||
{
|
||||
this.q = q;
|
||||
}
|
||||
public Chunker(KList<T> q) {
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public Chunker<T> threads(int threads)
|
||||
{
|
||||
this.threads = threads;
|
||||
return this;
|
||||
}
|
||||
public Chunker<T> threads(int threads) {
|
||||
this.threads = threads;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Chunker<T> workload(int workload)
|
||||
{
|
||||
this.workload = workload;
|
||||
return this;
|
||||
}
|
||||
public Chunker<T> workload(int workload) {
|
||||
this.workload = workload;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void execute(Consumer<T> consumer, Callback<Double> progress, int progressInterval)
|
||||
{
|
||||
ChronoLatch cl = new ChronoLatch(progressInterval);
|
||||
Contained<Integer> consumed = new Contained<Integer>(0);
|
||||
executor = Executors.newFixedThreadPool(threads);
|
||||
int length = q.size();
|
||||
int remaining = length;
|
||||
public void execute(Consumer<T> consumer, Callback<Double> progress, int progressInterval) {
|
||||
ChronoLatch cl = new ChronoLatch(progressInterval);
|
||||
Contained<Integer> consumed = new Contained<Integer>(0);
|
||||
executor = Executors.newFixedThreadPool(threads);
|
||||
int length = q.size();
|
||||
int remaining = length;
|
||||
|
||||
while(remaining > 0)
|
||||
{
|
||||
int at = remaining;
|
||||
remaining -= (remaining > workload ? workload : remaining);
|
||||
int to = remaining;
|
||||
while (remaining > 0) {
|
||||
int at = remaining;
|
||||
remaining -= (remaining > workload ? workload : remaining);
|
||||
int to = remaining;
|
||||
|
||||
executor.submit(() ->
|
||||
{
|
||||
J.dofor(at, (i) -> i >= to, -1, (i) -> J.attempt(() -> consumer.accept(q.get(i))));
|
||||
consumed.mod((c) -> c += workload);
|
||||
J.doif(() -> progress != null && cl.flip(), () -> progress.run((double) consumed.get() / (double) length));
|
||||
});
|
||||
}
|
||||
executor.submit(() ->
|
||||
{
|
||||
J.dofor(at, (i) -> i >= to, -1, (i) -> J.attempt(() -> consumer.accept(q.get(i))));
|
||||
consumed.mod((c) -> c += workload);
|
||||
J.doif(() -> progress != null && cl.flip(), () -> progress.run((double) consumed.get() / (double) length));
|
||||
});
|
||||
}
|
||||
|
||||
executor.shutdown();
|
||||
J.attempt(() -> executor.awaitTermination(100, TimeUnit.HOURS));
|
||||
}
|
||||
executor.shutdown();
|
||||
J.attempt(() -> executor.awaitTermination(100, TimeUnit.HOURS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
public @interface Command
|
||||
{
|
||||
String value() default "";
|
||||
public @interface Command {
|
||||
String value() default "";
|
||||
}
|
||||
|
||||
@@ -6,53 +6,44 @@ import java.util.Map;
|
||||
* The <code>TAG_Compound</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
*/
|
||||
public final class CompoundTag extends Tag
|
||||
{
|
||||
public final class CompoundTag extends Tag {
|
||||
|
||||
/**
|
||||
* The value.
|
||||
*/
|
||||
private final Map<String, Tag> value;
|
||||
/**
|
||||
* The value.
|
||||
*/
|
||||
private final Map<String, Tag> value;
|
||||
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name
|
||||
* The name.
|
||||
* @param value
|
||||
* The value.
|
||||
*/
|
||||
public CompoundTag(String name, Map<String, Tag> value)
|
||||
{
|
||||
super(name);
|
||||
this.value = value;
|
||||
}
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
*/
|
||||
public CompoundTag(String name, Map<String, Tag> value) {
|
||||
super(name);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Tag> getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public Map<String, Tag> getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if(name != null && !name.equals(""))
|
||||
{
|
||||
append = "(\"" + this.getName() + "\")";
|
||||
}
|
||||
StringBuilder bldr = new StringBuilder();
|
||||
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
|
||||
for(Map.Entry<String, Tag> entry : value.entrySet())
|
||||
{
|
||||
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
||||
}
|
||||
bldr.append("}");
|
||||
return bldr.toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
String name = getName();
|
||||
String append = "";
|
||||
if (name != null && !name.equals("")) {
|
||||
append = "(\"" + this.getName() + "\")";
|
||||
}
|
||||
StringBuilder bldr = new StringBuilder();
|
||||
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
|
||||
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
||||
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
||||
}
|
||||
bldr.append("}");
|
||||
return bldr.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Consumer2<A, B>
|
||||
{
|
||||
public void accept(A a, B b);
|
||||
public interface Consumer2<A, B> {
|
||||
void accept(A a, B b);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Consumer3<A, B, C>
|
||||
{
|
||||
public void accept(A a, B b, C c);
|
||||
public interface Consumer3<A, B, C> {
|
||||
void accept(A a, B b, C c);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Consumer4<A, B, C, D>
|
||||
{
|
||||
public void accept(A a, B b, C c, D d);
|
||||
public interface Consumer4<A, B, C, D> {
|
||||
void accept(A a, B b, C c, D d);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Consumer5<A, B, C, D, E>
|
||||
{
|
||||
public void accept(A a, B b, C c, D d, E e);
|
||||
public interface Consumer5<A, B, C, D, E> {
|
||||
void accept(A a, B b, C c, D d, E e);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Consumer6<A, B, C, D, E, F>
|
||||
{
|
||||
public void accept(A a, B b, C c, D d, E e, F f);
|
||||
public interface Consumer6<A, B, C, D, E, F> {
|
||||
void accept(A a, B b, C c, D d, E e, F f);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Consumer7<A, B, C, D, E, F, G>
|
||||
{
|
||||
public void accept(A a, B b, C c, D d, E e, F f, G g);
|
||||
public interface Consumer7<A, B, C, D, E, F, G> {
|
||||
void accept(A a, B b, C c, D d, E e, F f, G g);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Consumer8<A, B, C, D, E, F, G, H>
|
||||
{
|
||||
public void accept(A a, B b, C c, D d, E e, F f, G g, H h);
|
||||
public interface Consumer8<A, B, C, D, E, F, G, H> {
|
||||
void accept(A a, B b, C c, D d, E e, F f, G g, H h);
|
||||
}
|
||||
|
||||
@@ -2,32 +2,26 @@ package com.volmit.iris.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Contained<T>
|
||||
{
|
||||
private T t;
|
||||
public class Contained<T> {
|
||||
private T t;
|
||||
|
||||
public Contained(T t)
|
||||
{
|
||||
set(t);
|
||||
}
|
||||
public Contained(T t) {
|
||||
set(t);
|
||||
}
|
||||
|
||||
public Contained()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
public void mod(Function<T, T> x)
|
||||
{
|
||||
set(x.apply(t));
|
||||
}
|
||||
public Contained() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public T get()
|
||||
{
|
||||
return t;
|
||||
}
|
||||
public void mod(Function<T, T> x) {
|
||||
set(x.apply(t));
|
||||
}
|
||||
|
||||
public void set(T t)
|
||||
{
|
||||
this.t = t;
|
||||
}
|
||||
public T get() {
|
||||
return t;
|
||||
}
|
||||
|
||||
public void set(T t) {
|
||||
this.t = t;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
public @interface Control
|
||||
{
|
||||
public @interface Control {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,69 +2,59 @@ package com.volmit.iris.util;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
public abstract class Controller implements IController
|
||||
{
|
||||
private int tickRate;
|
||||
private String name;
|
||||
public abstract class Controller implements IController {
|
||||
private int tickRate;
|
||||
private final String name;
|
||||
|
||||
public Controller()
|
||||
{
|
||||
name = getClass().getSimpleName().replaceAll("Controller", "") + " Controller";
|
||||
tickRate = -1;
|
||||
}
|
||||
public Controller() {
|
||||
name = getClass().getSimpleName().replaceAll("Controller", "") + " Controller";
|
||||
tickRate = -1;
|
||||
}
|
||||
|
||||
protected void setTickRate(int rate)
|
||||
{
|
||||
this.tickRate = rate;
|
||||
}
|
||||
protected void setTickRate(int rate) {
|
||||
this.tickRate = rate;
|
||||
}
|
||||
|
||||
protected void disableTicking()
|
||||
{
|
||||
setTickRate(-1);
|
||||
}
|
||||
protected void disableTicking() {
|
||||
setTickRate(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void l(Object l)
|
||||
{
|
||||
Iris.info("[" + getName() + "]: " + l);
|
||||
}
|
||||
@Override
|
||||
public void l(Object l) {
|
||||
Iris.info("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void w(Object l)
|
||||
{
|
||||
Iris.warn("[" + getName() + "]: " + l);
|
||||
}
|
||||
@Override
|
||||
public void w(Object l) {
|
||||
Iris.warn("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void f(Object l)
|
||||
{
|
||||
Iris.error("[" + getName() + "]: " + l);
|
||||
}
|
||||
@Override
|
||||
public void f(Object l) {
|
||||
Iris.error("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void v(Object l)
|
||||
{
|
||||
Iris.verbose("[" + getName() + "]: " + l);
|
||||
}
|
||||
@Override
|
||||
public void v(Object l) {
|
||||
Iris.verbose("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void start();
|
||||
@Override
|
||||
public abstract void start();
|
||||
|
||||
@Override
|
||||
public abstract void stop();
|
||||
@Override
|
||||
public abstract void stop();
|
||||
|
||||
@Override
|
||||
public abstract void tick();
|
||||
@Override
|
||||
public abstract void tick();
|
||||
|
||||
@Override
|
||||
public int getTickInterval()
|
||||
{
|
||||
return tickRate;
|
||||
}
|
||||
@Override
|
||||
public int getTickInterval() {
|
||||
return tickRate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package com.volmit.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface Converter
|
||||
{
|
||||
public String getInExtension();
|
||||
public interface Converter {
|
||||
String getInExtension();
|
||||
|
||||
public String getOutExtension();
|
||||
String getOutExtension();
|
||||
|
||||
public void convert(File in, File out);
|
||||
void convert(File in, File out);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,12 +5,10 @@ package com.volmit.iris.util;
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class CuboidException extends Exception
|
||||
{
|
||||
public CuboidException(String string)
|
||||
{
|
||||
super(string);
|
||||
}
|
||||
public class CuboidException extends Exception {
|
||||
public CuboidException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -4,11 +4,9 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class CustomOutputStream extends GZIPOutputStream
|
||||
{
|
||||
public CustomOutputStream(OutputStream out, int level) throws IOException
|
||||
{
|
||||
super(out);
|
||||
def.setLevel(level);
|
||||
}
|
||||
public class CustomOutputStream extends GZIPOutputStream {
|
||||
public CustomOutputStream(OutputStream out, int level) throws IOException {
|
||||
super(out);
|
||||
def.setLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,16 @@ package com.volmit.iris.util;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public abstract class DOP
|
||||
{
|
||||
private String type;
|
||||
|
||||
public DOP(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public abstract Vector op(Vector v);
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
public abstract class DOP {
|
||||
private final String type;
|
||||
|
||||
public DOP(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public abstract Vector op(Vector v);
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,122 +4,101 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class DataPalette<T> implements Writable
|
||||
{
|
||||
private static final int DEFAULT_BITS_PER_BLOCK = 4;
|
||||
private static final int CAPACITY = 4096;
|
||||
private int bpb;
|
||||
private NibbleArray data;
|
||||
private KList<T> palette;
|
||||
public abstract class DataPalette<T> implements Writable {
|
||||
private static final int DEFAULT_BITS_PER_BLOCK = 4;
|
||||
private static final int CAPACITY = 4096;
|
||||
private int bpb;
|
||||
private NibbleArray data;
|
||||
private KList<T> palette;
|
||||
|
||||
public DataPalette(T defaultValue)
|
||||
{
|
||||
palette = new KList<>();
|
||||
bpb = DEFAULT_BITS_PER_BLOCK;
|
||||
data = new NibbleArray(bpb, CAPACITY);
|
||||
data.setAll(Byte.MIN_VALUE);
|
||||
getPaletteId(defaultValue);
|
||||
}
|
||||
public DataPalette(T defaultValue) {
|
||||
palette = new KList<>();
|
||||
bpb = DEFAULT_BITS_PER_BLOCK;
|
||||
data = new NibbleArray(bpb, CAPACITY);
|
||||
data.setAll(Byte.MIN_VALUE);
|
||||
getPaletteId(defaultValue);
|
||||
}
|
||||
|
||||
public abstract T readType(DataInputStream i) throws IOException;
|
||||
public abstract T readType(DataInputStream i) throws IOException;
|
||||
|
||||
public abstract void writeType(T t, DataOutputStream o) throws IOException;
|
||||
public abstract void writeType(T t, DataOutputStream o) throws IOException;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream o) throws IOException
|
||||
{
|
||||
o.writeByte(bpb + Byte.MIN_VALUE);
|
||||
o.writeByte(palette.size() + Byte.MIN_VALUE);
|
||||
@Override
|
||||
public void write(DataOutputStream o) throws IOException {
|
||||
o.writeByte(bpb + Byte.MIN_VALUE);
|
||||
o.writeByte(palette.size() + Byte.MIN_VALUE);
|
||||
|
||||
for(T i : palette)
|
||||
{
|
||||
writeType(i, o);
|
||||
}
|
||||
for (T i : palette) {
|
||||
writeType(i, o);
|
||||
}
|
||||
|
||||
data.write(o);
|
||||
}
|
||||
data.write(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream i) throws IOException
|
||||
{
|
||||
bpb = i.readByte() - Byte.MIN_VALUE;
|
||||
palette = new KList<>();
|
||||
int v = i.readByte() - Byte.MIN_VALUE;
|
||||
@Override
|
||||
public void read(DataInputStream i) throws IOException {
|
||||
bpb = i.readByte() - Byte.MIN_VALUE;
|
||||
palette = new KList<>();
|
||||
int v = i.readByte() - Byte.MIN_VALUE;
|
||||
|
||||
for(int j = 0; j < v; j++)
|
||||
{
|
||||
palette.add(readType(i));
|
||||
}
|
||||
for (int j = 0; j < v; j++) {
|
||||
palette.add(readType(i));
|
||||
}
|
||||
|
||||
data = new NibbleArray(CAPACITY, i);
|
||||
}
|
||||
data = new NibbleArray(CAPACITY, i);
|
||||
}
|
||||
|
||||
private final void expand()
|
||||
{
|
||||
if(bpb < 8)
|
||||
{
|
||||
changeBitsPerBlock(bpb + 1);
|
||||
}
|
||||
private final void expand() {
|
||||
if (bpb < 8) {
|
||||
changeBitsPerBlock(bpb + 1);
|
||||
} else {
|
||||
throw new IndexOutOfBoundsException("The Data Palette can only handle at most 256 block types per 16x16x16 region. We cannot use more than 8 bits per block!");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new IndexOutOfBoundsException("The Data Palette can only handle at most 256 block types per 16x16x16 region. We cannot use more than 8 bits per block!");
|
||||
}
|
||||
}
|
||||
public final void optimize() {
|
||||
int targetBits = bpb;
|
||||
int needed = palette.size();
|
||||
|
||||
public final void optimize()
|
||||
{
|
||||
int targetBits = bpb;
|
||||
int needed = palette.size();
|
||||
for (int i = 1; i < bpb; i++) {
|
||||
if (Math.pow(2, i) > needed) {
|
||||
targetBits = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 1; i < bpb; i++)
|
||||
{
|
||||
if(Math.pow(2, i) > needed)
|
||||
{
|
||||
targetBits = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
changeBitsPerBlock(targetBits);
|
||||
}
|
||||
|
||||
changeBitsPerBlock(targetBits);
|
||||
}
|
||||
private final void changeBitsPerBlock(int bits) {
|
||||
bpb = bits;
|
||||
data = new NibbleArray(bpb, CAPACITY, data);
|
||||
}
|
||||
|
||||
private final void changeBitsPerBlock(int bits)
|
||||
{
|
||||
bpb = bits;
|
||||
data = new NibbleArray(bpb, CAPACITY, data);
|
||||
}
|
||||
public final void set(int x, int y, int z, T d) {
|
||||
data.set(getCoordinateIndex(x, y, z), getPaletteId(d));
|
||||
}
|
||||
|
||||
public final void set(int x, int y, int z, T d)
|
||||
{
|
||||
data.set(getCoordinateIndex(x, y, z), getPaletteId(d));
|
||||
}
|
||||
public final T get(int x, int y, int z) {
|
||||
return palette.get(data.get(getCoordinateIndex(x, y, z)));
|
||||
}
|
||||
|
||||
public final T get(int x, int y, int z)
|
||||
{
|
||||
return palette.get(data.get(getCoordinateIndex(x, y, z)));
|
||||
}
|
||||
private final int getPaletteId(T d) {
|
||||
int index = palette.indexOf(d);
|
||||
|
||||
private final int getPaletteId(T d)
|
||||
{
|
||||
int index = palette.indexOf(d);
|
||||
if (index == -1) {
|
||||
index = palette.size();
|
||||
palette.add(d);
|
||||
|
||||
if(index == -1)
|
||||
{
|
||||
index = palette.size();
|
||||
palette.add(d);
|
||||
if (palette.size() > Math.pow(2, bpb)) {
|
||||
expand();
|
||||
}
|
||||
}
|
||||
|
||||
if(palette.size() > Math.pow(2, bpb))
|
||||
{
|
||||
expand();
|
||||
}
|
||||
}
|
||||
return index + Byte.MIN_VALUE;
|
||||
}
|
||||
|
||||
return index + Byte.MIN_VALUE;
|
||||
}
|
||||
|
||||
private final int getCoordinateIndex(int x, int y, int z)
|
||||
{
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
private final int getCoordinateIndex(int x, int y, int z) {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public class Denv
|
||||
{
|
||||
|
||||
public class Denv {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({ FIELD })
|
||||
@Target({FIELD})
|
||||
public @interface DependsOn {
|
||||
String[] value();
|
||||
String[] value();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({PARAMETER, TYPE, FIELD})
|
||||
public @interface Desc
|
||||
{
|
||||
String value();
|
||||
public @interface Desc {
|
||||
String value();
|
||||
}
|
||||
|
||||
@@ -5,82 +5,67 @@ package com.volmit.iris.util;
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class Dimension
|
||||
{
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int depth;
|
||||
public class Dimension {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int depth;
|
||||
|
||||
/**
|
||||
* Make a dimension
|
||||
*
|
||||
* @param width
|
||||
* width of this (X)
|
||||
* @param height
|
||||
* the height (Y)
|
||||
* @param depth
|
||||
* the depth (Z)
|
||||
*/
|
||||
public Dimension(int width, int height, int depth)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = depth;
|
||||
}
|
||||
/**
|
||||
* Make a dimension
|
||||
*
|
||||
* @param width width of this (X)
|
||||
* @param height the height (Y)
|
||||
* @param depth the depth (Z)
|
||||
*/
|
||||
public Dimension(int width, int height, int depth) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a dimension
|
||||
*
|
||||
* @param width
|
||||
* width of this (X)
|
||||
* @param height
|
||||
* the height (Y)
|
||||
*/
|
||||
public Dimension(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = 0;
|
||||
}
|
||||
/**
|
||||
* Make a dimension
|
||||
*
|
||||
* @param width width of this (X)
|
||||
* @param height the height (Y)
|
||||
*/
|
||||
public Dimension(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direction of the flat part of this dimension (null if no thin
|
||||
* face)
|
||||
*
|
||||
* @return the direction of the flat pane or null
|
||||
*/
|
||||
public DimensionFace getPane()
|
||||
{
|
||||
if(width == 1)
|
||||
{
|
||||
return DimensionFace.X;
|
||||
}
|
||||
/**
|
||||
* Get the direction of the flat part of this dimension (null if no thin
|
||||
* face)
|
||||
*
|
||||
* @return the direction of the flat pane or null
|
||||
*/
|
||||
public DimensionFace getPane() {
|
||||
if (width == 1) {
|
||||
return DimensionFace.X;
|
||||
}
|
||||
|
||||
if(height == 1)
|
||||
{
|
||||
return DimensionFace.Y;
|
||||
}
|
||||
if (height == 1) {
|
||||
return DimensionFace.Y;
|
||||
}
|
||||
|
||||
if(depth == 1)
|
||||
{
|
||||
return DimensionFace.Z;
|
||||
}
|
||||
if (depth == 1) {
|
||||
return DimensionFace.Z;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getDepth()
|
||||
{
|
||||
return depth;
|
||||
}
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
}
|
||||
@@ -5,20 +5,19 @@ package com.volmit.iris.util;
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public enum DimensionFace
|
||||
{
|
||||
/**
|
||||
* The X dimension (width)
|
||||
*/
|
||||
X,
|
||||
public enum DimensionFace {
|
||||
/**
|
||||
* The X dimension (width)
|
||||
*/
|
||||
X,
|
||||
|
||||
/**
|
||||
* The Y dimension (height)
|
||||
*/
|
||||
Y,
|
||||
/**
|
||||
* The Y dimension (height)
|
||||
*/
|
||||
Y,
|
||||
|
||||
/**
|
||||
* The Z dimension (depth)
|
||||
*/
|
||||
Z
|
||||
/**
|
||||
* The Z dimension (depth)
|
||||
*/
|
||||
Z
|
||||
}
|
||||
@@ -1,533 +1,415 @@
|
||||
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import com.volmit.iris.util.Cuboid.CuboidDirection;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.volmit.iris.util.Cuboid.CuboidDirection;
|
||||
|
||||
/**
|
||||
* Directions
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public enum Direction
|
||||
{
|
||||
U(0, 1, 0, CuboidDirection.Up),
|
||||
D(0, -1, 0, CuboidDirection.Down),
|
||||
N(0, 0, -1, CuboidDirection.North),
|
||||
S(0, 0, 1, CuboidDirection.South),
|
||||
E(1, 0, 0, CuboidDirection.East),
|
||||
W(-1, 0, 0, CuboidDirection.West);
|
||||
public enum Direction {
|
||||
U(0, 1, 0, CuboidDirection.Up),
|
||||
D(0, -1, 0, CuboidDirection.Down),
|
||||
N(0, 0, -1, CuboidDirection.North),
|
||||
S(0, 0, 1, CuboidDirection.South),
|
||||
E(1, 0, 0, CuboidDirection.East),
|
||||
W(-1, 0, 0, CuboidDirection.West);
|
||||
|
||||
private static KMap<GBiset<Direction, Direction>, DOP> permute = null;
|
||||
private static KMap<GBiset<Direction, Direction>, DOP> permute = null;
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private CuboidDirection f;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final CuboidDirection f;
|
||||
|
||||
public static Direction getDirection(BlockFace f)
|
||||
{
|
||||
switch(f)
|
||||
{
|
||||
case DOWN:
|
||||
return D;
|
||||
case EAST:
|
||||
return E;
|
||||
case EAST_NORTH_EAST:
|
||||
return E;
|
||||
case EAST_SOUTH_EAST:
|
||||
return E;
|
||||
case NORTH:
|
||||
return N;
|
||||
case NORTH_EAST:
|
||||
return N;
|
||||
case NORTH_NORTH_EAST:
|
||||
return N;
|
||||
case NORTH_NORTH_WEST:
|
||||
return N;
|
||||
case NORTH_WEST:
|
||||
return N;
|
||||
case SELF:
|
||||
return U;
|
||||
case SOUTH:
|
||||
return S;
|
||||
case SOUTH_EAST:
|
||||
return S;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return S;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return S;
|
||||
case SOUTH_WEST:
|
||||
return S;
|
||||
case UP:
|
||||
return U;
|
||||
case WEST:
|
||||
return W;
|
||||
case WEST_NORTH_WEST:
|
||||
return W;
|
||||
case WEST_SOUTH_WEST:
|
||||
return W;
|
||||
}
|
||||
public static Direction getDirection(BlockFace f) {
|
||||
switch (f) {
|
||||
case DOWN:
|
||||
return D;
|
||||
case EAST:
|
||||
return E;
|
||||
case EAST_NORTH_EAST:
|
||||
return E;
|
||||
case EAST_SOUTH_EAST:
|
||||
return E;
|
||||
case NORTH:
|
||||
return N;
|
||||
case NORTH_EAST:
|
||||
return N;
|
||||
case NORTH_NORTH_EAST:
|
||||
return N;
|
||||
case NORTH_NORTH_WEST:
|
||||
return N;
|
||||
case NORTH_WEST:
|
||||
return N;
|
||||
case SELF:
|
||||
return U;
|
||||
case SOUTH:
|
||||
return S;
|
||||
case SOUTH_EAST:
|
||||
return S;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return S;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return S;
|
||||
case SOUTH_WEST:
|
||||
return S;
|
||||
case UP:
|
||||
return U;
|
||||
case WEST:
|
||||
return W;
|
||||
case WEST_NORTH_WEST:
|
||||
return W;
|
||||
case WEST_SOUTH_WEST:
|
||||
return W;
|
||||
}
|
||||
|
||||
return D;
|
||||
}
|
||||
return D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return "Down";
|
||||
case E:
|
||||
return "East";
|
||||
case N:
|
||||
return "North";
|
||||
case S:
|
||||
return "South";
|
||||
case U:
|
||||
return "Up";
|
||||
case W:
|
||||
return "West";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return "Down";
|
||||
case E:
|
||||
return "East";
|
||||
case N:
|
||||
return "North";
|
||||
case S:
|
||||
return "South";
|
||||
case U:
|
||||
return "Up";
|
||||
case W:
|
||||
return "West";
|
||||
}
|
||||
|
||||
return "?";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
public boolean isVertical()
|
||||
{
|
||||
return equals(D) || equals(U);
|
||||
}
|
||||
public boolean isVertical() {
|
||||
return equals(D) || equals(U);
|
||||
}
|
||||
|
||||
public static Direction closest(Vector v)
|
||||
{
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
public static Direction closest(Vector v) {
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
|
||||
for(Direction i : values())
|
||||
{
|
||||
Vector x = i.toVector();
|
||||
double g = x.dot(v);
|
||||
for (Direction i : values()) {
|
||||
Vector x = i.toVector();
|
||||
double g = x.dot(v);
|
||||
|
||||
if(g < m)
|
||||
{
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
if (g < m) {
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Direction closest(Vector v, Direction... d)
|
||||
{
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
public static Direction closest(Vector v, Direction... d) {
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
|
||||
for(Direction i : d)
|
||||
{
|
||||
Vector x = i.toVector();
|
||||
double g = x.distance(v);
|
||||
for (Direction i : d) {
|
||||
Vector x = i.toVector();
|
||||
double g = x.distance(v);
|
||||
|
||||
if(g < m)
|
||||
{
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
if (g < m) {
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Direction closest(Vector v, KList<Direction> d)
|
||||
{
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
public static Direction closest(Vector v, KList<Direction> d) {
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
|
||||
for(Direction i : d)
|
||||
{
|
||||
Vector x = i.toVector();
|
||||
double g = x.distance(v);
|
||||
for (Direction i : d) {
|
||||
Vector x = i.toVector();
|
||||
double g = x.distance(v);
|
||||
|
||||
if(g < m)
|
||||
{
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
if (g < m) {
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public Vector toVector()
|
||||
{
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
public Vector toVector() {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public boolean isCrooked(Direction to)
|
||||
{
|
||||
if(equals(to.reverse()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public boolean isCrooked(Direction to) {
|
||||
if (equals(to.reverse())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(equals(to))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return !equals(to);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Direction(int x, int y, int z, CuboidDirection f) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
private Direction(int x, int y, int z, CuboidDirection f)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.f = f;
|
||||
}
|
||||
public Vector angle(Vector initial, Direction d) {
|
||||
calculatePermutations();
|
||||
|
||||
public Vector angle(Vector initial, Direction d)
|
||||
{
|
||||
calculatePermutations();
|
||||
for (GBiset<Direction, Direction> i : permute.keySet()) {
|
||||
if (i.getA().equals(this) && i.getB().equals(d)) {
|
||||
return permute.get(i).op(initial);
|
||||
}
|
||||
}
|
||||
|
||||
for(GBiset<Direction, Direction> i : permute.keySet())
|
||||
{
|
||||
if(i.getA().equals(this) && i.getB().equals(d))
|
||||
{
|
||||
return permute.get(i).op(initial);
|
||||
}
|
||||
}
|
||||
return initial;
|
||||
}
|
||||
|
||||
return initial;
|
||||
}
|
||||
public Direction reverse() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return U;
|
||||
case E:
|
||||
return W;
|
||||
case N:
|
||||
return S;
|
||||
case S:
|
||||
return N;
|
||||
case U:
|
||||
return D;
|
||||
case W:
|
||||
return E;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
public Direction reverse()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return U;
|
||||
case E:
|
||||
return W;
|
||||
case N:
|
||||
return S;
|
||||
case S:
|
||||
return N;
|
||||
case U:
|
||||
return D;
|
||||
case W:
|
||||
return E;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public int x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int x()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
public int y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int y()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
public int z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public int z()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
public CuboidDirection f() {
|
||||
return f;
|
||||
}
|
||||
|
||||
public CuboidDirection f()
|
||||
{
|
||||
return f;
|
||||
}
|
||||
public static KList<Direction> news() {
|
||||
return new KList<Direction>().add(N, E, W, S);
|
||||
}
|
||||
|
||||
public static KList<Direction> news()
|
||||
{
|
||||
return new KList<Direction>().add(N, E, W, S);
|
||||
}
|
||||
public static Direction getDirection(Vector v) {
|
||||
Vector k = VectorMath.triNormalize(v.clone().normalize());
|
||||
|
||||
public static Direction getDirection(Vector v)
|
||||
{
|
||||
Vector k = VectorMath.triNormalize(v.clone().normalize());
|
||||
for (Direction i : udnews()) {
|
||||
if (i.x == k.getBlockX() && i.y == k.getBlockY() && i.z == k.getBlockZ()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for(Direction i : udnews())
|
||||
{
|
||||
if(i.x == k.getBlockX() && i.y == k.getBlockY() && i.z == k.getBlockZ())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return Direction.N;
|
||||
}
|
||||
|
||||
return Direction.N;
|
||||
}
|
||||
public static KList<Direction> udnews() {
|
||||
return new KList<Direction>().add(U, D, N, E, W, S);
|
||||
}
|
||||
|
||||
public static KList<Direction> udnews()
|
||||
{
|
||||
return new KList<Direction>().add(U, D, N, E, W, S);
|
||||
}
|
||||
/**
|
||||
* Get the directional value from the given byte from common directional blocks
|
||||
* (MUST BE BETWEEN 0 and 5 INCLUSIVE)
|
||||
*
|
||||
* @param b the byte
|
||||
* @return the direction or null if the byte is outside of the inclusive range
|
||||
* 0-5
|
||||
*/
|
||||
public static Direction fromByte(byte b) {
|
||||
if (b > 5 || b < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directional value from the given byte from common directional blocks
|
||||
* (MUST BE BETWEEN 0 and 5 INCLUSIVE)
|
||||
*
|
||||
* @param b
|
||||
* the byte
|
||||
* @return the direction or null if the byte is outside of the inclusive range
|
||||
* 0-5
|
||||
*/
|
||||
public static Direction fromByte(byte b)
|
||||
{
|
||||
if(b > 5 || b < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (b == 0) {
|
||||
return D;
|
||||
} else if (b == 1) {
|
||||
return U;
|
||||
} else if (b == 2) {
|
||||
return N;
|
||||
} else if (b == 3) {
|
||||
return S;
|
||||
} else if (b == 4) {
|
||||
return W;
|
||||
} else {
|
||||
return E;
|
||||
}
|
||||
}
|
||||
|
||||
if(b == 0)
|
||||
{
|
||||
return D;
|
||||
}
|
||||
/**
|
||||
* Get the byte value represented in some directional blocks
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return 0;
|
||||
case E:
|
||||
return 5;
|
||||
case N:
|
||||
return 2;
|
||||
case S:
|
||||
return 3;
|
||||
case U:
|
||||
return 1;
|
||||
case W:
|
||||
return 4;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
else if(b == 1)
|
||||
{
|
||||
return U;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
else if(b == 2)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
public static void calculatePermutations() {
|
||||
if (permute != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
else if(b == 3)
|
||||
{
|
||||
return S;
|
||||
}
|
||||
permute = new KMap<GBiset<Direction, Direction>, DOP>();
|
||||
|
||||
else if(b == 4)
|
||||
{
|
||||
return W;
|
||||
}
|
||||
for (Direction i : udnews()) {
|
||||
for (Direction j : udnews()) {
|
||||
GBiset<Direction, Direction> b = new GBiset<Direction, Direction>(i, j);
|
||||
|
||||
else
|
||||
{
|
||||
return E;
|
||||
}
|
||||
}
|
||||
if (i.equals(j)) {
|
||||
permute.put(b, new DOP("DIRECT") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return v;
|
||||
}
|
||||
});
|
||||
} else if (i.reverse().equals(j)) {
|
||||
if (i.isVertical()) {
|
||||
permute.put(b, new DOP("R180CCZ") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CCZ(VectorMath.rotate90CCZ(v));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
permute.put(b, new DOP("R180CCY") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CCY(VectorMath.rotate90CCY(v));
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (getDirection(VectorMath.rotate90CX(i.toVector())).equals(j)) {
|
||||
permute.put(b, new DOP("R90CX") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CX(v);
|
||||
}
|
||||
});
|
||||
} else if (getDirection(VectorMath.rotate90CCX(i.toVector())).equals(j)) {
|
||||
permute.put(b, new DOP("R90CCX") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CCX(v);
|
||||
}
|
||||
});
|
||||
} else if (getDirection(VectorMath.rotate90CY(i.toVector())).equals(j)) {
|
||||
permute.put(b, new DOP("R90CY") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CY(v);
|
||||
}
|
||||
});
|
||||
} else if (getDirection(VectorMath.rotate90CCY(i.toVector())).equals(j)) {
|
||||
permute.put(b, new DOP("R90CCY") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CCY(v);
|
||||
}
|
||||
});
|
||||
} else if (getDirection(VectorMath.rotate90CZ(i.toVector())).equals(j)) {
|
||||
permute.put(b, new DOP("R90CZ") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CZ(v);
|
||||
}
|
||||
});
|
||||
} else if (getDirection(VectorMath.rotate90CCZ(i.toVector())).equals(j)) {
|
||||
permute.put(b, new DOP("R90CCZ") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return VectorMath.rotate90CCZ(v);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
permute.put(b, new DOP("FAIL") {
|
||||
@Override
|
||||
public Vector op(Vector v) {
|
||||
return v;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the byte value represented in some directional blocks
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return 0;
|
||||
case E:
|
||||
return 5;
|
||||
case N:
|
||||
return 2;
|
||||
case S:
|
||||
return 3;
|
||||
case U:
|
||||
return 1;
|
||||
case W:
|
||||
return 4;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
public BlockFace getFace() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return BlockFace.DOWN;
|
||||
case E:
|
||||
return BlockFace.EAST;
|
||||
case N:
|
||||
return BlockFace.NORTH;
|
||||
case S:
|
||||
return BlockFace.SOUTH;
|
||||
case U:
|
||||
return BlockFace.UP;
|
||||
case W:
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void calculatePermutations()
|
||||
{
|
||||
if(permute != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public Axis getAxis() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return Axis.Y;
|
||||
case E:
|
||||
return Axis.X;
|
||||
case N:
|
||||
return Axis.Z;
|
||||
case S:
|
||||
return Axis.Z;
|
||||
case U:
|
||||
return Axis.Y;
|
||||
case W:
|
||||
return Axis.X;
|
||||
}
|
||||
|
||||
permute = new KMap<GBiset<Direction, Direction>, DOP>();
|
||||
|
||||
for(Direction i : udnews())
|
||||
{
|
||||
for(Direction j : udnews())
|
||||
{
|
||||
GBiset<Direction, Direction> b = new GBiset<Direction, Direction>(i, j);
|
||||
|
||||
if(i.equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("DIRECT")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(i.reverse().equals(j))
|
||||
{
|
||||
if(i.isVertical())
|
||||
{
|
||||
permute.put(b, new DOP("R180CCZ")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCZ(VectorMath.rotate90CCZ(v));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
permute.put(b, new DOP("R180CCY")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCY(VectorMath.rotate90CCY(v));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CX(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CX")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CX(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CCX(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CCX")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCX(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CY(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CY")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CY(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CCY(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CCY")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCY(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CZ(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CZ")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CZ(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CCZ(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CCZ")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCZ(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
permute.put(b, new DOP("FAIL")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockFace getFace()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return BlockFace.DOWN;
|
||||
case E:
|
||||
return BlockFace.EAST;
|
||||
case N:
|
||||
return BlockFace.NORTH;
|
||||
case S:
|
||||
return BlockFace.SOUTH;
|
||||
case U:
|
||||
return BlockFace.UP;
|
||||
case W:
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Axis getAxis()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return Axis.Y;
|
||||
case E:
|
||||
return Axis.X;
|
||||
case N:
|
||||
return Axis.Z;
|
||||
case S:
|
||||
return Axis.Z;
|
||||
case U:
|
||||
return Axis.Y;
|
||||
case W:
|
||||
return Axis.X;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({FIELD, TYPE, CONSTRUCTOR, METHOD})
|
||||
public @interface DontObfuscate
|
||||
{
|
||||
public @interface DontObfuscate {
|
||||
|
||||
}
|
||||
|
||||
@@ -5,35 +5,28 @@ import com.google.common.util.concurrent.AtomicDoubleArray;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DoubleArrayUtils
|
||||
{
|
||||
public static void shiftRight(double[] values, double push)
|
||||
{
|
||||
for(int index = values.length - 2; index >= 0; index--)
|
||||
{
|
||||
values[index + 1] = values[index];
|
||||
}
|
||||
public class DoubleArrayUtils {
|
||||
public static void shiftRight(double[] values, double push) {
|
||||
for (int index = values.length - 2; index >= 0; index--) {
|
||||
values[index + 1] = values[index];
|
||||
}
|
||||
|
||||
values[0] = push;
|
||||
}
|
||||
values[0] = push;
|
||||
}
|
||||
|
||||
public static void wrapRight(double[] values)
|
||||
{
|
||||
double last = values[values.length - 1];
|
||||
shiftRight(values, last);
|
||||
}
|
||||
public static void wrapRight(double[] values) {
|
||||
double last = values[values.length - 1];
|
||||
shiftRight(values, last);
|
||||
}
|
||||
|
||||
public static void fill(double[] values, double value)
|
||||
{
|
||||
Arrays.fill(values, value);
|
||||
}
|
||||
public static void fill(double[] values, double value) {
|
||||
Arrays.fill(values, value);
|
||||
}
|
||||
|
||||
public static void fill(AtomicDoubleArray values, double value)
|
||||
{
|
||||
for(int i = 0; i < values.length(); i++)
|
||||
{
|
||||
values.set(i, value);
|
||||
}
|
||||
}
|
||||
public static void fill(AtomicDoubleArray values, double value) {
|
||||
for (int i = 0; i < values.length(); i++) {
|
||||
values.set(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,24 +2,24 @@ package com.volmit.iris.util;
|
||||
|
||||
/*
|
||||
* JNBT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2010 Graham Edgecombe
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the JNBT team nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -30,13 +30,13 @@ package com.volmit.iris.util;
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>TAG_Double</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
*/
|
||||
public final class DoubleTag extends Tag {
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class DoubleTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name The name.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
*/
|
||||
public DoubleTag(String name, double value) {
|
||||
|
||||
@@ -2,53 +2,52 @@ package com.volmit.iris.util;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Element
|
||||
{
|
||||
public MaterialBlock getMaterial();
|
||||
public interface Element {
|
||||
MaterialBlock getMaterial();
|
||||
|
||||
public Element setMaterial(MaterialBlock b);
|
||||
Element setMaterial(MaterialBlock b);
|
||||
|
||||
public boolean isEnchanted();
|
||||
boolean isEnchanted();
|
||||
|
||||
public Element setEnchanted(boolean enchanted);
|
||||
Element setEnchanted(boolean enchanted);
|
||||
|
||||
public String getId();
|
||||
String getId();
|
||||
|
||||
public String getName();
|
||||
String getName();
|
||||
|
||||
public Element setProgress(double progress);
|
||||
Element setProgress(double progress);
|
||||
|
||||
public double getProgress();
|
||||
double getProgress();
|
||||
|
||||
public short getEffectiveDurability();
|
||||
short getEffectiveDurability();
|
||||
|
||||
public Element setCount(int c);
|
||||
Element setCount(int c);
|
||||
|
||||
public int getCount();
|
||||
int getCount();
|
||||
|
||||
public ItemStack computeItemStack();
|
||||
ItemStack computeItemStack();
|
||||
|
||||
public Element setBackground(boolean bg);
|
||||
Element setBackground(boolean bg);
|
||||
|
||||
public boolean isBackgrond();
|
||||
boolean isBackgrond();
|
||||
|
||||
public Element setName(String name);
|
||||
Element setName(String name);
|
||||
|
||||
public Element addLore(String loreLine);
|
||||
Element addLore(String loreLine);
|
||||
|
||||
public KList<String> getLore();
|
||||
KList<String> getLore();
|
||||
|
||||
public Element call(ElementEvent event, Element context);
|
||||
Element call(ElementEvent event, Element context);
|
||||
|
||||
public Element onLeftClick(Callback<Element> clicked);
|
||||
Element onLeftClick(Callback<Element> clicked);
|
||||
|
||||
public Element onRightClick(Callback<Element> clicked);
|
||||
Element onRightClick(Callback<Element> clicked);
|
||||
|
||||
public Element onShiftLeftClick(Callback<Element> clicked);
|
||||
Element onShiftLeftClick(Callback<Element> clicked);
|
||||
|
||||
public Element onShiftRightClick(Callback<Element> clicked);
|
||||
Element onShiftRightClick(Callback<Element> clicked);
|
||||
|
||||
public Element onDraggedInto(Callback<Element> into);
|
||||
Element onDraggedInto(Callback<Element> into);
|
||||
|
||||
public Element onOtherDraggedInto(Callback<Element> other);
|
||||
Element onOtherDraggedInto(Callback<Element> other);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ package com.volmit.iris.util;
|
||||
* Element Event.
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public enum ElementEvent
|
||||
{
|
||||
LEFT,
|
||||
RIGHT,
|
||||
SHIFT_LEFT,
|
||||
SHIFT_RIGHT,
|
||||
DRAG_INTO,
|
||||
OTHER_DRAG_INTO;
|
||||
public enum ElementEvent {
|
||||
LEFT,
|
||||
RIGHT,
|
||||
SHIFT_LEFT,
|
||||
SHIFT_RIGHT,
|
||||
DRAG_INTO,
|
||||
OTHER_DRAG_INTO
|
||||
}
|
||||
|
||||
@@ -2,24 +2,24 @@ package com.volmit.iris.util;
|
||||
|
||||
/*
|
||||
* JNBT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2010 Graham Edgecombe
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the JNBT team nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -30,13 +30,13 @@ package com.volmit.iris.util;
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>TAG_End</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
*/
|
||||
public final class EndTag extends Tag {
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,38 +2,33 @@ package com.volmit.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileWatcher
|
||||
{
|
||||
protected final File file;
|
||||
private boolean exists;
|
||||
private long lastModified;
|
||||
private long size;
|
||||
public class FileWatcher {
|
||||
protected final File file;
|
||||
private boolean exists;
|
||||
private long lastModified;
|
||||
private long size;
|
||||
|
||||
public FileWatcher(File file)
|
||||
{
|
||||
this.file = file;
|
||||
readProperties();
|
||||
}
|
||||
public FileWatcher(File file) {
|
||||
this.file = file;
|
||||
readProperties();
|
||||
}
|
||||
|
||||
protected void readProperties()
|
||||
{
|
||||
exists = file.exists();
|
||||
lastModified = exists ? file.lastModified() : -1;
|
||||
size = exists ? file.isDirectory() ? -2 : file.length() : -1;
|
||||
}
|
||||
protected void readProperties() {
|
||||
exists = file.exists();
|
||||
lastModified = exists ? file.lastModified() : -1;
|
||||
size = exists ? file.isDirectory() ? -2 : file.length() : -1;
|
||||
}
|
||||
|
||||
public boolean checkModified()
|
||||
{
|
||||
long m = lastModified;
|
||||
long g = size;
|
||||
boolean mod = false;
|
||||
readProperties();
|
||||
public boolean checkModified() {
|
||||
long m = lastModified;
|
||||
long g = size;
|
||||
boolean mod = false;
|
||||
readProperties();
|
||||
|
||||
if(lastModified != m || g != size)
|
||||
{
|
||||
mod = true;
|
||||
}
|
||||
if (lastModified != m || g != size) {
|
||||
mod = true;
|
||||
}
|
||||
|
||||
return mod;
|
||||
}
|
||||
return mod;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,32 +5,26 @@ package com.volmit.iris.util;
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class FinalInteger extends Wrapper<Integer>
|
||||
{
|
||||
public FinalInteger(Integer t)
|
||||
{
|
||||
super(t);
|
||||
}
|
||||
public class FinalInteger extends Wrapper<Integer> {
|
||||
public FinalInteger(Integer t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to this value
|
||||
*
|
||||
* @param i
|
||||
* the number to add to this value (value = value + i)
|
||||
*/
|
||||
public void add(int i)
|
||||
{
|
||||
set(get() + i);
|
||||
}
|
||||
/**
|
||||
* Add to this value
|
||||
*
|
||||
* @param i the number to add to this value (value = value + i)
|
||||
*/
|
||||
public void add(int i) {
|
||||
set(get() + i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract from this value
|
||||
*
|
||||
* @param i
|
||||
* the number to subtract from this value (value = value - i)
|
||||
*/
|
||||
public void sub(int i)
|
||||
{
|
||||
set(get() - i);
|
||||
}
|
||||
/**
|
||||
* Subtract from this value
|
||||
*
|
||||
* @param i the number to subtract from this value (value = value - i)
|
||||
*/
|
||||
public void sub(int i) {
|
||||
set(get() - i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,24 +2,24 @@ package com.volmit.iris.util;
|
||||
|
||||
/*
|
||||
* JNBT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2010 Graham Edgecombe
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the JNBT team nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -30,13 +30,13 @@ package com.volmit.iris.util;
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>TAG_Float</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
*/
|
||||
public final class FloatTag extends Tag {
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class FloatTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name The name.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
*/
|
||||
public FloatTag(String name, float value) {
|
||||
|
||||
@@ -2,121 +2,94 @@ package com.volmit.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FolderWatcher extends FileWatcher
|
||||
{
|
||||
private KMap<File, FolderWatcher> watchers;
|
||||
private KList<File> changed;
|
||||
private KList<File> created;
|
||||
private KList<File> deleted;
|
||||
public class FolderWatcher extends FileWatcher {
|
||||
private KMap<File, FolderWatcher> watchers;
|
||||
private KList<File> changed;
|
||||
private KList<File> created;
|
||||
private KList<File> deleted;
|
||||
|
||||
public FolderWatcher(File file)
|
||||
{
|
||||
super(file);
|
||||
}
|
||||
public FolderWatcher(File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
protected void readProperties()
|
||||
{
|
||||
if(watchers == null)
|
||||
{
|
||||
watchers = new KMap<>();
|
||||
changed = new KList<>();
|
||||
created = new KList<>();
|
||||
deleted = new KList<>();
|
||||
}
|
||||
protected void readProperties() {
|
||||
if (watchers == null) {
|
||||
watchers = new KMap<>();
|
||||
changed = new KList<>();
|
||||
created = new KList<>();
|
||||
deleted = new KList<>();
|
||||
}
|
||||
|
||||
if(file.isDirectory())
|
||||
{
|
||||
for(File i : file.listFiles())
|
||||
{
|
||||
if(!watchers.containsKey(i))
|
||||
{
|
||||
watchers.put(i, new FolderWatcher(i));
|
||||
}
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
for (File i : file.listFiles()) {
|
||||
if (!watchers.containsKey(i)) {
|
||||
watchers.put(i, new FolderWatcher(i));
|
||||
}
|
||||
}
|
||||
|
||||
if(watchers == null)
|
||||
{
|
||||
System.out.print("wtf");
|
||||
}
|
||||
if (watchers == null) {
|
||||
System.out.print("wtf");
|
||||
}
|
||||
|
||||
for(File i : watchers.k())
|
||||
{
|
||||
if(!i.exists())
|
||||
{
|
||||
watchers.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (File i : watchers.k()) {
|
||||
if (!i.exists()) {
|
||||
watchers.remove(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.readProperties();
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
super.readProperties();
|
||||
}
|
||||
}
|
||||
public boolean checkModified() {
|
||||
changed.clear();
|
||||
created.clear();
|
||||
deleted.clear();
|
||||
|
||||
public boolean checkModified()
|
||||
{
|
||||
changed.clear();
|
||||
created.clear();
|
||||
deleted.clear();
|
||||
if (file.isDirectory()) {
|
||||
KMap<File, FolderWatcher> w = watchers.copy();
|
||||
readProperties();
|
||||
|
||||
if(file.isDirectory())
|
||||
{
|
||||
KMap<File, FolderWatcher> w = watchers.copy();
|
||||
readProperties();
|
||||
for (File i : w.k()) {
|
||||
if (!watchers.containsKey(i)) {
|
||||
deleted.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
for(File i : w.k())
|
||||
{
|
||||
if(!watchers.containsKey(i))
|
||||
{
|
||||
deleted.add(i);
|
||||
}
|
||||
}
|
||||
for (File i : watchers.k()) {
|
||||
if (!w.containsKey(i)) {
|
||||
created.add(i);
|
||||
} else {
|
||||
FolderWatcher fw = watchers.get(i);
|
||||
if (fw.checkModified()) {
|
||||
changed.add(fw.file);
|
||||
}
|
||||
|
||||
for(File i : watchers.k())
|
||||
{
|
||||
if(!w.containsKey(i))
|
||||
{
|
||||
created.add(i);
|
||||
}
|
||||
changed.addAll(fw.getChanged());
|
||||
created.addAll(fw.getCreated());
|
||||
deleted.addAll(fw.getDeleted());
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
FolderWatcher fw = watchers.get(i);
|
||||
if(fw.checkModified())
|
||||
{
|
||||
changed.add(fw.file);
|
||||
}
|
||||
return !changed.isEmpty() || !created.isEmpty() || !deleted.isEmpty();
|
||||
}
|
||||
|
||||
changed.addAll(fw.getChanged());
|
||||
created.addAll(fw.getCreated());
|
||||
deleted.addAll(fw.getDeleted());
|
||||
}
|
||||
}
|
||||
return super.checkModified();
|
||||
}
|
||||
|
||||
return !changed.isEmpty() || !created.isEmpty() || !deleted.isEmpty();
|
||||
}
|
||||
public KMap<File, FolderWatcher> getWatchers() {
|
||||
return watchers;
|
||||
}
|
||||
|
||||
return super.checkModified();
|
||||
}
|
||||
public KList<File> getChanged() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public KMap<File, FolderWatcher> getWatchers()
|
||||
{
|
||||
return watchers;
|
||||
}
|
||||
public KList<File> getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public KList<File> getChanged()
|
||||
{
|
||||
return changed;
|
||||
}
|
||||
|
||||
public KList<File> getCreated()
|
||||
{
|
||||
return created;
|
||||
}
|
||||
|
||||
public KList<File> getDeleted()
|
||||
{
|
||||
return deleted;
|
||||
}
|
||||
public KList<File> getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Function2<A, B, R>
|
||||
{
|
||||
public R apply(A a, B b);
|
||||
public interface Function2<A, B, R> {
|
||||
R apply(A a, B b);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Function3<A, B, C, R>
|
||||
{
|
||||
public R apply(A a, B b, C c);
|
||||
public interface Function3<A, B, C, R> {
|
||||
R apply(A a, B b, C c);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
@FunctionalInterface
|
||||
public interface Function4<A, B, C, D, R>
|
||||
{
|
||||
public R apply(A a, B b, C c, D d);
|
||||
public interface Function4<A, B, C, D, R> {
|
||||
R apply(A a, B b, C c, D d);
|
||||
}
|
||||
|
||||
@@ -6,72 +6,60 @@ import java.io.Serializable;
|
||||
/**
|
||||
* A Biset
|
||||
*
|
||||
* @param <A> the first object type
|
||||
* @param <B> the second object type
|
||||
* @author cyberpwn
|
||||
*
|
||||
* @param <A>
|
||||
* the first object type
|
||||
* @param <B>
|
||||
* the second object type
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
public class GBiset<A, B> implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private A a;
|
||||
private B b;
|
||||
public class GBiset<A, B> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private A a;
|
||||
private B b;
|
||||
|
||||
/**
|
||||
* Create a new Biset
|
||||
*
|
||||
* @param a
|
||||
* the first object
|
||||
* @param b
|
||||
* the second object
|
||||
*/
|
||||
public GBiset(A a, B b)
|
||||
{
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
/**
|
||||
* Create a new Biset
|
||||
*
|
||||
* @param a the first object
|
||||
* @param b the second object
|
||||
*/
|
||||
public GBiset(A a, B b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object of the type A
|
||||
*
|
||||
* @return the first object
|
||||
*/
|
||||
public A getA()
|
||||
{
|
||||
return a;
|
||||
}
|
||||
/**
|
||||
* Get the object of the type A
|
||||
*
|
||||
* @return the first object
|
||||
*/
|
||||
public A getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the first object
|
||||
*
|
||||
* @param a
|
||||
* the first object A
|
||||
*/
|
||||
public void setA(A a)
|
||||
{
|
||||
this.a = a;
|
||||
}
|
||||
/**
|
||||
* Set the first object
|
||||
*
|
||||
* @param a the first object A
|
||||
*/
|
||||
public void setA(A a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the second object
|
||||
*
|
||||
* @return the second object
|
||||
*/
|
||||
public B getB()
|
||||
{
|
||||
return b;
|
||||
}
|
||||
/**
|
||||
* Get the second object
|
||||
*
|
||||
* @return the second object
|
||||
*/
|
||||
public B getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the second object
|
||||
*
|
||||
* @param b
|
||||
*/
|
||||
public void setB(B b)
|
||||
{
|
||||
this.b = b;
|
||||
}
|
||||
/**
|
||||
* Set the second object
|
||||
*
|
||||
* @param b
|
||||
*/
|
||||
public void setB(B b) {
|
||||
this.b = b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,44 +6,36 @@ import java.util.List;
|
||||
/**
|
||||
* Adapts a list of objects into a list of other objects
|
||||
*
|
||||
* @param <FROM> the from object in lists (the item INSIDE the list)
|
||||
* @param <TO> the to object in lists (the item INSIDE the list)
|
||||
* @author cyberpwn
|
||||
* @param <FROM>
|
||||
* the from object in lists (the item INSIDE the list)
|
||||
* @param <TO>
|
||||
* the to object in lists (the item INSIDE the list)
|
||||
*/
|
||||
public abstract class GListAdapter<FROM, TO>
|
||||
{
|
||||
/**
|
||||
* Adapts a list of FROM to a list of TO
|
||||
*
|
||||
* @param from
|
||||
* the from list
|
||||
* @return the to list
|
||||
*/
|
||||
public List<TO> adapt(List<FROM> from)
|
||||
{
|
||||
List<TO> adapted = new KList<TO>();
|
||||
public abstract class GListAdapter<FROM, TO> {
|
||||
/**
|
||||
* Adapts a list of FROM to a list of TO
|
||||
*
|
||||
* @param from the from list
|
||||
* @return the to list
|
||||
*/
|
||||
public List<TO> adapt(List<FROM> from) {
|
||||
List<TO> adapted = new KList<TO>();
|
||||
|
||||
for(FROM i : from)
|
||||
{
|
||||
TO t = onAdapt(i);
|
||||
for (FROM i : from) {
|
||||
TO t = onAdapt(i);
|
||||
|
||||
if(t != null)
|
||||
{
|
||||
adapted.add(onAdapt(i));
|
||||
}
|
||||
}
|
||||
if (t != null) {
|
||||
adapted.add(onAdapt(i));
|
||||
}
|
||||
}
|
||||
|
||||
return adapted;
|
||||
}
|
||||
return adapted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts a list object FROM to TO for use with the adapt method
|
||||
*
|
||||
* @param from
|
||||
* the from object
|
||||
* @return the to object
|
||||
*/
|
||||
public abstract TO onAdapt(FROM from);
|
||||
/**
|
||||
* Adapts a list object FROM to TO for use with the adapt method
|
||||
*
|
||||
* @param from the from object
|
||||
* @return the to object
|
||||
*/
|
||||
public abstract TO onAdapt(FROM from);
|
||||
}
|
||||
|
||||
@@ -6,111 +6,88 @@ import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
|
||||
public class GroupedExecutor
|
||||
{
|
||||
private int xc;
|
||||
private ExecutorService service;
|
||||
private KMap<String, Integer> mirror;
|
||||
public class GroupedExecutor {
|
||||
private int xc;
|
||||
private final ExecutorService service;
|
||||
private final KMap<String, Integer> mirror;
|
||||
|
||||
public GroupedExecutor(int threadLimit, int priority, String name)
|
||||
{
|
||||
xc = 1;
|
||||
mirror = new KMap<String, Integer>();
|
||||
public GroupedExecutor(int threadLimit, int priority, String name) {
|
||||
xc = 1;
|
||||
mirror = new KMap<String, Integer>();
|
||||
|
||||
if(threadLimit == 1)
|
||||
{
|
||||
service = Executors.newSingleThreadExecutor((r) ->
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name);
|
||||
t.setPriority(priority);
|
||||
if (threadLimit == 1) {
|
||||
service = Executors.newSingleThreadExecutor((r) ->
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name);
|
||||
t.setPriority(priority);
|
||||
|
||||
return t;
|
||||
});
|
||||
}
|
||||
return t;
|
||||
});
|
||||
} else if (threadLimit > 1) {
|
||||
final ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
|
||||
@Override
|
||||
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
|
||||
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||
worker.setName(name + " " + xc++);
|
||||
worker.setPriority(priority);
|
||||
return worker;
|
||||
}
|
||||
};
|
||||
|
||||
else if(threadLimit > 1)
|
||||
{
|
||||
final ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory()
|
||||
{
|
||||
@Override
|
||||
public ForkJoinWorkerThread newThread(ForkJoinPool pool)
|
||||
{
|
||||
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||
worker.setName(name + " " + xc++);
|
||||
worker.setPriority(priority);
|
||||
return worker;
|
||||
}
|
||||
};
|
||||
service = new ForkJoinPool(threadLimit, factory, null, false);
|
||||
} else {
|
||||
service = Executors.newCachedThreadPool((r) ->
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name + " " + xc++);
|
||||
t.setPriority(priority);
|
||||
|
||||
service = new ForkJoinPool(threadLimit, factory, null, false);
|
||||
}
|
||||
return t;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
service = Executors.newCachedThreadPool((r) ->
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name + " " + xc++);
|
||||
t.setPriority(priority);
|
||||
public void waitFor(String g) {
|
||||
if (g == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return t;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!mirror.containsKey(g)) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void waitFor(String g)
|
||||
{
|
||||
if(g == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
if (mirror.get(g) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!mirror.containsKey(g))
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void queue(String q, NastyRunnable r) {
|
||||
mirror.compute(q, (k, v) -> k == null || v == null ? 1 : v + 1);
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(mirror.get(g) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
service.execute(() ->
|
||||
{
|
||||
try {
|
||||
r.run();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void queue(String q, NastyRunnable r)
|
||||
{
|
||||
mirror.compute(q, (k, v) -> k == null || v == null ? 1 : v + 1);
|
||||
mirror.compute(q, (k, v) -> v - 1);
|
||||
});
|
||||
}
|
||||
|
||||
service.execute(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
r.run();
|
||||
}
|
||||
public void close() {
|
||||
J.a(() ->
|
||||
{
|
||||
J.sleep(100);
|
||||
service.shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mirror.compute(q, (k, v) -> v - 1);
|
||||
});
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
J.a(() ->
|
||||
{
|
||||
J.sleep(100);
|
||||
service.shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
public void closeNow()
|
||||
{
|
||||
service.shutdown();
|
||||
}
|
||||
public void closeNow() {
|
||||
service.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,173 +29,161 @@ import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Convert an HTTP header to a JSONObject and back.
|
||||
*
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
*/
|
||||
public class HTTP
|
||||
{
|
||||
|
||||
/** Carriage return/line feed. */
|
||||
public static final String CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Convert an HTTP header string into a JSONObject. It can be a request
|
||||
* header or a response header. A request header will contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* Method: "POST" (for example),
|
||||
* "Request-URI": "/" (for example),
|
||||
* "HTTP-Version": "HTTP/1.1" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* A response header will contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||
* "Status-Code": "200" (for example),
|
||||
* "Reason-Phrase": "OK" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* In addition, the other parameters in the header will be captured, using
|
||||
* the HTTP field names as JSON names, so that
|
||||
*
|
||||
* <pre>
|
||||
* Date: Sun, 26 May 2002 18:06:04 GMT
|
||||
* Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
|
||||
* Cache-Control: no-cache
|
||||
* </pre>
|
||||
*
|
||||
* become
|
||||
*
|
||||
* <pre>
|
||||
* {...
|
||||
* Date: "Sun, 26 May 2002 18:06:04 GMT",
|
||||
* Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
|
||||
* "Cache-Control": "no-cache",
|
||||
* ...}
|
||||
* </pre>
|
||||
*
|
||||
* It does no further checking or conversion. It does not parse dates. It
|
||||
* does not do '%' transforms on URLs.
|
||||
*
|
||||
* @param string
|
||||
* An HTTP header string.
|
||||
* @return A JSONObject containing the elements and attributes of the XML
|
||||
* string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(String string) throws JSONException
|
||||
{
|
||||
JSONObject jo = new JSONObject();
|
||||
HTTPTokener x = new HTTPTokener(string);
|
||||
String token;
|
||||
|
||||
token = x.nextToken();
|
||||
if(token.toUpperCase().startsWith("HTTP"))
|
||||
{
|
||||
|
||||
// Response
|
||||
|
||||
jo.put("HTTP-Version", token);
|
||||
jo.put("Status-Code", x.nextToken());
|
||||
jo.put("Reason-Phrase", x.nextTo('\0'));
|
||||
x.next();
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
// Request
|
||||
|
||||
jo.put("Method", token);
|
||||
jo.put("Request-URI", x.nextToken());
|
||||
jo.put("HTTP-Version", x.nextToken());
|
||||
}
|
||||
|
||||
// Fields
|
||||
|
||||
while(x.more())
|
||||
{
|
||||
String name = x.nextTo(':');
|
||||
x.next(':');
|
||||
jo.put(name, x.nextTo('\0'));
|
||||
x.next();
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into an HTTP header. A request header must contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* Method: "POST" (for example),
|
||||
* "Request-URI": "/" (for example),
|
||||
* "HTTP-Version": "HTTP/1.1" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* A response header must contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||
* "Status-Code": "200" (for example),
|
||||
* "Reason-Phrase": "OK" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Any other members of the JSONObject will be output as HTTP fields. The
|
||||
* result will end with two CRLF pairs.
|
||||
*
|
||||
* @param jo
|
||||
* A JSONObject
|
||||
* @return An HTTP header string.
|
||||
* @throws JSONException
|
||||
* if the object does not contain enough information.
|
||||
*/
|
||||
public static String toString(JSONObject jo) throws JSONException
|
||||
{
|
||||
Iterator<String> keys = jo.keys();
|
||||
String string;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if(jo.has("Status-Code") && jo.has("Reason-Phrase"))
|
||||
{
|
||||
sb.append(jo.getString("HTTP-Version"));
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("Status-Code"));
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("Reason-Phrase"));
|
||||
} else if(jo.has("Method") && jo.has("Request-URI"))
|
||||
{
|
||||
sb.append(jo.getString("Method"));
|
||||
sb.append(' ');
|
||||
sb.append('"');
|
||||
sb.append(jo.getString("Request-URI"));
|
||||
sb.append('"');
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("HTTP-Version"));
|
||||
} else
|
||||
{
|
||||
throw new JSONException("Not enough material for an HTTP header.");
|
||||
}
|
||||
sb.append(CRLF);
|
||||
while(keys.hasNext())
|
||||
{
|
||||
string = keys.next();
|
||||
if(!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && !"Reason-Phrase".equals(string) && !"Method".equals(string) && !"Request-URI".equals(string) && !jo.isNull(string))
|
||||
{
|
||||
sb.append(string);
|
||||
sb.append(": ");
|
||||
sb.append(jo.getString(string));
|
||||
sb.append(CRLF);
|
||||
}
|
||||
}
|
||||
sb.append(CRLF);
|
||||
return sb.toString();
|
||||
}
|
||||
public class HTTP {
|
||||
|
||||
/**
|
||||
* Carriage return/line feed.
|
||||
*/
|
||||
public static final String CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Convert an HTTP header string into a JSONObject. It can be a request
|
||||
* header or a response header. A request header will contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* Method: "POST" (for example),
|
||||
* "Request-URI": "/" (for example),
|
||||
* "HTTP-Version": "HTTP/1.1" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* A response header will contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||
* "Status-Code": "200" (for example),
|
||||
* "Reason-Phrase": "OK" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* In addition, the other parameters in the header will be captured, using
|
||||
* the HTTP field names as JSON names, so that
|
||||
*
|
||||
* <pre>
|
||||
* Date: Sun, 26 May 2002 18:06:04 GMT
|
||||
* Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
|
||||
* Cache-Control: no-cache
|
||||
* </pre>
|
||||
* <p>
|
||||
* become
|
||||
*
|
||||
* <pre>
|
||||
* {...
|
||||
* Date: "Sun, 26 May 2002 18:06:04 GMT",
|
||||
* Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
|
||||
* "Cache-Control": "no-cache",
|
||||
* ...}
|
||||
* </pre>
|
||||
* <p>
|
||||
* It does no further checking or conversion. It does not parse dates. It
|
||||
* does not do '%' transforms on URLs.
|
||||
*
|
||||
* @param string An HTTP header string.
|
||||
* @return A JSONObject containing the elements and attributes of the XML
|
||||
* string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(String string) throws JSONException {
|
||||
JSONObject jo = new JSONObject();
|
||||
HTTPTokener x = new HTTPTokener(string);
|
||||
String token;
|
||||
|
||||
token = x.nextToken();
|
||||
if (token.toUpperCase().startsWith("HTTP")) {
|
||||
|
||||
// Response
|
||||
|
||||
jo.put("HTTP-Version", token);
|
||||
jo.put("Status-Code", x.nextToken());
|
||||
jo.put("Reason-Phrase", x.nextTo('\0'));
|
||||
x.next();
|
||||
|
||||
} else {
|
||||
|
||||
// Request
|
||||
|
||||
jo.put("Method", token);
|
||||
jo.put("Request-URI", x.nextToken());
|
||||
jo.put("HTTP-Version", x.nextToken());
|
||||
}
|
||||
|
||||
// Fields
|
||||
|
||||
while (x.more()) {
|
||||
String name = x.nextTo(':');
|
||||
x.next(':');
|
||||
jo.put(name, x.nextTo('\0'));
|
||||
x.next();
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JSONObject into an HTTP header. A request header must contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* Method: "POST" (for example),
|
||||
* "Request-URI": "/" (for example),
|
||||
* "HTTP-Version": "HTTP/1.1" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* A response header must contain
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* "HTTP-Version": "HTTP/1.1" (for example),
|
||||
* "Status-Code": "200" (for example),
|
||||
* "Reason-Phrase": "OK" (for example)
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* Any other members of the JSONObject will be output as HTTP fields. The
|
||||
* result will end with two CRLF pairs.
|
||||
*
|
||||
* @param jo A JSONObject
|
||||
* @return An HTTP header string.
|
||||
* @throws JSONException if the object does not contain enough information.
|
||||
*/
|
||||
public static String toString(JSONObject jo) throws JSONException {
|
||||
Iterator<String> keys = jo.keys();
|
||||
String string;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
|
||||
sb.append(jo.getString("HTTP-Version"));
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("Status-Code"));
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("Reason-Phrase"));
|
||||
} else if (jo.has("Method") && jo.has("Request-URI")) {
|
||||
sb.append(jo.getString("Method"));
|
||||
sb.append(' ');
|
||||
sb.append('"');
|
||||
sb.append(jo.getString("Request-URI"));
|
||||
sb.append('"');
|
||||
sb.append(' ');
|
||||
sb.append(jo.getString("HTTP-Version"));
|
||||
} else {
|
||||
throw new JSONException("Not enough material for an HTTP header.");
|
||||
}
|
||||
sb.append(CRLF);
|
||||
while (keys.hasNext()) {
|
||||
string = keys.next();
|
||||
if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && !"Reason-Phrase".equals(string) && !"Method".equals(string) && !"Request-URI".equals(string) && !jo.isNull(string)) {
|
||||
sb.append(string);
|
||||
sb.append(": ");
|
||||
sb.append(jo.getString(string));
|
||||
sb.append(CRLF);
|
||||
}
|
||||
}
|
||||
sb.append(CRLF);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,64 +28,53 @@ SOFTWARE.
|
||||
/**
|
||||
* The HTTPTokener extends the JSONTokener to provide additional methods for the
|
||||
* parsing of HTTP headers.
|
||||
*
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
*/
|
||||
public class HTTPTokener extends JSONTokener
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct an HTTPTokener from a string.
|
||||
*
|
||||
* @param string
|
||||
* A source string.
|
||||
*/
|
||||
public HTTPTokener(String string)
|
||||
{
|
||||
super(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next token or string. This is used in parsing HTTP headers.
|
||||
*
|
||||
* @throws JSONException
|
||||
* @return A String.
|
||||
*/
|
||||
public String nextToken() throws JSONException
|
||||
{
|
||||
char c;
|
||||
char q;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
do
|
||||
{
|
||||
c = next();
|
||||
} while(Character.isWhitespace(c));
|
||||
if(c == '"' || c == '\'')
|
||||
{
|
||||
q = c;
|
||||
for(;;)
|
||||
{
|
||||
c = next();
|
||||
if(c < ' ')
|
||||
{
|
||||
throw syntaxError("Unterminated string.");
|
||||
}
|
||||
if(c == q)
|
||||
{
|
||||
return sb.toString();
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
if(c == 0 || Character.isWhitespace(c))
|
||||
{
|
||||
return sb.toString();
|
||||
}
|
||||
sb.append(c);
|
||||
c = next();
|
||||
}
|
||||
}
|
||||
public class HTTPTokener extends JSONTokener {
|
||||
|
||||
/**
|
||||
* Construct an HTTPTokener from a string.
|
||||
*
|
||||
* @param string A source string.
|
||||
*/
|
||||
public HTTPTokener(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next token or string. This is used in parsing HTTP headers.
|
||||
*
|
||||
* @return A String.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public String nextToken() throws JSONException {
|
||||
char c;
|
||||
char q;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
do {
|
||||
c = next();
|
||||
} while (Character.isWhitespace(c));
|
||||
if (c == '"' || c == '\'') {
|
||||
q = c;
|
||||
for (; ; ) {
|
||||
c = next();
|
||||
if (c < ' ') {
|
||||
throw syntaxError("Unterminated string.");
|
||||
}
|
||||
if (c == q) {
|
||||
return sb.toString();
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
for (; ; ) {
|
||||
if (c == 0 || Character.isWhitespace(c)) {
|
||||
return sb.toString();
|
||||
}
|
||||
sb.append(c);
|
||||
c = next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,23 +2,19 @@ package com.volmit.iris.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class HeightMap
|
||||
{
|
||||
private final byte[] height;
|
||||
public class HeightMap {
|
||||
private final byte[] height;
|
||||
|
||||
public HeightMap()
|
||||
{
|
||||
height = new byte[256];
|
||||
Arrays.fill(height, Byte.MIN_VALUE);
|
||||
}
|
||||
public HeightMap() {
|
||||
height = new byte[256];
|
||||
Arrays.fill(height, Byte.MIN_VALUE);
|
||||
}
|
||||
|
||||
public void setHeight(int x, int z, int h)
|
||||
{
|
||||
height[x * 16 + z] = (byte) (h + Byte.MIN_VALUE);
|
||||
}
|
||||
public void setHeight(int x, int z, int h) {
|
||||
height[x * 16 + z] = (byte) (h + Byte.MIN_VALUE);
|
||||
}
|
||||
|
||||
public int getHeight(int x, int z)
|
||||
{
|
||||
return height[x * 16 + z] - Byte.MIN_VALUE;
|
||||
}
|
||||
public int getHeight(int x, int z) {
|
||||
return height[x * 16 + z] - Byte.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public interface IActivator
|
||||
{
|
||||
public interface IActivator {
|
||||
|
||||
}
|
||||
|
||||
@@ -4,52 +4,47 @@ package com.volmit.iris.util;
|
||||
* Represents a pawn command
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public interface ICommand
|
||||
{
|
||||
public KList<String> getRequiredPermissions();
|
||||
public interface ICommand {
|
||||
KList<String> getRequiredPermissions();
|
||||
|
||||
/**
|
||||
* Get the name of this command (node)
|
||||
*
|
||||
* @return the node
|
||||
*/
|
||||
public String getNode();
|
||||
/**
|
||||
* Get the name of this command (node)
|
||||
*
|
||||
* @return the node
|
||||
*/
|
||||
String getNode();
|
||||
|
||||
/**
|
||||
* Get all (realized) nodes of this command
|
||||
*
|
||||
* @return the nodes
|
||||
*/
|
||||
public KList<String> getNodes();
|
||||
/**
|
||||
* Get all (realized) nodes of this command
|
||||
*
|
||||
* @return the nodes
|
||||
*/
|
||||
KList<String> getNodes();
|
||||
|
||||
/**
|
||||
* Get all (every) node in this command
|
||||
*
|
||||
* @return all nodes
|
||||
*/
|
||||
public KList<String> getAllNodes();
|
||||
/**
|
||||
* Get all (every) node in this command
|
||||
*
|
||||
* @return all nodes
|
||||
*/
|
||||
KList<String> getAllNodes();
|
||||
|
||||
/**
|
||||
* Add a node to this command
|
||||
*
|
||||
* @param node
|
||||
* the node
|
||||
*/
|
||||
public void addNode(String node);
|
||||
/**
|
||||
* Add a node to this command
|
||||
*
|
||||
* @param node the node
|
||||
*/
|
||||
void addNode(String node);
|
||||
|
||||
/**
|
||||
* Handle a command. If this is a subcommand, parameters after the subcommand
|
||||
* will be adapted in args for you
|
||||
*
|
||||
* @param sender
|
||||
* the volume sender (pre-tagged)
|
||||
* @param args
|
||||
* the arguments after this command node
|
||||
* @return return true to mark it as handled
|
||||
*/
|
||||
public boolean handle(MortarSender sender, String[] args);
|
||||
/**
|
||||
* Handle a command. If this is a subcommand, parameters after the subcommand
|
||||
* will be adapted in args for you
|
||||
*
|
||||
* @param sender the volume sender (pre-tagged)
|
||||
* @param args the arguments after this command node
|
||||
* @return return true to mark it as handled
|
||||
*/
|
||||
boolean handle(MortarSender sender, String[] args);
|
||||
|
||||
public KList<String> handleTab(MortarSender sender, String[] args);
|
||||
KList<String> handleTab(MortarSender sender, String[] args);
|
||||
}
|
||||
|
||||
@@ -2,23 +2,22 @@ package com.volmit.iris.util;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public interface IController extends Listener
|
||||
{
|
||||
public String getName();
|
||||
public interface IController extends Listener {
|
||||
String getName();
|
||||
|
||||
public void start();
|
||||
void start();
|
||||
|
||||
public void stop();
|
||||
void stop();
|
||||
|
||||
public void tick();
|
||||
void tick();
|
||||
|
||||
public int getTickInterval();
|
||||
int getTickInterval();
|
||||
|
||||
public void l(Object l);
|
||||
void l(Object l);
|
||||
|
||||
public void w(Object l);
|
||||
void w(Object l);
|
||||
|
||||
public void f(Object l);
|
||||
void f(Object l);
|
||||
|
||||
public void v(Object l);
|
||||
void v(Object l);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public class ING
|
||||
{
|
||||
public ING(RNG rng)
|
||||
{
|
||||
|
||||
}
|
||||
public class ING {
|
||||
public ING(RNG rng) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ package com.volmit.iris.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IORunnable
|
||||
{
|
||||
public void run() throws IOException;
|
||||
public interface IORunnable {
|
||||
void run() throws IOException;
|
||||
}
|
||||
|
||||
@@ -4,25 +4,24 @@ import com.volmit.iris.object.tile.TileData;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public interface IObjectPlacer
|
||||
{
|
||||
public int getHighest(int x, int z);
|
||||
public interface IObjectPlacer {
|
||||
int getHighest(int x, int z);
|
||||
|
||||
public int getHighest(int x, int z, boolean ignoreFluid);
|
||||
int getHighest(int x, int z, boolean ignoreFluid);
|
||||
|
||||
public void set(int x, int y, int z, BlockData d);
|
||||
void set(int x, int y, int z, BlockData d);
|
||||
|
||||
public BlockData get(int x, int y, int z);
|
||||
BlockData get(int x, int y, int z);
|
||||
|
||||
public boolean isPreventingDecay();
|
||||
boolean isPreventingDecay();
|
||||
|
||||
public boolean isSolid(int x, int y, int z);
|
||||
boolean isSolid(int x, int y, int z);
|
||||
|
||||
public boolean isUnderwater(int x, int z);
|
||||
boolean isUnderwater(int x, int z);
|
||||
|
||||
public int getFluidHeight();
|
||||
int getFluidHeight();
|
||||
|
||||
public boolean isDebugSmartBore();
|
||||
boolean isDebugSmartBore();
|
||||
|
||||
void setTile(int xx, int yy, int zz, TileData<? extends TileState> tile);
|
||||
}
|
||||
|
||||
@@ -3,17 +3,16 @@ package com.volmit.iris.util;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
public interface IPostBlockAccess
|
||||
{
|
||||
public BlockData getPostBlock(int x, int y, int z, int currentPostX, int currentPostZ, ChunkData currentData);
|
||||
public interface IPostBlockAccess {
|
||||
BlockData getPostBlock(int x, int y, int z, int currentPostX, int currentPostZ, ChunkData currentData);
|
||||
|
||||
public void setPostBlock(int x, int y, int z, BlockData d, int currentPostX, int currentPostZ, ChunkData currentData);
|
||||
void setPostBlock(int x, int y, int z, BlockData d, int currentPostX, int currentPostZ, ChunkData currentData);
|
||||
|
||||
public int highestTerrainOrFluidBlock(int x, int z);
|
||||
int highestTerrainOrFluidBlock(int x, int z);
|
||||
|
||||
public int highestTerrainBlock(int x, int z);
|
||||
int highestTerrainBlock(int x, int z);
|
||||
|
||||
public void updateHeight(int x, int z, int h);
|
||||
void updateHeight(int x, int z, int h);
|
||||
|
||||
public KList<CaveResult> caveFloors(int x, int z);
|
||||
KList<CaveResult> caveFloors(int x, int z);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
public interface IRare
|
||||
{
|
||||
public int getRarity();
|
||||
public interface IRare {
|
||||
int getRarity();
|
||||
|
||||
public static int get(Object v)
|
||||
{
|
||||
return v instanceof IRare ? ((IRare) v).getRarity() : 1;
|
||||
}
|
||||
static int get(Object v) {
|
||||
return v instanceof IRare ? ((IRare) v).getRarity() : 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package com.volmit.iris.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Info
|
||||
{
|
||||
public static String getPortIP()
|
||||
{
|
||||
return Bukkit.getPort() + Bukkit.getIp();
|
||||
}
|
||||
public class Info {
|
||||
public static String getPortIP() {
|
||||
return Bukkit.getPort() + Bukkit.getIp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
public @interface Instance
|
||||
{
|
||||
public @interface Instance {
|
||||
|
||||
}
|
||||
|
||||
@@ -4,24 +4,24 @@ import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* JNBT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2015 Neil Wightman
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the JNBT team nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -32,13 +32,13 @@ import java.util.Arrays;
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>TAG_Int_Array</code> tag.
|
||||
*
|
||||
* @author Neil Wightman
|
||||
*
|
||||
*/
|
||||
public final class IntArrayTag extends Tag {
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class IntArrayTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name The name.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
*/
|
||||
public IntArrayTag(String name, int[] value) {
|
||||
|
||||
@@ -2,24 +2,24 @@ package com.volmit.iris.util;
|
||||
|
||||
/*
|
||||
* JNBT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2010 Graham Edgecombe
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the JNBT team nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -30,13 +30,13 @@ package com.volmit.iris.util;
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The <code>TAG_Int</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*
|
||||
*/
|
||||
public final class IntTag extends Tag {
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class IntTag extends Tag {
|
||||
/**
|
||||
* Creates the tag.
|
||||
*
|
||||
* @param name The name.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
*/
|
||||
public IntTag(String name, int value) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.volmit.iris.util;
|
||||
public enum InterpolationType
|
||||
{
|
||||
LINEAR,
|
||||
PARAMETRIC_2,
|
||||
PARAMETRIC_4,
|
||||
BEZIER,
|
||||
NONE;
|
||||
|
||||
public enum InterpolationType {
|
||||
LINEAR,
|
||||
PARAMETRIC_2,
|
||||
PARAMETRIC_4,
|
||||
BEZIER,
|
||||
NONE
|
||||
}
|
||||
@@ -1,53 +1,44 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
public class InvertedBiomeGrid implements BiomeGrid {
|
||||
private final BiomeGrid grid;
|
||||
|
||||
public class InvertedBiomeGrid implements BiomeGrid
|
||||
{
|
||||
private BiomeGrid grid;
|
||||
public InvertedBiomeGrid(BiomeGrid real) {
|
||||
this.grid = real;
|
||||
}
|
||||
|
||||
public InvertedBiomeGrid(BiomeGrid real)
|
||||
{
|
||||
this.grid = real;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Biome getBiome(int arg0, int arg1) {
|
||||
return grid.getBiome(arg0, arg1);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Biome getBiome(int arg0, int arg1)
|
||||
{
|
||||
return grid.getBiome(arg0, arg1);
|
||||
}
|
||||
@Override
|
||||
public Biome getBiome(int arg0, int arg1, int arg2) {
|
||||
if (!Iris.biome3d) {
|
||||
return getBiome(arg0, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int arg0, int arg1, int arg2)
|
||||
{
|
||||
if(!Iris.biome3d)
|
||||
{
|
||||
return getBiome(arg0, arg2);
|
||||
}
|
||||
return grid.getBiome(arg0, 255 - arg1, arg2);
|
||||
}
|
||||
|
||||
return grid.getBiome(arg0, 255 - arg1, arg2);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void setBiome(int arg0, int arg1, Biome arg2) {
|
||||
grid.setBiome(arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void setBiome(int arg0, int arg1, Biome arg2)
|
||||
{
|
||||
grid.setBiome(arg0, arg1, arg2);
|
||||
}
|
||||
@Override
|
||||
public void setBiome(int arg0, int arg1, int arg2, Biome arg3) {
|
||||
if (!Iris.biome3d) {
|
||||
setBiome(arg0, arg2, arg3);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int arg0, int arg1, int arg2, Biome arg3)
|
||||
{
|
||||
if(!Iris.biome3d)
|
||||
{
|
||||
setBiome(arg0, arg2, arg3);
|
||||
return;
|
||||
}
|
||||
|
||||
grid.setBiome(arg0, 255 - arg1, arg2, arg3);
|
||||
}
|
||||
grid.setBiome(arg0, 255 - arg1, arg2, arg3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,74 +3,62 @@ package com.volmit.iris.util;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
public class IrisBiomeStorage
|
||||
{
|
||||
private static final int e;
|
||||
private static final int f;
|
||||
public static final int a;
|
||||
public static final int b;
|
||||
public static final int c;
|
||||
private final Biome[] g;
|
||||
public class IrisBiomeStorage {
|
||||
private static final int e;
|
||||
private static final int f;
|
||||
public static final int a;
|
||||
public static final int b;
|
||||
public static final int c;
|
||||
private final Biome[] g;
|
||||
|
||||
static
|
||||
{
|
||||
e = (int) Math.round(Math.log(16.0) / Math.log(2.0)) - 2;
|
||||
f = (int) Math.round(Math.log(256.0) / Math.log(2.0)) - 2; // TODO: WARNING HEIGHT
|
||||
a = 1 << IrisBiomeStorage.e + IrisBiomeStorage.e + IrisBiomeStorage.f;
|
||||
b = (1 << IrisBiomeStorage.e) - 1;
|
||||
c = (1 << IrisBiomeStorage.f) - 1;
|
||||
}
|
||||
static {
|
||||
e = (int) Math.round(Math.log(16.0) / Math.log(2.0)) - 2;
|
||||
f = (int) Math.round(Math.log(256.0) / Math.log(2.0)) - 2; // TODO: WARNING HEIGHT
|
||||
a = 1 << IrisBiomeStorage.e + IrisBiomeStorage.e + IrisBiomeStorage.f;
|
||||
b = (1 << IrisBiomeStorage.e) - 1;
|
||||
c = (1 << IrisBiomeStorage.f) - 1;
|
||||
}
|
||||
|
||||
public IrisBiomeStorage(final Biome[] aBiome)
|
||||
{
|
||||
this.g = aBiome;
|
||||
}
|
||||
public IrisBiomeStorage(final Biome[] aBiome) {
|
||||
this.g = aBiome;
|
||||
}
|
||||
|
||||
public IrisBiomeStorage()
|
||||
{
|
||||
this(new Biome[IrisBiomeStorage.a]);
|
||||
}
|
||||
public IrisBiomeStorage() {
|
||||
this(new Biome[IrisBiomeStorage.a]);
|
||||
}
|
||||
|
||||
public IrisBiomeStorage b()
|
||||
{
|
||||
return new IrisBiomeStorage(this.g.clone());
|
||||
}
|
||||
public IrisBiomeStorage b() {
|
||||
return new IrisBiomeStorage(this.g.clone());
|
||||
}
|
||||
|
||||
public void inject(BiomeGrid grid)
|
||||
{
|
||||
// TODO: WARNING HEIGHT
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
for(int j = 0; j < 16; j++)
|
||||
{
|
||||
for(int k = 0; k < 16; k++)
|
||||
{
|
||||
Biome b = getBiome(j, i, k);
|
||||
public void inject(BiomeGrid grid) {
|
||||
// TODO: WARNING HEIGHT
|
||||
for (int i = 0; i < 256; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
for (int k = 0; k < 16; k++) {
|
||||
Biome b = getBiome(j, i, k);
|
||||
|
||||
if(b == null || b.equals(Biome.THE_VOID))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (b == null || b.equals(Biome.THE_VOID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
grid.setBiome(j, i, k, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
grid.setBiome(j, i, k, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Biome getBiome(final int x, final int y, final int z)
|
||||
{
|
||||
final int l = x & IrisBiomeStorage.b;
|
||||
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);
|
||||
final int j2 = z & IrisBiomeStorage.b;
|
||||
return this.g[i2 << IrisBiomeStorage.e + IrisBiomeStorage.e | j2 << IrisBiomeStorage.e | l];
|
||||
}
|
||||
public Biome getBiome(final int x, final int y, final int z) {
|
||||
final int l = x & IrisBiomeStorage.b;
|
||||
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);
|
||||
final int j2 = z & IrisBiomeStorage.b;
|
||||
return this.g[i2 << IrisBiomeStorage.e + IrisBiomeStorage.e | j2 << IrisBiomeStorage.e | l];
|
||||
}
|
||||
|
||||
public void setBiome(final int x, final int y, final int z, final Biome biome)
|
||||
{
|
||||
final int l = x & IrisBiomeStorage.b;
|
||||
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);
|
||||
final int j2 = z & IrisBiomeStorage.b;
|
||||
this.g[i2 << IrisBiomeStorage.e + IrisBiomeStorage.e | j2 << IrisBiomeStorage.e | l] = biome;
|
||||
}
|
||||
public void setBiome(final int x, final int y, final int z, final Biome biome) {
|
||||
final int l = x & IrisBiomeStorage.b;
|
||||
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);
|
||||
final int j2 = z & IrisBiomeStorage.b;
|
||||
this.g[i2 << IrisBiomeStorage.e + IrisBiomeStorage.e | j2 << IrisBiomeStorage.e | l] = biome;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,46 +1,36 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Data
|
||||
public class IrisLock
|
||||
{
|
||||
private transient final ReentrantLock lock;
|
||||
private transient final String name;
|
||||
private transient boolean disabled = false;
|
||||
public class IrisLock {
|
||||
private transient final ReentrantLock lock;
|
||||
private transient final String name;
|
||||
private transient boolean disabled = false;
|
||||
|
||||
public IrisLock(String name)
|
||||
{
|
||||
this.name = name;
|
||||
lock = new ReentrantLock(false);
|
||||
}
|
||||
public IrisLock(String name) {
|
||||
this.name = name;
|
||||
lock = new ReentrantLock(false);
|
||||
}
|
||||
|
||||
public void lock()
|
||||
{
|
||||
if(disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void lock() {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
}
|
||||
lock.lock();
|
||||
}
|
||||
|
||||
public void unlock()
|
||||
{
|
||||
if(disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
lock.unlock();
|
||||
}
|
||||
public void unlock() {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
lock.unlock();
|
||||
} catch (Throwable e) {
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,548 +4,448 @@ import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
public class IrisMathHelper
|
||||
{
|
||||
public static final float a;
|
||||
private static final Random c;
|
||||
private static final int[] d;
|
||||
private static final double e;
|
||||
private static final double[] f;
|
||||
private static final double[] g;
|
||||
public class IrisMathHelper {
|
||||
public static final float a;
|
||||
private static final Random c;
|
||||
private static final int[] d;
|
||||
private static final double e;
|
||||
private static final double[] f;
|
||||
private static final double[] g;
|
||||
|
||||
public static float c(final float var0)
|
||||
{
|
||||
return (float) Math.sqrt(var0);
|
||||
}
|
||||
public static float c(final float var0) {
|
||||
return (float) Math.sqrt(var0);
|
||||
}
|
||||
|
||||
public static float sqrt(final double var0)
|
||||
{
|
||||
return (float) Math.sqrt(var0);
|
||||
}
|
||||
public static float sqrt(final double var0) {
|
||||
return (float) Math.sqrt(var0);
|
||||
}
|
||||
|
||||
public static int d(final float var0)
|
||||
{
|
||||
final int var = (int) var0;
|
||||
return (var0 < var) ? (var - 1) : var;
|
||||
}
|
||||
public static int d(final float var0) {
|
||||
final int var = (int) var0;
|
||||
return (var0 < var) ? (var - 1) : var;
|
||||
}
|
||||
|
||||
public static int floor(final double var0)
|
||||
{
|
||||
final int var = (int) var0;
|
||||
return (var0 < var) ? (var - 1) : var;
|
||||
}
|
||||
public static int floor(final double var0) {
|
||||
final int var = (int) var0;
|
||||
return (var0 < var) ? (var - 1) : var;
|
||||
}
|
||||
|
||||
public static long d(final double var0)
|
||||
{
|
||||
final long var = (long) var0;
|
||||
return (var0 < var) ? (var - 1L) : var;
|
||||
}
|
||||
public static long d(final double var0) {
|
||||
final long var = (long) var0;
|
||||
return (var0 < var) ? (var - 1L) : var;
|
||||
}
|
||||
|
||||
public static float e(final float var0)
|
||||
{
|
||||
return Math.abs(var0);
|
||||
}
|
||||
public static float e(final float var0) {
|
||||
return Math.abs(var0);
|
||||
}
|
||||
|
||||
public static int a(final int var0)
|
||||
{
|
||||
return Math.abs(var0);
|
||||
}
|
||||
public static int a(final int var0) {
|
||||
return Math.abs(var0);
|
||||
}
|
||||
|
||||
public static int f(final float var0)
|
||||
{
|
||||
final int var = (int) var0;
|
||||
return (var0 > var) ? (var + 1) : var;
|
||||
}
|
||||
public static int f(final float var0) {
|
||||
final int var = (int) var0;
|
||||
return (var0 > var) ? (var + 1) : var;
|
||||
}
|
||||
|
||||
public static int f(final double var0)
|
||||
{
|
||||
final int var = (int) var0;
|
||||
return (var0 > var) ? (var + 1) : var;
|
||||
}
|
||||
public static int f(final double var0) {
|
||||
final int var = (int) var0;
|
||||
return (var0 > var) ? (var + 1) : var;
|
||||
}
|
||||
|
||||
public static int clamp(final int var0, final int var1, final int var2)
|
||||
{
|
||||
if(var0 < var1)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
if(var0 > var2)
|
||||
{
|
||||
return var2;
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
public static int clamp(final int var0, final int var1, final int var2) {
|
||||
if (var0 < var1) {
|
||||
return var1;
|
||||
}
|
||||
if (var0 > var2) {
|
||||
return var2;
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float a(final float var0, final float var1, final float var2)
|
||||
{
|
||||
if(var0 < var1)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
if(var0 > var2)
|
||||
{
|
||||
return var2;
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
public static float a(final float var0, final float var1, final float var2) {
|
||||
if (var0 < var1) {
|
||||
return var1;
|
||||
}
|
||||
if (var0 > var2) {
|
||||
return var2;
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double a(final double var0, final double var2, final double var4)
|
||||
{
|
||||
if(var0 < var2)
|
||||
{
|
||||
return var2;
|
||||
}
|
||||
if(var0 > var4)
|
||||
{
|
||||
return var4;
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
public static double a(final double var0, final double var2, final double var4) {
|
||||
if (var0 < var2) {
|
||||
return var2;
|
||||
}
|
||||
if (var0 > var4) {
|
||||
return var4;
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double b(final double var0, final double var2, final double var4)
|
||||
{
|
||||
if(var4 < 0.0)
|
||||
{
|
||||
return var0;
|
||||
}
|
||||
if(var4 > 1.0)
|
||||
{
|
||||
return var2;
|
||||
}
|
||||
return d(var4, var0, var2);
|
||||
}
|
||||
public static double b(final double var0, final double var2, final double var4) {
|
||||
if (var4 < 0.0) {
|
||||
return var0;
|
||||
}
|
||||
if (var4 > 1.0) {
|
||||
return var2;
|
||||
}
|
||||
return d(var4, var0, var2);
|
||||
}
|
||||
|
||||
public static double a(double var0, double var2)
|
||||
{
|
||||
if(var0 < 0.0)
|
||||
{
|
||||
var0 = -var0;
|
||||
}
|
||||
if(var2 < 0.0)
|
||||
{
|
||||
var2 = -var2;
|
||||
}
|
||||
return (var0 > var2) ? var0 : var2;
|
||||
}
|
||||
public static double a(double var0, double var2) {
|
||||
if (var0 < 0.0) {
|
||||
var0 = -var0;
|
||||
}
|
||||
if (var2 < 0.0) {
|
||||
var2 = -var2;
|
||||
}
|
||||
return (var0 > var2) ? var0 : var2;
|
||||
}
|
||||
|
||||
public static int a(final int var0, final int var1)
|
||||
{
|
||||
return Math.floorDiv(var0, var1);
|
||||
}
|
||||
public static int a(final int var0, final int var1) {
|
||||
return Math.floorDiv(var0, var1);
|
||||
}
|
||||
|
||||
public static int nextInt(final Random var0, final int var1, final int var2)
|
||||
{
|
||||
if(var1 >= var2)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
public static int nextInt(final Random var0, final int var1, final int var2) {
|
||||
if (var1 >= var2) {
|
||||
return var1;
|
||||
}
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
|
||||
public static float a(final Random var0, final float var1, final float var2)
|
||||
{
|
||||
if(var1 >= var2)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
public static float a(final Random var0, final float var1, final float var2) {
|
||||
if (var1 >= var2) {
|
||||
return var1;
|
||||
}
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double a(final Random var0, final double var1, final double var3)
|
||||
{
|
||||
if(var1 >= var3)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
return var0.nextDouble() * (var3 - var1) + var1;
|
||||
}
|
||||
public static double a(final Random var0, final double var1, final double var3) {
|
||||
if (var1 >= var3) {
|
||||
return var1;
|
||||
}
|
||||
return var0.nextDouble() * (var3 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double a(final long[] var0)
|
||||
{
|
||||
long var = 0L;
|
||||
for(final long var2 : var0)
|
||||
{
|
||||
var += var2;
|
||||
}
|
||||
return var / (double) var0.length;
|
||||
}
|
||||
public static double a(final long[] var0) {
|
||||
long var = 0L;
|
||||
for (final long var2 : var0) {
|
||||
var += var2;
|
||||
}
|
||||
return var / (double) var0.length;
|
||||
}
|
||||
|
||||
public static boolean b(final double var0, final double var2)
|
||||
{
|
||||
return Math.abs(var2 - var0) < 9.999999747378752E-6;
|
||||
}
|
||||
public static boolean b(final double var0, final double var2) {
|
||||
return Math.abs(var2 - var0) < 9.999999747378752E-6;
|
||||
}
|
||||
|
||||
public static int b(final int var0, final int var1)
|
||||
{
|
||||
return Math.floorMod(var0, var1);
|
||||
}
|
||||
public static int b(final int var0, final int var1) {
|
||||
return Math.floorMod(var0, var1);
|
||||
}
|
||||
|
||||
public static float g(final float var0)
|
||||
{
|
||||
float var = var0 % 360.0f;
|
||||
if(var >= 180.0f)
|
||||
{
|
||||
var -= 360.0f;
|
||||
}
|
||||
if(var < -180.0f)
|
||||
{
|
||||
var += 360.0f;
|
||||
}
|
||||
return var;
|
||||
}
|
||||
public static float g(final float var0) {
|
||||
float var = var0 % 360.0f;
|
||||
if (var >= 180.0f) {
|
||||
var -= 360.0f;
|
||||
}
|
||||
if (var < -180.0f) {
|
||||
var += 360.0f;
|
||||
}
|
||||
return var;
|
||||
}
|
||||
|
||||
public static double g(final double var0)
|
||||
{
|
||||
double var = var0 % 360.0;
|
||||
if(var >= 180.0)
|
||||
{
|
||||
var -= 360.0;
|
||||
}
|
||||
if(var < -180.0)
|
||||
{
|
||||
var += 360.0;
|
||||
}
|
||||
return var;
|
||||
}
|
||||
public static double g(final double var0) {
|
||||
double var = var0 % 360.0;
|
||||
if (var >= 180.0) {
|
||||
var -= 360.0;
|
||||
}
|
||||
if (var < -180.0) {
|
||||
var += 360.0;
|
||||
}
|
||||
return var;
|
||||
}
|
||||
|
||||
public static float c(final float var0, final float var1)
|
||||
{
|
||||
return g(var1 - var0);
|
||||
}
|
||||
public static float c(final float var0, final float var1) {
|
||||
return g(var1 - var0);
|
||||
}
|
||||
|
||||
public static float d(final float var0, final float var1)
|
||||
{
|
||||
return e(c(var0, var1));
|
||||
}
|
||||
public static float d(final float var0, final float var1) {
|
||||
return e(c(var0, var1));
|
||||
}
|
||||
|
||||
public static float b(final float var0, final float var1, final float var2)
|
||||
{
|
||||
final float var3 = c(var0, var1);
|
||||
final float var4 = a(var3, -var2, var2);
|
||||
return var1 - var4;
|
||||
}
|
||||
public static float b(final float var0, final float var1, final float var2) {
|
||||
final float var3 = c(var0, var1);
|
||||
final float var4 = a(var3, -var2, var2);
|
||||
return var1 - var4;
|
||||
}
|
||||
|
||||
public static float c(final float var0, final float var1, float var2)
|
||||
{
|
||||
var2 = e(var2);
|
||||
if(var0 < var1)
|
||||
{
|
||||
return a(var0 + var2, var0, var1);
|
||||
}
|
||||
return a(var0 - var2, var1, var0);
|
||||
}
|
||||
public static float c(final float var0, final float var1, float var2) {
|
||||
var2 = e(var2);
|
||||
if (var0 < var1) {
|
||||
return a(var0 + var2, var0, var1);
|
||||
}
|
||||
return a(var0 - var2, var1, var0);
|
||||
}
|
||||
|
||||
public static float d(final float var0, final float var1, final float var2)
|
||||
{
|
||||
final float var3 = c(var0, var1);
|
||||
return c(var0, var0 + var3, var2);
|
||||
}
|
||||
public static float d(final float var0, final float var1, final float var2) {
|
||||
final float var3 = c(var0, var1);
|
||||
return c(var0, var0 + var3, var2);
|
||||
}
|
||||
|
||||
public static int c(final int var0)
|
||||
{
|
||||
int var = var0 - 1;
|
||||
var |= var >> 1;
|
||||
var |= var >> 2;
|
||||
var |= var >> 4;
|
||||
var |= var >> 8;
|
||||
var |= var >> 16;
|
||||
return var + 1;
|
||||
}
|
||||
public static int c(final int var0) {
|
||||
int var = var0 - 1;
|
||||
var |= var >> 1;
|
||||
var |= var >> 2;
|
||||
var |= var >> 4;
|
||||
var |= var >> 8;
|
||||
var |= var >> 16;
|
||||
return var + 1;
|
||||
}
|
||||
|
||||
public static boolean d(final int var0)
|
||||
{
|
||||
return var0 != 0 && (var0 & var0 - 1) == 0x0;
|
||||
}
|
||||
public static boolean d(final int var0) {
|
||||
return var0 != 0 && (var0 & var0 - 1) == 0x0;
|
||||
}
|
||||
|
||||
public static int e(int var0)
|
||||
{
|
||||
var0 = (d(var0) ? var0 : c(var0));
|
||||
return IrisMathHelper.d[(int) (var0 * 125613361L >> 27) & 0x1F];
|
||||
}
|
||||
public static int e(int var0) {
|
||||
var0 = (d(var0) ? var0 : c(var0));
|
||||
return IrisMathHelper.d[(int) (var0 * 125613361L >> 27) & 0x1F];
|
||||
}
|
||||
|
||||
public static int f(final int var0)
|
||||
{
|
||||
return e(var0) - (d(var0) ? 0 : 1);
|
||||
}
|
||||
public static int f(final int var0) {
|
||||
return e(var0) - (d(var0) ? 0 : 1);
|
||||
}
|
||||
|
||||
public static int c(final int var0, int var1)
|
||||
{
|
||||
if(var1 == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(var0 == 0)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
if(var0 < 0)
|
||||
{
|
||||
var1 *= -1;
|
||||
}
|
||||
final int var2 = var0 % var1;
|
||||
if(var2 == 0)
|
||||
{
|
||||
return var0;
|
||||
}
|
||||
return var0 + var1 - var2;
|
||||
}
|
||||
public static int c(final int var0, int var1) {
|
||||
if (var1 == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (var0 == 0) {
|
||||
return var1;
|
||||
}
|
||||
if (var0 < 0) {
|
||||
var1 *= -1;
|
||||
}
|
||||
final int var2 = var0 % var1;
|
||||
if (var2 == 0) {
|
||||
return var0;
|
||||
}
|
||||
return var0 + var1 - var2;
|
||||
}
|
||||
|
||||
public static float h(final float var0)
|
||||
{
|
||||
return var0 - d(var0);
|
||||
}
|
||||
public static float h(final float var0) {
|
||||
return var0 - d(var0);
|
||||
}
|
||||
|
||||
public static double h(final double var0)
|
||||
{
|
||||
return var0 - d(var0);
|
||||
}
|
||||
public static double h(final double var0) {
|
||||
return var0 - d(var0);
|
||||
}
|
||||
|
||||
public static long c(final int var0, final int var1, final int var2)
|
||||
{
|
||||
long var3 = (long) (var0 * 3129871) ^ var2 * 116129781L ^ (long) var1;
|
||||
var3 = var3 * var3 * 42317861L + var3 * 11L;
|
||||
return var3 >> 16;
|
||||
}
|
||||
public static long c(final int var0, final int var1, final int var2) {
|
||||
long var3 = (long) (var0 * 3129871) ^ var2 * 116129781L ^ (long) var1;
|
||||
var3 = var3 * var3 * 42317861L + var3 * 11L;
|
||||
return var3 >> 16;
|
||||
}
|
||||
|
||||
public static UUID a(final Random var0)
|
||||
{
|
||||
final long var = (var0.nextLong() & 0xFFFFFFFFFFFF0FFFL) | 0x4000L;
|
||||
final long var2 = (var0.nextLong() & 0x3FFFFFFFFFFFFFFFL) | Long.MIN_VALUE;
|
||||
return new UUID(var, var2);
|
||||
}
|
||||
public static UUID a(final Random var0) {
|
||||
final long var = (var0.nextLong() & 0xFFFFFFFFFFFF0FFFL) | 0x4000L;
|
||||
final long var2 = (var0.nextLong() & 0x3FFFFFFFFFFFFFFFL) | Long.MIN_VALUE;
|
||||
return new UUID(var, var2);
|
||||
}
|
||||
|
||||
public static UUID a()
|
||||
{
|
||||
return a(IrisMathHelper.c);
|
||||
}
|
||||
public static UUID a() {
|
||||
return a(IrisMathHelper.c);
|
||||
}
|
||||
|
||||
public static double c(final double var0, final double var2, final double var4)
|
||||
{
|
||||
return (var0 - var2) / (var4 - var2);
|
||||
}
|
||||
public static double c(final double var0, final double var2, final double var4) {
|
||||
return (var0 - var2) / (var4 - var2);
|
||||
}
|
||||
|
||||
public static double d(double var0, double var2)
|
||||
{
|
||||
final double var3 = var2 * var2 + var0 * var0;
|
||||
if(Double.isNaN(var3))
|
||||
{
|
||||
return Double.NaN;
|
||||
}
|
||||
final boolean var4 = var0 < 0.0;
|
||||
if(var4)
|
||||
{
|
||||
var0 = -var0;
|
||||
}
|
||||
final boolean var5 = var2 < 0.0;
|
||||
if(var5)
|
||||
{
|
||||
var2 = -var2;
|
||||
}
|
||||
final boolean var6 = var0 > var2;
|
||||
if(var6)
|
||||
{
|
||||
final double var7 = var2;
|
||||
var2 = var0;
|
||||
var0 = var7;
|
||||
}
|
||||
final double var7 = i(var3);
|
||||
var2 *= var7;
|
||||
var0 *= var7;
|
||||
final double var8 = IrisMathHelper.e + var0;
|
||||
final int var9 = (int) Double.doubleToRawLongBits(var8);
|
||||
final double var10 = IrisMathHelper.f[var9];
|
||||
final double var11 = IrisMathHelper.g[var9];
|
||||
final double var12 = var8 - IrisMathHelper.e;
|
||||
final double var13 = var0 * var11 - var2 * var12;
|
||||
final double var14 = (6.0 + var13 * var13) * var13 * 0.16666666666666666;
|
||||
double var15 = var10 + var14;
|
||||
if(var6)
|
||||
{
|
||||
var15 = 1.5707963267948966 - var15;
|
||||
}
|
||||
if(var5)
|
||||
{
|
||||
var15 = 3.141592653589793 - var15;
|
||||
}
|
||||
if(var4)
|
||||
{
|
||||
var15 = -var15;
|
||||
}
|
||||
return var15;
|
||||
}
|
||||
public static double d(double var0, double var2) {
|
||||
final double var3 = var2 * var2 + var0 * var0;
|
||||
if (Double.isNaN(var3)) {
|
||||
return Double.NaN;
|
||||
}
|
||||
final boolean var4 = var0 < 0.0;
|
||||
if (var4) {
|
||||
var0 = -var0;
|
||||
}
|
||||
final boolean var5 = var2 < 0.0;
|
||||
if (var5) {
|
||||
var2 = -var2;
|
||||
}
|
||||
final boolean var6 = var0 > var2;
|
||||
if (var6) {
|
||||
final double var7 = var2;
|
||||
var2 = var0;
|
||||
var0 = var7;
|
||||
}
|
||||
final double var7 = i(var3);
|
||||
var2 *= var7;
|
||||
var0 *= var7;
|
||||
final double var8 = IrisMathHelper.e + var0;
|
||||
final int var9 = (int) Double.doubleToRawLongBits(var8);
|
||||
final double var10 = IrisMathHelper.f[var9];
|
||||
final double var11 = IrisMathHelper.g[var9];
|
||||
final double var12 = var8 - IrisMathHelper.e;
|
||||
final double var13 = var0 * var11 - var2 * var12;
|
||||
final double var14 = (6.0 + var13 * var13) * var13 * 0.16666666666666666;
|
||||
double var15 = var10 + var14;
|
||||
if (var6) {
|
||||
var15 = 1.5707963267948966 - var15;
|
||||
}
|
||||
if (var5) {
|
||||
var15 = 3.141592653589793 - var15;
|
||||
}
|
||||
if (var4) {
|
||||
var15 = -var15;
|
||||
}
|
||||
return var15;
|
||||
}
|
||||
|
||||
public static double i(double var0)
|
||||
{
|
||||
final double var = 0.5 * var0;
|
||||
long var2 = Double.doubleToRawLongBits(var0);
|
||||
var2 = 6910469410427058090L - (var2 >> 1);
|
||||
var0 = Double.longBitsToDouble(var2);
|
||||
var0 *= 1.5 - var * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
public static double i(double var0) {
|
||||
final double var = 0.5 * var0;
|
||||
long var2 = Double.doubleToRawLongBits(var0);
|
||||
var2 = 6910469410427058090L - (var2 >> 1);
|
||||
var0 = Double.longBitsToDouble(var2);
|
||||
var0 *= 1.5 - var * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int f(final float var0, final float var1, final float var2)
|
||||
{
|
||||
final int var3 = (int) (var0 * 6.0f) % 6;
|
||||
final float var4 = var0 * 6.0f - var3;
|
||||
final float var5 = var2 * (1.0f - var1);
|
||||
final float var6 = var2 * (1.0f - var4 * var1);
|
||||
final float var7 = var2 * (1.0f - (1.0f - var4) * var1);
|
||||
float var8 = 0.0f;
|
||||
float var9 = 0.0f;
|
||||
float var10 = 0.0f;
|
||||
switch(var3)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
var8 = var2;
|
||||
var9 = var7;
|
||||
var10 = var5;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
var8 = var6;
|
||||
var9 = var2;
|
||||
var10 = var5;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
var8 = var5;
|
||||
var9 = var2;
|
||||
var10 = var7;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
var8 = var5;
|
||||
var9 = var6;
|
||||
var10 = var2;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
var8 = var7;
|
||||
var9 = var5;
|
||||
var10 = var2;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
var8 = var2;
|
||||
var9 = var5;
|
||||
var10 = var6;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
|
||||
}
|
||||
}
|
||||
final int var11 = clamp((int) (var8 * 255.0f), 0, 255);
|
||||
final int var12 = clamp((int) (var9 * 255.0f), 0, 255);
|
||||
final int var13 = clamp((int) (var10 * 255.0f), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
}
|
||||
public static int f(final float var0, final float var1, final float var2) {
|
||||
final int var3 = (int) (var0 * 6.0f) % 6;
|
||||
final float var4 = var0 * 6.0f - var3;
|
||||
final float var5 = var2 * (1.0f - var1);
|
||||
final float var6 = var2 * (1.0f - var4 * var1);
|
||||
final float var7 = var2 * (1.0f - (1.0f - var4) * var1);
|
||||
float var8 = 0.0f;
|
||||
float var9 = 0.0f;
|
||||
float var10 = 0.0f;
|
||||
switch (var3) {
|
||||
case 0: {
|
||||
var8 = var2;
|
||||
var9 = var7;
|
||||
var10 = var5;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
var8 = var6;
|
||||
var9 = var2;
|
||||
var10 = var5;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
var8 = var5;
|
||||
var9 = var2;
|
||||
var10 = var7;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
var8 = var5;
|
||||
var9 = var6;
|
||||
var10 = var2;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
var8 = var7;
|
||||
var9 = var5;
|
||||
var10 = var2;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
var8 = var2;
|
||||
var9 = var5;
|
||||
var10 = var6;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
|
||||
}
|
||||
}
|
||||
final int var11 = clamp((int) (var8 * 255.0f), 0, 255);
|
||||
final int var12 = clamp((int) (var9 * 255.0f), 0, 255);
|
||||
final int var13 = clamp((int) (var10 * 255.0f), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
}
|
||||
|
||||
public static int g(int var0)
|
||||
{
|
||||
var0 ^= var0 >>> 16;
|
||||
var0 *= -2048144789;
|
||||
var0 ^= var0 >>> 13;
|
||||
var0 *= -1028477387;
|
||||
var0 ^= var0 >>> 16;
|
||||
return var0;
|
||||
}
|
||||
public static int g(int var0) {
|
||||
var0 ^= var0 >>> 16;
|
||||
var0 *= -2048144789;
|
||||
var0 ^= var0 >>> 13;
|
||||
var0 *= -1028477387;
|
||||
var0 ^= var0 >>> 16;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int a(int var0, final int var1, final IntPredicate var2)
|
||||
{
|
||||
int var3 = var1 - var0;
|
||||
while(var3 > 0)
|
||||
{
|
||||
final int var4 = var3 / 2;
|
||||
final int var5 = var0 + var4;
|
||||
if(var2.test(var5))
|
||||
{
|
||||
var3 = var4;
|
||||
}
|
||||
else
|
||||
{
|
||||
var0 = var5 + 1;
|
||||
var3 -= var4 + 1;
|
||||
}
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
public static int a(int var0, final int var1, final IntPredicate var2) {
|
||||
int var3 = var1 - var0;
|
||||
while (var3 > 0) {
|
||||
final int var4 = var3 / 2;
|
||||
final int var5 = var0 + var4;
|
||||
if (var2.test(var5)) {
|
||||
var3 = var4;
|
||||
} else {
|
||||
var0 = var5 + 1;
|
||||
var3 -= var4 + 1;
|
||||
}
|
||||
}
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float g(final float var0, final float var1, final float var2)
|
||||
{
|
||||
return var1 + var0 * (var2 - var1);
|
||||
}
|
||||
public static float g(final float var0, final float var1, final float var2) {
|
||||
return var1 + var0 * (var2 - var1);
|
||||
}
|
||||
|
||||
public static double d(final double var0, final double var2, final double var4)
|
||||
{
|
||||
return var2 + var0 * (var4 - var2);
|
||||
}
|
||||
public static double d(final double var0, final double var2, final double var4) {
|
||||
return var2 + var0 * (var4 - var2);
|
||||
}
|
||||
|
||||
public static double a(final double var0, final double var2, final double var4, final double var6, final double var8, final double var10)
|
||||
{
|
||||
return d(var2, d(var0, var4, var6), d(var0, var8, var10));
|
||||
}
|
||||
public static double a(final double var0, final double var2, final double var4, final double var6, final double var8, final double var10) {
|
||||
return d(var2, d(var0, var4, var6), d(var0, var8, var10));
|
||||
}
|
||||
|
||||
public static double a(final double var0, final double var2, final double var4, final double var6, final double var8, final double var10, final double var12, final double var14, final double var16, final double var18, final double var20)
|
||||
{
|
||||
return d(var4, a(var0, var2, var6, var8, var10, var12), a(var0, var2, var14, var16, var18, var20));
|
||||
}
|
||||
public static double a(final double var0, final double var2, final double var4, final double var6, final double var8, final double var10, final double var12, final double var14, final double var16, final double var18, final double var20) {
|
||||
return d(var4, a(var0, var2, var6, var8, var10, var12), a(var0, var2, var14, var16, var18, var20));
|
||||
}
|
||||
|
||||
public static double j(final double var0)
|
||||
{
|
||||
return var0 * var0 * var0 * (var0 * (var0 * 6.0 - 15.0) + 10.0);
|
||||
}
|
||||
public static double j(final double var0) {
|
||||
return var0 * var0 * var0 * (var0 * (var0 * 6.0 - 15.0) + 10.0);
|
||||
}
|
||||
|
||||
public static int k(final double var0)
|
||||
{
|
||||
if(var0 == 0.0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (var0 > 0.0) ? 1 : -1;
|
||||
}
|
||||
public static int k(final double var0) {
|
||||
if (var0 == 0.0) {
|
||||
return 0;
|
||||
}
|
||||
return (var0 > 0.0) ? 1 : -1;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float j(final float var0, final float var1, final float var2)
|
||||
{
|
||||
float var3;
|
||||
for(var3 = var1 - var0; var3 < -180.0f; var3 += 360.0f)
|
||||
{
|
||||
}
|
||||
while(var3 >= 180.0f)
|
||||
{
|
||||
var3 -= 360.0f;
|
||||
}
|
||||
return var0 + var2 * var3;
|
||||
}
|
||||
@Deprecated
|
||||
public static float j(final float var0, final float var1, final float var2) {
|
||||
float var3;
|
||||
for (var3 = var1 - var0; var3 < -180.0f; var3 += 360.0f) {
|
||||
}
|
||||
while (var3 >= 180.0f) {
|
||||
var3 -= 360.0f;
|
||||
}
|
||||
return var0 + var2 * var3;
|
||||
}
|
||||
|
||||
public static float k(final float var0)
|
||||
{
|
||||
return var0 * var0;
|
||||
}
|
||||
public static float k(final float var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
a = c(2.0f);
|
||||
c = new Random();
|
||||
d = new int[] {0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
e = Double.longBitsToDouble(4805340802404319232L);
|
||||
f = new double[257];
|
||||
g = new double[257];
|
||||
for(int var2 = 0; var2 < 257; ++var2)
|
||||
{
|
||||
final double var3 = var2 / 256.0;
|
||||
final double var4 = Math.asin(var3);
|
||||
IrisMathHelper.g[var2] = Math.cos(var4);
|
||||
IrisMathHelper.f[var2] = var4;
|
||||
}
|
||||
}
|
||||
static {
|
||||
a = c(2.0f);
|
||||
c = new Random();
|
||||
d = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
e = Double.longBitsToDouble(4805340802404319232L);
|
||||
f = new double[257];
|
||||
g = new double[257];
|
||||
for (int var2 = 0; var2 < 257; ++var2) {
|
||||
final double var3 = var2 / 256.0;
|
||||
final double var4 = Math.asin(var3);
|
||||
IrisMathHelper.g[var2] = Math.cos(var4);
|
||||
IrisMathHelper.f[var2] = var4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,384 +8,295 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class J
|
||||
{
|
||||
private static int tid = 0;
|
||||
private static final ExecutorService e = Executors.newCachedThreadPool(new ThreadFactory()
|
||||
{
|
||||
@Override
|
||||
public Thread newThread(Runnable r)
|
||||
{
|
||||
tid++;
|
||||
Thread t = new Thread(r);
|
||||
t.setName("Iris Actuator " + tid);
|
||||
t.setPriority(8);
|
||||
t.setUncaughtExceptionHandler((et, e) ->
|
||||
{
|
||||
Iris.info("Exception encountered in " + et.getName());
|
||||
e.printStackTrace();
|
||||
});
|
||||
public class J {
|
||||
private static int tid = 0;
|
||||
private static final ExecutorService e = Executors.newCachedThreadPool(new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
tid++;
|
||||
Thread t = new Thread(r);
|
||||
t.setName("Iris Actuator " + tid);
|
||||
t.setPriority(8);
|
||||
t.setUncaughtExceptionHandler((et, e) ->
|
||||
{
|
||||
Iris.info("Exception encountered in " + et.getName());
|
||||
e.printStackTrace();
|
||||
});
|
||||
|
||||
return t;
|
||||
}
|
||||
});
|
||||
return t;
|
||||
}
|
||||
});
|
||||
|
||||
public static void dofor(int a, Function<Integer, Boolean> c, int ch, Consumer<Integer> d)
|
||||
{
|
||||
for(int i = a; c.apply(i); i += ch)
|
||||
{
|
||||
c.apply(i);
|
||||
}
|
||||
}
|
||||
public static void dofor(int a, Function<Integer, Boolean> c, int ch, Consumer<Integer> d) {
|
||||
for (int i = a; c.apply(i); i += ch) {
|
||||
c.apply(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean doif(Supplier<Boolean> c, Runnable g)
|
||||
{
|
||||
try {
|
||||
if (c.get()) {
|
||||
g.run();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
// TODO: Fix this because this is just a suppression for an NPE on g
|
||||
return false;
|
||||
}
|
||||
public static boolean doif(Supplier<Boolean> c, Runnable g) {
|
||||
try {
|
||||
if (c.get()) {
|
||||
g.run();
|
||||
return true;
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
// TODO: Fix this because this is just a suppression for an NPE on g
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void arun(Runnable a)
|
||||
{
|
||||
e.submit(() -> {
|
||||
try
|
||||
{
|
||||
a.run();
|
||||
}
|
||||
public static void arun(Runnable a) {
|
||||
e.submit(() -> {
|
||||
try {
|
||||
a.run();
|
||||
} catch (Throwable e) {
|
||||
System.out.println("Failed to run async task");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
System.out.println("Failed to run async task");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void a(Runnable a) {
|
||||
e.submit(() -> {
|
||||
try {
|
||||
a.run();
|
||||
} catch (Throwable e) {
|
||||
System.out.println("Failed to run async task");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void a(Runnable a)
|
||||
{
|
||||
e.submit(() -> {
|
||||
try
|
||||
{
|
||||
a.run();
|
||||
}
|
||||
public static <T> Future<T> a(Callable<T> a) {
|
||||
return e.submit(a);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
System.out.println("Failed to run async task");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void attemptAsync(NastyRunnable r) {
|
||||
J.a(() -> J.attempt(r));
|
||||
}
|
||||
|
||||
public static <T> Future<T> a(Callable<T> a)
|
||||
{
|
||||
return e.submit(a);
|
||||
}
|
||||
public static <R> R attemptResult(NastyFuture<R> r, R onError) {
|
||||
try {
|
||||
return r.run();
|
||||
} catch (Throwable e) {
|
||||
|
||||
public static void attemptAsync(NastyRunnable r)
|
||||
{
|
||||
J.a(() -> J.attempt(r));
|
||||
}
|
||||
}
|
||||
|
||||
public static <R> R attemptResult(NastyFuture<R> r, R onError)
|
||||
{
|
||||
try
|
||||
{
|
||||
return r.run();
|
||||
}
|
||||
return onError;
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
public static <T, R> R attemptFunction(NastyFunction<T, R> r, T param, R onError) {
|
||||
try {
|
||||
return r.run(param);
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return onError;
|
||||
}
|
||||
return onError;
|
||||
}
|
||||
|
||||
public static <T, R> R attemptFunction(NastyFunction<T, R> r, T param, R onError)
|
||||
{
|
||||
try
|
||||
{
|
||||
return r.run(param);
|
||||
}
|
||||
public static boolean sleep(long ms) {
|
||||
return J.attempt(() -> Thread.sleep(ms));
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
public static boolean attempt(NastyRunnable r) {
|
||||
return attemptCatch(r) == null;
|
||||
}
|
||||
|
||||
}
|
||||
public static Throwable attemptCatch(NastyRunnable r) {
|
||||
try {
|
||||
r.run();
|
||||
} catch (Throwable e) {
|
||||
return e;
|
||||
}
|
||||
|
||||
return onError;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean sleep(long ms)
|
||||
{
|
||||
return J.attempt(() -> Thread.sleep(ms));
|
||||
}
|
||||
public static <T> T attempt(Supplier<T> t, T i) {
|
||||
try {
|
||||
return t.get();
|
||||
} catch (Throwable e) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean attempt(NastyRunnable r)
|
||||
{
|
||||
return attemptCatch(r) == null;
|
||||
}
|
||||
private static KList<Runnable> afterStartup = new KList<>();
|
||||
private static KList<Runnable> afterStartupAsync = new KList<>();
|
||||
private static boolean started = false;
|
||||
|
||||
public static Throwable attemptCatch(NastyRunnable r)
|
||||
{
|
||||
try
|
||||
{
|
||||
r.run();
|
||||
}
|
||||
/**
|
||||
* Dont call this unless you know what you are doing!
|
||||
*/
|
||||
public static void executeAfterStartupQueue() {
|
||||
if (started) {
|
||||
return;
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
return e;
|
||||
}
|
||||
started = true;
|
||||
|
||||
return null;
|
||||
}
|
||||
for (Runnable r : afterStartup) {
|
||||
s(r);
|
||||
}
|
||||
|
||||
public static <T> T attempt(Supplier<T> t, T i)
|
||||
{
|
||||
try
|
||||
{
|
||||
return t.get();
|
||||
}
|
||||
for (Runnable r : afterStartupAsync) {
|
||||
a(r);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
afterStartup = null;
|
||||
afterStartupAsync = null;
|
||||
}
|
||||
|
||||
private static KList<Runnable> afterStartup = new KList<>();
|
||||
private static KList<Runnable> afterStartupAsync = new KList<>();
|
||||
private static boolean started = false;
|
||||
/**
|
||||
* Schedule a sync task to be run right after startup. If the server has already
|
||||
* started ticking, it will simply run it in a sync task.
|
||||
* <p>
|
||||
* If you dont know if you should queue this or not, do so, it's pretty
|
||||
* forgiving.
|
||||
*
|
||||
* @param r the runnable
|
||||
*/
|
||||
public static void ass(Runnable r) {
|
||||
if (started) {
|
||||
s(r);
|
||||
} else {
|
||||
afterStartup.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dont call this unless you know what you are doing!
|
||||
*/
|
||||
public static void executeAfterStartupQueue()
|
||||
{
|
||||
if(started)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Schedule an async task to be run right after startup. If the server has
|
||||
* already started ticking, it will simply run it in an async task.
|
||||
* <p>
|
||||
* If you dont know if you should queue this or not, do so, it's pretty
|
||||
* forgiving.
|
||||
*
|
||||
* @param r the runnable
|
||||
*/
|
||||
public static void asa(Runnable r) {
|
||||
if (started) {
|
||||
a(r);
|
||||
} else {
|
||||
afterStartupAsync.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
started = true;
|
||||
/**
|
||||
* Queue a sync task
|
||||
*
|
||||
* @param r the runnable
|
||||
*/
|
||||
public static void s(Runnable r) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r);
|
||||
}
|
||||
|
||||
for(Runnable r : afterStartup)
|
||||
{
|
||||
s(r);
|
||||
}
|
||||
/**
|
||||
* Queue a sync task
|
||||
*
|
||||
* @param r the runnable
|
||||
* @param delay the delay to wait in ticks before running
|
||||
*/
|
||||
public static void s(Runnable r, int delay) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r, delay);
|
||||
}
|
||||
|
||||
for(Runnable r : afterStartupAsync)
|
||||
{
|
||||
a(r);
|
||||
}
|
||||
/**
|
||||
* Cancel a sync repeating task
|
||||
*
|
||||
* @param id the task id
|
||||
*/
|
||||
public static void csr(int id) {
|
||||
Bukkit.getScheduler().cancelTask(id);
|
||||
}
|
||||
|
||||
afterStartup = null;
|
||||
afterStartupAsync = null;
|
||||
}
|
||||
/**
|
||||
* Start a sync repeating task
|
||||
*
|
||||
* @param r the runnable
|
||||
* @param interval the interval
|
||||
* @return the task id
|
||||
*/
|
||||
public static int sr(Runnable r, int interval) {
|
||||
return Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, r, 0, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a sync task to be run right after startup. If the server has already
|
||||
* started ticking, it will simply run it in a sync task.
|
||||
*
|
||||
* If you dont know if you should queue this or not, do so, it's pretty
|
||||
* forgiving.
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
*/
|
||||
public static void ass(Runnable r)
|
||||
{
|
||||
if(started)
|
||||
{
|
||||
s(r);
|
||||
}
|
||||
/**
|
||||
* Start a sync repeating task for a limited amount of ticks
|
||||
*
|
||||
* @param r the runnable
|
||||
* @param interval the interval in ticks
|
||||
* @param intervals the maximum amount of intervals to run
|
||||
*/
|
||||
public static void sr(Runnable r, int interval, int intervals) {
|
||||
FinalInteger fi = new FinalInteger(0);
|
||||
|
||||
else
|
||||
{
|
||||
afterStartup.add(r);
|
||||
}
|
||||
}
|
||||
new SR() {
|
||||
@Override
|
||||
public void run() {
|
||||
fi.add(1);
|
||||
r.run();
|
||||
|
||||
/**
|
||||
* Schedule an async task to be run right after startup. If the server has
|
||||
* already started ticking, it will simply run it in an async task.
|
||||
*
|
||||
* If you dont know if you should queue this or not, do so, it's pretty
|
||||
* forgiving.
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
*/
|
||||
public static void asa(Runnable r)
|
||||
{
|
||||
if(started)
|
||||
{
|
||||
a(r);
|
||||
}
|
||||
if (fi.get() >= intervals) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
afterStartupAsync.add(r);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Call an async task dealyed
|
||||
*
|
||||
* @param r the runnable
|
||||
* @param delay the delay to wait before running
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void a(Runnable r, int delay) {
|
||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(Iris.instance, r, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a sync task
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
*/
|
||||
public static void s(Runnable r)
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r);
|
||||
}
|
||||
/**
|
||||
* Cancel an async repeat task
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public static void car(int id) {
|
||||
Bukkit.getScheduler().cancelTask(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a sync task
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
* @param delay
|
||||
* the delay to wait in ticks before running
|
||||
*/
|
||||
public static void s(Runnable r, int delay)
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r, delay);
|
||||
}
|
||||
/**
|
||||
* Start an async repeat task
|
||||
*
|
||||
* @param r the runnable
|
||||
* @param interval the interval in ticks
|
||||
* @return the task id
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static int ar(Runnable r, int interval) {
|
||||
return Bukkit.getScheduler().scheduleAsyncRepeatingTask(Iris.instance, r, 0, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel a sync repeating task
|
||||
*
|
||||
* @param id
|
||||
* the task id
|
||||
*/
|
||||
public static void csr(int id)
|
||||
{
|
||||
Bukkit.getScheduler().cancelTask(id);
|
||||
}
|
||||
/**
|
||||
* Start an async repeating task for a limited time
|
||||
*
|
||||
* @param r the runnable
|
||||
* @param interval the interval
|
||||
* @param intervals the intervals to run
|
||||
*/
|
||||
public static void ar(Runnable r, int interval, int intervals) {
|
||||
FinalInteger fi = new FinalInteger(0);
|
||||
|
||||
/**
|
||||
* Start a sync repeating task
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
* @param interval
|
||||
* the interval
|
||||
* @return the task id
|
||||
*/
|
||||
public static int sr(Runnable r, int interval)
|
||||
{
|
||||
return Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, r, 0, interval);
|
||||
}
|
||||
new AR() {
|
||||
@Override
|
||||
public void run() {
|
||||
fi.add(1);
|
||||
r.run();
|
||||
|
||||
/**
|
||||
* Start a sync repeating task for a limited amount of ticks
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
* @param interval
|
||||
* the interval in ticks
|
||||
* @param intervals
|
||||
* the maximum amount of intervals to run
|
||||
*/
|
||||
public static void sr(Runnable r, int interval, int intervals)
|
||||
{
|
||||
FinalInteger fi = new FinalInteger(0);
|
||||
|
||||
new SR()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
fi.add(1);
|
||||
r.run();
|
||||
|
||||
if(fi.get() >= intervals)
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Call an async task dealyed
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
* @param delay
|
||||
* the delay to wait before running
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void a(Runnable r, int delay)
|
||||
{
|
||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(Iris.instance, r, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel an async repeat task
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
public static void car(int id)
|
||||
{
|
||||
Bukkit.getScheduler().cancelTask(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an async repeat task
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
* @param interval
|
||||
* the interval in ticks
|
||||
* @return the task id
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static int ar(Runnable r, int interval)
|
||||
{
|
||||
return Bukkit.getScheduler().scheduleAsyncRepeatingTask(Iris.instance, r, 0, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an async repeating task for a limited time
|
||||
*
|
||||
* @param r
|
||||
* the runnable
|
||||
* @param interval
|
||||
* the interval
|
||||
* @param intervals
|
||||
* the intervals to run
|
||||
*/
|
||||
public static void ar(Runnable r, int interval, int intervals)
|
||||
{
|
||||
FinalInteger fi = new FinalInteger(0);
|
||||
|
||||
new AR()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
fi.add(1);
|
||||
r.run();
|
||||
|
||||
if(fi.get() >= intervals)
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
if (fi.get() >= intervals) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,44 +7,38 @@ package com.volmit.iris.util;
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
*/
|
||||
public class JSONException extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 0;
|
||||
private Throwable cause;
|
||||
|
||||
/**
|
||||
* Constructs a JSONException with an explanatory message.
|
||||
*
|
||||
* @param message
|
||||
* Detail about the reason for the exception.
|
||||
*/
|
||||
public JSONException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new JSONException with the specified cause.
|
||||
*
|
||||
* @param cause
|
||||
* The cause.
|
||||
*/
|
||||
public JSONException(Throwable cause)
|
||||
{
|
||||
super(cause.getMessage());
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception or null if the cause is nonexistent
|
||||
* or unknown.
|
||||
*
|
||||
* @return the cause of this exception or null if the cause is nonexistent
|
||||
* or unknown.
|
||||
*/
|
||||
@Override
|
||||
public Throwable getCause()
|
||||
{
|
||||
return this.cause;
|
||||
}
|
||||
public class JSONException extends RuntimeException {
|
||||
private static final long serialVersionUID = 0;
|
||||
private Throwable cause;
|
||||
|
||||
/**
|
||||
* Constructs a JSONException with an explanatory message.
|
||||
*
|
||||
* @param message Detail about the reason for the exception.
|
||||
*/
|
||||
public JSONException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new JSONException with the specified cause.
|
||||
*
|
||||
* @param cause The cause.
|
||||
*/
|
||||
public JSONException(Throwable cause) {
|
||||
super(cause.getMessage());
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this exception or null if the cause is nonexistent
|
||||
* or unknown.
|
||||
*
|
||||
* @return the cause of this exception or null if the cause is nonexistent
|
||||
* or unknown.
|
||||
*/
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
return this.cause;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,521 +35,428 @@ import java.util.Iterator;
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
*/
|
||||
public class JSONML
|
||||
{
|
||||
|
||||
/**
|
||||
* Parse XML values and store them in a JSONArray.
|
||||
*
|
||||
* @param x
|
||||
* The XMLTokener containing the source string.
|
||||
* @param arrayForm
|
||||
* true if array form, false if object form.
|
||||
* @param ja
|
||||
* The JSONArray that is containing the current tag or null if we
|
||||
* are at the outermost level.
|
||||
* @return A JSONArray if the value is the outermost tag, otherwise null.
|
||||
* @throws JSONException
|
||||
*/
|
||||
private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja) throws JSONException
|
||||
{
|
||||
String attribute;
|
||||
char c;
|
||||
String closeTag = null;
|
||||
int i;
|
||||
JSONArray newja = null;
|
||||
JSONObject newjo = null;
|
||||
Object token;
|
||||
String tagName = null;
|
||||
|
||||
// Test for and skip past these forms:
|
||||
// <!-- ... -->
|
||||
// <![ ... ]]>
|
||||
// <! ... >
|
||||
// <? ... ?>
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(!x.more())
|
||||
{
|
||||
throw x.syntaxError("Bad XML");
|
||||
}
|
||||
token = x.nextContent();
|
||||
if(token == XML.LT)
|
||||
{
|
||||
token = x.nextToken();
|
||||
if(token instanceof Character)
|
||||
{
|
||||
if(token == XML.SLASH)
|
||||
{
|
||||
|
||||
// Close tag </
|
||||
|
||||
token = x.nextToken();
|
||||
if(!(token instanceof String))
|
||||
{
|
||||
throw new JSONException("Expected a closing name instead of '" + token + "'.");
|
||||
}
|
||||
if(x.nextToken() != XML.GT)
|
||||
{
|
||||
throw x.syntaxError("Misshaped close tag");
|
||||
}
|
||||
return token;
|
||||
} else if(token == XML.BANG)
|
||||
{
|
||||
|
||||
// <!
|
||||
|
||||
c = x.next();
|
||||
if(c == '-')
|
||||
{
|
||||
if(x.next() == '-')
|
||||
{
|
||||
x.skipPast("-->");
|
||||
} else
|
||||
{
|
||||
x.back();
|
||||
}
|
||||
} else if(c == '[')
|
||||
{
|
||||
token = x.nextToken();
|
||||
if(token.equals("CDATA") && x.next() == '[')
|
||||
{
|
||||
if(ja != null)
|
||||
{
|
||||
ja.put(x.nextCDATA());
|
||||
}
|
||||
} else
|
||||
{
|
||||
throw x.syntaxError("Expected 'CDATA['");
|
||||
}
|
||||
} else
|
||||
{
|
||||
i = 1;
|
||||
do
|
||||
{
|
||||
token = x.nextMeta();
|
||||
if(token == null)
|
||||
{
|
||||
throw x.syntaxError("Missing '>' after '<!'.");
|
||||
} else if(token == XML.LT)
|
||||
{
|
||||
i += 1;
|
||||
} else if(token == XML.GT)
|
||||
{
|
||||
i -= 1;
|
||||
}
|
||||
} while(i > 0);
|
||||
}
|
||||
} else if(token == XML.QUEST)
|
||||
{
|
||||
|
||||
// <?
|
||||
|
||||
x.skipPast("?>");
|
||||
} else
|
||||
{
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
|
||||
// Open tag <
|
||||
|
||||
} else
|
||||
{
|
||||
if(!(token instanceof String))
|
||||
{
|
||||
throw x.syntaxError("Bad tagName '" + token + "'.");
|
||||
}
|
||||
tagName = (String) token;
|
||||
newja = new JSONArray();
|
||||
newjo = new JSONObject();
|
||||
if(arrayForm)
|
||||
{
|
||||
newja.put(tagName);
|
||||
if(ja != null)
|
||||
{
|
||||
ja.put(newja);
|
||||
}
|
||||
} else
|
||||
{
|
||||
newjo.put("tagName", tagName);
|
||||
if(ja != null)
|
||||
{
|
||||
ja.put(newjo);
|
||||
}
|
||||
}
|
||||
token = null;
|
||||
for(;;)
|
||||
{
|
||||
if(token == null)
|
||||
{
|
||||
token = x.nextToken();
|
||||
}
|
||||
if(token == null)
|
||||
{
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
if(!(token instanceof String))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// attribute = value
|
||||
|
||||
attribute = (String) token;
|
||||
if(!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute)))
|
||||
{
|
||||
throw x.syntaxError("Reserved attribute.");
|
||||
}
|
||||
token = x.nextToken();
|
||||
if(token == XML.EQ)
|
||||
{
|
||||
token = x.nextToken();
|
||||
if(!(token instanceof String))
|
||||
{
|
||||
throw x.syntaxError("Missing value");
|
||||
}
|
||||
newjo.accumulate(attribute, XML.stringToValue((String) token));
|
||||
token = null;
|
||||
} else
|
||||
{
|
||||
newjo.accumulate(attribute, "");
|
||||
}
|
||||
}
|
||||
if(arrayForm && newjo.length() > 0)
|
||||
{
|
||||
newja.put(newjo);
|
||||
}
|
||||
|
||||
// Empty tag <.../>
|
||||
|
||||
if(token == XML.SLASH)
|
||||
{
|
||||
if(x.nextToken() != XML.GT)
|
||||
{
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
if(ja == null)
|
||||
{
|
||||
if(arrayForm)
|
||||
{
|
||||
return newja;
|
||||
} else
|
||||
{
|
||||
return newjo;
|
||||
}
|
||||
}
|
||||
|
||||
// Content, between <...> and </...>
|
||||
|
||||
} else
|
||||
{
|
||||
if(token != XML.GT)
|
||||
{
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
closeTag = (String) parse(x, arrayForm, newja);
|
||||
if(closeTag != null)
|
||||
{
|
||||
if(!closeTag.equals(tagName))
|
||||
{
|
||||
throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'");
|
||||
}
|
||||
tagName = null;
|
||||
if(!arrayForm && newja.length() > 0)
|
||||
{
|
||||
newjo.put("childNodes", newja);
|
||||
}
|
||||
if(ja == null)
|
||||
{
|
||||
if(arrayForm)
|
||||
{
|
||||
return newja;
|
||||
} else
|
||||
{
|
||||
return newjo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if(ja != null)
|
||||
{
|
||||
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONArray using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONArray in which the first element is the tag name. If the tag has
|
||||
* attributes, then the second element will be JSONObject containing the
|
||||
* name/value pairs. If the tag contains children, then strings and
|
||||
* JSONArrays will represent the child tags. Comments, prologs, DTDs, and
|
||||
* <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param string
|
||||
* The source string.
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(String string) throws JSONException
|
||||
{
|
||||
return toJSONArray(new XMLTokener(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONArray using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONArray in which the first element is the tag name. If the tag has
|
||||
* attributes, then the second element will be JSONObject containing the
|
||||
* name/value pairs. If the tag contains children, then strings and
|
||||
* JSONArrays will represent the child content and tags. Comments, prologs,
|
||||
* DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param x
|
||||
* An XMLTokener.
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(XMLTokener x) throws JSONException
|
||||
{
|
||||
return (JSONArray) parse(x, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONObject using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONObject with a "tagName" property. If the tag has attributes, then the
|
||||
* attributes will be in the JSONObject as properties. If the tag contains
|
||||
* children, the object will have a "childNodes" property which will be an
|
||||
* array of strings and JsonML JSONObjects.
|
||||
*
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param x
|
||||
* An XMLTokener of the XML source text.
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(XMLTokener x) throws JSONException
|
||||
{
|
||||
return (JSONObject) parse(x, false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONObject using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONObject with a "tagName" property. If the tag has attributes, then the
|
||||
* attributes will be in the JSONObject as properties. If the tag contains
|
||||
* children, the object will have a "childNodes" property which will be an
|
||||
* array of strings and JsonML JSONObjects.
|
||||
*
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param string
|
||||
* The XML source text.
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(String string) throws JSONException
|
||||
{
|
||||
return toJSONObject(new XMLTokener(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
||||
*
|
||||
* @param ja
|
||||
* A JSONArray.
|
||||
* @return An XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONArray ja) throws JSONException
|
||||
{
|
||||
int i;
|
||||
JSONObject jo;
|
||||
String key;
|
||||
Iterator<String> keys;
|
||||
int length;
|
||||
Object object;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String tagName;
|
||||
String value;
|
||||
|
||||
// Emit <tagName
|
||||
|
||||
tagName = ja.getString(0);
|
||||
XML.noSpace(tagName);
|
||||
tagName = XML.escape(tagName);
|
||||
sb.append('<');
|
||||
sb.append(tagName);
|
||||
|
||||
object = ja.opt(1);
|
||||
if(object instanceof JSONObject)
|
||||
{
|
||||
i = 2;
|
||||
jo = (JSONObject) object;
|
||||
|
||||
// Emit the attributes
|
||||
|
||||
keys = jo.keys();
|
||||
while(keys.hasNext())
|
||||
{
|
||||
key = keys.next();
|
||||
XML.noSpace(key);
|
||||
value = jo.optString(key);
|
||||
if(value != null)
|
||||
{
|
||||
sb.append(' ');
|
||||
sb.append(XML.escape(key));
|
||||
sb.append('=');
|
||||
sb.append('"');
|
||||
sb.append(XML.escape(value));
|
||||
sb.append('"');
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
i = 1;
|
||||
}
|
||||
|
||||
// Emit content in body
|
||||
|
||||
length = ja.length();
|
||||
if(i >= length)
|
||||
{
|
||||
sb.append('/');
|
||||
sb.append('>');
|
||||
} else
|
||||
{
|
||||
sb.append('>');
|
||||
do
|
||||
{
|
||||
object = ja.get(i);
|
||||
i += 1;
|
||||
if(object != null)
|
||||
{
|
||||
if(object instanceof String)
|
||||
{
|
||||
sb.append(XML.escape(object.toString()));
|
||||
} else if(object instanceof JSONObject)
|
||||
{
|
||||
sb.append(toString((JSONObject) object));
|
||||
} else if(object instanceof JSONArray)
|
||||
{
|
||||
sb.append(toString((JSONArray) object));
|
||||
} else
|
||||
{
|
||||
sb.append(object.toString());
|
||||
}
|
||||
}
|
||||
} while(i < length);
|
||||
sb.append('<');
|
||||
sb.append('/');
|
||||
sb.append(tagName);
|
||||
sb.append('>');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONObject.
|
||||
* The JSONObject must contain a "tagName" property. If it has children,
|
||||
* then it must have a "childNodes" property containing an array of objects.
|
||||
* The other properties are attributes with string values.
|
||||
*
|
||||
* @param jo
|
||||
* A JSONObject.
|
||||
* @return An XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONObject jo) throws JSONException
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i;
|
||||
JSONArray ja;
|
||||
String key;
|
||||
Iterator<String> keys;
|
||||
int length;
|
||||
Object object;
|
||||
String tagName;
|
||||
String value;
|
||||
|
||||
// Emit <tagName
|
||||
|
||||
tagName = jo.optString("tagName");
|
||||
if(tagName == null)
|
||||
{
|
||||
return XML.escape(jo.toString());
|
||||
}
|
||||
XML.noSpace(tagName);
|
||||
tagName = XML.escape(tagName);
|
||||
sb.append('<');
|
||||
sb.append(tagName);
|
||||
|
||||
// Emit the attributes
|
||||
|
||||
keys = jo.keys();
|
||||
while(keys.hasNext())
|
||||
{
|
||||
key = keys.next();
|
||||
if(!"tagName".equals(key) && !"childNodes".equals(key))
|
||||
{
|
||||
XML.noSpace(key);
|
||||
value = jo.optString(key);
|
||||
if(value != null)
|
||||
{
|
||||
sb.append(' ');
|
||||
sb.append(XML.escape(key));
|
||||
sb.append('=');
|
||||
sb.append('"');
|
||||
sb.append(XML.escape(value));
|
||||
sb.append('"');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Emit content in body
|
||||
|
||||
ja = jo.optJSONArray("childNodes");
|
||||
if(ja == null)
|
||||
{
|
||||
sb.append('/');
|
||||
sb.append('>');
|
||||
} else
|
||||
{
|
||||
sb.append('>');
|
||||
length = ja.length();
|
||||
for(i = 0; i < length; i += 1)
|
||||
{
|
||||
object = ja.get(i);
|
||||
if(object != null)
|
||||
{
|
||||
if(object instanceof String)
|
||||
{
|
||||
sb.append(XML.escape(object.toString()));
|
||||
} else if(object instanceof JSONObject)
|
||||
{
|
||||
sb.append(toString((JSONObject) object));
|
||||
} else if(object instanceof JSONArray)
|
||||
{
|
||||
sb.append(toString((JSONArray) object));
|
||||
} else
|
||||
{
|
||||
sb.append(object.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append('<');
|
||||
sb.append('/');
|
||||
sb.append(tagName);
|
||||
sb.append('>');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
public class JSONML {
|
||||
|
||||
/**
|
||||
* Parse XML values and store them in a JSONArray.
|
||||
*
|
||||
* @param x The XMLTokener containing the source string.
|
||||
* @param arrayForm true if array form, false if object form.
|
||||
* @param ja The JSONArray that is containing the current tag or null if we
|
||||
* are at the outermost level.
|
||||
* @return A JSONArray if the value is the outermost tag, otherwise null.
|
||||
* @throws JSONException
|
||||
*/
|
||||
private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja) throws JSONException {
|
||||
String attribute;
|
||||
char c;
|
||||
String closeTag = null;
|
||||
int i;
|
||||
JSONArray newja = null;
|
||||
JSONObject newjo = null;
|
||||
Object token;
|
||||
String tagName = null;
|
||||
|
||||
// Test for and skip past these forms:
|
||||
// <!-- ... -->
|
||||
// <![ ... ]]>
|
||||
// <! ... >
|
||||
// <? ... ?>
|
||||
|
||||
while (true) {
|
||||
if (!x.more()) {
|
||||
throw x.syntaxError("Bad XML");
|
||||
}
|
||||
token = x.nextContent();
|
||||
if (token == XML.LT) {
|
||||
token = x.nextToken();
|
||||
if (token instanceof Character) {
|
||||
if (token == XML.SLASH) {
|
||||
|
||||
// Close tag </
|
||||
|
||||
token = x.nextToken();
|
||||
if (!(token instanceof String)) {
|
||||
throw new JSONException("Expected a closing name instead of '" + token + "'.");
|
||||
}
|
||||
if (x.nextToken() != XML.GT) {
|
||||
throw x.syntaxError("Misshaped close tag");
|
||||
}
|
||||
return token;
|
||||
} else if (token == XML.BANG) {
|
||||
|
||||
// <!
|
||||
|
||||
c = x.next();
|
||||
if (c == '-') {
|
||||
if (x.next() == '-') {
|
||||
x.skipPast("-->");
|
||||
} else {
|
||||
x.back();
|
||||
}
|
||||
} else if (c == '[') {
|
||||
token = x.nextToken();
|
||||
if (token.equals("CDATA") && x.next() == '[') {
|
||||
if (ja != null) {
|
||||
ja.put(x.nextCDATA());
|
||||
}
|
||||
} else {
|
||||
throw x.syntaxError("Expected 'CDATA['");
|
||||
}
|
||||
} else {
|
||||
i = 1;
|
||||
do {
|
||||
token = x.nextMeta();
|
||||
if (token == null) {
|
||||
throw x.syntaxError("Missing '>' after '<!'.");
|
||||
} else if (token == XML.LT) {
|
||||
i += 1;
|
||||
} else if (token == XML.GT) {
|
||||
i -= 1;
|
||||
}
|
||||
} while (i > 0);
|
||||
}
|
||||
} else if (token == XML.QUEST) {
|
||||
|
||||
// <?
|
||||
|
||||
x.skipPast("?>");
|
||||
} else {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
|
||||
// Open tag <
|
||||
|
||||
} else {
|
||||
if (!(token instanceof String)) {
|
||||
throw x.syntaxError("Bad tagName '" + token + "'.");
|
||||
}
|
||||
tagName = (String) token;
|
||||
newja = new JSONArray();
|
||||
newjo = new JSONObject();
|
||||
if (arrayForm) {
|
||||
newja.put(tagName);
|
||||
if (ja != null) {
|
||||
ja.put(newja);
|
||||
}
|
||||
} else {
|
||||
newjo.put("tagName", tagName);
|
||||
if (ja != null) {
|
||||
ja.put(newjo);
|
||||
}
|
||||
}
|
||||
token = null;
|
||||
for (; ; ) {
|
||||
if (token == null) {
|
||||
token = x.nextToken();
|
||||
}
|
||||
if (token == null) {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
if (!(token instanceof String)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// attribute = value
|
||||
|
||||
attribute = (String) token;
|
||||
if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {
|
||||
throw x.syntaxError("Reserved attribute.");
|
||||
}
|
||||
token = x.nextToken();
|
||||
if (token == XML.EQ) {
|
||||
token = x.nextToken();
|
||||
if (!(token instanceof String)) {
|
||||
throw x.syntaxError("Missing value");
|
||||
}
|
||||
newjo.accumulate(attribute, XML.stringToValue((String) token));
|
||||
token = null;
|
||||
} else {
|
||||
newjo.accumulate(attribute, "");
|
||||
}
|
||||
}
|
||||
if (arrayForm && newjo.length() > 0) {
|
||||
newja.put(newjo);
|
||||
}
|
||||
|
||||
// Empty tag <.../>
|
||||
|
||||
if (token == XML.SLASH) {
|
||||
if (x.nextToken() != XML.GT) {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
if (ja == null) {
|
||||
if (arrayForm) {
|
||||
return newja;
|
||||
} else {
|
||||
return newjo;
|
||||
}
|
||||
}
|
||||
|
||||
// Content, between <...> and </...>
|
||||
|
||||
} else {
|
||||
if (token != XML.GT) {
|
||||
throw x.syntaxError("Misshaped tag");
|
||||
}
|
||||
closeTag = (String) parse(x, arrayForm, newja);
|
||||
if (closeTag != null) {
|
||||
if (!closeTag.equals(tagName)) {
|
||||
throw x.syntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'");
|
||||
}
|
||||
tagName = null;
|
||||
if (!arrayForm && newja.length() > 0) {
|
||||
newjo.put("childNodes", newja);
|
||||
}
|
||||
if (ja == null) {
|
||||
if (arrayForm) {
|
||||
return newja;
|
||||
} else {
|
||||
return newjo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ja != null) {
|
||||
ja.put(token instanceof String ? XML.stringToValue((String) token) : token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONArray using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONArray in which the first element is the tag name. If the tag has
|
||||
* attributes, then the second element will be JSONObject containing the
|
||||
* name/value pairs. If the tag contains children, then strings and
|
||||
* JSONArrays will represent the child tags. Comments, prologs, DTDs, and
|
||||
* <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param string The source string.
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(String string) throws JSONException {
|
||||
return toJSONArray(new XMLTokener(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONArray using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONArray in which the first element is the tag name. If the tag has
|
||||
* attributes, then the second element will be JSONObject containing the
|
||||
* name/value pairs. If the tag contains children, then strings and
|
||||
* JSONArrays will represent the child content and tags. Comments, prologs,
|
||||
* DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param x An XMLTokener.
|
||||
* @return A JSONArray containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONArray toJSONArray(XMLTokener x) throws JSONException {
|
||||
return (JSONArray) parse(x, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONObject using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONObject with a "tagName" property. If the tag has attributes, then the
|
||||
* attributes will be in the JSONObject as properties. If the tag contains
|
||||
* children, the object will have a "childNodes" property which will be an
|
||||
* array of strings and JsonML JSONObjects.
|
||||
* <p>
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param x An XMLTokener of the XML source text.
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(XMLTokener x) throws JSONException {
|
||||
return (JSONObject) parse(x, false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a well-formed (but not necessarily valid) XML string into a
|
||||
* JSONObject using the JsonML transform. Each XML tag is represented as a
|
||||
* JSONObject with a "tagName" property. If the tag has attributes, then the
|
||||
* attributes will be in the JSONObject as properties. If the tag contains
|
||||
* children, the object will have a "childNodes" property which will be an
|
||||
* array of strings and JsonML JSONObjects.
|
||||
* <p>
|
||||
* Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.
|
||||
*
|
||||
* @param string The XML source text.
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static JSONObject toJSONObject(String string) throws JSONException {
|
||||
return toJSONObject(new XMLTokener(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONArray.
|
||||
*
|
||||
* @param ja A JSONArray.
|
||||
* @return An XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONArray ja) throws JSONException {
|
||||
int i;
|
||||
JSONObject jo;
|
||||
String key;
|
||||
Iterator<String> keys;
|
||||
int length;
|
||||
Object object;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String tagName;
|
||||
String value;
|
||||
|
||||
// Emit <tagName
|
||||
|
||||
tagName = ja.getString(0);
|
||||
XML.noSpace(tagName);
|
||||
tagName = XML.escape(tagName);
|
||||
sb.append('<');
|
||||
sb.append(tagName);
|
||||
|
||||
object = ja.opt(1);
|
||||
if (object instanceof JSONObject) {
|
||||
i = 2;
|
||||
jo = (JSONObject) object;
|
||||
|
||||
// Emit the attributes
|
||||
|
||||
keys = jo.keys();
|
||||
while (keys.hasNext()) {
|
||||
key = keys.next();
|
||||
XML.noSpace(key);
|
||||
value = jo.optString(key);
|
||||
if (value != null) {
|
||||
sb.append(' ');
|
||||
sb.append(XML.escape(key));
|
||||
sb.append('=');
|
||||
sb.append('"');
|
||||
sb.append(XML.escape(value));
|
||||
sb.append('"');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
i = 1;
|
||||
}
|
||||
|
||||
// Emit content in body
|
||||
|
||||
length = ja.length();
|
||||
if (i >= length) {
|
||||
sb.append('/');
|
||||
sb.append('>');
|
||||
} else {
|
||||
sb.append('>');
|
||||
do {
|
||||
object = ja.get(i);
|
||||
i += 1;
|
||||
if (object != null) {
|
||||
if (object instanceof String) {
|
||||
sb.append(XML.escape(object.toString()));
|
||||
} else if (object instanceof JSONObject) {
|
||||
sb.append(toString((JSONObject) object));
|
||||
} else if (object instanceof JSONArray) {
|
||||
sb.append(toString((JSONArray) object));
|
||||
} else {
|
||||
sb.append(object);
|
||||
}
|
||||
}
|
||||
} while (i < length);
|
||||
sb.append('<');
|
||||
sb.append('/');
|
||||
sb.append(tagName);
|
||||
sb.append('>');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the JSONML transformation, making an XML text from a JSONObject.
|
||||
* The JSONObject must contain a "tagName" property. If it has children,
|
||||
* then it must have a "childNodes" property containing an array of objects.
|
||||
* The other properties are attributes with string values.
|
||||
*
|
||||
* @param jo A JSONObject.
|
||||
* @return An XML string.
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String toString(JSONObject jo) throws JSONException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i;
|
||||
JSONArray ja;
|
||||
String key;
|
||||
Iterator<String> keys;
|
||||
int length;
|
||||
Object object;
|
||||
String tagName;
|
||||
String value;
|
||||
|
||||
// Emit <tagName
|
||||
|
||||
tagName = jo.optString("tagName");
|
||||
if (tagName == null) {
|
||||
return XML.escape(jo.toString());
|
||||
}
|
||||
XML.noSpace(tagName);
|
||||
tagName = XML.escape(tagName);
|
||||
sb.append('<');
|
||||
sb.append(tagName);
|
||||
|
||||
// Emit the attributes
|
||||
|
||||
keys = jo.keys();
|
||||
while (keys.hasNext()) {
|
||||
key = keys.next();
|
||||
if (!"tagName".equals(key) && !"childNodes".equals(key)) {
|
||||
XML.noSpace(key);
|
||||
value = jo.optString(key);
|
||||
if (value != null) {
|
||||
sb.append(' ');
|
||||
sb.append(XML.escape(key));
|
||||
sb.append('=');
|
||||
sb.append('"');
|
||||
sb.append(XML.escape(value));
|
||||
sb.append('"');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Emit content in body
|
||||
|
||||
ja = jo.optJSONArray("childNodes");
|
||||
if (ja == null) {
|
||||
sb.append('/');
|
||||
sb.append('>');
|
||||
} else {
|
||||
sb.append('>');
|
||||
length = ja.length();
|
||||
for (i = 0; i < length; i += 1) {
|
||||
object = ja.get(i);
|
||||
if (object != null) {
|
||||
if (object instanceof String) {
|
||||
sb.append(XML.escape(object.toString()));
|
||||
} else if (object instanceof JSONObject) {
|
||||
sb.append(toString((JSONObject) object));
|
||||
} else if (object instanceof JSONArray) {
|
||||
sb.append(toString((JSONArray) object));
|
||||
} else {
|
||||
sb.append(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append('<');
|
||||
sb.append('/');
|
||||
sb.append(tagName);
|
||||
sb.append('>');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,13 +9,12 @@ package com.volmit.iris.util;
|
||||
* <code>toJSONString</code> method will be used instead of the default behavior
|
||||
* of using the Object's <code>toString()</code> method and quoting the result.
|
||||
*/
|
||||
public interface JSONString
|
||||
{
|
||||
/**
|
||||
* The <code>toJSONString</code> method allows a class to produce its own
|
||||
* JSON serialization.
|
||||
*
|
||||
* @return A strictly syntactically correct JSON text.
|
||||
*/
|
||||
public String toJSONString();
|
||||
public interface JSONString {
|
||||
/**
|
||||
* The <code>toJSONString</code> method allows a class to produce its own
|
||||
* JSON serialization.
|
||||
*
|
||||
* @return A strictly syntactically correct JSON text.
|
||||
*/
|
||||
String toJSONString();
|
||||
}
|
||||
|
||||
@@ -40,13 +40,13 @@ import java.io.StringWriter;
|
||||
* <code>endObject</code> methods which make and bound object values. All of
|
||||
* these methods return the JSONWriter instance, permitting cascade style. For
|
||||
* example,
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* myString = new JSONStringer().object().key("JSON").value("Hello, World!").endObject().toString();
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* which produces the string
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* {"JSON":"Hello, World!"}
|
||||
* </pre>
|
||||
@@ -56,31 +56,28 @@ import java.io.StringWriter;
|
||||
* you. Objects and arrays can be nested up to 20 levels deep.
|
||||
* <p>
|
||||
* This can sometimes be easier than using a JSONObject to build a string.
|
||||
*
|
||||
*
|
||||
* @author JSON.org
|
||||
* @version 2008-09-18
|
||||
*/
|
||||
public class JSONStringer extends JSONWriter
|
||||
{
|
||||
/**
|
||||
* Make a fresh JSONStringer. It can be used to build one JSON text.
|
||||
*/
|
||||
public JSONStringer()
|
||||
{
|
||||
super(new StringWriter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JSON text. This method is used to obtain the product of the
|
||||
* JSONStringer instance. It will return <code>null</code> if there was a
|
||||
* problem in the construction of the JSON text (such as the calls to
|
||||
* <code>array</code> were not properly balanced with calls to
|
||||
* <code>endArray</code>).
|
||||
*
|
||||
* @return The JSON text.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return this.mode == 'd' ? this.writer.toString() : null;
|
||||
}
|
||||
public class JSONStringer extends JSONWriter {
|
||||
/**
|
||||
* Make a fresh JSONStringer. It can be used to build one JSON text.
|
||||
*/
|
||||
public JSONStringer() {
|
||||
super(new StringWriter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JSON text. This method is used to obtain the product of the
|
||||
* JSONStringer instance. It will return <code>null</code> if there was a
|
||||
* problem in the construction of the JSON text (such as the calls to
|
||||
* <code>array</code> were not properly balanced with calls to
|
||||
* <code>endArray</code>).
|
||||
*
|
||||
* @return The JSON text.
|
||||
*/
|
||||
public String toString() {
|
||||
return this.mode == 'd' ? this.writer.toString() : null;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user