2014-03-08 22:53:59 -06:00
|
|
|
package com.graywolf336.jail;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.graywolf336.jail.beans.Stick;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages the jail stick users.
|
|
|
|
*
|
|
|
|
* @author graywolf336
|
|
|
|
* @version 1.0.0
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class JailStickManager {
|
|
|
|
private ArrayList<String> stickers;
|
|
|
|
private HashMap<Material, Stick> sticks;
|
|
|
|
|
|
|
|
public JailStickManager(JailMain plugin) {
|
|
|
|
this.stickers = new ArrayList<String>();
|
|
|
|
this.sticks = new HashMap<Material, Stick>();
|
|
|
|
|
|
|
|
this.loadJailSticks(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadJailSticks(JailMain pl) {
|
|
|
|
FileConfiguration config = pl.getConfig();
|
|
|
|
|
|
|
|
//item name,time,jail name,reason
|
|
|
|
for(String s : config.getStringList("jailstick")) {
|
|
|
|
String[] a = s.split(",");
|
|
|
|
|
2014-03-08 23:39:11 -06:00
|
|
|
//Check if the jail given, if any, exists
|
|
|
|
if(!a[2].isEmpty()) {
|
|
|
|
if(!pl.getJailManager().isValidJail(a[2])) {
|
|
|
|
pl.getLogger().warning(s);
|
|
|
|
pl.getLogger().warning("The above jail stick configuration is invalid and references a jail that doesn't exist.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-08 22:53:59 -06:00
|
|
|
try {
|
|
|
|
this.sticks.put(Material.getMaterial(a[0]), new Stick(a[2], a[1], Long.valueOf(a[3])));
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
pl.getLogger().info(s);
|
|
|
|
pl.getLogger().severe("Unable to create a new stick for " + a[0] + ", see the exception above for details.");
|
2014-03-08 23:39:11 -06:00
|
|
|
continue;
|
2014-03-08 22:53:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int c = sticks.size();
|
|
|
|
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) {
|
|
|
|
return this.sticks.get(mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Checks if the provided Material is a valid {@link Stick jail stick}. */
|
|
|
|
public boolean isValidStick(Material mat) {
|
|
|
|
return this.sticks.containsKey(mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a player to be using a jail stick, with the player instance.
|
|
|
|
*
|
|
|
|
* @param player to add
|
|
|
|
*/
|
|
|
|
public void addUsingStick(Player player) {
|
|
|
|
this.stickers.add(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a player to be using a jail stick, with their username.
|
|
|
|
*
|
|
|
|
* @param name of the player to add
|
|
|
|
*/
|
|
|
|
public void addUsingStick(String name) {
|
|
|
|
this.stickers.add(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a player from using a jail stick, with the player instance.
|
|
|
|
*
|
|
|
|
* @param player to remove using a jail stick
|
|
|
|
*/
|
|
|
|
public void removeUsingStick(Player player) {
|
|
|
|
this.stickers.remove(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a player from using a jail stick, with their username.
|
|
|
|
*
|
|
|
|
* @param name of the player to remove using a jail stick
|
|
|
|
*/
|
|
|
|
public void removeUsingStick(String name) {
|
|
|
|
this.stickers.remove(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not the player is using a jail stick.
|
|
|
|
*
|
|
|
|
* @param player to check if using one
|
|
|
|
* @return true if the player is using a jail stick, false if not
|
|
|
|
*/
|
2014-03-08 23:39:11 -06:00
|
|
|
public boolean isUsingJailStick(Player player) {
|
2014-03-08 22:53:59 -06:00
|
|
|
return this.stickers.contains(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not the player is using a jail stick.
|
|
|
|
*
|
|
|
|
* @param name of the player to check if using one
|
|
|
|
* @return true if the player is using a jail stick, false if not
|
|
|
|
*/
|
2014-03-08 23:39:11 -06:00
|
|
|
public boolean isUsingJailStick(String name) {
|
2014-03-08 22:53:59 -06:00
|
|
|
return this.stickers.contains(name);
|
|
|
|
}
|
2014-03-08 23:39:11 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
|
|
|
|
*
|
2014-03-11 13:03:11 -05:00
|
|
|
* @param player to toggle using a stick
|
2014-03-08 23:39:11 -06:00
|
|
|
* @return true if we enabled it, false if we disabled it.
|
|
|
|
*/
|
|
|
|
public boolean toggleUsingStick(Player player) {
|
|
|
|
return this.toggleUsingStick(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
|
|
|
|
*
|
|
|
|
* @param name of the person to toggle
|
|
|
|
* @return true if we enabled it, false if we disabled it.
|
|
|
|
*/
|
|
|
|
public boolean toggleUsingStick(String name) {
|
|
|
|
if(this.stickers.contains(name)) {
|
|
|
|
this.stickers.remove(name);
|
|
|
|
return false;
|
|
|
|
}else {
|
|
|
|
this.stickers.add(name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 22:53:59 -06:00
|
|
|
}
|