Update and mavericks-review-hub plugin [stand alone]

Added NBT Utils
Added Format util for color
Fixed bounding box calculations in UtilBlock
Improved getPlugin in UtilServer
Added BuildDataCylinder
Added Particle support for saving builds
Added Debug command to BuildMavericks
Changed some backend DB stuff for saving builds

Added mavericks-review-hub plugin:
*
This commit is contained in:
xGamingDudex 2016-06-17 14:14:39 +02:00
parent 1141a05310
commit d6afe986ea
22 changed files with 1752 additions and 128 deletions

View File

@ -19,6 +19,8 @@
package com.java.sk89q.jnbt;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -26,6 +28,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_8_R3.NBTBase;
import net.minecraft.server.v1_8_R3.NBTTagByte;
@ -188,6 +194,33 @@ public final class NBTUtils {
}
public static byte[] toBytesCompressed(String name, CompoundTag tag)
{
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try (NBTOutputStream nbtStream = new NBTOutputStream(new GZIPOutputStream(byteStream)))
{
nbtStream.writeNamedTag(name, tag);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return byteStream.toByteArray();
}
public static NamedTag getFromBytesCompressed(byte[] bytes)
{
try (NBTInputStream stream = new NBTInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes)));)
{
return stream.readNamedTag();
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public static NBTBase toNative(Tag tag) {
@ -400,4 +433,9 @@ public final class NBTUtils {
return nbttaglist;
}
public static Vector getVector(CompoundTag tag)
{
return new Vector(tag.asDouble("x"), tag.asDouble("y"), tag.asDouble("z"));
}
}

View File

@ -280,7 +280,7 @@ public class Schematic
public boolean hasIndex(int index)
{
return index < _blocks.length;
return index < _blocks.length && index >= 0;
}
public short getBlock(int x, int y, int z)

View File

@ -14,7 +14,6 @@ import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;

View File

@ -1,11 +1,9 @@
package mineplex.core.common.util;
import mineplex.core.common.Rank;
import java.util.LinkedList;
import org.bukkit.ChatColor;
import mineplex.core.common.Rank;
public class F
{
public static String main(String module, String body)
@ -29,6 +27,11 @@ public class F
return C.mGame + elem + C.mBody;
}
public static String color(String msg, String color)
{
return color + msg + C.mBody;
}
public static String ta(String message)
{
return C.cGreen + message + C.cWhite;

View File

@ -606,10 +606,10 @@ public class UtilBlock
}
public static ArrayList<Block> getInBoundingBox(Location a, Location b, boolean ignoreAir) {
return getInBoundingBox(a, b, ignoreAir, false, true, true);
return getInBoundingBox(a, b, ignoreAir, false, false, false);
}
public static ArrayList<Block> getInBoundingBox(Location a, Location b, boolean ignoreAir, boolean hollow, boolean walls, boolean ceilfloor)
public static ArrayList<Block> getInBoundingBox(Location a, Location b, boolean ignoreAir, boolean hollow, boolean wallsOnly, boolean ceilfloorOnly)
{
ArrayList<Block> blocks = new ArrayList<Block>();
@ -626,26 +626,25 @@ public class UtilBlock
for (int y = ymin; y <= ymax; y++)
for (int z = zmin; z <= zmax; z++)
{
if(hollow)
{
if(!(x == xmin || x == xmax || y == ymin || y == ymax || z == zmin || z == zmax)) continue;
}
if(!walls)
if(wallsOnly)
{
if(
(x == xmin || x == xmax) ||
(z == zmin || z == zmax)
(x != xmin && x != xmax) &&
(z != zmin && z != zmax)
)
{
continue;
}
}
if(!ceilfloor)
if(ceilfloorOnly)
{
if(y == ymin || y == ymax)
if(y != ymin && y != ymax)
{
continue;
}

View File

@ -11,6 +11,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Field;
@ -112,7 +113,7 @@ public class UtilServer
public static Plugin getPlugin()
{
return getPluginManager().getPlugins()[0];
return JavaPlugin.getProvidingPlugin(UtilServer.class);
}
public static PluginManager getPluginManager()

View File

@ -9,7 +9,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
@ -734,7 +733,7 @@ public class Build extends SoloGame
if (data == null)
return;
if (event.getTo().getY() > Math.max(data.CornerA.getBlockY(), data.CornerB.getBlockY()) + 3 &&
if (event.getTo().getY() > data.getMaxHeight() + 3 &&
UtilMath.offset(data.Spawn, event.getFrom()) < UtilMath.offset(data.Spawn, event.getTo()))
{
//Inform

View File

@ -1,24 +1,13 @@
package nautilus.game.arcade.game.games.build;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.recharge.Recharge;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -32,6 +21,26 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import com.java.sk89q.jnbt.CompoundTag;
import com.java.sk89q.jnbt.DoubleTag;
import com.java.sk89q.jnbt.NBTUtils;
import com.java.sk89q.jnbt.StringTag;
import com.java.sk89q.jnbt.Tag;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.recharge.Recharge;
import net.minecraft.server.v1_8_R3.EntityLightning;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityWeather;
@ -66,10 +75,15 @@ public class BuildData
private double _totalPoints = 0;
public BuildData(Player player, Location spawn, ArrayList<Location> buildBorders)
protected BuildData(Player player, Location spawn)
{
Player = player;
Spawn = spawn;
}
public BuildData(Player player, Location spawn, ArrayList<Location> buildBorders)
{
this(player, spawn);
CornerA = UtilAlg.findClosest(spawn, buildBorders);
buildBorders.remove(CornerA);
@ -359,12 +373,84 @@ public class BuildData
IsAbusive = true;
}
protected Location getMin()
{
return Vector.getMinimum(CornerA.toVector(), CornerB.toVector()).toLocation(CornerA.getWorld()).subtract(0, 1, 0);
}
protected Location getMax()
{
return Vector.getMaximum(CornerA.toVector(), CornerB.toVector()).toLocation(CornerA.getWorld());
}
public double getMaxHeight()
{
return Math.max(CornerA.getY(), CornerB.getY());
}
/**
* Converts all the blocks inside the build to a schematic
* @return
*/
public Schematic convertToSchematic()
{
return UtilSchematic.createSchematic(CornerA, CornerB);
Location min = getMin();
Location max = getMax();
return UtilSchematic.createSchematic(min, max);
}
public Map<Vector, ParticleType> getParticles()
{
Bukkit.broadcastMessage("Getting particles [" + Player.getName() + "]");
Vector min = getMin().toVector();
Map<Vector, ParticleType> map = new HashMap<>();
for(Entry<Location, ParticleType> e : Particles.entrySet())
{
Vector v = e.getKey().toVector().subtract(min);
map.put(v, e.getValue());
}
Bukkit.broadcastMessage("Returning map [" + map.size() + "]:\n" + map);
return map;
}
public byte[] getParticlesBytes()
{
Map<String, Tag> map = new HashMap<String, Tag>();
int i = 0;
for(Entry<Vector, ParticleType> e : getParticles().entrySet())
{
Map<String, Tag> entryMap = new HashMap<>();
entryMap.put("x", new DoubleTag(e.getKey().getX()));
entryMap.put("y", new DoubleTag(e.getKey().getY()));
entryMap.put("z", new DoubleTag(e.getKey().getZ()));
entryMap.put("particle", new StringTag(e.getValue().name()));
CompoundTag entry = new CompoundTag(entryMap);
map.put("particle" + i++, entry);
Bukkit.broadcastMessage("Adding entry: 'particle" + i + "'\n" + entry);
}
CompoundTag parent = new CompoundTag(map);
Bukkit.broadcastMessage("Compressing main: " + parent);
byte[] bytes = NBTUtils.toBytesCompressed("particles", parent);
if(bytes == null)
{
Bukkit.broadcastMessage("Returning bytes = null!");
}
else
{
Bukkit.broadcastMessage("Returning bytes: " + bytes.length + "\n" + new String(bytes));
}
return bytes;
}
}

View File

@ -0,0 +1,95 @@
package nautilus.game.arcade.game.games.buildmavericks;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.game.games.build.BuildData;
import nautilus.game.arcade.game.games.build.GroundData;
public class BuildDataCylinder extends BuildData
{
private final double RADIUS = 11;
private final double HEIGHT = 25;
private final Location _blockSpawn;
public BuildDataCylinder(Player player, Location spawn)
{
super(player, spawn);
_blockSpawn = spawn.getWorld().getHighestBlockAt(spawn).getLocation().add(0.5, 0, 0.5);
}
@Override
public boolean inBuildArea(Block block)
{
if(!block.getWorld().equals(_blockSpawn.getWorld())) return false;
Location loc = block.getLocation().add(0.5, 0, 0.5);
loc.setY(_blockSpawn.getY());
double yDiff = block.getY()-_blockSpawn.getY();
if(yDiff < 0 || yDiff > HEIGHT) return false;
return loc.distanceSquared(_blockSpawn) < RADIUS*RADIUS;
}
@Override
public void setGround(GroundData ground)
{
if (!Recharge.Instance.use(Player, "Change Ground", 2000, true, false))
{
Player.playSound(Player.getLocation(), Sound.NOTE_BASS_GUITAR, 1f, 0.1f);
return;
}
Material mat = ground.getMaterial();
byte data = ground.getData();
if (mat == Material.LAVA_BUCKET) mat = Material.LAVA;
else if (mat == Material.WATER_BUCKET) mat = Material.WATER;
//Set everything to air first to prevent the forming of obby.
Set<Block> blocks = UtilBlock.getInRadius(_blockSpawn, RADIUS, 0).keySet();
UtilBlock.startQuickRecording();
for(Block b : blocks)
{
if(!UtilItem.isLiquid(b.getType())) continue;
UtilBlock.setQuick(_blockSpawn.getWorld(), b.getX(), b.getY()-1, b.getZ(), 0, (byte) 0);
}
for(Block b : blocks)
{
UtilBlock.setQuick(_blockSpawn.getWorld(), b.getX(), b.getY()-1, b.getZ(), mat.getId(), data);
}
UtilBlock.stopQuickRecording();
}
@Override
protected Location getMin()
{
return _blockSpawn.clone().subtract(RADIUS, 1, RADIUS);
}
@Override
protected Location getMax()
{
return _blockSpawn.clone().add(RADIUS, HEIGHT, RADIUS);
}
@Override
public double getMaxHeight()
{
return _blockSpawn.getY() + HEIGHT;
}
}

View File

@ -23,7 +23,11 @@ import org.bukkit.util.Vector;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTextMiddle;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.games.build.Build;
@ -69,10 +73,12 @@ public class BuildMavericks extends Build
_reposetory = new MavericksRepository();
//TODO: REMOVE AFTER DEBUG!
_buildTime = 10000;
/*
_buildTime = 20000;
_voteTime = 4000;
_viewTime = 7000;
Bukkit.broadcastMessage("Time updated!");
*/
// Bukkit.getPluginManager().registerEvents(new SchematicTester(), UtilServer.getPlugin());
@ -111,6 +117,7 @@ public class BuildMavericks extends Build
UUID uuid = e.getKey().getUniqueId();
String name = e.getKey().getName();
Schematic schematic = data.convertToSchematic();
@ -119,15 +126,15 @@ public class BuildMavericks extends Build
Bukkit.broadcastMessage("--> Place: " + place);
if(place == -1) continue;
MavericksBuildWrapper wrapper = new MavericksBuildWrapper(uuid, _word, data.getPoints(), place,
System.currentTimeMillis(), UtilSchematic.getBytes(schematic));
MavericksBuildWrapper wrapper = new MavericksBuildWrapper(-1, uuid, name, _word, data.getPoints(), place,
System.currentTimeMillis(), UtilSchematic.getBytes(schematic), data.getParticlesBytes(), false);
Bukkit.broadcastMessage("--> Uploading...");
_reposetory.add(wrapper).thenCompose(BukkitFuture.accept(sucess -> {
Bukkit.broadcastMessage("Success: " + sucess);
if(!sucess)
new RuntimeException("Unable to save build data and schematic for player '" + e.getKey().getName() + "': " + wrapper).printStackTrace();;
new RuntimeException("Unable to save build data and schematic for player '" + e.getKey().getName() + "': " + wrapper).printStackTrace();
}));
}
}
@ -249,5 +256,62 @@ public class BuildMavericks extends Build
}
@EventHandler
public void prepare(GameStateChangeEvent event)
{
if (event.GetState() == GameState.Prepare)
{
if (GetPlayers(true).size() > GetTeamList().get(0).GetSpawns().size())
{
SetState(GameState.End);
Announce(C.Bold + "Too Many Players...");
return;
}
}
else if (event.GetState() == GameState.Live)
{
for (Player player : GetPlayers(true))
{
Location spawn = UtilAlg.findClosest(player.getLocation(), this.GetTeamList().get(0).GetSpawns());
_data.put(player, new BuildDataCylinder(player, spawn));
player.setFlySpeed(0.1f);
}
if (!_useHolidayWords || Math.random() >= 0.5)
_word = _words[UtilMath.r(_words.length)];
else
_word = _holidayWords[UtilMath.r(_holidayWords.length)];
UtilTextMiddle.display(null, C.cYellow + "Build " + C.cWhite + _word, 0, 80, 5);
this.WorldTimeSet = -1;
}
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event)
{
if(event.getMessage().equals("/endbuildtime"))
{
event.setCancelled(true);
if(GetState() != GameState.Live)
{
event.getPlayer().sendMessage(F.main(GetName(), "The game is not currently running."));
return;
}
if(_buildTime < 0)
{
event.getPlayer().sendMessage(F.main(GetName(), "Build time is over!"));
return;
}
Announce(event.getPlayer().getName() + " has ended the build time", true);
_buildTime = 0;
}
}
}

View File

@ -1,32 +1,62 @@
package nautilus.game.arcade.game.games.buildmavericks.repository;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.util.Vector;
import com.java.sk89q.jnbt.CompoundTag;
import com.java.sk89q.jnbt.NBTUtils;
import com.java.sk89q.jnbt.Tag;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.UtilParticle.ParticleType;
/**
* A simple wrapper class for Mavericks-MasterBuilders SQL data
*/
public class MavericksBuildWrapper
{
private final long _buildId;
private final UUID _uuid;
private final String _theme;
private final double _points;
private final int _place;
private final long _dateStamp;
private final byte[] _schematic;
private final byte[] _particles;
private boolean _reviewed;
private final String _name;
public MavericksBuildWrapper(UUID uuid, String theme, double points, int place, long dateStamp, byte[] schematic)
public MavericksBuildWrapper(long buildId, UUID uuid, String name, String theme, double points, int place, long dateStamp,
byte[] schematic, byte[] particles, boolean reviewed)
{
this._buildId = buildId;
this._uuid = uuid;
this._name = name;
this._theme = theme;
this._points = points;
this._place = place;
this._dateStamp = dateStamp;
this._schematic = schematic;
this._particles = particles;
this._reviewed = reviewed;
}
public MavericksBuildWrapper(long buildId, UUID uuid, String theme, double points, int place, long dateStamp,
byte[] schematic, byte[] particles, boolean reviewed)
{
this(buildId, uuid, null, theme, points, place, dateStamp, schematic, particles, reviewed);
}
public long getBuildId()
{
return _buildId;
}
public UUID getUUID()
@ -34,6 +64,16 @@ public class MavericksBuildWrapper
return _uuid;
}
public String getName()
{
return _name;
}
public boolean hasNameSet()
{
return _name != null;
}
public String getTheme()
{
return _theme;
@ -59,6 +99,16 @@ public class MavericksBuildWrapper
return _schematic;
}
public boolean isReviewed()
{
return _reviewed;
}
public void setReviewed(boolean reviewed)
{
_reviewed = reviewed;
}
public Schematic getSchematic()
{
try
@ -67,10 +117,49 @@ public class MavericksBuildWrapper
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public boolean hasParticles()
{
return _particles != null && _particles.length > 0;
}
public byte[] getParticlesRaw()
{
return _particles;
}
public Map<Vector, ParticleType> getParticles()
{
Map<Vector, ParticleType> map = new HashMap<>();
if(!hasParticles()) return map;
try
{
CompoundTag tag = (CompoundTag) NBTUtils.getFromBytesCompressed(_particles).getTag();
for(Entry<String, Tag> e : tag.getValue().entrySet())
{
CompoundTag parent = (CompoundTag) e.getValue();
Vector v = NBTUtils.getVector(parent);
ParticleType particle = ParticleType.valueOf(parent.getString("particle"));
while(map.containsKey(v)) v.add(new Vector(0.00000001, 0, 0));
map.put(v, particle);
}
}
catch (Exception e)
{
e.printStackTrace();
}
return map;
}
@Override
public String toString()
{
@ -78,5 +167,4 @@ public class MavericksBuildWrapper
+ ",date=" + _dateStamp + ",Schematic=ByteArray[" + _schematic.length + "]]";
}
}

View File

@ -2,11 +2,7 @@ package nautilus.game.arcade.game.games.buildmavericks.repository;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import mineplex.serverdata.database.DBPool;
@ -40,97 +36,20 @@ public class MavericksRepository
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("REPLACE INTO " + TABLE + " (accountId, BuildTheme, Points, Place, Date, Schematic) SELECT accounts.id, ?, ?, ?, ?, ? FROM accounts WHERE uuid=?");
PreparedStatement stmt = conn.prepareStatement("REPLACE INTO " + TABLE + " (accountId, BuildTheme, Points, Place, Date, Schematic, Particles) SELECT accounts.id, ?, ?, ?, ?, ?, ? FROM accounts WHERE uuid=?");
stmt.setString(1, data.getTheme());
stmt.setDouble(2, data.getPoints());
stmt.setInt(3, data.getPlace());
stmt.setLong(4, data.getDateStamp());
stmt.setBytes(5, data.getSchematicBytes());
stmt.setString(6, data.getUUID().toString());
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
throw new RuntimeException(e);
}
});
}
public CompletableFuture<List<MavericksBuildWrapper>> getAll(UUID uuid)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("SELECT BuildTheme, Votes, Place, Date, Schematic FROM " + TABLE + " WHERE accountId = (SELECT id FROM accounts WHERE uuid=?)");
stmt.setString(1, uuid.toString());
ResultSet set = stmt.executeQuery();
List<MavericksBuildWrapper> list = new ArrayList<>();
while (set.next())
{
String theme = set.getString(1);
int votes = set.getInt(2);
int place = set.getInt(3);
long dateStamp = set.getLong(4);
byte[] schematic = set.getBytes(5);
list.add(new MavericksBuildWrapper(uuid, theme, votes, place, dateStamp, schematic));
}
return list;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
public CompletableFuture<List<MavericksBuildWrapper>> getToReview(boolean onlyUnreviewed, int limit, int offset)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
String filter = onlyUnreviewed ? "WHERE Reviewed=0 " : "";
PreparedStatement stmt = conn.prepareStatement("SELECT (SELECT uuid FROM accounts WHERE accounts.id=" + TABLE + ".accountId),BuildTheme,Points,Place,Date,Schematic FROM " + TABLE + " " + filter + " ORDER BY Points LIMIT " + limit + " OFFSET " + offset);
ResultSet set = stmt.executeQuery();
List<MavericksBuildWrapper> list = new ArrayList<>();
while (set.next())
{
UUID uuid = UUID.fromString(set.getString(1));
String theme = set.getString(2);
int votes = set.getInt(3);
int place = set.getInt(4);
long dateStamp = set.getLong(5);
byte[] schematic = set.getBytes(6);
list.add(new MavericksBuildWrapper(uuid, theme, votes, place, dateStamp, schematic));
}
return list;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Boolean> setReviewed(long dateStamp, boolean reviewed)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE + " SET Reviewed=? WHERE Date=?");
stmt.setInt(1, reviewed? 1 : 0);
stmt.setLong(2, dateStamp);
stmt.setBytes(6, data.getParticlesRaw());
stmt.setString(7, data.getUUID().toString());
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});

