Some work on the plugin, added a couple things and worked on the

preparing the jail.
This commit is contained in:
graywolf336 2013-12-24 22:25:14 -06:00
parent a27596bcfb
commit 63032ad6cc
7 changed files with 101 additions and 18 deletions

View File

@ -1,5 +1,13 @@
package com.graywolf336.jail;
import org.bukkit.entity.Player;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.enums.LangString;
import com.graywolf336.jail.enums.Settings;
public class PrisonerManager {
private JailMain pl;
@ -7,7 +15,56 @@ public class PrisonerManager {
this.pl = plugin;
}
public void prepareSomething() {
pl.getLogger().info("Preparing something.");
/**
* Prepare the jailing of this player.
*
* @param player The player we are preparing the jail for.
* @param prisoner The prisoner file.
*/
public void prepareJail(Jail jail, Cell cell, Player player, Prisoner prisoner) throws Exception {
//Do some checks of whether the passed params are null.
if(jail == null)
throw new Exception("The jail can not be null.");
if(prisoner == null)
throw new Exception("Prisoner data can not be null.");
//Set whether the prisoner is offline or not.
prisoner.setOfflinePending(player == null);
//Now that we've got those checks out of the way, let's start preparing.
if(cell == null) {
jail.addPrisoner(prisoner);
}else {
jail.getCell(cell.getName()).setPrisoner(prisoner);
}
//Save the jail after adding them to the jail
pl.getJailIO().saveJail(jail);
//If they are offline, handle different..?
if(prisoner.isOfflinePending()) {
}else {
}
//Get a message ready for broadcasting or logging.
String msg = "";
if(prisoner.getRemainingTime() < 0)
msg = pl.getJailIO().getLanguageString(LangString.BROADCASTMESSAGEFOREVER, new String[] { prisoner.getName() });
else//
msg = pl.getJailIO().getLanguageString(LangString.BROADCASTMESSAGEFOREVER, new String[] { prisoner.getName(), String.valueOf(prisoner.getRemainingTimeInMinutes()) });
//Broadcast the message, if it is enabled
if(pl.getConfig().getBoolean(Settings.BROADCASTJAILING.getPath(), false)) {
pl.getServer().broadcastMessage(msg);
}
//Log the message, if it is enabled
if(pl.getConfig().getBoolean(Settings.LOGJAILING.getPath(), true)) {
pl.getLogger().info(msg);
}
}
}

View File

@ -129,6 +129,11 @@ public class Jail {
return this.free.getLocation();
}
/** Add a prisoner to this jail. */
public void addPrisoner(Prisoner p) {
this.nocellPrisoners.add(p);
}
/** Adds a cell to the Jail. */
public void addCell(Cell cell, boolean save) {
if(save) plugin.getJailIO().saveJail(this);

View File

@ -1,5 +1,7 @@
package com.graywolf336.jail.beans;
import java.util.concurrent.TimeUnit;
/**
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
*
@ -9,7 +11,7 @@ package com.graywolf336.jail.beans;
*/
public class Prisoner {
private String name;
private boolean muted;
private boolean muted, offlinePending;
private long time;
/**
@ -40,26 +42,32 @@ public class Prisoner {
this.muted = muted;
}
/** Gets the remaining time the prisoner has.
*
* <p />
*
* <strong>WARNING:</strong> The time system hasn't been implemented so this is likely to change.
*/
/** Gets the remaining time the prisoner has. */
public long getRemainingTime() {
return this.time;
}
/** Gets the remaining time the prisoner has in minutes. */
public long getRemainingTimeInMinutes() {
return TimeUnit.MINUTES.convert(time, TimeUnit.MILLISECONDS);
}
/**
* Sets the remaining time the prisoner has left.
*
* <p />
*
* <strong>WARNING:</strong> The time system hasn't been implemented so this is likely to change.
*
* @param time The amount of time left, in milliseconds.
*/
public void setRemainingTime(long time) {
this.time = time;
}
/** Gets whether the player is offline or not. */
public boolean isOfflinePending() {
return this.offlinePending;
}
/** Sets whether the player is offline or not. */
public void setOfflinePending(boolean offline) {
this.offlinePending = offline;
}
}

View File

@ -57,7 +57,8 @@ public class JailCommand implements Command {
//Check the jail params. If it is empty, let's get the default jail
//from the config. If that is nearest, let's make a call to getting the nearest jail to
//the sender but otherwise if it isn't nearest then let's set it to the default jail
//which is defined in the config.
//which is defined in the config. After that is done, we set the name of it in the params
//so that we can keep consistency.
if(params.jail().isEmpty()) {
String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
@ -71,11 +72,14 @@ public class JailCommand implements Command {
return true;
}
//Trying out the time.
//Try to parse the time, if they give us nothing in the time parameter then we get the default time
//from the config and if that isn't there then we default to thirty minutes.
Long time = 10L;
try {
if(params.time().isEmpty()) {
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
}else if(Integer.valueOf(params.time()) == -1) {
time = -1L;
}else {
time = Util.getTime(params.time());
}
@ -84,6 +88,7 @@ public class JailCommand implements Command {
return true;
}
//Get the jail instance from the name of jail in the params.
Jail j = jm.getJail(params.jail());
Prisoner pris = new Prisoner(params.player(), params.muted(), time);
Player p = jm.getPlugin().getServer().getPlayer(params.player());

View File

@ -1,6 +1,10 @@
package com.graywolf336.jail.enums;
public enum LangString {
/** The message sent when we broadcast/log the message for time below -1. */
BROADCASTMESSAGEFOREVER,
/** The message sent when we broadcast/log the message for any time above -1. */
BROADCASTMESSAGEFORMINUTES,
/** The message sent when players are jailed without a reason. */
JAILED,
/** The message sent when players are jailed with a reason. */

View File

@ -1,10 +1,12 @@
package com.graywolf336.jail.enums;
public enum Settings {
BROADCASTJAILING("jailing.jail.broadcastJailing"),
DEBUG("system.debug"),
DEFAULTJAIL("jailing.jail.defaultJail"),
UPDATENOTIFICATIONS("system.updateNotifications"),
JAILDEFAULTTIME("jailing.jail.defaultTime");
JAILDEFAULTTIME("jailing.jail.defaultTime"),
LOGJAILING("jailing.jail.logToConsole"),
UPDATENOTIFICATIONS("system.updateNotifications");
private String path;

View File

@ -1,4 +1,6 @@
language:
jailed: "&cYou have been jailed!"
jailedwithreason: "&cYou have been jailed for: %0%"
unjailed: "&2You have been released! Please respect the server rules."
unjailed: "&2You have been released! Please respect the server rules."
broadcastmessageforever: "&9%0% has been jailed forever."
broadcastmessageforminutes: "&9%0% has been jailed for %1% minutes."