Moved mavericks repository resources to core, merging review and game
This commit is contained in:
parent
d6afe986ea
commit
318c137aba
@ -0,0 +1,119 @@
|
||||
package mineplex.core.mavericks;
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package mineplex.core.mavericks;
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> add(MavericksBuildWrapper data)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
try (Connection conn = DBPool.getAccount().getConnection())
|
||||
{
|
||||
|
||||
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.setBytes(6, data.getParticlesRaw());
|
||||
stmt.setString(7, data.getUUID().toString());
|
||||
|
||||
return stmt.executeUpdate() > 0;
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository;
|
||||
package mineplex.core.mavericks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
@ -21,10 +21,10 @@ public class BuildDataCylinder extends BuildData
|
||||
private final double HEIGHT = 25;
|
||||
private final Location _blockSpawn;
|
||||
|
||||
public BuildDataCylinder(Player player, Location spawn)
|
||||
public BuildDataCylinder(Player player, Location spawn, Location center)
|
||||
{
|
||||
super(player, spawn);
|
||||
_blockSpawn = spawn.getWorld().getHighestBlockAt(spawn).getLocation().add(0.5, 0, 0.5);
|
||||
_blockSpawn = center;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,12 +28,12 @@ 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 mineplex.core.mavericks.MavericksBuildRepository;
|
||||
import mineplex.core.mavericks.MavericksBuildWrapper;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.games.build.Build;
|
||||
import nautilus.game.arcade.game.games.build.BuildData;
|
||||
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksBuildWrapper;
|
||||
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksRepository;
|
||||
|
||||
/**
|
||||
* A custom implementation of the Master Builders game in conjunction with the Mavericks basketball team.
|
||||
@ -41,7 +41,7 @@ import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksReposi
|
||||
public class BuildMavericks extends Build
|
||||
{
|
||||
|
||||
private MavericksRepository _reposetory;
|
||||
private MavericksBuildRepository _reposetory;
|
||||
private List<Player> _places;
|
||||
private Map<Player, BuildData> _dataClone = new HashMap<>();
|
||||
|
||||
@ -70,7 +70,7 @@ public class BuildMavericks extends Build
|
||||
"Water Gun", "Astronaut", "Wither", "Meteor"
|
||||
};
|
||||
|
||||
_reposetory = new MavericksRepository();
|
||||
_reposetory = new MavericksBuildRepository();
|
||||
|
||||
//TODO: REMOVE AFTER DEBUG!
|
||||
/*
|
||||
@ -275,7 +275,9 @@ public class BuildMavericks extends Build
|
||||
{
|
||||
Location spawn = UtilAlg.findClosest(player.getLocation(), this.GetTeamList().get(0).GetSpawns());
|
||||
|
||||
_data.put(player, new BuildDataCylinder(player, spawn));
|
||||
Location center = UtilAlg.findClosest(player.getLocation(), WorldData.GetDataLocs("YELLOW"));
|
||||
|
||||
_data.put(player, new BuildDataCylinder(player, spawn, center));
|
||||
|
||||
player.setFlySpeed(0.1f);
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
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),
|
||||
INDEX acc_ind (accountId),
|
||||
FOREIGN KEY (accountId) REFERENCES accounts(id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
*/
|
||||
public class MavericksRepository
|
||||
{
|
||||
|
||||
private static final String TABLE = "mavericksMasterBuildersBuilds";
|
||||
|
||||
public CompletableFuture<Boolean> add(MavericksBuildWrapper data)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
try (Connection conn = DBPool.getAccount().getConnection())
|
||||
{
|
||||
|
||||
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.setBytes(6, data.getParticlesRaw());
|
||||
stmt.setString(7, data.getUUID().toString());
|
||||
|
||||
return stmt.executeUpdate() > 0;
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,8 @@ import mineplex.core.ignore.IgnoreManager;
|
||||
import mineplex.core.incognito.IncognitoManager;
|
||||
import mineplex.core.inventory.InventoryManager;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.mavericks.MavericksApprovedRepository;
|
||||
import mineplex.core.mavericks.MavericksBuildRepository;
|
||||
import mineplex.core.memory.MemoryFix;
|
||||
import mineplex.core.message.MessageManager;
|
||||
import mineplex.core.monitor.LagMeter;
|
||||
@ -43,8 +45,6 @@ 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
|
||||
|
@ -18,15 +18,14 @@ 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.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@ -50,18 +49,18 @@ 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.UtilServer;
|
||||
import mineplex.core.common.util.worldgen.WorldGenCleanRoom;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.mavericks.MavericksApprovedRepository;
|
||||
import mineplex.core.mavericks.MavericksBuildRepository;
|
||||
import mineplex.core.mavericks.MavericksBuildWrapper;
|
||||
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
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nautilus.game.arcade.game.games.buildmavericks.repository.MavericksBuildWrapper;
|
||||
import mineplex.core.mavericks.MavericksBuildWrapper;
|
||||
|
||||
public class ReviewData
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository;
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository2;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
@ -1,4 +1,4 @@
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository;
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository2;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
@ -1,4 +1,4 @@
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository;
|
||||
package nautilus.game.arcade.game.games.buildmavericks.repository2;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
Loading…
Reference in New Issue
Block a user