View File

@ -0,0 +1,3 @@
name: Mavericks-Review-Hub
main: mineplex.mavericks.review.Hub
version: 0.1

View File

@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mineplex</groupId>
<artifactId>mineplex-plugin</artifactId>
<version>dev-SNAPSHOT</version>
<relativePath>../plugin.xml</relativePath>
</parent>
<name>mavericks-review-hub</name>
<artifactId>mavericks-review-hub</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mineplex-minecraft-game-classcombat</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,145 @@
package mineplex.mavericks.review;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.CustomTagFix;
import mineplex.core.FoodDupeFix;
import mineplex.core.PacketsInteractionFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat;
import mineplex.core.command.CommandCenter;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.creature.Creature;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.elo.EloManager;
import mineplex.core.friend.FriendManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.give.Give;
import mineplex.core.hologram.HologramManager;
import mineplex.core.ignore.IgnoreManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.memory.MemoryFix;
import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
import mineplex.core.mount.MountManager;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.pet.PetManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.core.velocity.VelocityFix;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksApprovedRepository;
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksBuildRepository;
import net.minecraft.server.v1_8_R3.MinecraftServer;
public class Hub extends JavaPlugin
{
private String WEB_CONFIG = "webServer";
// Modules
private CoreClientManager _clientManager;
private DonationManager _donationManager;
@Override
public void onEnable()
{
Bukkit.setSpawnRadius(0);
// Delete Old Games Folders
// Configs
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
saveConfig();
String webServerAddress = getConfig().getString(WEB_CONFIG);
// Static Modules
CommandCenter.Initialize(this);
_clientManager = new CoreClientManager(this, webServerAddress);
CommandCenter.Instance.setClientManager(_clientManager);
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
VisibilityManager.Initialize(this);
Give.Initialize(this);
// Velocity Fix
new VelocityFix(this);
_donationManager = new DonationManager(this, _clientManager, webServerAddress);
PacketHandler packetHandler = new PacketHandler(this);
IncognitoManager incognito = new IncognitoManager(this, _clientManager, packetHandler);
PreferencesManager preferenceManager = new PreferencesManager(this, incognito, _clientManager, _donationManager);
incognito.setPreferencesManager(preferenceManager);
Creature creature = new Creature(this);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager));
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
Punish punish = new Punish(this, webServerAddress, _clientManager);
AntiHack.Initialize(this, punish, portal, preferenceManager, _clientManager);
AntiHack.Instance.setKick(false);
IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal);
StatsManager statsManager = new StatsManager(this, _clientManager);
EloManager eloManager = new EloManager(this, _clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, _donationManager, incognito, eloManager);
FriendManager friendManager = new FriendManager(this, _clientManager, preferenceManager, portal);
Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat);
BlockRestore blockRestore = new BlockRestore(this);
ProjectileManager projectileManager = new ProjectileManager(this);
HologramManager hologramManager = new HologramManager(this, packetHandler);
// Inventory
InventoryManager inventoryManager = new InventoryManager(this, _clientManager);
PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore,
webServerAddress);
MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager);
GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager,
preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager);
CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager,
mountManager, petManager, null);
cosmeticManager.setInterfaceSlot(7);
cosmeticManager.disableTeamArmor();
new MemoryFix(this);
new CustomTagFix(this, packetHandler);
new PacketsInteractionFix(this, packetHandler);
new FoodDupeFix(this);
new MavericksReviewManager(this, new MavericksBuildRepository(), new MavericksApprovedRepository());
new ProfileCacheManager(this);
// Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
MinecraftServer.getServer().getPropertyManager().setProperty("debug", true);
}
}

