Finalized the hub module and finished local testing

Cleaned up some source. Applied some small updates. Finished local
testing.
This commit is contained in:
xGamingDudex 2016-06-27 00:34:17 +02:00
parent 966eaf1616
commit d6672c44f4
15 changed files with 383 additions and 488 deletions

View File

@ -0,0 +1,115 @@
package mineplex.core.mavericks;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.util.Vector;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.SchematicData;
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;
public class DisplaySlot
{
private MavericksApprovedWrapper _data;
private Location _loc;
private ArrayList<Entity> _pastedEntities = new ArrayList<>();
private Map<Vector, ParticleType> _particles = null;
public DisplaySlot(Location loc)
{
_loc = loc.clone();
}
public MavericksApprovedWrapper getData()
{
return _data;
}
public void setData(MavericksApprovedWrapper data)
{
clearEntities();
Schematic schematic = data.getBuild().getSchematic();
Location a = _loc;
Location b = _loc.clone().add(schematic.getWidth(), schematic.getHeight(), schematic.getLength());
for(int x = a.getBlockX(); x < b.getX(); x++)
{
for(int y = a.getBlockY(); y < b.getY(); y++)
{
for(int z = a.getBlockZ(); z < b.getZ(); z++)
{
UtilBlock.setQuick(a.getWorld(), x, y, z, 0, (byte) 0);
}
}
}
SchematicData pasteData = schematic.paste(_loc, true, false);
for(Entity e : pasteData.getEntities())
{
if(e instanceof Item)
{
//Don't despawn
e.setTicksLived(32768);
//Prevent Pickup
((Item)e).setPickupDelay(32767);
}
else
{
UtilEnt.Vegetate(e, true);
UtilEnt.ghost(e, true, false);
}
_pastedEntities.add(e);
}
_particles = data.getBuild().getParticles();
_data = data;
}
public void updateParticles()
{
if(_particles == null) return;
for(Entry<Vector, ParticleType> e : _particles.entrySet())
{
Location loc = _loc.clone().add(2, 0, 7).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);
}
}
private void clearEntities()
{
for(Entity e : _pastedEntities)
{
e.remove();
}
_pastedEntities.clear();
}
public boolean isDisplaySlotEntity(Entity e)
{
return _pastedEntities.contains(e);
}
}

View File

