Skip to content

Commit

Permalink
The Late Update
Browse files Browse the repository at this point in the history
To fix the arena not dropping blocks (Decimal formater generating a ','
instead of a '.')
and the inventory title size limit.
  • Loading branch information
ChagnonSebastien committed May 29, 2016
1 parent cb29e96 commit ecc4261
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Bukkit/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CubeRunner
main : me.poutineqc.cuberunner.CubeRunner
version: 2.4.1
version: 2.4.2
description: Blocks are falling over your head! Can you outrun them?
load: postworld
author: PoutineQc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,41 @@
import me.poutineqc.cuberunner.Language.Messages;

public abstract class CRInventory {
protected Inventory inventory;
protected CRPlayer crPlayer;
protected int amountOfRows;
protected String title;

public CRInventory(CRPlayer crPlayer) {
this.crPlayer = crPlayer;
}

public abstract void fillInventory() throws PlayerStatsException;

public abstract void update(ItemStack itemStack, InventoryAction action);

public static boolean areEqualOnColorStrip(String itemA, String itemB) {
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', itemA))
.equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', itemB)));
}

protected void createInventory() {
inventory = Bukkit.createInventory(crPlayer.getPlayer(), amountOfRows * 9, getFullTitle());
}

protected String getFullTitle() {
return ChatColor.translateAlternateColorCodes('&', crPlayer.getLanguage().get(Messages.PREFIX_LONG) + " " + title);
}

protected void openInventory() {
crPlayer.getPlayer().openInventory(inventory);
crPlayer.setCurrentInventory(this);
}

protected void closeInventory() {
crPlayer.getPlayer().closeInventory();
crPlayer.setCurrentInventory(null);
}
protected Inventory inventory;
protected CRPlayer crPlayer;
protected int amountOfRows;
protected String title;

public CRInventory(CRPlayer crPlayer) {
this.crPlayer = crPlayer;
}

public abstract void fillInventory() throws PlayerStatsException;

public abstract void update(ItemStack itemStack, InventoryAction action);

public static boolean areEqualOnColorStrip(String itemA, String itemB) {
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', itemA))
.equalsIgnoreCase(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', itemB)));
}

protected void createInventory() {
inventory = Bukkit.createInventory(crPlayer.getPlayer(), amountOfRows * 9, getFullTitle());
}

protected String getFullTitle() {
String title = ChatColor.translateAlternateColorCodes('&',
crPlayer.getLanguage().get(Messages.PREFIX_SHORT) + " " + this.title);
return title;
}

protected void openInventory() {
crPlayer.getPlayer().openInventory(inventory);
crPlayer.setCurrentInventory(this);
}

protected void closeInventory() {
crPlayer.getPlayer().closeInventory();
crPlayer.setCurrentInventory(null);
}
}
67 changes: 36 additions & 31 deletions Bukkit/src/me/poutineqc/cuberunner/game/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public static void loadExistingArenas() {

if (mysql.hasConnection()) {
try {
ResultSet arenas = mysql.query("SELECT * FROM " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS;");
ResultSet arenas = mysql
.query("SELECT * FROM " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS;");
while (arenas.next()) {
String name = arenas.getString("name");
Long colorIndice = arenas.getLong("colorIndice");
Expand Down Expand Up @@ -211,10 +212,10 @@ public Arena(String name, Player player) {
resetScoreboard();

if (mysql.hasConnection()) {
mysql.update("INSERT INTO " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS (name, world) " + "VALUES ('" + name + "','"
+ world.getName() + "');");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET colorIndice=" + (long) 1 + " WHERE name='" + name
+ "';");
mysql.update("INSERT INTO " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS (name, world) "
+ "VALUES ('" + name + "','" + world.getName() + "');");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET colorIndice="
+ (long) 1 + " WHERE name='" + name + "';");
} else {
arenaData.getData().set("arenas." + name + ".world", world.getName());
arenaData.getData().set("arenas." + name + ".colorIndice", (long) 1);
Expand Down Expand Up @@ -245,7 +246,8 @@ public void delete(Player player) {
arenas.remove(this);

if (mysql.hasConnection()) {
mysql.update("DELETE FROM " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS WHERE name='" + name + "';");
mysql.update("DELETE FROM " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS WHERE name='" + name
+ "';");
} else {
arenaData.getData().set("arenas." + name, null);
arenaData.saveArenaData();
Expand All @@ -272,10 +274,10 @@ public void setArena(Player player) {
local.sendMsg(player, local.get(Messages.EDIT_REGION).replace("%arena%", name));

if (mysql.hasConnection()) {
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='" + world.getName() + "',minPointX="
+ minPoint.getBlockX() + ",minPointY=" + minPoint.getBlockY() + ",minPointZ=" + minPoint.getBlockZ()
+ ",maxPointX=" + maxPoint.getBlockX() + ",maxPointY=" + maxPoint.getBlockY() + ",maxPointZ="
+ maxPoint.getBlockZ() + " WHERE name='" + name + "';");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='"
+ world.getName() + "',minPointX=" + minPoint.getBlockX() + ",minPointY=" + minPoint.getBlockY()
+ ",minPointZ=" + minPoint.getBlockZ() + ",maxPointX=" + maxPoint.getBlockX() + ",maxPointY="
+ maxPoint.getBlockY() + ",maxPointZ=" + maxPoint.getBlockZ() + " WHERE name='" + name + "';");
} else {
arenaData.getData().set("arenas." + name + ".world", world.getName());
arenaData.getData().set("arenas." + name + ".minPoint.X", minPoint.getBlockX());
Expand All @@ -301,9 +303,10 @@ public void setLobby(Player player) {
local.sendMsg(player, local.get(Messages.EDIT_LOBBY).replace("%arena%", name));

if (mysql.hasConnection()) {
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='" + world.getName() + "',lobbyX="
+ lobby.getX() + ",lobbyY=" + lobby.getY() + ",lobbyZ=" + lobby.getZ() + ",lobbyPitch="
+ lobby.getPitch() + ",lobbyYaw=" + lobby.getYaw() + " WHERE name='" + name + "';");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='"
+ world.getName() + "',lobbyX=" + lobby.getX() + ",lobbyY=" + lobby.getY() + ",lobbyZ="
+ lobby.getZ() + ",lobbyPitch=" + lobby.getPitch() + ",lobbyYaw=" + lobby.getYaw() + " WHERE name='"
+ name + "';");
} else {
arenaData.getData().set("arenas." + name + ".world", world.getName());
arenaData.getData().set("arenas." + name + ".lobby.X", lobby.getX());
Expand All @@ -328,10 +331,10 @@ public void setStartPoint(Player player) {
local.sendMsg(player, local.get(Messages.EDIT_STARTPOINT).replace("%arena%", name));

if (mysql.hasConnection()) {
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='" + world.getName() + "',startPointX="
+ startPoint.getX() + ",startPointY=" + startPoint.getY() + ",startPointZ=" + startPoint.getZ()
+ ",startPointPitch=" + startPoint.getPitch() + ",startPointYaw=" + startPoint.getYaw()
+ " WHERE name='" + name + "';");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET world='"
+ world.getName() + "',startPointX=" + startPoint.getX() + ",startPointY=" + startPoint.getY()
+ ",startPointZ=" + startPoint.getZ() + ",startPointPitch=" + startPoint.getPitch()
+ ",startPointYaw=" + startPoint.getYaw() + " WHERE name='" + name + "';");
} else {
arenaData.getData().set("arenas." + name + ".world", world.getName());
arenaData.getData().set("arenas." + name + ".startPoint.X", startPoint.getX());
Expand Down Expand Up @@ -370,8 +373,8 @@ public void setMinPlayer(int amount, Player player) {
}

if (mysql.hasConnection()) {
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET minAmountPlayer=" + amount + " WHERE name='"
+ name + "';");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET minAmountPlayer="
+ amount + " WHERE name='" + name + "';");
} else {
arenaData.getData().set("arenas." + name + ".minAmountPlayer", amount);
arenaData.saveArenaData();
Expand Down Expand Up @@ -402,8 +405,8 @@ public void setMaxPlayer(int amount, Player player) {
}

if (mysql.hasConnection()) {
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET maxAmountPlayer=" + amount + " WHERE name='"
+ name + "';");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET maxAmountPlayer="
+ amount + " WHERE name='" + name + "';");
} else {
arenaData.getData().set("arenas." + name + ".maxAmountPlayer", amount);
arenaData.saveArenaData();
Expand Down Expand Up @@ -536,8 +539,8 @@ public void addPlayer(Player player, boolean teleport) {

User user = null;
if (teleport || gameState != GameState.ACTIVE) {
user = new User(CubeRunner.get().getConfiguration(), CubeRunner.get().getCRPlayer(player), this, gameState == GameState.ACTIVE,
teleport);
user = new User(CubeRunner.get().getConfiguration(), CubeRunner.get().getCRPlayer(player), this,
gameState == GameState.ACTIVE, teleport);
users.add(user);
CRSign.updateSigns(this);
}
Expand Down Expand Up @@ -565,7 +568,8 @@ public void addPlayer(Player player, boolean teleport) {
localAlt.sendMsg(u, localAlt.get(Messages.JOIN_OTHERS).replace("%player%", player.getDisplayName()));
}

if (gameState == GameState.READY && CubeRunner.get().getConfiguration().autostart && getAmountOfPlayerInGame() >= minAmountPlayer)
if (gameState == GameState.READY && CubeRunner.get().getConfiguration().autostart
&& getAmountOfPlayerInGame() >= minAmountPlayer)
initiateGame(null);
}

Expand Down Expand Up @@ -817,7 +821,7 @@ public void run() {
for (User user : arena.users) {
if (user.isEliminated())
continue;

if (user.getLastTreeSecondsDistance() < 1 && user.getScore() >= 2)
arena.eliminateUser(user, LeavingReason.HIDING);

Expand All @@ -832,10 +836,10 @@ public void run() {
player.getLocation().getZ());

NumberFormat formater = new DecimalFormat("#.#####");
double xOffset = Double
.parseDouble(formater.format(l.getX() > 0 ? l.getX() % 1 : 1 + (l.getX() % 1)));
double zOffset = Double
.parseDouble(formater.format(l.getZ() > 0 ? l.getZ() % 1 : 1 + (l.getZ() % 1)));
double xOffset = Double.parseDouble(
formater.format(l.getX() > 0 ? l.getX() % 1 : 1 + (l.getX() % 1)).replace(",", "."));
double zOffset = Double.parseDouble(
formater.format(l.getZ() > 0 ? l.getZ() % 1 : 1 + (l.getZ() % 1)).replace(",", "."));

if (xOffset <= 0.7 && xOffset >= 0.3)
l.setX(Math.floor(l.getX()) + 0.5D);
Expand Down Expand Up @@ -1075,8 +1079,9 @@ private void endingSequence() {
}

if (mysql.hasConnection()) {
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET highestScore='" + user.getScore()
+ "', highestPlayer='" + user.getPlayer().getName() + "' WHERE name='" + name + "';");
mysql.update("UPDATE " + CubeRunner.get().getConfiguration().tablePrefix + "ARENAS SET highestScore='"
+ user.getScore() + "', highestPlayer='" + user.getPlayer().getName() + "' WHERE name='" + name
+ "';");
} else {
arenaData.getData().set("arenas." + name + ".highestScore.score", highestScore);
arenaData.getData().set("arenas." + name + ".highestScore.player", user.getPlayer().getName());
Expand Down

0 comments on commit ecc4261

Please sign in to comment.