View File

@ -0,0 +1,665 @@
package mineplex.mavericks.review;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCreativeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import mineplex.core.MiniPlugin;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.SchematicData;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.worldgen.WorldGenCleanRoom;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksApprovedRepository;
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksBuildRepository;
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksBuildWrapper;
public class MavericksReviewManager extends MiniPlugin
{
private MavericksBuildRepository _repoBuilds;
private MavericksApprovedRepository _repoApprove;
private Map<Player, ReviewData> _reviewers = new HashMap<>();
private Location _spawn;
private World _world;
private List<MavericksBuildWrapper> _reviewQueue = new ArrayList<>();
private ItemStack _itemEnterReviewMode;
private ItemStack _itemExitReviewMode;
private ItemStack _itemNext;
private ItemStack _itemPrevious;
private ItemStack _itemApprove;
private ItemStack _itemDeny;
private ItemStack _itemFilter;
public MavericksReviewManager(JavaPlugin plugin, MavericksBuildRepository repoBuilds, MavericksApprovedRepository repoApprove)
{
super("MavericksReviewManager", plugin);
_repoBuilds = repoBuilds;
_repoApprove = repoApprove;
_world = Bukkit.getWorlds().get(0);
_spawn = _world.getSpawnLocation().getBlock().getLocation();
//Apply Clean Room Generator to default world
((CraftWorld)_world).getPopulators().addAll(new WorldGenCleanRoom().getDefaultPopulators(_world));
_world.setGameRuleValue("keepInventory", "true");
_itemEnterReviewMode = ItemStackFactory.Instance.CreateStack(Material.PAPER, (byte) 0, 1, C.cGreen + C.Bold + "Enter Review Mode");
_itemExitReviewMode = ItemStackFactory.Instance.CreateStack(Material.COMPASS, (byte) 0, 1, C.cRed + C.Bold + "Exit Review Mode");
_itemNext = ItemStackFactory.Instance.CreateStack(Material.ARROW, (byte) 0, 1, C.cGold + C.Bold + "Next Build");
_itemPrevious = ItemStackFactory.Instance.CreateStack(Material.ARROW, (byte) 0, 1, C.cGold + C.Bold + "Previous Build");
_itemApprove = ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, (byte) 5, 1, C.cGreen + C.Bold + "Approve");
_itemDeny = ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, (byte) 14, 1, C.cRed + C.Bold + "Deny");
_itemFilter = ItemStackFactory.Instance.CreateStack(Material.HOPPER, (byte) 0, 1, C.cGold + C.Bold + "Filter Settings");
}
private boolean isActionItem(ItemStack item)
{
if(_itemApprove.equals(item)) return true;
if(_itemDeny.equals(item)) return true;
if(_itemEnterReviewMode.equals(item)) return true;
if(_itemExitReviewMode.equals(item)) return true;
if(_itemFilter.equals(item)) return true;
if(_itemNext.equals(item)) return true;
if(_itemPrevious.equals(item)) return true;
return false;
}
@EventHandler
public void onGameMode(PlayerGameModeChangeEvent event)
{
boolean flying = event.getPlayer().isFlying();
new BukkitRunnable()
{
public void run()
{
event.getPlayer().setAllowFlight(true);
event.getPlayer().setFlying(flying);
}
}.runTask(UtilServer.getPlugin());
}
@EventHandler
public void onPhysics(BlockPhysicsEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onPickup(PlayerPickupItemEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onDamage(EntityDamageEvent event)
{
if(event.getCause() == DamageCause.VOID) return;
if(event.getCause() == DamageCause.CUSTOM) return;
if(event.getCause() == DamageCause.SUICIDE) return;
event.setCancelled(true);
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
event.getPlayer().getInventory().removeItem(_itemApprove, _itemDeny, _itemExitReviewMode, _itemFilter, _itemNext, _itemPrevious);
event.getPlayer().getInventory().setItem(0, _itemEnterReviewMode);
event.getPlayer().setGameMode(GameMode.ADVENTURE);
}
@EventHandler
public void onHunger(FoodLevelChangeEvent event)
{
event.setFoodLevel(20);
}
@EventHandler
public void onWeather(WeatherChangeEvent event)
{
if(event.getWorld().getName().equals(_spawn.getWorld().getName()))
{
if(event.toWeatherState()) event.setCancelled(true);
}
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
if(isActionItem(event.getCurrentItem()) || isActionItem(event.getCursor())) event.setCancelled(true);
}
@EventHandler
public void onCreativeInventoryClick(InventoryCreativeEvent event)
{
if(isActionItem(event.getCurrentItem()) || isActionItem(event.getCursor())) event.setCancelled(true);
}
@EventHandler
public void onDrop(PlayerDropItemEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
Player player = event.getPlayer();
if(isActionItem(event.getItem()))
{
event.setCancelled(true);
}
else
{
return;
}
if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
String name = event.getItem().getItemMeta().getDisplayName();
if(!Recharge.Instance.use(player, "MavericksReviewManager Action - " + name, 500, false, false)) return;
if(event.getItem().equals(_itemEnterReviewMode))
{
if(isInReviewMode(player))
{
player.sendMessage(F.main(getName(), "You are already in " + F.item("review mode")));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
return;
}
ReviewData data = new ReviewData(player, getAvalibleLocation());
for(int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, null);
}
player.getInventory().setItem(0, _itemPrevious);
player.getInventory().setItem(1, _itemNext);
player.getInventory().setItem(3, _itemApprove);
player.getInventory().setItem(4, _itemDeny);
player.getInventory().setItem(6, _itemFilter);
player.getInventory().setItem(8, _itemExitReviewMode);
_reviewers.put(player, data);
pasteBuild(player, true);
}
else if(event.getItem().equals(_itemExitReviewMode))
{
if(!isInReviewMode(player))
{
player.sendMessage(F.main(getName(), "You are not currently in " + F.item("review mode")));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
return;
}
for(int i = 0; i < 9; i++)
{
player.getInventory().setItem(i, null);
}
player.getInventory().setItem(0, _itemEnterReviewMode);
_reviewers.remove(player);
player.teleport(_spawn);
}
else if(!isInReviewMode(player))
{
player.sendMessage(F.main(getName(), "Invalid action!"));
player.sendMessage(F.main(getName(), "You are not currently in " + F.item("review mode")));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
return;
}
else if(event.getItem().equals(_itemApprove))
{
ReviewData reviewData = _reviewers.get(player);
MavericksBuildWrapper data = reviewData.getData();
if(data == null)
{
player.sendMessage(F.main(getName(), "Invalid action!"));
player.sendMessage(F.main(getName(), "You are currently not reviewing a build."));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
return;
}
if(data.isReviewed())
{
player.sendMessage(F.main(getName(), "This build has already been reviewed!"));
player.sendMessage(F.main(getName(), "Contact the tech wizards if you want to change the"));
player.sendMessage(F.main(getName(), "state of the already reviewed build."));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
return;
}
_repoApprove.add(data, player.getUniqueId()).thenCompose(BukkitFuture.accept((success) ->
{
if(success)
{
player.sendMessage(F.main(getName(), "Marked build as " + F.color("approved", C.cGreen) + "."));
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 0);
_repoBuilds.setReviewed(_reviewers.get(player).getData().getBuildId(), true).thenCompose(BukkitFuture.accept((success2) ->
{
if(success2)
{
data.setReviewed(true);
player.sendMessage(F.main(getName(), "Marked build as " + F.item("processed") + "."));
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 0);
player.sendMessage(F.main(getName(), "Loading next build..."));
pasteBuild(player, true);
}
else
{
player.sendMessage(F.main(getName(), "Unable to mark the build as " + F.color("denied", C.cRed) + "!"));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
}
}));
}
else
{
player.sendMessage(F.main(getName(), "Unable to mark the build as " + F.color("denied", C.cRed) + "!"));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
}
}));
}
else if(event.getItem().equals(_itemDeny))
{
MavericksBuildWrapper data = _reviewers.get(player).getData();
if(data == null)
{
player.sendMessage(F.main(getName(), "Invalid action!"));
player.sendMessage(F.main(getName(), "You are currently not reviewing a build."));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
return;
}
if(data.isReviewed())
{
player.sendMessage(F.main(getName(), "This build has already been reviewed!"));
player.sendMessage(F.main(getName(), "Contact the tech wizards if you want to change the"));
player.sendMessage(F.main(getName(), "state of the already reviewed build."));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
return;
}
_repoBuilds.setReviewed(_reviewers.get(player).getData().getBuildId(), true).thenCompose(BukkitFuture.accept((success) ->
{
if(success)
{
player.sendMessage(F.main(getName(), "Marked build as " + F.color("denied", C.cRed) + "."));
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 0);
player.sendMessage(F.main(getName(), "Loading next build..."));
pasteBuild(player, true);
}
else
{
player.sendMessage(F.main(getName(), "Unable to mark the build as " + F.color("denied", C.cRed) + "!"));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
}
}));
}
else if(event.getItem().equals(_itemFilter))
{
player.sendMessage(F.main(getName(), "Not yet implemented."));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
}
else if(event.getItem().equals(_itemNext))
{
pasteBuild(player, true);
}
else if(event.getItem().equals(_itemPrevious))
{
pasteBuild(player, false);
}
}
public void pasteBuild(Player player, boolean next)
{
ReviewData review = _reviewers.get(player);
if(review == null)
{
player.sendMessage(F.main(getName(), "Invalid action!"));
player.sendMessage(F.main(getName(), "You are not currently in " + F.item("review mode")));
return;
}
MavericksBuildWrapper data = null;
if(next)
{
data = review.getNext();
}
else
{
data = review.getPrevious();
}
if(!next && data == null)
{
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.5f);
player.sendMessage(F.main(getName(), "No more previous build"));
return;
}
if(next && data == null)
{
player.sendMessage(F.main(getName(), "Pulling new data, please wait..."));
getNext((pulledData) ->
{
if(pulledData == null)
{
player.sendMessage(F.main(getName(), "No new data was found."));
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
}
else
{
Bukkit.broadcastMessage("Displaying from DB -2");
try {
display(player, review, pulledData);
} catch(Exception e)
{
e.printStackTrace();
}
}
});
}
if(data != null)
{
Bukkit.broadcastMessage("Displaying fast");
display(player, review, data);
}
}
private void display(Player player, ReviewData review, MavericksBuildWrapper data)
{
Location loc = review.getLoc();
Location paste = loc.clone().add(8, -8, 0);
loc.setDirection(paste.clone().subtract(loc).toVector());
Bukkit.broadcastMessage("Trying to parse from " + data.getDateStamp());
Bukkit.broadcastMessage("SBytes: " + data.getSchematicBytes().length + ", Schematic: " + data.getSchematic());
Schematic schematic = data.getSchematic();
paste.subtract(0, 0, schematic.getLength()/2);
//Clear old blocks for stuff like lava and so on.
for(Block b : UtilBlock.getInBoundingBox(paste, paste.clone().add(32, 26, 32)))
{
UtilBlock.setQuick(_world, b.getX(), b.getY(), b.getZ(), 0, (byte) 0);
}
List<Entity> list = review.getEntitiesInArea();
for(Entity e : list)
{
e.remove();
}
Bukkit.broadcastMessage("Cleared " + list.size() + " entities in area");
SchematicData pasteData = schematic.paste(paste, false, false);
for(Entity e : pasteData.getEntities())
{
if(e instanceof Item)
{
//Don't despawn
e.setTicksLived(32768);
}
else
{
UtilEnt.Vegetate(e, true);
UtilEnt.ghost(e, true, false);
}
}
Location a = paste.clone().add(-1, -1, -1);
Location b = paste.clone().add(schematic.getWidth(), -1, schematic.getLength()+1);
//Display mode, floor and edge
for(Block block : UtilBlock.getInBoundingBox(a, b, false))
{
UtilBlock.setQuick(_world, block.getX(), block.getY(), block.getZ(), 95, (byte) 1);
}
for(Block block : UtilBlock.getInBoundingBox(a, b, false, true, true, false))
{
UtilBlock.setQuick(_world, block.getX(), block.getY()+1, block.getZ(), 95, (byte) 0);
}
/*
* Alternative display mode, everything inside a box
b.add(0, schematic.getHeight()+2, 0);
for(Block block : UtilBlock.getInBoundingBox(a, b, false, true, false, false))
{
UtilBlock.setQuick(_world, block.getX(), block.getY(), block.getZ(), 95, (byte) 0);
}
*/
player.sendMessage(ArcadeFormat.Line);
String key = C.cGreen + C.Bold;
String value = C.cYellow + C.Bold;
SimpleDateFormat dformat = new SimpleDateFormat("LL-MM-DD kk:mm:ss z");
player.sendMessage(key + "BuildId: " + value + data.getBuildId());
player.sendMessage(key + "Creator: " + value + data.getUUID());
player.sendMessage(key + "Last C Name: " + value + (data.hasNameSet() ? data.getName() : C.Italics + "Not Avalible"));
player.sendMessage(key + "Word: " + value + data.getTheme());
player.sendMessage(key + "Place: " + value + data.getPlace());
player.sendMessage(key + "Points: " + value + data.getPoints());
player.sendMessage(key + "Date: " + value + dformat.format(new Date(data.getDateStamp())));
player.sendMessage(key + "Reviewed: " + value + data.isReviewed());
player.sendMessage(ArcadeFormat.Line);
player.setVelocity(new Vector(0,0,0));
player.setAllowFlight(true);
player.setFlying(true);
player.teleport(loc);
review.setData(data);
}
@EventHandler
public void onUpdateParticles(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST) return;
for(ReviewData data : _reviewers.values())
{
if(data.getData() == null) continue;
if(!data.getData().hasParticles()) continue;
for(Entry<Vector, ParticleType> e : data.getData().getParticles().entrySet())
{
Location loc = data.getAreaMin().add(2, 0, 2).add(e.getKey());
ParticleType type = e.getValue();
int amount = 8;
if (type == ParticleType.HUGE_EXPLOSION ||
type == ParticleType.LARGE_EXPLODE ||
type == ParticleType.NOTE)
amount = 1;
UtilParticle.PlayParticleToAll(type, loc, 0.4f, 0.4f, 0.4f, 0, amount, ViewDist.LONG);
}
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
ReviewData data = _reviewers.get(event.getPlayer());
if(data != null)
{
for(Entity e : data.getEntitiesInArea()) e.remove();
for(Block b : UtilBlock.getInBoundingBox(data.getAreaMin(), data.getAreaMax()))
{
UtilBlock.setQuick(_world, b.getX(), b.getY(), b.getZ(), 0, (byte) 0);
}
}
exitReviewMode(event.getPlayer());
}
public boolean isInReviewMode(Player player)
{
return _reviewers.containsKey(player);
}
public void enterReviewMode(Player player)
{
if(isInReviewMode(player)) return;
}
public void exitReviewMode(Player player)
{
if(!isInReviewMode(player)) return;
_reviewers.remove(player);
}
public Location getAvalibleLocation()
{
for(int i = 0; i < 500; i++)
{
Location loc = _spawn.clone().add(100*i, 0, 0);
loc.setY(200);
if(isTaken(loc)) continue;
return loc;
}
return null;
}
private boolean isTaken(Location loc)
{
for(ReviewData data : _reviewers.values())
{
if(data.getData() == null) continue;
if(data.getLoc().equals(loc)) return true;
}
return false;
}
private boolean isTaken(MavericksBuildWrapper wrapper)
{
if(wrapper.isReviewed()) return true;
for(ReviewData data : _reviewers.values())
{
if(data.containsData(wrapper)) return true;
// if(data.getData() == null) continue;
// if(data.getData().equals(wrapper)) return true;
}
return false;
}
public void getNext(Consumer<MavericksBuildWrapper> consumer)
{
pullQueue(getNextIndex(), consumer);
}
public int getNextIndex()
{
for(int i = 0; i < _reviewQueue.size(); i++)
{
MavericksBuildWrapper wrapper = _reviewQueue.get(i);
if(isTaken(wrapper)) continue;
if(wrapper.isReviewed()) continue;
if(wrapper.getSchematic() == null) continue;
Bukkit.broadcastMessage("Found avalible index: " + i);
return i;
}
Bukkit.broadcastMessage("Found no avalible indexes, returning next one: " + _reviewQueue.size());
return _reviewQueue.size();
}
public void pullQueue(int index, Consumer<MavericksBuildWrapper> consumer)
{
if(_reviewQueue.size() > index)
{
consumer.accept(_reviewQueue.get(index));
Bukkit.broadcastMessage("Local queue is bigger then index");
return;
}
Bukkit.broadcastMessage("Pulling from DB, limit: " + (index-_reviewQueue.size()+1) + ", offset " + _reviewQueue.size());
_repoBuilds.getToReview(true, index-_reviewQueue.size()+1, _reviewQueue.size()).thenCompose(BukkitFuture.accept((list) ->
{
Bukkit.broadcastMessage("Retrived " + list.size() + " entries from DB");
_reviewQueue.addAll(list);
if(_reviewQueue.size() > index)
{
Bukkit.broadcastMessage("Found new entry to process!");
consumer.accept(_reviewQueue.get(index));
}
else
{
Bukkit.broadcastMessage("Still not enough though");
consumer.accept(null);
}
}));
}
}