@ -1,6 +1,7 @@
package mineplex.core.mavericks;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -28,7 +29,8 @@ import mineplex.serverdata.database.DBPool;
public class MavericksApprovedRepository
{
private static final String TABLE = "mavericksMasterBuildersApproved";
private static final String TABLE_APPROVED = "mavericksMasterBuildersApproved";
private static final String TABLE_BUILD = "mavericksMasterBuildersBuilds";
public CompletableFuture<Boolean> add(MavericksBuildWrapper data, UUID approvedBy)
{
@ -41,7 +43,7 @@ public class MavericksApprovedRepository
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("REPLACE INTO " + TABLE + " (BuildId, ApprovedBy, Display) SELECT ?, accounts.id, ? FROM accounts WHERE uuid=?");
PreparedStatement stmt = conn.prepareStatement("REPLACE INTO " + TABLE_APPROVED + " (BuildId, ApprovedBy, Display) SELECT ?, accounts.id, ? FROM accounts WHERE uuid=?");
stmt.setLong(1, data.getBuildId());
stmt.setBoolean(2, display);
stmt.setString(3, approvedBy.toString());
@ -56,34 +58,61 @@ public class MavericksApprovedRepository
});
}
public CompletableFuture<List<MavericksBuildWrapper>> getToDisplay(boolean onlyDisplay, int limit, int offset)
public CompletableFuture<List<MavericksApprovedWrapper>> 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);
String filter = onlyDisplay ? " WHERE Display=1 " : " ";
// PreparedStatement stmt3 = conn.prepareStatement("SELECT BuildId," +
// "(SELECT uuid from accounts WHERE accounts.id=" + TABLE_APPROVED + ".accountId)," +
// "(SELECT name from accounts WHERE accounts.id=" + TABLE_APPROVED + ".accountId)," +
// ",BuildTheme,Points,Place,Date,Schematic,Reviewed FROM " + TABLE_APPROVED + " " + filter +
// " LIMIT " + limit + " OFFSET " + offset);
PreparedStatement stmt = conn.prepareStatement(
"SELECT " +
TABLE_APPROVED + ".BuildId, ApprovedDate," +
"(SELECT uuid FROM accounts WHERE accounts.id=ApprovedBy)," +
"Display, FirstDisplayed," +
"BuildTheme," +
"(SELECT uuid FROM accounts WHERE accounts.id=accountId)," +
"(SELECT name FROM accounts WHERE accounts.id=accountId)," +
"Points, Place, Date, Schematic, Particles, Reviewed " +
"FROM " + TABLE_APPROVED + " " +
"INNER JOIN " + TABLE_BUILD + " " +
"ON " + TABLE_APPROVED + ".BuildId = " + TABLE_BUILD + ".BuildId" +
filter +
"LIMIT " + limit + " OFFSET " + offset);
ResultSet set = stmt.executeQuery();
List<MavericksBuildWrapper> list = new ArrayList<>();
List<MavericksApprovedWrapper> 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));
long approvedDate = set.getLong(2);
UUID approvedBy = UUID.fromString(set.getString(3));
boolean display = set.getBoolean(4);
Long firstDisplayed = set.getLong(5);
if(set.wasNull()) firstDisplayed = null;
String theme = set.getString(6);
UUID uuid = UUID.fromString(set.getString(7));
String lastName = set.getString(8);
int votes = set.getInt(9);
int place = set.getInt(10);
long dateStamp = set.getLong(11);
byte[] schematic = set.getBytes(12);
byte[] particles = set.getBytes(13);
boolean reviewed = set.getBoolean(14);
MavericksBuildWrapper build = new MavericksBuildWrapper(buildId, uuid, lastName, theme, votes, place, dateStamp, schematic, particles, reviewed);
MavericksApprovedWrapper approved = new MavericksApprovedWrapper(build, approvedDate, approvedBy, display, firstDisplayed);
list.add(approved);
}
return list;
}
@ -95,16 +124,25 @@ public class MavericksApprovedRepository
});
}
public CompletableFuture<Boolean> setDisplay(long buildid, boolean display)
public CompletableFuture<Boolean> setDisplay(boolean display, long... buildids)
{
if(buildids.length == 0) return null;
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE + " SET Display=? WHERE BuildId=?");
String where = "WHERE BuildId=?";
for(int i = 1; i < buildids.length; i++)
{
where += " OR BuildId=?";
}
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE_APPROVED + " SET Display=? " + where);
stmt.setBoolean(1, display);
stmt.setLong(2, buildid);
for(int i = 0; i < buildids.length; i++)
{
stmt.setLong(2+i, buildids[i]);
}
return stmt.executeUpdate() > 0;
}
@ -115,5 +153,25 @@ public class MavericksApprovedRepository
}
});
}
public CompletableFuture<Boolean> setDisplayDate(long buildid)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE_APPROVED + " SET FirstDisplayed=? WHERE BuildId=?");
stmt.setDate(1, new Date(System.currentTimeMillis()));
stmt.setLong(2, buildid);
return stmt.executeUpdate() > 0;
}
catch(Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
}

View File

@ -0,0 +1,58 @@
package mineplex.core.mavericks;
import java.util.UUID;
/**
* A wrapper class to SQL data in the mavericksMasterBuildersApproved SQL table
*/
public class MavericksApprovedWrapper
{
private final MavericksBuildWrapper _build;
private final long _approvedDate;
private final UUID _approvedBy;
private final boolean _display;
private Long _firstDisplayed;
public MavericksApprovedWrapper(MavericksBuildWrapper build, long approvedDate, UUID approvedBy, boolean display, Long firstDisplayed)
{
_build = build;
_approvedDate = approvedDate;
_approvedBy = approvedBy;
_display = display;
_firstDisplayed = firstDisplayed;
}
public MavericksBuildWrapper getBuild()
{
return _build;
}
public long getApprovedDate()
{
return _approvedDate;
}
public UUID getApprovedBy()
{
return _approvedBy;
}
public Long getFirstDisplayed()
{
return _firstDisplayed;
}
public void setFirstDisplayed(Long firstDisplayed)
{
_firstDisplayed = firstDisplayed;
}
public boolean isDisplay()
{
return _display;
}
}

