Add an interface for the Jail Stick Manager.

Adding the API further this way if someone wants to handle items in a
different way or handle their own implementation of it, they can easily
do it.
This commit is contained in:
graywolf336 2015-05-21 14:20:17 -05:00
parent e2ad5c00e5
commit cf50e37910
4 changed files with 79 additions and 38 deletions

View File

@ -13,6 +13,7 @@ import com.graywolf336.jail.command.CommandHandler;
import com.graywolf336.jail.command.JailHandler; import com.graywolf336.jail.command.JailHandler;
import com.graywolf336.jail.enums.Lang; import com.graywolf336.jail.enums.Lang;
import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.interfaces.IJailStickManager;
import com.graywolf336.jail.legacy.LegacyManager; import com.graywolf336.jail.legacy.LegacyManager;
import com.graywolf336.jail.listeners.CacheListener; import com.graywolf336.jail.listeners.CacheListener;
import com.graywolf336.jail.listeners.CellSignListener; import com.graywolf336.jail.listeners.CellSignListener;
@ -38,7 +39,7 @@ public class JailMain extends JavaPlugin {
private JailIO io; private JailIO io;
private JailManager jm; private JailManager jm;
private JailPayManager jpm; private JailPayManager jpm;
private JailStickManager jsm; private IJailStickManager jsm;
private JailTimer jt; private JailTimer jt;
private JailVoteManager jvm; private JailVoteManager jvm;
private PrisonerManager pm; private PrisonerManager pm;
@ -306,7 +307,7 @@ public class JailMain extends JavaPlugin {
} }
/** Gets the {@link JailStickManager} instance. */ /** Gets the {@link JailStickManager} instance. */
public JailStickManager getJailStickManager() { public IJailStickManager getJailStickManager() {
return this.jsm; return this.jsm;
} }

View File

@ -8,6 +8,7 @@ import org.bukkit.Material;
import com.graywolf336.jail.beans.Stick; import com.graywolf336.jail.beans.Stick;
import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.interfaces.IJailStickManager;
/** /**
* Manages the jail stick users. * Manages the jail stick users.
@ -17,7 +18,7 @@ import com.graywolf336.jail.enums.Settings;
* @since 3.0.0 * @since 3.0.0
* *
*/ */
public class JailStickManager { public class JailStickManager implements IJailStickManager {
private ArrayList<UUID> stickers; private ArrayList<UUID> stickers;
private HashMap<Material, Stick> sticks; private HashMap<Material, Stick> sticks;
@ -79,56 +80,27 @@ public class JailStickManager {
int c = sticks.size(); int c = sticks.size();
pl.getLogger().info("Loaded " + c + " jail stick" + (c == 1 ? "" : "s") + "."); pl.getLogger().info("Loaded " + c + " jail stick" + (c == 1 ? "" : "s") + ".");
} }
/**
* Gets the {@link Stick jail stick} by the provided {@link Material}, can be null.
*
* @param mat of the stick to get
* @return The {@link Stick jail stick}
*/
public Stick getStick(Material mat) { public Stick getStick(Material mat) {
return this.sticks.get(mat); return this.sticks.get(mat);
} }
/** Checks if the provided Material is a valid {@link Stick jail stick}. */
public boolean isValidStick(Material mat) { public boolean isValidStick(Material mat) {
return this.sticks.containsKey(mat); return this.sticks.containsKey(mat);
} }
/**
* Adds a player to be using a jail stick, with the uuid of the player.
*
* @param id of the player to add
*/
public void addUsingStick(UUID id) { public void addUsingStick(UUID id) {
this.stickers.add(id); this.stickers.add(id);
} }
/**
* Removes a player from using a jail stick, with the uuid of the player.
*
* @param id of the player to remove using a jail stick
*/
public void removeUsingStick(UUID id) { public void removeUsingStick(UUID id) {
this.stickers.remove(id); this.stickers.remove(id);
} }
/**
* Returns whether or not the player is using a jail stick.
*
* @param id of the player to check if using one
* @return true if the player is using a jail stick, false if not
*/
public boolean isUsingJailStick(UUID id) { public boolean isUsingJailStick(UUID id) {
return this.stickers.contains(id); return this.stickers.contains(id);
} }
/**
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
*
* @param id of the player to toggle using a stick
* @return true if we enabled it, false if we disabled it.
*/
public boolean toggleUsingStick(UUID id) { public boolean toggleUsingStick(UUID id) {
if(this.stickers.contains(id)) { if(this.stickers.contains(id)) {
this.stickers.remove(id); this.stickers.remove(id);
@ -139,7 +111,6 @@ public class JailStickManager {
} }
} }
/** Removes all the users currently using the sticks. */
public void removeAllStickUsers() { public void removeAllStickUsers() {
for(UUID id : stickers) { for(UUID id : stickers) {
this.removeUsingStick(id); this.removeUsingStick(id);

View File

@ -1,5 +1,7 @@
package com.graywolf336.jail; package com.graywolf336.jail;
import com.graywolf336.jail.interfaces.IJailStickManager;
/** /**
* The static api interface for Jail plugin. * The static api interface for Jail plugin.
* *
@ -40,12 +42,12 @@ public class JailsAPI {
} }
/** /**
* The instance of the {@link JailStickManager} which handles all the jail sticks. * Gets an instance of the {@link IJailStickManager} which handles all the jail sticks.
* *
* @return instance of the {@link JailStickManager} * @return an instance of the {@link IJailStickManager}
* @see JailStickManager * @see IJailStickManager
*/ */
public static JailStickManager getJailStickManager() { public static IJailStickManager getJailStickManager() {
return pl.getJailStickManager(); return pl.getJailStickManager();
} }

View File

@ -0,0 +1,67 @@
package com.graywolf336.jail.interfaces;
import java.util.UUID;
import org.bukkit.Material;
import com.graywolf336.jail.beans.Stick;
/**
* Interface for the jail stick manager.
*
* @author graywolf336
* @version 1.0.0
* @since 3.0.0
*
*/
public interface IJailStickManager {
/**
* Gets the {@link Stick jail stick} by the provided {@link Material}, can be null.
*
* @param mat of the stick to get
* @return The {@link Stick jail stick}
*/
public Stick getStick(Material mat);
/**
* Checks if the provided Material is a valid {@link Stick jail stick}
*
* @param mat the {@link Material} to check
* @return whether the provided material is a valid stick
*/
public boolean isValidStick(Material mat);
/**
* Adds a player to be using a jail stick, with the uuid of the player.
*
* @param id of the player to add
*/
public void addUsingStick(UUID id);
/**
* Removes a player from using a jail stick, with the uuid of the player.
*
* @param id of the player to remove using a jail stick
*/
public void removeUsingStick(UUID id);
/**
* Returns whether or not the player is using a jail stick.
*
* @param id of the player to check if using one
* @return true if the player is using a jail stick, false if not
*/
public boolean isUsingJailStick(UUID id);
/**
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
*
* @param id of the player to toggle using a stick
* @return true if we enabled it, false if we disabled it.
*/
public boolean toggleUsingStick(UUID id);
/** Removes all the users currently using the sticks. */
public void removeAllStickUsers();
}