View File

@ -0,0 +1,103 @@
package mineplex.mavericks.review;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksBuildWrapper;
public class ReviewData
{
private Player _player;
private MavericksBuildWrapper _data;
private List<MavericksBuildWrapper> _logg = new ArrayList<>();
private Location _loc;
public ReviewData(Player player, Location loc)
{
_player = player;
_loc = loc.getBlock().getLocation().add(0.5, 0, 0.5);
}
public Player getPlayer()
{
return _player;
}
public Location getLoc()
{
return _loc.clone();
}
public MavericksBuildWrapper getData()
{
return _data;
}
public void setData(MavericksBuildWrapper data)
{
if(!_logg.contains(_data))
{
_logg.add(_data);
}
if(!_logg.contains(data))
{
_logg.add(data);
}
_data = data;
}
public MavericksBuildWrapper getPrevious()
{
int index = _logg.indexOf(_data);
if(index <= 0) return null;
return _logg.get(index-1);
}
public MavericksBuildWrapper getNext()
{
int index = _logg.indexOf(_data);
if(index == -1) return null;
if(index+1 >= _logg.size()) return null;
return _logg.get(index+1);
}
public boolean containsData(MavericksBuildWrapper data)
{
return _logg.contains(data);
}
public Location getAreaMin()
{
return _loc.clone().add(8-2, -8, 0-16-2);
}
public Location getAreaMax()
{
return _loc.clone().add(8+32+2, -8+25+1, 0-16+32+2);
}
public List<Entity> getEntitiesInArea()
{
List<Entity> list = new ArrayList<>();
for(Entity e : _loc.getWorld().getEntities())
{
if(e instanceof Player) continue;
if(isInsideArea(e.getLocation())) list.add(e);
}
return list;
}
public boolean isInsideArea(Location loc)
{
return loc.toVector().isInAABB(getAreaMin().toVector(), getAreaMax().toVector());
}
}