View File

@ -1,5 +1,9 @@
package mineplex.hub;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.CustomTagFix;
import mineplex.core.PacketsInteractionFix;
import mineplex.core.account.CoreClientManager;
@ -8,9 +12,6 @@ import mineplex.core.antihack.AntiHack;
import mineplex.core.aprilfools.AprilFoolsManager;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.SnapshotPlugin;
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
import mineplex.core.command.CommandCenter;
import mineplex.core.common.events.ServerShutdownEvent;
import mineplex.core.creature.Creature;
@ -43,8 +44,6 @@ import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.sponsorbranding.BrandingManager;
@ -58,6 +57,7 @@ import mineplex.core.updater.Updater;
import mineplex.core.velocity.VelocityFix;
import mineplex.core.visibility.VisibilityManager;
import mineplex.hub.modules.BillboardManager;
import mineplex.hub.modules.MavericksManager;
import mineplex.hub.modules.StackerManager;
import mineplex.hub.queue.QueueManager;
import mineplex.hub.server.ServerManager;
@ -72,10 +72,6 @@ import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Hub extends JavaPlugin implements IRelation
{
private String WEB_CONFIG = "webServer";

View File

@ -112,6 +112,7 @@ import mineplex.hub.modules.ForcefieldManager;
import mineplex.hub.modules.HubVisibilityManager;
import mineplex.hub.modules.JumpManager;
import mineplex.hub.modules.KothManager;
import mineplex.hub.modules.MavericksManager;
import mineplex.hub.modules.NewsManager;
import mineplex.hub.modules.ParkourManager;
import mineplex.hub.modules.SoccerManager;
@ -169,6 +170,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
private BonusManager _bonusManager;
// private HalloweenSpookinessManager _halloweenManager;
// private TrickOrTreatManager _trickOrTreatManager;
private MavericksManager _mavericksManager;
private Location _spawn;
private int _scoreboardTick = 0;
@ -215,6 +217,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
new WorldManager(this);
new JumpManager(this);
//new TournamentInviter(this);
_mavericksManager = new MavericksManager(plugin);
_news = new NewsManager(this);
@ -920,6 +924,11 @@ public class HubManager extends MiniClientPlugin<HubClient>
{
return _punishManager;
}
public MavericksManager getMavericksManager()
{
return _mavericksManager;
}
// public HalloweenSpookinessManager getHalloweenManager()
// {

View File

@ -2,22 +2,30 @@ package mineplex.hub.modules;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.mavericks.DisplaySlot;
import mineplex.core.mavericks.MavericksApprovedRepository;
import mineplex.core.mavericks.MavericksBuildWrapper;
import mineplex.core.mavericks.MavericksApprovedWrapper;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.modules.mavericks.DisplaySlot;
import mineplex.hub.modules.mavericks.MavericksPortalManager;
public class MavericksManager extends MiniPlugin
{
// private static final long ROTATION_TIME = 1000*60*60*6;
private static final long ROTATION_TIME = 1000*30;
private MavericksPortalManager _portalManager;
private MavericksApprovedRepository _repoApproved;
@ -28,29 +36,33 @@ public class MavericksManager extends MiniPlugin
super("Mavericks", plugin);
_portalManager = new MavericksPortalManager(_plugin);
_repoApproved = new MavericksApprovedRepository();
_displaySlots.add(new DisplaySlot(new Location(Bukkit.getWorld("world"), -19, 63, -118)));
_displaySlots.add(new DisplaySlot(new Location(Bukkit.getWorld("world"), -19, 63, -145)));
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if(event.getType() != UpdateType.MIN_02) return;
if(event.getType() != UpdateType.SLOW) return;
_repoApproved.getToDisplay(true, _displaySlots.size(), 0).thenCompose(BukkitFuture.accept((list) ->
{
Function<? super List<MavericksApprovedWrapper>, ? extends CompletionStage<Void>> updateTask = BukkitFuture.accept((list) ->
{
List<DisplaySlot> openSlots = new ArrayList<>();
List<MavericksBuildWrapper> undisplayedData = new ArrayList<>();
List<MavericksApprovedWrapper> undisplayedData = new ArrayList<>();
undisplayedData.addAll(list);
slots:
for(DisplaySlot slot : _displaySlots)
{
for(MavericksBuildWrapper build : list)
if(slot.getData() != null)
{
if(slot.getData().getBuildId() == build.getBuildId())
for(MavericksApprovedWrapper build : list)
{
undisplayedData.remove(build);
continue slots;
if(slot.getData().getBuild().getBuildId() == build.getBuild().getBuildId())
{
undisplayedData.remove(build);
continue slots;
}
}
}
openSlots.add(slot);
@ -58,11 +70,74 @@ public class MavericksManager extends MiniPlugin
for(int i = 0; i < Math.min(openSlots.size(), undisplayedData.size()); i++)
{
openSlots.get(i).setData(undisplayedData.get(i));
MavericksApprovedWrapper approved = undisplayedData.get(i);
if(approved.getFirstDisplayed() == null)
{
_repoApproved.setDisplayDate(approved.getBuild().getBuildId());
}
openSlots.get(i).setData(approved);
}
}));
});
List<DisplaySlot> outdated = new ArrayList<>();
for(DisplaySlot slot : _displaySlots)
{
if(slot.getData() == null) continue;
if(slot.getData().getFirstDisplayed() == null)
{
_repoApproved.setDisplayDate(slot.getData().getBuild().getBuildId());
slot.getData().setFirstDisplayed(System.currentTimeMillis());
}
else if(slot.getData().getFirstDisplayed() + ROTATION_TIME < System.currentTimeMillis())
{
outdated.add(slot);
}
}
if(outdated.size() > 0)
{
_repoApproved.getToDisplay(true, outdated.size(), _displaySlots.size()).thenCompose(BukkitFuture.accept((list2) ->
{
if(list2.isEmpty()) return;
long[] ids = new long[list2.size()];
for(int i = 0; i < list2.size(); i++)
{
ids[i] = outdated.get(i).getData().getBuild().getBuildId();
}
_repoApproved.setDisplay(false, ids).thenCompose(BukkitFuture.accept((success) ->
{
_repoApproved.getToDisplay(true, _displaySlots.size(), 0).thenCompose(updateTask);
}));
}));
}
else
{
_repoApproved.getToDisplay(true, _displaySlots.size(), 0).thenCompose(updateTask);
}
}
@EventHandler
public void updateParticles(UpdateEvent event)
{
if(event.getType() == UpdateType.FAST)
{
for(DisplaySlot d : _displaySlots)
{
d.updateParticles();
}
}
}
public boolean isStatueEntity(Entity e)
{
for(DisplaySlot d : _displaySlots)
{
if(d.isDisplaySlotEntity(e)) return true;
}
return false;
}
public MavericksPortalManager getPortalManager()
{

View File

@ -81,6 +81,9 @@ public class StackerManager extends MiniPlugin implements IThrown
if (stackee instanceof EnderDragon)
return;
if (Manager.getMavericksManager().isStatueEntity(stackee))
return;
if (stackee instanceof Player && ((Player)stackee).getGameMode() != GameMode.SURVIVAL)
return;

View File

@ -1,47 +0,0 @@
package mineplex.hub.modules.mavericks;
import org.bukkit.Location;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.mavericks.MavericksBuildWrapper;
public class DisplaySlot
{
private MavericksBuildWrapper _data;
private Location _loc;
public DisplaySlot(Location loc)
{
_loc = loc.clone();
}
public MavericksBuildWrapper getData()
{
return _data;
}
public void setData(MavericksBuildWrapper data)
{
Schematic schematic = data.getSchematic();
Location a = _loc;
Location b = _loc.clone().add(schematic.getWidth(), schematic.getHeight(), schematic.getLength());
for(int x = a.getBlockX(); x < b.getX(); x++)
{
for(int y = a.getBlockY(); y < b.getY(); y++)
{
for(int z = a.getBlockZ(); z < b.getZ(); z++)
{
UtilBlock.setQuick(a.getWorld(), x, y, z, 0, (byte) 0);
}
}
}
schematic.paste(_loc, true, false);
_data = data;
}
}

View File

@ -33,11 +33,11 @@ public class MavericksPortalManager extends MiniPlugin
super("Mavericks Teleporter", plugin);
_portalHubMavericks = new Box("world", new Vector(0, 200, 0), new Vector(10, 210, 10));
_destMavericks = new Location(Bukkit.getWorld("world"), 100, 200, 100);
_portalHubMavericks = new Box("world", new Vector(6, 72, -1), new Vector(5, 75, 1));
_destMavericks = new Location(Bukkit.getWorld("world"), -32, 63, -119, -90, 0);
_portalMavericksHub = new Box("world", new Vector(0, 100, 0), new Vector(10, 110, 10));
_destHub = new Location(Bukkit.getWorld("world"), 100, 100, 100);
_portalMavericksHub = new Box("world", new Vector(-36, 63, -120), new Vector(-35, 66, -117));
_destHub = new Location(Bukkit.getWorld("world"), 0.5, 80, 0.5);
}
@EventHandler

View File

@ -375,12 +375,12 @@ public class BuildData
protected Location getMin()
{
return Vector.getMinimum(CornerA.toVector(), CornerB.toVector()).toLocation(CornerA.getWorld()).subtract(0, 1, 0);
return Vector.getMinimum(CornerA.toVector(), CornerB.toVector()).toBlockVector().toLocation(CornerA.getWorld()).subtract(0, 1, 0);
}
protected Location getMax()
{
return Vector.getMaximum(CornerA.toVector(), CornerB.toVector()).toLocation(CornerA.getWorld());
return Vector.getMaximum(CornerA.toVector(), CornerB.toVector()).toBlockVector().toLocation(CornerA.getWorld());
}
public double getMaxHeight()

View File

@ -24,7 +24,7 @@ public class BuildDataCylinder extends BuildData
public BuildDataCylinder(Player player, Location spawn, Location center)
{
super(player, spawn);
_blockSpawn = center;
_blockSpawn = center.getBlock().getLocation();
}
@Override

View File

@ -22,6 +22,7 @@ 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.BlockIgniteEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -134,6 +135,12 @@ public class MavericksReviewManager extends MiniPlugin
}.runTask(UtilServer.getPlugin());
}
@EventHandler
public void onIgnite(BlockIgniteEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onPhysics(BlockPhysicsEvent event)
{
@ -530,7 +537,7 @@ public class MavericksReviewManager extends MiniPlugin
for(Entry<Vector, ParticleType> e : data.getData().getParticles().entrySet())
{
Location loc = data.getAreaMin().add(2, 0, 2).add(e.getKey());
Location loc = data.getAreaMin().add(2, 0, 7).add(e.getKey());
ParticleType type = e.getValue();
@ -642,8 +649,13 @@ public class MavericksReviewManager extends MiniPlugin
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) ->
int offset = 0;
for(MavericksBuildWrapper build : _reviewQueue)
{
if(!build.isReviewed()) offset++;
}
Bukkit.broadcastMessage("Pulling from DB, limit: " + (index-_reviewQueue.size()+1) + ", offset " + offset);
_repoBuilds.getToReview(true, index-_reviewQueue.size()+1, offset).thenCompose(BukkitFuture.accept((list) ->
{
Bukkit.broadcastMessage("Retrived " + list.size() + " entries from DB");
_reviewQueue.addAll(list);

View File

@ -1,119 +0,0 @@
package nautilus.game.arcade.game.games.buildmavericks.repository2;
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

@ -1,95 +0,0 @@
package nautilus.game.arcade.game.games.buildmavericks.repository2;
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

@ -1,170 +0,0 @@
package nautilus.game.arcade.game.games.buildmavericks.repository2;
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 + "]]";
}
}