I don't know if this is the right section for this but,
This is the code
Spoiler for code for jail:
Code:
package org.model.content;
import java.util.HashMap;
import java.util.Iterator;
import org.model.Client;
import org.model.PlayerHandler;
import org.model.commandmanager.Command;
/**
* Jail system
*
* @author Innocence
*
*/
public class JailHandler implements Command {
private static JailHandler instance = new JailHandler();
public static JailHandler getInstance() {
return instance;
}
private static HashMap<Client, Integer> playerInJail = new HashMap<>();
/**
* The Command
*/
@Override
public void execute(Client c, String playerCommand) {
try {
String[] args = playerCommand.split(" ");
if (args.length == 2) {
String otherPName = String.valueOf(args[1]);
int otherPIndex = PlayerHandler.getPlayerID(otherPName);
if (otherPIndex != -1) {
Client p = (Client) PlayerHandler.players[otherPIndex];
{
playerInJail.put(p, 1);
p.savegame(false);
jailed(c);
p.sM("You have been put in jail by " + c.playerName);
}
} else {
c.sM("That player doesn't seem to exist or isn't online");
}
}
} catch (Exception e) {
c.sM("Use as ::jail playername");
}
}
private void jailed(Client c) {
c.addItem(ITEMS[0][0], ITEMS[0][1]);
c.sM("Mine 50 tin ores to get out of here");
c.movePlayer(2936, 3282, 0);
}
private final int ITEMS[][] = { { 1265, 1 }, // items added
{ 439, 50 } // items required to get out of jail
};
public boolean action(Client player) {
if (isInJail(player)) {
player.sM("You cannot do this while in jail!");
return true;
} else
return false;
}
private void freePlayer() {
Iterator<Client> iterator = playerInJail.keySet().iterator();
while (iterator.hasNext()) {
Client player = iterator.next();
if (player == null) {
continue;
}
if (playerInJail.containsKey(player)) {
playerInJail.remove(player);
}
player.triggerTele(2657, 2639, 0);
player.sM("You are now free from jail");
}
}
public static boolean isInJail(Client player) {
return playerInJail.containsKey(player);
}
public void objects(int objectID, Client c, int x, int y) {
switch (objectID) {
case 6774:
if (c.playerHasItem(ITEMS[1][0], ITEMS[1][1]))
freePlayer();
break;
}
}
public int object[] = { 6774 };
}
I was just wondering if this is any good for delta. It works just fine but what improvements can be made?