View File

@ -0,0 +1,8 @@
package nautilus.game.arcade;
import mineplex.core.common.util.C;
public class ArcadeFormat
{
public static String Line = C.cDGreen + C.Strike + "=============================================";
}

View File

@ -0,0 +1,119 @@
package nautilus.game.arcade.game.games.buildmavericks.repository;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import mineplex.serverdata.database.DBPool;
/**
* Repository for Mavericks-MasterBuilders SQL game data
* -
* Table to back this repository may be created with
* CREATE TABLE mavericksMasterBuildersApproved (
buildId INT NOT NULL AUTO_INCREMENT,
ApproveDate INT NOT NULL,
ApprovedBy VARCHAR(36) NOT NULL DEFAULT '',
Display TINYINT(1) NOT NULL DEFAULT '1',
PRIMARY KEY (buildId),
CONSTRAINT account_id FOREIGN KEY (ApprovedBy) REFERENCES accounts (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT build_id FOREIGN KEY (BuildId) REFERENCES mavericksMasterBuildersBuilds (BuildId) ON DELETE NO ACTION ON UPDATE NO ACTION
)
*/
public class MavericksApprovedRepository
{
private static final String TABLE = "mavericksMasterBuildersApproved";
public CompletableFuture<Boolean> add(MavericksBuildWrapper data, UUID approvedBy)
{
return add(data, approvedBy, true);
}
public CompletableFuture<Boolean> add(MavericksBuildWrapper data, UUID approvedBy, boolean display)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("REPLACE INTO " + TABLE + " (BuildId, ApprovedBy, Display) SELECT ?, accounts.id, ? FROM accounts WHERE uuid=?");
stmt.setLong(1, data.getBuildId());
stmt.setBoolean(2, display);
stmt.setString(3, approvedBy.toString());
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<List<MavericksBuildWrapper>> getToDisplay(boolean onlyDisplay, int limit, int offset)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
String filter = onlyDisplay ? "WHERE Display=1 " : "";
PreparedStatement stmt = conn.prepareStatement("SELECT BuildId," +
"(SELECT uuid from accounts WHERE accounts.id=" + TABLE + ".accountId)," +
"(SELECT name from accounts WHERE accounts.id=" + TABLE + ".accountId)," +
",BuildTheme,Points,Place,Date,Schematic,Reviewed FROM " + TABLE + " " + filter +
" LIMIT " + limit + " OFFSET " + offset);
ResultSet set = stmt.executeQuery();
List<MavericksBuildWrapper> list = new ArrayList<>();
while (set.next())
{
long buildId = set.getLong(1);
UUID uuid = UUID.fromString(set.getString(2));
String lastName = set.getString(3);
String theme = set.getString(4);
int votes = set.getInt(5);
int place = set.getInt(6);
long dateStamp = set.getLong(7);
byte[] schematic = set.getBytes(8);
byte[] particles = set.getBytes(9);
boolean reviewed = set.getBoolean(10);
list.add(new MavericksBuildWrapper(buildId, uuid, lastName, theme, votes, place, dateStamp, schematic, particles, reviewed));
}
return list;
}
catch (SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Boolean> setDisplay(long buildid, boolean display)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE + " SET Display=? WHERE BuildId=?");
stmt.setBoolean(1, display);
stmt.setLong(2, buildid);
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
}

