Commit 8d727eae authored by Kenix Whisperwind's avatar Kenix Whisperwind

Server configuration is now a non-static class member of Server

parent dc30b153
package com.openrsc.server.plugins.commands;
import com.openrsc.server.Constants;
import com.openrsc.server.Server;
import com.openrsc.server.external.EntityHandler;
import com.openrsc.server.model.Point;
......@@ -76,7 +75,7 @@ public final class Development implements CommandListener {
}
Point npcLoc = new Point(x,y);
final Npc n = new Npc(id, x, y, x - radius, x + radius, y - radius, y + radius);
final Npc n = new Npc(player.getWorld(), id, x, y, x - radius, x + radius, y - radius, y + radius);
if (EntityHandler.getNpcDef(id) == null) {
player.message(messagePrefix + "Invalid npc id");
......@@ -86,7 +85,7 @@ public final class Development implements CommandListener {
World.getWorld().registerNpc(n);
n.setShouldRespawn(true);
player.message(messagePrefix + "Added NPC to database: " + n.getDef().getName() + " at " + npcLoc + " with radius " + radius);
DatabaseConnection.getDatabase().executeUpdate("INSERT INTO `" + Constants.GameServer.MYSQL_TABLE_PREFIX
DatabaseConnection.getDatabase().executeUpdate("INSERT INTO `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
+ "npclocs`(`id`,`startX`,`minX`,`maxX`,`startY`,`minY`,`maxY`) VALUES('" + n.getLoc().getId()
+ "', '" + n.getLoc().startX() + "', '" + n.getLoc().minX() + "', '" + n.getLoc().maxX() + "','"
+ n.getLoc().startY() + "','" + n.getLoc().minY() + "','" + n.getLoc().maxY() + "')");
......@@ -115,7 +114,7 @@ public final class Development implements CommandListener {
player.message(messagePrefix + "Removed NPC from database: " + npc.getDef().getName() + " with instance ID " + id);
DatabaseConnection.getDatabase()
.executeUpdate("DELETE FROM `" + Constants.GameServer.MYSQL_TABLE_PREFIX
.executeUpdate("DELETE FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
+ "npclocs` WHERE `id` = '" + npc.getID() + "' AND startX='" + npc.getLoc().startX
+ "' AND startY='" + npc.getLoc().startY + "' AND minX='" + npc.getLoc().minX
+ "' AND maxX = '" + npc.getLoc().maxX + "' AND minY='" + npc.getLoc().minY
......@@ -169,7 +168,7 @@ public final class Development implements CommandListener {
player.message(messagePrefix + "Removed object from database: " + object.getGameObjectDef().getName() + " with instance ID " + object.getID());
DatabaseConnection.getDatabase()
.executeUpdate("DELETE FROM `" + Constants.GameServer.MYSQL_TABLE_PREFIX
.executeUpdate("DELETE FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
+ "objects` WHERE `x` = '" + object.getX() + "' AND `y` = '" + object.getY()
+ "' AND `id` = '" + object.getID() + "' AND `direction` = '" + object.getDirection()
+ "' AND `type` = '" + object.getType() + "'");
......@@ -225,11 +224,11 @@ public final class Development implements CommandListener {
return;
}
GameObject newObject = new GameObject(Point.location(x, y), id, 0, 0);
GameObject newObject = new GameObject(player.getWorld(), Point.location(x, y), id, 0, 0);
World.getWorld().registerGameObject(newObject);
player.message(messagePrefix + "Added object to database: " + newObject.getGameObjectDef().getName() + " with instance ID " + newObject.getID() + " at " + newObject.getLocation());
DatabaseConnection.getDatabase()
.executeUpdate("INSERT INTO `" + Constants.GameServer.MYSQL_TABLE_PREFIX
.executeUpdate("INSERT INTO `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
+ "objects`(`x`, `y`, `id`, `direction`, `type`) VALUES ('"
+ newObject.getX() + "', '" + newObject.getY() + "', '" + newObject.getID() + "', '"
+ newObject.getDirection() + "', '" + newObject.getType() + "')");
......@@ -301,17 +300,17 @@ public final class Development implements CommandListener {
}
DatabaseConnection.getDatabase()
.executeUpdate("DELETE FROM `" + Constants.GameServer.MYSQL_TABLE_PREFIX + "objects` WHERE `x` = '"
.executeUpdate("DELETE FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "objects` WHERE `x` = '"
+ object.getX() + "' AND `y` = '" + object.getY() + "' AND `id` = '" + object.getID()
+ "' AND `direction` = '" + object.getDirection() + "' AND `type` = '" + object.getType()
+ "'");
World.getWorld().unregisterGameObject(object);
GameObject newObject = new GameObject(Point.location(x, y), object.getID(), direction, object.getType());
GameObject newObject = new GameObject(player.getWorld(), Point.location(x, y), object.getID(), direction, object.getType());
World.getWorld().registerGameObject(newObject);
DatabaseConnection.getDatabase()
.executeUpdate("INSERT INTO `" + Constants.GameServer.MYSQL_TABLE_PREFIX
.executeUpdate("INSERT INTO `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX
+ "objects`(`x`, `y`, `id`, `direction`, `type`) VALUES ('" + newObject.getX() + "', '"
+ newObject.getY() + "', '" + newObject.getID() + "', '" + newObject.getDirection() + "', '"
+ newObject.getType() + "')");
......
package com.openrsc.server.plugins.commands;
import com.openrsc.server.Constants;
import com.openrsc.server.Server;
import com.openrsc.server.event.SingleEvent;
import com.openrsc.server.model.Point;
import com.openrsc.server.model.Skills;
import com.openrsc.server.model.entity.GameObject;
import com.openrsc.server.model.entity.player.Group;
import com.openrsc.server.model.entity.player.Player;
......@@ -332,7 +330,7 @@ public final class Event implements CommandListener {
messagePrefix + "No online character found named '" + targetUsername + "'.. checking database..");
try {
PreparedStatement statement = DatabaseConnection.getDatabase()
.prepareStatement("SELECT `login_ip` FROM `" + Constants.GameServer.MYSQL_TABLE_PREFIX + "players` WHERE `username`=?");
.prepareStatement("SELECT `login_ip` FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "players` WHERE `username`=?");
statement.setString(1, targetUsername);
ResultSet result = statement.executeQuery();
if (!result.next()) {
......@@ -358,7 +356,7 @@ public final class Event implements CommandListener {
try {
PreparedStatement statement = DatabaseConnection.getDatabase()
.prepareStatement("SELECT `username`, `group_id` FROM `" + Constants.GameServer.MYSQL_TABLE_PREFIX + "players` WHERE `login_ip` LIKE ?");
.prepareStatement("SELECT `username`, `group_id` FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "players` WHERE `login_ip` LIKE ?");
statement.setString(1, currentIp);
ResultSet result = statement.executeQuery();
......@@ -438,7 +436,7 @@ public final class Event implements CommandListener {
World.getWorld().unregisterGameObject(existingObject);
player.message(messagePrefix + "Seers party hall " + (upstairs ? "upstairs" : "downstairs") + " has been disabled.");
} else {
GameObject newObject = new GameObject(objectLoc, 18, 0, 0);
GameObject newObject = new GameObject(player.getWorld(), objectLoc, 18, 0, 0);
World.getWorld().registerGameObject(newObject);
Server.getServer().getGameEventHandler().add(new SingleEvent(null, time * 60000, "Unregister Seers Party Hall") {
@Override
......@@ -601,7 +599,7 @@ public final class Event implements CommandListener {
stat = Integer.parseInt(args[1]);
}
catch (NumberFormatException ex) {
stat = Skills.getSkillIndex(args[1].toLowerCase());
stat = player.getWorld().getServer().getConstants().getSkills().getSkillIndex(args[1].toLowerCase());
if(stat == -1) {
player.message(messagePrefix + "Invalid stat");
......@@ -610,7 +608,7 @@ public final class Event implements CommandListener {
}
try {
statName = Skills.getSkillName(stat);
statName = player.getWorld().getServer().getConstants().getSkills().getSkillName(stat);
}
catch (IndexOutOfBoundsException ex) {
player.message(messagePrefix + "Invalid stat");
......@@ -658,7 +656,7 @@ public final class Event implements CommandListener {
stat = Integer.parseInt(args[2]);
}
catch (NumberFormatException e) {
stat = Skills.getSkillIndex(args[2].toLowerCase());
stat = player.getWorld().getServer().getConstants().getSkills().getSkillIndex(args[2].toLowerCase());
if(stat == -1) {
player.message(messagePrefix + "Invalid stat");
......@@ -667,7 +665,7 @@ public final class Event implements CommandListener {
}
try {
statName = Skills.getSkillName(stat);
statName = player.getWorld().getServer().getConstants().getSkills().getSkillName(stat);
}
catch (IndexOutOfBoundsException e) {
player.message(messagePrefix + "Invalid stat");
......@@ -694,8 +692,8 @@ public final class Event implements CommandListener {
if(stat != -1) {
if(level < 1)
level = 1;
if(level > Constants.GameServer.PLAYER_LEVEL_LIMIT)
level = Constants.GameServer.PLAYER_LEVEL_LIMIT;
if(level > Server.getServer().getConfig().PLAYER_LEVEL_LIMIT)
level = Server.getServer().getConfig().PLAYER_LEVEL_LIMIT;
p.getSkills().setLevelTo(stat, level);
p.checkEquipment();
......@@ -705,7 +703,7 @@ public final class Event implements CommandListener {
}
}
else {
for(int i = 0; i < Skills.getSkillCount(); i++) {
for(int i = 0; i < player.getWorld().getServer().getConstants().getSkills().getSkillsCount(); i++) {
p.getSkills().setLevelTo(i, level);
}
......@@ -742,7 +740,7 @@ public final class Event implements CommandListener {
stat = Integer.parseInt(args[1]);
}
catch (NumberFormatException ex) {
stat = Skills.getSkillIndex(args[1].toLowerCase());
stat = player.getWorld().getServer().getConstants().getSkills().getSkillIndex(args[1].toLowerCase());
if(stat == -1) {
player.message(messagePrefix + "Invalid stat");
......@@ -751,7 +749,7 @@ public final class Event implements CommandListener {
}
try {
statName = Skills.getSkillName(stat);
statName = player.getWorld().getServer().getConstants().getSkills().getSkillName(stat);
}
catch (IndexOutOfBoundsException ex) {
player.message(messagePrefix + "Invalid stat");
......@@ -799,7 +797,7 @@ public final class Event implements CommandListener {
stat = Integer.parseInt(args[2]);
}
catch (NumberFormatException e) {
stat = Skills.getSkillIndex(args[2].toLowerCase());
stat = player.getWorld().getServer().getConstants().getSkills().getSkillIndex(args[2].toLowerCase());
if(stat == -1) {
player.message(messagePrefix + "Invalid stat");
......@@ -808,7 +806,7 @@ public final class Event implements CommandListener {
}
try {
statName = Skills.getSkillName(stat);
statName = player.getWorld().getServer().getConstants().getSkills().getSkillName(stat);
}
catch (IndexOutOfBoundsException e) {
player.message(messagePrefix + "Invalid stat");
......@@ -846,7 +844,7 @@ public final class Event implements CommandListener {
}
}
else {
for(int i = 0; i < Skills.getSkillCount(); i++) {
for(int i = 0; i < player.getWorld().getServer().getConstants().getSkills().getSkillsCount(); i++) {
p.getSkills().setLevel(i, level);
}
......
package com.openrsc.server.plugins.commands;
import com.openrsc.server.Constants;
import com.openrsc.server.Server;
import com.openrsc.server.content.clan.ClanInvite;
import com.openrsc.server.model.entity.npc.Npc;
import com.openrsc.server.content.party.PartyPlayer;
import com.openrsc.server.content.party.PartyRank;
import com.openrsc.server.external.EntityHandler;
import com.openrsc.server.model.entity.player.Group;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.model.snapshot.Chatlog;
import com.openrsc.server.model.world.World;
import com.openrsc.server.net.rsc.ActionSender;
import com.openrsc.server.plugins.Functions;
import com.openrsc.server.content.party.*;
import com.openrsc.server.plugins.listeners.action.CommandListener;
import com.openrsc.server.sql.DatabaseConnection;
import com.openrsc.server.sql.GameLogging;
import com.openrsc.server.sql.query.logs.ChatLog;
import com.openrsc.server.util.rsc.DataConversions;
import com.openrsc.server.util.rsc.MessageType;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -39,7 +39,7 @@ public final class RegularPlayer implements CommandListener {
}
public boolean isCommandAllowed(Player player, String cmd) {
return Constants.GameServer.PLAYER_COMMANDS || player.isMod();
return Server.getServer().getConfig().PLAYER_COMMANDS || player.isMod();
}
public void handleCommand(String cmd, String[] args, Player player) {
......@@ -64,7 +64,7 @@ public final class RegularPlayer implements CommandListener {
return;
}
try {
PreparedStatement statement = DatabaseConnection.getDatabase().prepareStatement("SELECT salt FROM " + Constants.GameServer.MYSQL_TABLE_PREFIX + "players WHERE `username`=?");
PreparedStatement statement = DatabaseConnection.getDatabase().prepareStatement("SELECT salt FROM " + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "players WHERE `username`=?");
statement.setString(1, player.getUsername());
ResultSet result = statement.executeQuery();
if (result.next()) {
......@@ -101,7 +101,7 @@ public final class RegularPlayer implements CommandListener {
+ "P2P wilderness(Wild Lvl. 48-56) : @dre@" + PLAYERS_IN_P2P_WILD + "@whi@ player" + (PLAYERS_IN_P2P_WILD == 1 ? "" : "s") + " %"
+ "Edge dungeon wilderness(Wild Lvl. 1-9) : @dre@" + EDGE_DUNGEON + "@whi@ player" + (EDGE_DUNGEON == 1 ? "" : "s") + " %"
, false);
} else if (cmd.equalsIgnoreCase("c") && Constants.GameServer.WANT_CLANS) {
} else if (cmd.equalsIgnoreCase("c") && Server.getServer().getConfig().WANT_CLANS) {
if (player.getClan() == null) {
player.message(messagePrefix + "You are not in a clan.");
return;
......@@ -111,7 +111,7 @@ public final class RegularPlayer implements CommandListener {
message = message + arg + " ";
}
player.getClan().messageChat(player, "@cya@" + player.getUsername() + ":@whi@ " + message);
} else if (cmd.equalsIgnoreCase("clanaccept") && Constants.GameServer.WANT_CLANS) {
} else if (cmd.equalsIgnoreCase("clanaccept") && Server.getServer().getConfig().WANT_CLANS) {
if (player.getActiveClanInvite() == null) {
player.message(messagePrefix + "You have not been invited to a clan.");
return;
......@@ -125,7 +125,7 @@ public final class RegularPlayer implements CommandListener {
}
player.getActivePartyInvite().accept();
player.message(messagePrefix + "You have joined the party");
} else if (cmd.equalsIgnoreCase("claninvite") && Constants.GameServer.WANT_CLANS) {
} else if (cmd.equalsIgnoreCase("claninvite") && Server.getServer().getConfig().WANT_CLANS) {
if (args.length < 1) {
player.message(badSyntaxPrefix + cmd.toUpperCase() + " [name]");
return;
......@@ -145,7 +145,7 @@ public final class RegularPlayer implements CommandListener {
ClanInvite.createClanInvite(player, invited);
player.message(messagePrefix + invited.getUsername() + " has been invited into clan " + player.getClan().getClanName());
} else if (cmd.equalsIgnoreCase("clankick") && Constants.GameServer.WANT_CLANS) {
} else if (cmd.equalsIgnoreCase("clankick") && Server.getServer().getConfig().WANT_CLANS) {
if (args.length < 1) {
player.message(badSyntaxPrefix + cmd.toUpperCase() + " [name]");
return;
......@@ -203,7 +203,7 @@ public final class RegularPlayer implements CommandListener {
}
player.teleport(World.EVENT_X, World.EVENT_Y);
} else if (cmd.equalsIgnoreCase("g") || cmd.equalsIgnoreCase("p")) {
if (!Constants.GameServer.WANT_GLOBAL_CHAT) return;
if (!Server.getServer().getConfig().WANT_GLOBAL_CHAT) return;
if (player.isMuted()) {
player.message(messagePrefix + "You are muted, you cannot send messages");
return;
......@@ -266,7 +266,7 @@ public final class RegularPlayer implements CommandListener {
World.getWorld().addEntryToSnapshots(new Chatlog(player.getUsername(), "(PKing) " + newStr));
}
} else if (cmd.equalsIgnoreCase("party")) {
if (!Constants.GameServer.WANT_GLOBAL_CHAT) return;
if (!Server.getServer().getConfig().WANT_GLOBAL_CHAT) return;
if (player.isMuted()) {
player.message(messagePrefix + "You are muted, you cannot send messages");
return;
......@@ -386,19 +386,17 @@ public final class RegularPlayer implements CommandListener {
ActionSender.sendBox(player, "@whi@Server Groups:%" + StringUtils.join(groups, "%"), true);
} else if (cmd.equalsIgnoreCase("time") || cmd.equalsIgnoreCase("date") || cmd.equalsIgnoreCase("datetime")) {
player.message(messagePrefix + " the current time/date is:@gre@ " + new java.util.Date().toString());
} else if (Constants.GameServer.NPC_KILL_LIST && cmd.equalsIgnoreCase("kills")) {
} else if (Server.getServer().getConfig().NPC_KILL_LIST && cmd.equalsIgnoreCase("kills")) {
StringBuilder kills = new StringBuilder("NPC Kill List for " + player.getUsername() + " % %");
try {
PreparedStatement statement = DatabaseConnection.getDatabase().prepareStatement(
"SELECT * FROM `" + Constants.GameServer.MYSQL_TABLE_PREFIX + "npckills` WHERE playerID = ? ORDER BY killCount DESC LIMIT 16");
"SELECT * FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "npckills` WHERE playerID = ? ORDER BY killCount DESC LIMIT 16");
statement.setInt(1, player.getDatabaseID());
ResultSet result = statement.executeQuery();
Npc n = new Npc();
while (result.next()) {
int npcID = result.getInt("npcID");
n.setID(npcID);
int killCount = result.getInt("killCount");
kills.append("NPC: ").append(n.getDef().getName()).append(" - Kill Count: ").append(killCount).append("%");
kills.append("NPC: ").append(EntityHandler.getNpcDef(npcID).getName()).append(" - Kill Count: ").append(killCount).append("%");
}
result.close();
ActionSender.sendBox(player, kills.toString(), true);
......
package com.openrsc.server.plugins.commands;
import com.openrsc.server.Constants;
import com.openrsc.server.Server;
import com.openrsc.server.external.EntityHandler;
import com.openrsc.server.external.ItemDropDef;
......@@ -232,7 +231,7 @@ public final class SuperModerator implements CommandListener {
} else if (cmd.equalsIgnoreCase("reloaddrops")) {
try {
PreparedStatement statement = DatabaseConnection.getDatabase().prepareStatement(
"SELECT * FROM `" + Constants.GameServer.MYSQL_TABLE_PREFIX + "npcdrops` WHERE npcdef_id = ?");
"SELECT * FROM `" + Server.getServer().getConfig().MYSQL_TABLE_PREFIX + "npcdrops` WHERE npcdef_id = ?");
for (int i = 0; i < EntityHandler.npcs.size(); i++) {
statement.setInt(1, i);
ResultSet dropResult = statement.executeQuery();
......
package com.openrsc.server.plugins.defaults;
import com.openrsc.server.Constants;
import com.openrsc.server.Server;
import com.openrsc.server.event.ShortEvent;
import com.openrsc.server.external.EntityHandler;
import com.openrsc.server.external.ItemId;
import com.openrsc.server.external.NpcId;
import com.openrsc.server.model.Skills.SKILLS;
import com.openrsc.server.constants.ItemId;
import com.openrsc.server.constants.NpcId;
import com.openrsc.server.constants.Skills;
import com.openrsc.server.model.TelePoint;
import com.openrsc.server.model.entity.GameObject;
import com.openrsc.server.model.entity.npc.Npc;
......@@ -33,7 +32,7 @@ public class Ladders {
public void onObjectAction(GameObject obj, String command, Player player) {
player.setBusyTimer(650);
if (obj.getID() == 487 && !Constants.GameServer.MEMBER_WORLD) {
if (obj.getID() == 487 && !Server.getServer().getConfig().MEMBER_WORLD) {
player.message(player.MEMBER_MESSAGE);
return;
} else if (obj.getID() == 79 && obj.getX() == 243 && obj.getY() == 95) {
......@@ -136,7 +135,7 @@ public class Ladders {
"Oh sorry");
if (op == 0) {
playerTalk(player, abbot, "Well can I join your order?");
if (getCurrentLevel(player, SKILLS.PRAYER.id()) >= 31) {
if (getCurrentLevel(player, Skills.PRAYER) >= 31) {
npcTalk(player, abbot, "Ok I see you are someone suitable for our order",
"You may join");
player.getCache().set("prayer_guild", 1);
......@@ -167,7 +166,7 @@ public class Ladders {
} else if (obj.getID() == 223 && obj.getX() == 274 && obj.getY() == 566) { // Mining
// Guild
// Ladder
if (getCurrentLevel(player, SKILLS.MINING.id()) < 60) {
if (getCurrentLevel(player, Skills.MINING) < 60) {
player.setBusy(true);
Npc dwarf = World.getWorld().getNpc(NpcId.DWARF_MINING_GUILD.id(), 272, 277, 563, 567);
if (dwarf != null) {
......@@ -227,7 +226,7 @@ public class Ladders {
player.teleport(222, 110, false);
} else if (obj.getID() == 331 && obj.getX() == 150 && obj.getY() == 558) {
player.teleport(151, 1505, false);
} else if (obj.getID() == 6 && obj.getX() == 282 && obj.getY() == 185 && !Constants.GameServer.MEMBER_WORLD) {
} else if (obj.getID() == 6 && obj.getX() == 282 && obj.getY() == 185 && !Server.getServer().getConfig().MEMBER_WORLD) {
player.message(player.MEMBER_MESSAGE);
} else if (obj.getID() == 6 && obj.getX() == 148 && obj.getY() == 1507) {
player.teleport(148, 563, false);
......
......@@ -4,9 +4,9 @@ package com.openrsc.server.plugins.itemactions;
import com.openrsc.server.Server;
import com.openrsc.server.event.ShortEvent;
import com.openrsc.server.event.SingleEvent;
import com.openrsc.server.external.ItemId;
import com.openrsc.server.constants.ItemId;
import com.openrsc.server.model.Point;
import com.openrsc.server.model.Skills.SKILLS;
import com.openrsc.server.constants.Skills;
import com.openrsc.server.model.container.Item;
import com.openrsc.server.model.entity.GameObject;
import com.openrsc.server.model.entity.player.Player;
......@@ -50,7 +50,7 @@ InvUseOnObjectExecutiveListener {
boolean fail = Formulae.cutCacti();
if (fail) {
getOwner().message("You make a mistake and fail to fill your waterskin.");
getOwner().incExp(SKILLS.WOODCUT.id(), 4, true);
getOwner().incExp(Skills.WOODCUT, 4, true);
getOwner().getInventory().add(new Item(s, 1));
getOwner().setBusy(false);
return;
......@@ -66,12 +66,12 @@ InvUseOnObjectExecutiveListener {
// Add dried cacti
Point loc = object.getLocation();
final GameObject cacti = new GameObject(loc, 1028, 0, 0);
final GameObject cacti = new GameObject(getOwner().getWorld(), loc, 1028, 0, 0);
world.registerGameObject(cacti);
// Remove healthy cacti
world.unregisterGameObject(object);
getOwner().incExp(SKILLS.WOODCUT.id(), 100, true); // Woodcutting XP
getOwner().incExp(Skills.WOODCUT, 100, true); // Woodcutting XP
</