Allow easier Prisoner creations.
All a whole variety of prisoner class creation, making API usage very nice and easy.
This commit is contained in:
parent
2dfa34c05c
commit
1f9035646d
@ -4,12 +4,12 @@ import com.graywolf336.jail.interfaces.IJailStickManager;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The static api interface for Jail plugin.
|
* The static api interface for Jail plugin.
|
||||||
*
|
*
|
||||||
* <p />
|
* <p />
|
||||||
*
|
*
|
||||||
* If you're looking for non-static methods, please see the
|
* If you're looking for non-static methods, please see the
|
||||||
* {@link JailMain} interface.
|
* {@link JailMain} interface.
|
||||||
*
|
*
|
||||||
* @author graywolf336
|
* @author graywolf336
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
@ -23,7 +23,7 @@ public class JailsAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The instance of the {@link JailManager} which contains all the jails and in return prisoners.
|
* The instance of the {@link JailManager} which contains all the jails and in return prisoners.
|
||||||
*
|
*
|
||||||
* @return instance of the {@link JailManager}
|
* @return instance of the {@link JailManager}
|
||||||
* @see JailManager
|
* @see JailManager
|
||||||
*/
|
*/
|
||||||
@ -33,17 +33,17 @@ public class JailsAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The instance of the {@link PrisonerManager} which handles all the jailing of players.
|
* The instance of the {@link PrisonerManager} which handles all the jailing of players.
|
||||||
*
|
*
|
||||||
* @return instance of the {@link PrisonerManager}
|
* @return instance of the {@link PrisonerManager}
|
||||||
* @see PrisonerManager
|
* @see PrisonerManager
|
||||||
*/
|
*/
|
||||||
public static PrisonerManager getPrisonerManager() {
|
public static PrisonerManager getPrisonerManager() {
|
||||||
return pl.getPrisonerManager();
|
return pl.getPrisonerManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an instance of the {@link IJailStickManager} which handles all the jail sticks.
|
* Gets an instance of the {@link IJailStickManager} which handles all the jail sticks.
|
||||||
*
|
*
|
||||||
* @return an instance of the {@link IJailStickManager}
|
* @return an instance of the {@link IJailStickManager}
|
||||||
* @see IJailStickManager
|
* @see IJailStickManager
|
||||||
*/
|
*/
|
||||||
@ -53,21 +53,32 @@ public class JailsAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The instance of the {@link HandCuffManager} which handles all the handcuffing of players.
|
* The instance of the {@link HandCuffManager} which handles all the handcuffing of players.
|
||||||
*
|
*
|
||||||
* @return instance of the {@link HandCuffManager}
|
* @return instance of the {@link HandCuffManager}
|
||||||
* @see HandCuffManager
|
* @see HandCuffManager
|
||||||
*/
|
*/
|
||||||
public static HandCuffManager getHandCuffManager() {
|
public static HandCuffManager getHandCuffManager() {
|
||||||
return pl.getHandCuffManager();
|
return pl.getHandCuffManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The instance of the {@link JailVoteManager} which handles all the voting to jail players.
|
* The instance of the {@link JailVoteManager} which handles all the voting to jail players.
|
||||||
*
|
*
|
||||||
* @return instance of the {@link JailVoteManager}
|
* @return instance of the {@link JailVoteManager}
|
||||||
* @see JailVoteManager
|
* @see JailVoteManager
|
||||||
*/
|
*/
|
||||||
public static JailVoteManager getJailVoteManager() {
|
public static JailVoteManager getJailVoteManager() {
|
||||||
return pl.getJailVoteManager();
|
return pl.getJailVoteManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the amount of time from the provided time which the Jail plugin uses.
|
||||||
|
*
|
||||||
|
* @param time A string in the format "30minutes"
|
||||||
|
* @return the amount of time
|
||||||
|
* @throws Exception if the provided time string is in an invalid format
|
||||||
|
*/
|
||||||
|
public static long getTimeFromString(String time) throws Exception {
|
||||||
|
return Util.getTime(time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,24 +6,27 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.enums.Lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
|
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
|
||||||
*
|
*
|
||||||
* @author graywolf336
|
* @author graywolf336
|
||||||
* @since 2.x.x
|
* @since 2.x.x
|
||||||
* @version 3.0.2
|
* @version 3.1.0
|
||||||
*/
|
*/
|
||||||
public class Prisoner {
|
public class Prisoner {
|
||||||
private String uuid, name, jailer, reason, inventory, armor;
|
private String uuid, name, jailer, reason, inventory, armor;
|
||||||
private boolean muted, offlinePending, teleporting, toBeTransferred, changed;
|
private boolean muted = true, offlinePending = false, teleporting = false, toBeTransferred = false, changed = false;
|
||||||
private long time, afk;
|
private long time = -1L, afk = 0L;
|
||||||
private Location previousPosition;
|
private Location previousPosition;
|
||||||
private GameMode previousGameMode;
|
private GameMode previousGameMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new prisoner with a name and whether they are muted or not.
|
* Creates the prisoner instance with the lot of data provided.
|
||||||
*
|
*
|
||||||
* @param uuid The uuid of the prisoner
|
* @param uuid The uuid of the prisoner
|
||||||
* @param name The name of the prisoner
|
* @param name The name of the prisoner
|
||||||
* @param muted Whether the prisoner is muted or not
|
* @param muted Whether the prisoner is muted or not
|
||||||
@ -38,15 +41,134 @@ public class Prisoner {
|
|||||||
this.time = time;
|
this.time = time;
|
||||||
this.jailer = jailer;
|
this.jailer = jailer;
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.offlinePending = false;
|
finishSetup();
|
||||||
this.teleporting = false;
|
}
|
||||||
this.toBeTransferred = false;
|
|
||||||
this.previousPosition = null;
|
/**
|
||||||
this.previousGameMode = GameMode.SURVIVAL;
|
* Creates the prisoner instance with the lot of data provided.
|
||||||
this.inventory = "";
|
*
|
||||||
this.armor = "";
|
* @param uuid The uuid of the prisoner
|
||||||
this.afk = 0;
|
* @param name The name of the prisoner
|
||||||
this.changed = false;
|
* @param time The amount of remaining time the prisoner has
|
||||||
|
* @param jailer The name of the person who jailed this prisoner
|
||||||
|
* @param reason The reason why this prisoner is in jail
|
||||||
|
*/
|
||||||
|
public Prisoner(String uuid, String name, long time, String jailer, String reason) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.name = name;
|
||||||
|
this.time = time;
|
||||||
|
this.jailer = jailer;
|
||||||
|
this.reason = reason;
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the prisoner instance with the lot of data provided.
|
||||||
|
*
|
||||||
|
* @param uuid The uuid of the prisoner
|
||||||
|
* @param name The name of the prisoner
|
||||||
|
* @param time The amount of remaining time the prisoner has
|
||||||
|
* @param reason The reason why this prisoner is in jail
|
||||||
|
*/
|
||||||
|
public Prisoner(String uuid, String name, long time, String reason) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.name = name;
|
||||||
|
this.time = time;
|
||||||
|
this.reason = reason;
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the prisoner instance with the lot of data provided.
|
||||||
|
*
|
||||||
|
* @param uuid The uuid of the prisoner
|
||||||
|
* @param name The name of the prisoner
|
||||||
|
* @param time The amount of remaining time the prisoner has
|
||||||
|
*/
|
||||||
|
public Prisoner(String uuid, String name, long time) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.name = name;
|
||||||
|
this.time = time;
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the prisoner instance with the data provided.
|
||||||
|
*
|
||||||
|
* @param player The instance of the player who is to be jailed
|
||||||
|
* @param muted Whether the prisoner is muted or not
|
||||||
|
* @param time The amount of remaining time the prisoner has
|
||||||
|
* @param jailer The jailer who jailed the prisoner
|
||||||
|
* @param reason The reason why this prisoner is in jail
|
||||||
|
*/
|
||||||
|
public Prisoner(Player player, boolean muted, long time, String jailer, String reason) {
|
||||||
|
this.uuid = player.getUniqueId().toString();
|
||||||
|
this.name = player.getName();
|
||||||
|
this.muted = muted;
|
||||||
|
this.time = time;
|
||||||
|
this.jailer = jailer;
|
||||||
|
this.reason = reason;
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the prisoner instance with the data provided.
|
||||||
|
*
|
||||||
|
* @param player The instance of the player who is to be jailed
|
||||||
|
* @param time The amount of remaining time the prisoner has
|
||||||
|
* @param jailer The jailer who jailed the prisoner
|
||||||
|
* @param reason The reason why this prisoner is in jail
|
||||||
|
*/
|
||||||
|
public Prisoner(Player player, long time, String jailer, String reason) {
|
||||||
|
this.uuid = player.getUniqueId().toString();
|
||||||
|
this.name = player.getName();
|
||||||
|
this.time = time;
|
||||||
|
this.jailer = jailer;
|
||||||
|
this.reason = reason;
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The most basic prisoner instance creation via providing the player, time, and reason.
|
||||||
|
*
|
||||||
|
* @param player The instance of the player who is to be jailed
|
||||||
|
* @param time The amount of remaining time the prisoner has
|
||||||
|
* @param reason The reason why this prisoner is in jail
|
||||||
|
*/
|
||||||
|
public Prisoner(Player player, long time, String reason) {
|
||||||
|
this.uuid = player.getUniqueId().toString();
|
||||||
|
this.name = player.getName();
|
||||||
|
this.time = time;
|
||||||
|
this.reason = reason;
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The most basic prisoner instance creation via providing the player and time.
|
||||||
|
*
|
||||||
|
* @param player The instance of the player who is to be jailed
|
||||||
|
* @param time The amount of remaining time the prisoner has
|
||||||
|
*/
|
||||||
|
public Prisoner(Player player, long time) {
|
||||||
|
this.uuid = player.getUniqueId().toString();
|
||||||
|
this.name = player.getName();
|
||||||
|
this.time = time;
|
||||||
|
finishSetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Finishes the setup of the prisoner data, set to defaults. */
|
||||||
|
private void finishSetup() {
|
||||||
|
if(jailer == null)
|
||||||
|
jailer = Lang.DEFAULTJAILER.get();
|
||||||
|
if(reason == null)
|
||||||
|
Lang.DEFAULTJAILEDREASON.get();
|
||||||
|
if(inventory == null)
|
||||||
|
inventory = "";
|
||||||
|
if(armor == null)
|
||||||
|
armor = "";
|
||||||
|
if(previousGameMode == null)
|
||||||
|
previousGameMode = GameMode.SURVIVAL;
|
||||||
|
previousPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the UUID of the prisoner. */
|
/** Returns the UUID of the prisoner. */
|
||||||
@ -73,7 +195,7 @@ public class Prisoner {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the reason this player was jailed for.
|
* Sets the reason this player was jailed for.
|
||||||
*
|
*
|
||||||
* @param reason the player was jailed.
|
* @param reason the player was jailed.
|
||||||
* @return the reason the player was jailed, what we have stored about them.
|
* @return the reason the player was jailed, what we have stored about them.
|
||||||
*/
|
*/
|
||||||
@ -122,7 +244,7 @@ public class Prisoner {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the remaining time the prisoner has left.
|
* Sets the remaining time the prisoner has left.
|
||||||
*
|
*
|
||||||
* @param time The amount of time left, in milliseconds.
|
* @param time The amount of time left, in milliseconds.
|
||||||
*/
|
*/
|
||||||
public void setRemainingTime(long time) {
|
public void setRemainingTime(long time) {
|
||||||
@ -132,31 +254,31 @@ public class Prisoner {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given time to the remaining time the prisoner has left, unless they're jailed forever.
|
* Adds the given time to the remaining time the prisoner has left, unless they're jailed forever.
|
||||||
*
|
*
|
||||||
* @param time to add to the prisoner's remaining time.
|
* @param time to add to the prisoner's remaining time.
|
||||||
* @return the new remaining time the prisoner has
|
* @return the new remaining time the prisoner has
|
||||||
*/
|
*/
|
||||||
public long addTime(long time) {
|
public long addTime(long time) {
|
||||||
if(this.time != -1L) {
|
if(this.time != -1L) {
|
||||||
this.time += time;
|
this.time += time;
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtracts the given time from the remaining time the prisoner has left, unless they're jailed forever.
|
* Subtracts the given time from the remaining time the prisoner has left, unless they're jailed forever.
|
||||||
*
|
*
|
||||||
* @param time to subtract from the prisoner's remaining time.
|
* @param time to subtract from the prisoner's remaining time.
|
||||||
* @return the new remaining time the prisoner has
|
* @return the new remaining time the prisoner has
|
||||||
*/
|
*/
|
||||||
public long subtractTime(long time) {
|
public long subtractTime(long time) {
|
||||||
if(this.time != -1L) {
|
if(this.time != -1L) {
|
||||||
this.time -= time;
|
this.time -= time;
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ public enum Lang {
|
|||||||
CANTBEJAILED("jailing"),
|
CANTBEJAILED("jailing"),
|
||||||
/** The message sent to the sender when they are trying to jail into a cell which is not empty. */
|
/** The message sent to the sender when they are trying to jail into a cell which is not empty. */
|
||||||
CELLNOTEMPTY("jailing"),
|
CELLNOTEMPTY("jailing"),
|
||||||
|
/** The jailer set whenever a jailer is not provided. */
|
||||||
|
DEFAULTJAILER("jailing"),
|
||||||
/** The message sent when someone is jailed without a reason. */
|
/** The message sent when someone is jailed without a reason. */
|
||||||
DEFAULTJAILEDREASON("jailing"),
|
DEFAULTJAILEDREASON("jailing"),
|
||||||
/** The message sent when someone is unjailed yet they never came online and so they were forcefully unjailed. */
|
/** The message sent when someone is unjailed yet they never came online and so they were forcefully unjailed. */
|
||||||
@ -201,7 +203,7 @@ public enum Lang {
|
|||||||
PAYPAIDLOWEREDTIME("jailpay", "paidloweredtime"),
|
PAYPAIDLOWEREDTIME("jailpay", "paidloweredtime"),
|
||||||
/** The message sent when they pay and lower someone else's time. */
|
/** The message sent when they pay and lower someone else's time. */
|
||||||
PAYPAIDLOWEREDTIMEELSE("jailpay", "paidloweredtimeelse"),
|
PAYPAIDLOWEREDTIMEELSE("jailpay", "paidloweredtimeelse"),
|
||||||
|
|
||||||
// Jail vote
|
// Jail vote
|
||||||
/** The header sent when broadcasting a new jail vote. */
|
/** The header sent when broadcasting a new jail vote. */
|
||||||
VOTEBROADCASTHEADER("jailvote.broadcast", "header"),
|
VOTEBROADCASTHEADER("jailvote.broadcast", "header"),
|
||||||
@ -265,7 +267,7 @@ public enum Lang {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link YamlConfiguration} instance to use.
|
* Sets the {@link YamlConfiguration} instance to use.
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* of the language to use.
|
* of the language to use.
|
||||||
*/
|
*/
|
||||||
@ -304,7 +306,7 @@ public enum Lang {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the message in the language, with the provided variables being replaced.
|
* Returns the message in the language, with the provided variables being replaced.
|
||||||
*
|
*
|
||||||
* @param variables
|
* @param variables
|
||||||
* All the variables to replace, in order from 0 to however many.
|
* All the variables to replace, in order from 0 to however many.
|
||||||
* @return The message as a colorful message or an empty message if that
|
* @return The message as a colorful message or an empty message if that
|
||||||
|
@ -49,6 +49,7 @@ language:
|
|||||||
cancelledbyanotherplugin: '&cJailing %0% was cancelled by another plugin and they did not leave you a message.'
|
cancelledbyanotherplugin: '&cJailing %0% was cancelled by another plugin and they did not leave you a message.'
|
||||||
cantbejailed: '&cThat player can not be jailed.'
|
cantbejailed: '&cThat player can not be jailed.'
|
||||||
cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.'
|
cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.'
|
||||||
|
defaultjailer: 'Al Capone'
|
||||||
defaultjailedreason: 'Breaking the rules.'
|
defaultjailedreason: 'Breaking the rules.'
|
||||||
forceunjailed: '&c%0% was forcefully unjailed.'
|
forceunjailed: '&c%0% was forcefully unjailed.'
|
||||||
jailed: '&cYou have been jailed!'
|
jailed: '&cYou have been jailed!'
|
||||||
|
@ -98,6 +98,7 @@ public class TestJailLanguage {
|
|||||||
assertEquals(colorize("&cJailing graywolf336 was cancelled by another plugin and they did not leave you a message."), Lang.CANCELLEDBYANOTHERPLUGIN.get("graywolf336"));
|
assertEquals(colorize("&cJailing graywolf336 was cancelled by another plugin and they did not leave you a message."), Lang.CANCELLEDBYANOTHERPLUGIN.get("graywolf336"));
|
||||||
assertEquals(colorize("&cThat player can not be jailed."), Lang.CANTBEJAILED.get());
|
assertEquals(colorize("&cThat player can not be jailed."), Lang.CANTBEJAILED.get());
|
||||||
assertEquals(colorize("&cThe destination cell, cell_n01, already has a prisoner in it."), Lang.CELLNOTEMPTY.get("cell_n01"));
|
assertEquals(colorize("&cThe destination cell, cell_n01, already has a prisoner in it."), Lang.CELLNOTEMPTY.get("cell_n01"));
|
||||||
|
assertEquals("Al Capone", Lang.DEFAULTJAILER.get());
|
||||||
assertEquals("Breaking the rules.", Lang.DEFAULTJAILEDREASON.get());
|
assertEquals("Breaking the rules.", Lang.DEFAULTJAILEDREASON.get());
|
||||||
assertEquals(colorize("&cgraywolf336 was forcefully unjailed."), Lang.FORCEUNJAILED.get("graywolf336"));
|
assertEquals(colorize("&cgraywolf336 was forcefully unjailed."), Lang.FORCEUNJAILED.get("graywolf336"));
|
||||||
assertEquals(colorize("&cYou have been jailed!"), Lang.JAILED.get());
|
assertEquals(colorize("&cYou have been jailed!"), Lang.JAILED.get());
|
||||||
|
Loading…
Reference in New Issue
Block a user