View File

@ -0,0 +1,95 @@
package nautilus.game.arcade.game.games.buildmavericks.repository;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import mineplex.serverdata.database.DBPool;
/**
* Repository for Mavericks-MasterBuilders SQL game data
* -
* Table to back this repository may be created with
* CREATE TABLE IF NOT EXISTS mavericksMasterBuildersBuilds (
accountId INT NOT NULL,
BuildTheme VARCHAR(255) NOT NULL,
Points DOUBLE NOT NULL,
Place INT NOT NULL,
Date BIGINT NOT NULL,
Schematic BLOB,
Reviewed TINYINT,
PRIMARY KEY (accountId,Date),
FOREIGN KEY (accountId) REFERENCES accounts(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
*/
public class MavericksBuildRepository
{
private static final String TABLE = "mavericksMasterBuildersBuilds";
public CompletableFuture<List<MavericksBuildWrapper>> getToReview(boolean onlyUnreviewed, int limit, int offset)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
String filter = onlyUnreviewed ? "WHERE Reviewed=0 " : "";
PreparedStatement stmt = conn.prepareStatement("SELECT BuildId," +
"(SELECT uuid from accounts WHERE accounts.id=" + TABLE + ".accountId)," +
"(SELECT name from accounts WHERE accounts.id=" + TABLE + ".accountId)," +
"BuildTheme,Points,Place,Date,Schematic,Particles,Reviewed FROM " + TABLE + " " + filter +
" ORDER BY Points DESC LIMIT " + limit + " OFFSET " + offset);
ResultSet set = stmt.executeQuery();
List<MavericksBuildWrapper> list = new ArrayList<>();
while (set.next())
{
long buildId = set.getLong(1);
UUID uuid = UUID.fromString(set.getString(2));
String lastName = set.getString(3);
String theme = set.getString(4);
int votes = set.getInt(5);
int place = set.getInt(6);
long dateStamp = set.getLong(7);
byte[] schematic = set.getBytes(8);
byte[] particles = set.getBytes(9);
boolean reviewed = set.getBoolean(10);
list.add(new MavericksBuildWrapper(buildId, uuid, lastName, theme, votes, place, dateStamp, schematic, particles, reviewed));
}
return list;
}
catch (SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Boolean> setReviewed(long buildId, boolean reviewed)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE + " SET Reviewed=? WHERE BuildId=?");
stmt.setBoolean(1, reviewed);
stmt.setLong(2, buildId);
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
}

