mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-29 04:04:43 +02:00
Nothing is implemented, but it can compile and "run" on sponge now.
This commit is contained in:
@ -0,0 +1,77 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.*;
|
||||
import com.plotsquared.bukkit.titles.AbstractTitle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
public class CommentManager {
|
||||
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
|
||||
|
||||
public static void sendTitle(final PlotPlayer player, final Plot plot) {
|
||||
if (!Settings.COMMENT_NOTIFICATIONS) {
|
||||
return;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID())) {
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskLaterAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Collection<CommentInbox> boxes = CommentManager.inboxes.values();
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final AtomicInteger size = new AtomicInteger(boxes.size());
|
||||
for (final CommentInbox inbox : inboxes.values()) {
|
||||
inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
int total;
|
||||
if (value != null) {
|
||||
int num = 0;
|
||||
for (PlotComment comment : (ArrayList<PlotComment>) value) {
|
||||
if (comment.timestamp > getTimestamp(player, inbox.toString())) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
total = count.addAndGet(num);
|
||||
}
|
||||
else {
|
||||
total = count.get();
|
||||
}
|
||||
if (size.decrementAndGet() == 0 && total > 0) {
|
||||
AbstractTitle.sendTitle(player, "", C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
||||
public static long getTimestamp(PlotPlayer player, String inbox) {
|
||||
Object meta = player.getMeta("inbox:"+inbox);
|
||||
if (meta == null) {
|
||||
return player.getPreviousLogin();
|
||||
}
|
||||
return (Long) meta;
|
||||
}
|
||||
|
||||
public static void addInbox(CommentInbox inbox) {
|
||||
inboxes.put(inbox.toString().toLowerCase(), inbox);
|
||||
}
|
||||
|
||||
public static void registerDefaultInboxes() {
|
||||
addInbox(new InboxReport());
|
||||
addInbox(new InboxPublic());
|
||||
addInbox(new InboxOwner());
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
|
||||
public abstract class EventUtil {
|
||||
|
||||
|
@ -16,6 +16,106 @@ public class MathMan {
|
||||
}
|
||||
return count / array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns [x, y, z]
|
||||
* @param yaw
|
||||
* @param pitch
|
||||
* @return
|
||||
*/
|
||||
public static float[] getDirection(float yaw, float pitch) {
|
||||
double pitch_sin = Math.sin(pitch);
|
||||
return new float[] {
|
||||
(float) (pitch_sin * Math.cos(yaw)),
|
||||
(float) (pitch_sin * Math.sin(yaw)),
|
||||
(float) Math.cos(pitch)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns [ pitch, yaw ]
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public static float[] getPitchAndYaw(float x, float y, float z) {
|
||||
float distance = sqrtApprox(z * z + x * x);
|
||||
return new float[] { atan2(y, distance), atan2(x, z) };
|
||||
}
|
||||
|
||||
private static final int ATAN2_BITS = 7;
|
||||
|
||||
private static final int ATAN2_BITS2 = ATAN2_BITS << 1;
|
||||
private static final int ATAN2_MASK = ~(-1 << ATAN2_BITS2);
|
||||
private static final int ATAN2_COUNT = ATAN2_MASK + 1;
|
||||
private static final int ATAN2_DIM = (int) Math.sqrt(ATAN2_COUNT);
|
||||
|
||||
private static final float INV_ATAN2_DIM_MINUS_1 = 1.0f / (ATAN2_DIM - 1);
|
||||
|
||||
private static final float[] atan2 = new float[ATAN2_COUNT];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < ATAN2_DIM; i++) {
|
||||
for (int j = 0; j < ATAN2_DIM; j++) {
|
||||
float x0 = (float) i / ATAN2_DIM;
|
||||
float y0 = (float) j / ATAN2_DIM;
|
||||
|
||||
atan2[j * ATAN2_DIM + i] = (float) Math.atan2(y0, x0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final float atan2(float y, float x) {
|
||||
float add, mul;
|
||||
|
||||
if (x < 0.0f) {
|
||||
if (y < 0.0f) {
|
||||
x = -x;
|
||||
y = -y;
|
||||
|
||||
mul = 1.0f;
|
||||
} else {
|
||||
x = -x;
|
||||
mul = -1.0f;
|
||||
}
|
||||
|
||||
add = -3.141592653f;
|
||||
} else {
|
||||
if (y < 0.0f) {
|
||||
y = -y;
|
||||
mul = -1.0f;
|
||||
} else {
|
||||
mul = 1.0f;
|
||||
}
|
||||
|
||||
add = 0.0f;
|
||||
}
|
||||
|
||||
float invDiv = 1.0f / (((x < y) ? y : x) * INV_ATAN2_DIM_MINUS_1);
|
||||
|
||||
int xi = (int) (x * invDiv);
|
||||
int yi = (int) (y * invDiv);
|
||||
|
||||
return (atan2[yi * ATAN2_DIM + xi] + add) * mul;
|
||||
}
|
||||
|
||||
public static float sqrtApprox(float f) {
|
||||
return f * Float.intBitsToFloat(0x5f375a86 - (Float.floatToIntBits(f) >> 1));
|
||||
}
|
||||
|
||||
public static double sqrtApprox(double d) {
|
||||
return Double.longBitsToDouble( ( ( Double.doubleToLongBits( d )-(1l<<52) )>>1 ) + ( 1l<<61 ) );
|
||||
}
|
||||
|
||||
public static float invSqrt(float x) {
|
||||
float xhalf = 0.5f*x;
|
||||
int i = Float.floatToIntBits(x);
|
||||
i = 0x5f3759df - (i>>1);
|
||||
x = Float.intBitsToFloat(i);
|
||||
x = x*(1.5f - xhalf*x*x);
|
||||
return x;
|
||||
}
|
||||
|
||||
public static int getPositiveId(int i) {
|
||||
if (i < 0) {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.intellectualcrafters.plot.generator.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SetupUtils {
|
||||
|
||||
public static SetupUtils manager;
|
||||
|
||||
public final static Map<String, SetupObject> setupMap = new HashMap<>();
|
||||
public static HashMap<String, PlotGenerator<?>> generators = new HashMap<>();
|
||||
|
||||
public abstract void updateGenerators();
|
||||
|
||||
public abstract String getGenerator(PlotWorld plotworld);
|
||||
|
||||
public abstract String setupWorld(final SetupObject object);
|
||||
}
|
Reference in New Issue
Block a user