View File

@ -0,0 +1,170 @@
package nautilus.game.arcade.game.games.buildmavericks.repository;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.util.Vector;
import com.java.sk89q.jnbt.CompoundTag;
import com.java.sk89q.jnbt.NBTUtils;
import com.java.sk89q.jnbt.Tag;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.UtilParticle.ParticleType;
/**
* A simple wrapper class for Mavericks-MasterBuilders SQL data
*/
public class MavericksBuildWrapper
{
private final long _buildId;
private final UUID _uuid;
private final String _theme;
private final double _points;
private final int _place;
private final long _dateStamp;
private final byte[] _schematic;
private final byte[] _particles;
private boolean _reviewed;
private final String _name;
public MavericksBuildWrapper(long buildId, UUID uuid, String name, String theme, double points, int place, long dateStamp,
byte[] schematic, byte[] particles, boolean reviewed)
{
this._buildId = buildId;
this._uuid = uuid;
this._name = name;
this._theme = theme;
this._points = points;
this._place = place;
this._dateStamp = dateStamp;
this._schematic = schematic;
this._particles = particles;
this._reviewed = reviewed;
}
public MavericksBuildWrapper(long buildId, UUID uuid, String theme, double points, int place, long dateStamp,
byte[] schematic, byte[] particles, boolean reviewed)
{
this(buildId, uuid, null, theme, points, place, dateStamp, schematic, particles, reviewed);
}
public long getBuildId()
{
return _buildId;
}
public UUID getUUID()
{
return _uuid;
}
public String getName()
{
return _name;
}
public boolean hasNameSet()
{
return _name != null;
}
public String getTheme()
{
return _theme;
}
public double getPoints()
{
return _points;
}
public int getPlace()
{
return _place;
}
public long getDateStamp()
{
return _dateStamp;
}
public byte[] getSchematicBytes()
{
return _schematic;
}
public boolean isReviewed()
{
return _reviewed;
}
public void setReviewed(boolean reviewed)
{
_reviewed = reviewed;
}
public Schematic getSchematic()
{
try
{
return UtilSchematic.loadSchematic(_schematic);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public boolean hasParticles()
{
return _particles != null && _particles.length > 0;
}
public byte[] getParticlesRaw()
{
return _particles;
}
public Map<Vector, ParticleType> getParticles()
{
Map<Vector, ParticleType> map = new HashMap<>();
if(!hasParticles()) return map;
try
{
CompoundTag tag = (CompoundTag) NBTUtils.getFromBytesCompressed(_particles).getTag();
for(Entry<String, Tag> e : tag.getValue().entrySet())
{
CompoundTag parent = (CompoundTag) e.getValue();
Vector v = NBTUtils.getVector(parent);
ParticleType particle = ParticleType.valueOf(parent.getString("particle"));
while(map.containsKey(v)) v.add(new Vector(0.00000001, 0, 0));
map.put(v, particle);
}
}
catch (Exception e)
{
e.printStackTrace();
}
return map;
}
@Override
public String toString()
{
return "MavericksBuildWrapper[uuid='" + _uuid + "',theme='" + _theme + "',points=" + _points + ",place=" + _place
+ ",date=" + _dateStamp + ",Schematic=ByteArray[" + _schematic.length + "]]";
}
}

View File

@ -36,6 +36,8 @@
<module>Mineplex.StaffServer</module>
<module>Mineplex.Votifier</module>
<module>Nautilus.Game.Arcade</module>
<module>mavericks-review-hub</module>
</modules>
<repositories>