Remove NMS, update json chat component

This commit is contained in:
boosik 2020-07-10 11:36:04 +02:00
parent 4c7a663c43
commit 7a2b32a3d2
37 changed files with 557 additions and 818 deletions

View File

@ -5,11 +5,8 @@ import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import nms.NMS; import net.md_5.bungee.chat.ComponentSerializer;
import nms.NMSNotHookedException;
import nms.NMSSetupResponse;
/** /**
* A JSON Object is the base for any JSON message using this library. * A JSON Object is the base for any JSON message using this library.
@ -21,16 +18,16 @@ import nms.NMSSetupResponse;
*/ */
public class JSON { public class JSON {
private List<JSONComponentSimple> components = new ArrayList<JSONComponentSimple>(); private final List<JSONComponentSimple> components = new ArrayList<JSONComponentSimple>();
private String generatedJSON; private String generatedJSON;
private boolean generated; private boolean generated;
/** /**
* Constructs a new JSON Object with a base JSONComponentSimple Object. * Constructs a new JSON Object with a base JSONComponentSimple Object.
* *
* @param JSONComponentSimple (JSONComponentSimple) - the base JSONComponentSimple Object * @param jsonComponent (JSONComponentSimple) - the base JSONComponentSimple Object
*/ */
public JSON(JSONComponentSimple jsonComponent) { public JSON(final JSONComponentSimple jsonComponent) {
if (jsonComponent == null) { if (jsonComponent == null) {
throw new IllegalArgumentException("component cannot be null!"); throw new IllegalArgumentException("component cannot be null!");
@ -48,14 +45,14 @@ public class JSON {
* *
* @param components (JSONComponentSimple[]) - the JSONComponentSimple Objects * @param components (JSONComponentSimple[]) - the JSONComponentSimple Objects
*/ */
public JSON(JSONComponentSimple... components) { public JSON(final JSONComponentSimple... components) {
if (components == null) { if (components == null) {
throw new IllegalArgumentException("component cannot be null!"); throw new IllegalArgumentException("component cannot be null!");
} }
if (components.length > 0) { if (components.length > 0) {
for (JSONComponentSimple component : components) { for (final JSONComponentSimple component : components) {
this.components.add(component); this.components.add(component);
} }
} }
@ -65,22 +62,13 @@ public class JSON {
} }
/**
* This method needs to be called in the onEnable() method.
*
* @see NMS#setup()
*/
public static NMSSetupResponse setup(Plugin pl) {
return NMS.setup(pl);
}
/** /**
* Sends a JSON message to a player. * Sends a JSON message to a player.
* *
* @param to (Player) - the player to send the message to * @param to (Player) - the player to send the message to
* @param json (String) - the raw JSON to send * @param json (String) - the raw JSON to send
*/ */
public static void sendJSON(Player to, String json) { public static void sendJSON(final Player to, final String json) {
if (to == null) { if (to == null) {
throw new IllegalArgumentException("player cannot be null!"); throw new IllegalArgumentException("player cannot be null!");
@ -88,12 +76,7 @@ public class JSON {
if (json == null) { if (json == null) {
throw new IllegalArgumentException("json cannot be null!"); throw new IllegalArgumentException("json cannot be null!");
} }
to.spigot().sendMessage(ComponentSerializer.parse(json));
try {
NMS.getHook().sendJSON(json, to);
} catch (NMSNotHookedException e) {
e.printStackTrace();
}
} }
/** /**
@ -103,7 +86,7 @@ public class JSON {
* @param to (Player) - the player to send the message to * @param to (Player) - the player to send the message to
* @param json (JSON) - the JSON Object to send * @param json (JSON) - the JSON Object to send
*/ */
public static void sendJSON(Player to, JSON json) { public static void sendJSON(final Player to, final JSON json) {
sendJSON(to, json.get()); sendJSON(to, json.get());
} }
@ -113,14 +96,14 @@ public class JSON {
* @param jsons (JSON[]) - the JSON Objects to combine * @param jsons (JSON[]) - the JSON Objects to combine
* @return (JSON) - the combined JSON. * @return (JSON) - the combined JSON.
*/ */
public static JSON combineToNewJSON(JSON... jsons) { public static JSON combineToNewJSON(final JSON... jsons) {
JSON baseJSON; final JSON baseJSON;
baseJSON = (JSON) jsons[0].clone(); baseJSON = jsons[0].clone();
for (int i = 1; i < jsons.length; i++) { for (int i = 1; i < jsons.length; i++) {
for (JSONComponentSimple comp : jsons[i].getComponents()) { for (final JSONComponentSimple comp : jsons[i].getComponents()) {
baseJSON.add(comp.clone()); baseJSON.add(comp.clone());
} }
} }
@ -135,7 +118,7 @@ public class JSON {
@Override @Override
public JSON clone() { public JSON clone() {
JSONComponentSimple[] comps = new JSONComponentSimple[components.size()]; final JSONComponentSimple[] comps = new JSONComponentSimple[components.size()];
for (int i = 0; i < components.size(); i++) { for (int i = 0; i < components.size(); i++) {
comps[i] = components.get(i).clone(); comps[i] = components.get(i).clone();
@ -151,7 +134,7 @@ public class JSON {
* @param component (JSONComponentSimple) - the JSONComponentSimple to add. * @param component (JSONComponentSimple) - the JSONComponentSimple to add.
* @return (JSON) - this JSON Object, for chaining. * @return (JSON) - this JSON Object, for chaining.
*/ */
public JSON add(JSONComponentSimple component) { public JSON add(final JSONComponentSimple component) {
if (component == null) { if (component == null) {
throw new IllegalArgumentException("component cannot be null!"); throw new IllegalArgumentException("component cannot be null!");
@ -171,7 +154,7 @@ public class JSON {
* @param component (JSONComponentSimple) - the JSONComponentSimple to remove. * @param component (JSONComponentSimple) - the JSONComponentSimple to remove.
* @return (JSON) - this JSON Object, for chaining. * @return (JSON) - this JSON Object, for chaining.
*/ */
public JSON remove(JSONComponentSimple component) { public JSON remove(final JSONComponentSimple component) {
if (component == null) { if (component == null) {
throw new IllegalArgumentException("component cannot be null!"); throw new IllegalArgumentException("component cannot be null!");
@ -201,10 +184,10 @@ public class JSON {
* @param jsons (JSON[]) - the JSON Objects to add to this one * @param jsons (JSON[]) - the JSON Objects to add to this one
* @return JSON - this JSON Object, with all other JSON Objects added. * @return JSON - this JSON Object, with all other JSON Objects added.
*/ */
public JSON combine(JSON... jsons) { public JSON combine(final JSON... jsons) {
for (JSON json : jsons) { for (final JSON json : jsons) {
for (JSONComponentSimple component : json.getComponents()) { for (final JSONComponentSimple component : json.getComponents()) {
this.add(component); this.add(component);
} }
} }
@ -223,7 +206,7 @@ public class JSON {
generatedJSON = "{\"text\":\"\",\"extra\":["; generatedJSON = "{\"text\":\"\",\"extra\":[";
for (JSONComponentSimple component : components) { for (final JSONComponentSimple component : components) {
generatedJSON += component.get() + ","; generatedJSON += component.get() + ",";
} }
@ -256,7 +239,7 @@ public class JSON {
* @param player (Player) - the player to send the message to * @param player (Player) - the player to send the message to
* @return (JSON) - this JSON Object, for chaining. * @return (JSON) - this JSON Object, for chaining.
*/ */
public JSON send(Player player) { public JSON send(final Player player) {
if (player == null) { if (player == null) {
throw new IllegalArgumentException("player cannot be null!"); throw new IllegalArgumentException("player cannot be null!");
@ -278,7 +261,7 @@ public class JSON {
String s = ""; String s = "";
for (JSONComponentSimple comp : components) { for (final JSONComponentSimple comp : components) {
s += ChatColor.RESET + comp.getChatColorVersion(); s += ChatColor.RESET + comp.getChatColorVersion();
} }

View File

@ -16,7 +16,7 @@ public interface JSONClickAction<T> {
* @return (?) - the value. * @return (?) - the value.
* @see #setValue(Object) * @see #setValue(Object)
*/ */
public T getValue(); T getValue();
/** /**
* Sets the value of this JSONClickAction. * Sets the value of this JSONClickAction.
@ -24,7 +24,7 @@ public interface JSONClickAction<T> {
* @param newValue (?) - the new value * @param newValue (?) - the new value
* @return (JSONHoverAction: ?) - this JSONClickAction Object, for chaining. * @return (JSONHoverAction: ?) - this JSONClickAction Object, for chaining.
*/ */
public JSONClickAction<T> setValue(T newValue); JSONClickAction<T> setValue(T newValue);
/** /**
* Gets the value associated with this JSONClickAction transformed to a String. * Gets the value associated with this JSONClickAction transformed to a String.
@ -32,7 +32,7 @@ public interface JSONClickAction<T> {
* @return (String) - the value as a String. * @return (String) - the value as a String.
* @see #getValue() * @see #getValue()
*/ */
public String getValueString(); String getValueString();
/** /**
* Gets the action name associated with this JSONClickAction. * Gets the action name associated with this JSONClickAction.
@ -40,12 +40,12 @@ public interface JSONClickAction<T> {
* *
* @return (String) - the action name. * @return (String) - the action name.
*/ */
public String getActionName(); String getActionName();
/** /**
* Runs a command as the player who clicks on the text in the chat. * Runs a command as the player who clicks on the text in the chat.
*/ */
public class RunCommand class RunCommand
implements JSONClickAction<String> { implements JSONClickAction<String> {
/** /**
@ -62,7 +62,7 @@ public interface JSONClickAction<T> {
* *
* @param value (String) - the value associated with this JSONClickAction * @param value (String) - the value associated with this JSONClickAction
*/ */
public RunCommand(String value) { public RunCommand(final String value) {
this.value = value; this.value = value;
@ -74,7 +74,7 @@ public interface JSONClickAction<T> {
} }
@Override @Override
public JSONClickAction<String> setValue(String newValue) { public JSONClickAction<String> setValue(final String newValue) {
value = newValue; value = newValue;
return this; return this;
} }
@ -94,7 +94,7 @@ public interface JSONClickAction<T> {
/** /**
* Pastes a command in the chat of the player who clicks on the text in the chat. * Pastes a command in the chat of the player who clicks on the text in the chat.
*/ */
public class SuggestCommand class SuggestCommand
implements JSONClickAction<String> { implements JSONClickAction<String> {
/** /**
@ -111,7 +111,7 @@ public interface JSONClickAction<T> {
* *
* @param value (String) - the value associated with this JSONClickAction * @param value (String) - the value associated with this JSONClickAction
*/ */
public SuggestCommand(String value) { public SuggestCommand(final String value) {
this.value = value; this.value = value;
@ -123,7 +123,7 @@ public interface JSONClickAction<T> {
} }
@Override @Override
public JSONClickAction<String> setValue(String newValue) { public JSONClickAction<String> setValue(final String newValue) {
value = newValue; value = newValue;
return this; return this;
} }
@ -143,7 +143,7 @@ public interface JSONClickAction<T> {
/** /**
* Opens a URL in the default browser of the player who clicks on the text in the chat. * Opens a URL in the default browser of the player who clicks on the text in the chat.
*/ */
public class OpenURL class OpenURL
implements JSONClickAction<String> { implements JSONClickAction<String> {
/** /**
@ -160,7 +160,7 @@ public interface JSONClickAction<T> {
* *
* @param value (String) - the value associated with this JSONClickAction * @param value (String) - the value associated with this JSONClickAction
*/ */
public OpenURL(String value) { public OpenURL(final String value) {
this.value = value; this.value = value;
@ -172,7 +172,7 @@ public interface JSONClickAction<T> {
} }
@Override @Override
public JSONClickAction<String> setValue(String newValue) { public JSONClickAction<String> setValue(final String newValue) {
value = newValue; value = newValue;
return this; return this;
} }

View File

@ -30,14 +30,14 @@ public enum JSONColor {
private final String code; private final String code;
JSONColor(String code) { JSONColor(final String code) {
this.code = code; this.code = code;
} }
public static JSONColor fromString(String text) { public static JSONColor fromString(String text) {
if (text != null) { if (text != null) {
text = text.replace("§", "&"); text = text.replace("§", "&");
for (JSONColor b : JSONColor.values()) { for (final JSONColor b : JSONColor.values()) {
if (text.equalsIgnoreCase(b.code)) { if (text.equalsIgnoreCase(b.code)) {
return b; return b;
} }

View File

@ -11,7 +11,7 @@ public class JSONComponent
private JSONHoverAction<?> hoverAction; private JSONHoverAction<?> hoverAction;
private JSONClickAction<?> clickAction; private JSONClickAction<?> clickAction;
public JSONComponent(String text) { public JSONComponent(final String text) {
super(text); super(text);
} }
@ -77,7 +77,7 @@ public class JSONComponent
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
* @see #getHoverAction() * @see #getHoverAction()
*/ */
public JSONComponent setHoverAction(JSONHoverAction<?> hoverAction) { public JSONComponent setHoverAction(final JSONHoverAction<?> hoverAction) {
if (hoverAction == null) { if (hoverAction == null) {
throw new IllegalArgumentException("hoverAction cannot be null!"); throw new IllegalArgumentException("hoverAction cannot be null!");
} }
@ -102,7 +102,7 @@ public class JSONComponent
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
* @see #getClickAction() * @see #getClickAction()
*/ */
public JSONComponent setClickAction(JSONClickAction<?> clickAction) { public JSONComponent setClickAction(final JSONClickAction<?> clickAction) {
if (clickAction == null) { if (clickAction == null) {
throw new IllegalArgumentException("clickAction cannot be null!"); throw new IllegalArgumentException("clickAction cannot be null!");
} }

View File

@ -28,7 +28,7 @@ public class JSONComponentSimple {
* *
* @param text (String) - the base text this JSONComponent contains * @param text (String) - the base text this JSONComponent contains
*/ */
public JSONComponentSimple(String text) { public JSONComponentSimple(final String text) {
if (text == null) { if (text == null) {
throw new IllegalArgumentException("text cannot be null!"); throw new IllegalArgumentException("text cannot be null!");
@ -51,11 +51,11 @@ public class JSONComponentSimple {
* @return (JSONComponent) - the JSONComponent matching the String or null if the String is invalid. * @return (JSONComponent) - the JSONComponent matching the String or null if the String is invalid.
* @see #toString() * @see #toString()
*/ */
public static JSONComponentSimple fromString(String str) { public static JSONComponentSimple fromString(final String str) {
try { try {
String[] parts = str.split("|||"); final String[] parts = str.split("|||");
if (parts == null || parts.length != 7) { if (parts == null || parts.length != 7) {
return null; return null;
@ -69,7 +69,7 @@ public class JSONComponentSimple {
.setUnderlined(Boolean.valueOf(parts[5])) .setUnderlined(Boolean.valueOf(parts[5]))
.setObfuscated(Boolean.valueOf(parts[6])); .setObfuscated(Boolean.valueOf(parts[6]));
} catch (Exception e) { } catch (final Exception e) {
return null; return null;
} }
@ -114,11 +114,11 @@ public class JSONComponentSimple {
* @param withComponents (JSONComponent[]) - the JSONComponent Objects to combine this JSONComponent with * @param withComponents (JSONComponent[]) - the JSONComponent Objects to combine this JSONComponent with
* @return (JSON) - a newly created JSON Object containing this and all specified JSONComponent Objects. * @return (JSON) - a newly created JSON Object containing this and all specified JSONComponent Objects.
*/ */
public JSON combine(JSONComponentSimple... withComponents) { public JSON combine(final JSONComponentSimple... withComponents) {
JSON json = new JSON(this); final JSON json = new JSON(this);
for (JSONComponentSimple with : withComponents) { for (final JSONComponentSimple with : withComponents) {
json.add(with); json.add(with);
} }
@ -134,7 +134,7 @@ public class JSONComponentSimple {
* @see JSON#add(JSONComponent) * @see JSON#add(JSONComponent)
* @see JSONComponent#toJSON() * @see JSONComponent#toJSON()
*/ */
public JSONComponentSimple addToJSON(JSON json) { public JSONComponentSimple addToJSON(final JSON json) {
json.add(this); json.add(this);
@ -173,7 +173,7 @@ public class JSONComponentSimple {
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
* @see JSONComponent_old#get() * @see JSONComponent_old#get()
*/ */
public JSONComponentSimple send(Player to) { public JSONComponentSimple send(final Player to) {
JSON.sendJSON(to, get()); JSON.sendJSON(to, get());
@ -231,7 +231,7 @@ public class JSONComponentSimple {
* @param text (String) - the new text * @param text (String) - the new text
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
*/ */
public JSONComponentSimple setText(String text) { public JSONComponentSimple setText(final String text) {
if (text == null) { if (text == null) {
throw new IllegalArgumentException("text cannot be null!"); throw new IllegalArgumentException("text cannot be null!");
} }
@ -259,7 +259,7 @@ public class JSONComponentSimple {
* @param color (JSONColor) - the color to set this JSONObject to * @param color (JSONColor) - the color to set this JSONObject to
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
*/ */
public JSONComponentSimple setColor(JSONColor color) { public JSONComponentSimple setColor(final JSONColor color) {
if (color == null) { if (color == null) {
throw new IllegalArgumentException("color cannot be null!"); throw new IllegalArgumentException("color cannot be null!");
} }
@ -284,7 +284,7 @@ public class JSONComponentSimple {
* @param bold (boolean) - whether the text should be bold * @param bold (boolean) - whether the text should be bold
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
*/ */
public JSONComponentSimple setBold(boolean bold) { public JSONComponentSimple setBold(final boolean bold) {
this.bold = bold; this.bold = bold;
generated = false; generated = false;
return this; return this;
@ -306,7 +306,7 @@ public class JSONComponentSimple {
* @param italic (boolean) - whether the text should be italic * @param italic (boolean) - whether the text should be italic
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
*/ */
public JSONComponentSimple setItalic(boolean italic) { public JSONComponentSimple setItalic(final boolean italic) {
this.italic = italic; this.italic = italic;
generated = false; generated = false;
return this; return this;
@ -328,7 +328,7 @@ public class JSONComponentSimple {
* @param strikethrough (boolean) - whether the text should be strikethrough * @param strikethrough (boolean) - whether the text should be strikethrough
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
*/ */
public JSONComponentSimple setStrikethrough(boolean strikethrough) { public JSONComponentSimple setStrikethrough(final boolean strikethrough) {
this.strikethrough = strikethrough; this.strikethrough = strikethrough;
generated = false; generated = false;
return this; return this;
@ -350,7 +350,7 @@ public class JSONComponentSimple {
* @param underlined (boolean) - whether the text should be underlined * @param underlined (boolean) - whether the text should be underlined
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
*/ */
public JSONComponentSimple setUnderlined(boolean underlined) { public JSONComponentSimple setUnderlined(final boolean underlined) {
this.underlined = underlined; this.underlined = underlined;
generated = false; generated = false;
return this; return this;
@ -372,7 +372,7 @@ public class JSONComponentSimple {
* @param obfuscated (boolean) - whether the text should be obfuscated * @param obfuscated (boolean) - whether the text should be obfuscated
* @return (JSONComponent) - this JSONComponent Object, for chaining. * @return (JSONComponent) - this JSONComponent Object, for chaining.
*/ */
public JSONComponentSimple setObfuscated(boolean obfuscated) { public JSONComponentSimple setObfuscated(final boolean obfuscated) {
this.obfuscated = obfuscated; this.obfuscated = obfuscated;
generated = false; generated = false;
return this; return this;

View File

@ -4,6 +4,8 @@ import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import cz.boosik.boosCooldown.BoosCoolDown;
/** /**
* Represents a hover action. * Represents a hover action.
* All rights reserved. * All rights reserved.
@ -20,7 +22,7 @@ public interface JSONHoverAction<T> {
* @return (?) - the value. * @return (?) - the value.
* @see #setValue(Object) * @see #setValue(Object)
*/ */
public T getValue(); T getValue();
/** /**
* Sets the value of this JSONHoverAction. * Sets the value of this JSONHoverAction.
@ -28,7 +30,7 @@ public interface JSONHoverAction<T> {
* @param newValue (?) - the new value * @param newValue (?) - the new value
* @return (JSONHoverAction: ?) - this JSONHoverAction Object, for chaining. * @return (JSONHoverAction: ?) - this JSONHoverAction Object, for chaining.
*/ */
public JSONHoverAction<T> setValue(T newValue); JSONHoverAction<T> setValue(T newValue);
/** /**
* Gets the value associated with this JSONHoverAction transformed to a String. * Gets the value associated with this JSONHoverAction transformed to a String.
@ -36,7 +38,7 @@ public interface JSONHoverAction<T> {
* @return (String) - the value as a String. * @return (String) - the value as a String.
* @see #getValue() * @see #getValue()
*/ */
public String getValueString(); String getValueString();
/** /**
* Gets the action name associated with this JSONHoverAction. * Gets the action name associated with this JSONHoverAction.
@ -44,12 +46,12 @@ public interface JSONHoverAction<T> {
* *
* @return (String) - the action name. * @return (String) - the action name.
*/ */
public String getActionName(); String getActionName();
/** /**
* Shows some JSON-formed text when hovering over the text in the chat. * Shows some JSON-formed text when hovering over the text in the chat.
*/ */
public class ShowText class ShowText
implements JSONHoverAction<JSON> { implements JSONHoverAction<JSON> {
/** /**
@ -66,7 +68,7 @@ public interface JSONHoverAction<T> {
* *
* @param value (JSON) - the value associated with this JSONHoverAction * @param value (JSON) - the value associated with this JSONHoverAction
*/ */
public ShowText(JSON value) { public ShowText(final JSON value) {
this.value = value; this.value = value;
@ -78,7 +80,7 @@ public interface JSONHoverAction<T> {
} }
@Override @Override
public JSONHoverAction<JSON> setValue(JSON newValue) { public JSONHoverAction<JSON> setValue(final JSON newValue) {
value = newValue; value = newValue;
return this; return this;
} }
@ -98,7 +100,7 @@ public interface JSONHoverAction<T> {
/** /**
* Shows some JSON-formed text when hovering over the text in the chat. * Shows some JSON-formed text when hovering over the text in the chat.
*/ */
public class ShowStringText class ShowStringText
implements JSONHoverAction<String> { implements JSONHoverAction<String> {
/** /**
@ -115,7 +117,7 @@ public interface JSONHoverAction<T> {
* *
* @param value (JSON) - the value associated with this JSONHoverAction * @param value (JSON) - the value associated with this JSONHoverAction
*/ */
public ShowStringText(String value) { public ShowStringText(final String value) {
this.value = value; this.value = value;
@ -127,7 +129,7 @@ public interface JSONHoverAction<T> {
} }
@Override @Override
public JSONHoverAction<String> setValue(String newValue) { public JSONHoverAction<String> setValue(final String newValue) {
value = newValue; value = newValue;
return this; return this;
} }
@ -147,7 +149,7 @@ public interface JSONHoverAction<T> {
/** /**
* Shows an item when hovering over the text in the chat. * Shows an item when hovering over the text in the chat.
*/ */
public class ShowItem class ShowItem
implements JSONHoverAction<Material> { implements JSONHoverAction<Material> {
/** /**
@ -164,7 +166,7 @@ public interface JSONHoverAction<T> {
* *
* @param value (JSON) - the value associated with this JSONHoverAction * @param value (JSON) - the value associated with this JSONHoverAction
*/ */
public ShowItem(Material value) { public ShowItem(final Material value) {
this.value = value; this.value = value;
@ -176,7 +178,7 @@ public interface JSONHoverAction<T> {
} }
@Override @Override
public JSONHoverAction<Material> setValue(Material newValue) { public JSONHoverAction<Material> setValue(final Material newValue) {
value = newValue; value = newValue;
return this; return this;
} }
@ -213,18 +215,18 @@ public interface JSONHoverAction<T> {
* *
* @param value (JSON) - the value associated with this JSONHoverAction * @param value (JSON) - the value associated with this JSONHoverAction
*/ */
public ShowItemStack(ItemStack value) { public ShowItemStack(final ItemStack value) {
this.value = value; this.value = value;
} }
public static String toTitleCase(String givenString) { public static String toTitleCase(final String givenString) {
if (givenString == null || "".equals(givenString)) { if (givenString == null || "".equals(givenString)) {
return ""; return "";
} }
String[] arr = givenString.split(" "); final String[] arr = givenString.split(" ");
StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
sb.append(Character.toUpperCase(arr[i].charAt(0))) sb.append(Character.toUpperCase(arr[i].charAt(0)))
@ -239,25 +241,25 @@ public interface JSONHoverAction<T> {
} }
@Override @Override
public JSONHoverAction<ItemStack> setValue(ItemStack newValue) { public JSONHoverAction<ItemStack> setValue(final ItemStack newValue) {
value = newValue; value = newValue;
return this; return this;
} }
@Override @Override
public String getValueString() { public String getValueString() {
String material = value.getData().getItemType().toString().toLowerCase(); final String material = value.getData().getItemType().toString().toLowerCase();
String value2 = "{id:\\\"minecraft:" + material + "\\\",Damage:" + value.getDurability() + ",Count:" + value.getAmount() + ",tag:{"; String value2 = "{id:\\\"minecraft:" + material + "\\\",Damage:" + value.getDurability() + ",Count:" + value.getAmount() + ",tag:{";
if (value.getItemMeta().hasEnchants()) { if (value.getItemMeta().hasEnchants()) {
value2 += "ench:["; value2 += "Enchantments:[";
int i = 0; int i = 0;
int size = value.getItemMeta().getEnchants().keySet().size(); final int size = value.getItemMeta().getEnchants().keySet().size();
for (Enchantment ench : value.getItemMeta().getEnchants().keySet()) { for (final Enchantment ench : value.getItemMeta().getEnchants().keySet()) {
if (i + 1 == size) { if (i + 1 == size) {
value2 += "{lvl:" + value.getItemMeta().getEnchants().get(ench) + "s,id:" + ench.getKey() + "s}"; value2 += "{lvl:" + value.getItemMeta().getEnchants().get(ench) + ",id:\\\"" + ench.getKey() + "\\\"}";
} else { } else {
value2 += "{lvl:" + value.getItemMeta().getEnchants().get(ench) + "s,id:" + ench.getKey() + "s},"; value2 += "{lvl:" + value.getItemMeta().getEnchants().get(ench) + ",id:\\\"" + ench.getKey() + "\\\"},";
} }
i++; i++;
} }
@ -274,7 +276,7 @@ public interface JSONHoverAction<T> {
if (value.getItemMeta().hasLore()) { if (value.getItemMeta().hasLore()) {
value2 += ",Lore:["; value2 += ",Lore:[";
for (String lore : value.getItemMeta().getLore()) { for (final String lore : value.getItemMeta().getLore()) {
value2 = value2 + (value.getItemMeta().getLore().size() == 1 || value value2 = value2 + (value.getItemMeta().getLore().size() == 1 || value
.getItemMeta() .getItemMeta()
.getLore() .getLore()

View File

@ -25,7 +25,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.mcstats.MetricsLite; import org.mcstats.MetricsLite;
import com.coloredcarrot.mcapi.json.JSON;
import cz.boosik.boosCooldown.Listeners.BoosEntityDamageListener; import cz.boosik.boosCooldown.Listeners.BoosEntityDamageListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerDeathListener; import cz.boosik.boosCooldown.Listeners.BoosPlayerDeathListener;
import cz.boosik.boosCooldown.Listeners.BoosPlayerGameModeChangeListener; import cz.boosik.boosCooldown.Listeners.BoosPlayerGameModeChangeListener;
@ -40,7 +39,6 @@ import cz.boosik.boosCooldown.Managers.BoosLimitManager;
import cz.boosik.boosCooldown.Runnables.BoosGlobalLimitResetRunnable; import cz.boosik.boosCooldown.Runnables.BoosGlobalLimitResetRunnable;
import net.milkbowl.vault.Vault; import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import nms.NMSSetupResponse;
import util.BoosChat; import util.BoosChat;
public class BoosCoolDown extends JavaPlugin implements Runnable { public class BoosCoolDown extends JavaPlugin implements Runnable {
@ -52,7 +50,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
private static boolean usingVault = false; private static boolean usingVault = false;
private PluginManager pm; private PluginManager pm;
public static void commandLogger(String player, String command) { public static void commandLogger(final String player, final String command) {
log.info("[" + "boosLogger" + "] " + player + " used command " + command); log.info("[" + "boosLogger" + "] " + player + " used command " + command);
} }
@ -68,26 +66,26 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
return log; return log;
} }
static boolean isPluginOnForPlayer(Player player) { static boolean isPluginOnForPlayer(final Player player) {
boolean on; final boolean on;
on = !player.hasPermission("booscooldowns.exception") && !player.isOp(); on = !player.hasPermission("booscooldowns.exception") && !player.isOp();
return on; return on;
} }
private static void startLimitResetTimersGlobal() { private static void startLimitResetTimersGlobal() {
YamlConfiguration confusers = BoosConfigManager.getConfusers(); final YamlConfiguration confusers = BoosConfigManager.getConfusers();
ConfigurationSection global = confusers.getConfigurationSection("global"); final ConfigurationSection global = confusers.getConfigurationSection("global");
if (global != null) { if (global != null) {
Set<String> globalKeys = global.getKeys(false); final Set<String> globalKeys = global.getKeys(false);
BukkitScheduler scheduler = Bukkit.getScheduler(); final BukkitScheduler scheduler = Bukkit.getScheduler();
for (String key : globalKeys) { for (final String key : globalKeys) {
String confTime = confusers.getString("global." + key + ".reset"); final String confTime = confusers.getString("global." + key + ".reset");
long limitResetDelay = BoosConfigManager.getLimitResetDelayGlobal(key); final long limitResetDelay = BoosConfigManager.getLimitResetDelayGlobal(key);
Date endDate = getTime(confTime); final Date endDate = getTime(confTime);
Date startDate = getCurrTime(); final Date startDate = getCurrTime();
Calendar calcurrTime = Calendar.getInstance(); final Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(startDate); calcurrTime.setTime(startDate);
Calendar callastTime = Calendar.getInstance(); final Calendar callastTime = Calendar.getInstance();
callastTime.setTime(endDate); callastTime.setTime(endDate);
long time = secondsBetween(calcurrTime, callastTime, limitResetDelay); long time = secondsBetween(calcurrTime, callastTime, limitResetDelay);
if (limitResetDelay != -65535) { if (limitResetDelay != -65535) {
@ -105,16 +103,16 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} }
} }
public static void startLimitResetTimerGlobal(String key) { public static void startLimitResetTimerGlobal(final String key) {
YamlConfiguration confusers = BoosConfigManager.getConfusers(); final YamlConfiguration confusers = BoosConfigManager.getConfusers();
BukkitScheduler scheduler = Bukkit.getScheduler(); final BukkitScheduler scheduler = Bukkit.getScheduler();
String confTime = confusers.getString("global." + key + ".reset"); final String confTime = confusers.getString("global." + key + ".reset");
long limitResetDelay = BoosConfigManager.getLimitResetDelayGlobal(key); final long limitResetDelay = BoosConfigManager.getLimitResetDelayGlobal(key);
Date endDate = getTime(confTime); final Date endDate = getTime(confTime);
Date startDate = getCurrTime(); final Date startDate = getCurrTime();
Calendar calcurrTime = Calendar.getInstance(); final Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(startDate); calcurrTime.setTime(startDate);
Calendar callastTime = Calendar.getInstance(); final Calendar callastTime = Calendar.getInstance();
callastTime.setTime(endDate); callastTime.setTime(endDate);
long time = secondsBetween(calcurrTime, callastTime, limitResetDelay); long time = secondsBetween(calcurrTime, callastTime, limitResetDelay);
if (limitResetDelay != -65535) { if (limitResetDelay != -65535) {
@ -130,7 +128,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} }
} }
private static long secondsBetween(Calendar startDate, Calendar endDate, long limitResetDelay) { private static long secondsBetween(final Calendar startDate, final Calendar endDate, final long limitResetDelay) {
long secondsBetween = 0; long secondsBetween = 0;
secondsBetween = ((endDate.getTimeInMillis() - startDate.getTimeInMillis()) / 1000) + limitResetDelay; secondsBetween = ((endDate.getTimeInMillis() - startDate.getTimeInMillis()) / 1000) + limitResetDelay;
return secondsBetween; return secondsBetween;
@ -138,27 +136,27 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
private static Date getCurrTime() { private static Date getCurrTime() {
String currTime = ""; String currTime = "";
Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime()); currTime = sdf.format(cal.getTime());
Date time; final Date time;
try { try {
time = sdf.parse(currTime); time = sdf.parse(currTime);
return time; return time;
} catch (ParseException e) { } catch (final ParseException e) {
return null; return null;
} }
} }
private static Date getTime(String confTime) { private static Date getTime(final String confTime) {
if (confTime != null && !confTime.equals("")) { if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate; final Date lastDate;
try { try {
lastDate = sdf.parse(confTime); lastDate = sdf.parse(confTime);
return lastDate; return lastDate;
} catch (ParseException e) { } catch (final ParseException e) {
return null; return null;
} }
} }
@ -166,7 +164,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} }
private void initializeVault() { private void initializeVault() {
Plugin x = pm.getPlugin("Vault"); final Plugin x = pm.getPlugin("Vault");
if (x != null & x instanceof Vault) { if (x != null & x instanceof Vault) {
log.info("[" + pdfFile.getName() + "]" + " found [Vault] searching for economy plugin."); log.info("[" + pdfFile.getName() + "]" + " found [Vault] searching for economy plugin.");
usingVault = true; usingVault = true;
@ -181,10 +179,9 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} }
} }
@SuppressWarnings("deprecation")
@Override @Override
public boolean onCommand(CommandSender sender, Command c, String commandLabel, String[] args) { public boolean onCommand(final CommandSender sender, final Command c, final String commandLabel, final String[] args) {
String command = c.getName().toLowerCase(); final String command = c.getName().toLowerCase();
if (command.equalsIgnoreCase("booscooldowns")) { if (command.equalsIgnoreCase("booscooldowns")) {
if (args.length == 1) { if (args.length == 1) {
if (sender.hasPermission("booscooldowns.reload") && args[0].equalsIgnoreCase("reload")) { if (sender.hasPermission("booscooldowns.reload") && args[0].equalsIgnoreCase("reload")) {
@ -193,13 +190,13 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
return true; return true;
} else if (sender.hasPermission("booscooldowns.list.limits") && args[0].equalsIgnoreCase("limits")) { } else if (sender.hasPermission("booscooldowns.list.limits") && args[0].equalsIgnoreCase("limits")) {
try { try {
Player send = (Player) sender; final Player send = (Player) sender;
Set<String> commands = BoosConfigManager.getCommands(send); final Set<String> commands = BoosConfigManager.getCommands(send);
for (String comm : commands) { for (final String comm : commands) {
int lim = BoosConfigManager.getLimit(comm, send); final int lim = BoosConfigManager.getLimit(comm, send);
BoosLimitManager.getLimitListMessages(send, comm, lim); BoosLimitManager.getLimitListMessages(send, comm, lim);
} }
} catch (ClassCastException e) { } catch (final ClassCastException e) {
log.warning("You cannot use this command from console!"); log.warning("You cannot use this command from console!");
} }
return true; return true;
@ -212,49 +209,49 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
return true; return true;
} }
} else if (args.length == 2) { } else if (args.length == 2) {
String jmeno = args[1]; final String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno); final Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
if (args[0].equalsIgnoreCase("chat")) { if (args[0].equalsIgnoreCase("chat")) {
player.chat(args[1]); player.chat(args[1]);
} else if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) { } else if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown"; final String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid); BoosConfigManager.clearSomething(co, uuid);
BoosChat.sendMessageToCommandSender(sender, BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " cooldowns of player " + jmeno + " cleared"); "&6[" + pdfFile.getName() + "]&e" + " cooldowns of player " + jmeno + " cleared");
return true; return true;
} else if (sender.hasPermission("booscooldowns.clearuses") && command.equalsIgnoreCase("booscooldowns") && args[0].equalsIgnoreCase( } else if (sender.hasPermission("booscooldowns.clearuses") && command.equalsIgnoreCase("booscooldowns") && args[0].equalsIgnoreCase(
"clearuses")) { "clearuses")) {
String co = "uses"; final String co = "uses";
BoosConfigManager.clearSomething(co, uuid); BoosConfigManager.clearSomething(co, uuid);
BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " uses of player " + jmeno + " cleared"); BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " uses of player " + jmeno + " cleared");
return true; return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups") && command.equalsIgnoreCase("booscooldowns") } else if (sender.hasPermission("booscooldowns.clearwarmups") && command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearwarmups")) { && args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup"; final String co = "warmup";
BoosConfigManager.clearSomething(co, uuid); BoosConfigManager.clearSomething(co, uuid);
BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " warmups of player " + jmeno + " cleared"); BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " warmups of player " + jmeno + " cleared");
return true; return true;
} }
} else if (args.length == 3) { } else if (args.length == 3) {
String jmeno = args[1]; final String jmeno = args[1];
Player player = Bukkit.getPlayerExact(jmeno); final Player player = Bukkit.getPlayerExact(jmeno);
UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
String command2 = args[2].trim(); final String command2 = args[2].trim();
if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) { if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown"; final String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid, command2); BoosConfigManager.clearSomething(co, uuid, command2);
BoosChat.sendMessageToCommandSender(sender, BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " cooldown for command " + command2 + " of player " + uuid + " cleared"); "&6[" + pdfFile.getName() + "]&e" + " cooldown for command " + command2 + " of player " + uuid + " cleared");
return true; return true;
} else if (sender.hasPermission("booscooldowns.clearuses") && args[0].equalsIgnoreCase("clearuses")) { } else if (sender.hasPermission("booscooldowns.clearuses") && args[0].equalsIgnoreCase("clearuses")) {
String co = "uses"; final String co = "uses";
BoosConfigManager.clearSomething(co, uuid, command2); BoosConfigManager.clearSomething(co, uuid, command2);
BoosChat.sendMessageToCommandSender(sender, BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " uses for command " + command2 + " of player " + jmeno + " cleared"); "&6[" + pdfFile.getName() + "]&e" + " uses for command " + command2 + " of player " + jmeno + " cleared");
return true; return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups") && args[0].equalsIgnoreCase("clearwarmups")) { } else if (sender.hasPermission("booscooldowns.clearwarmups") && args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup"; final String co = "warmup";
BoosConfigManager.clearSomething(co, uuid, command2); BoosConfigManager.clearSomething(co, uuid, command2);
BoosChat.sendMessageToCommandSender(sender, BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " warmups for command " + command2 + " of player " + jmeno + " cleared"); "&6[" + pdfFile.getName() + "]&e" + " warmups for command " + command2 + " of player " + jmeno + " cleared");
@ -263,10 +260,10 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} }
} else if (args.length == 4) { } else if (args.length == 4) {
if (sender.hasPermission("booscooldowns.set") && args[0].equalsIgnoreCase("set")) { if (sender.hasPermission("booscooldowns.set") && args[0].equalsIgnoreCase("set")) {
String what = args[1]; final String what = args[1];
String comm = args[2]; String comm = args[2];
String value = args[3]; final String value = args[3];
String group = "default"; final String group = "default";
if (comm.startsWith("/") || comm.equals("*")) { if (comm.startsWith("/") || comm.equals("*")) {
if (comm.contains("_")) { if (comm.contains("_")) {
comm = comm.replace("_", " "); comm = comm.replace("_", " ");
@ -283,10 +280,10 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} else if (args.length == 5) { } else if (args.length == 5) {
if (sender.hasPermission("booscooldowns.set") && args[0].equalsIgnoreCase("set")) { if (sender.hasPermission("booscooldowns.set") && args[0].equalsIgnoreCase("set")) {
String what = args[1]; final String what = args[1];
String comm = args[2]; String comm = args[2];
String value = args[3]; final String value = args[3];
String group = args[4]; final String group = args[4];
if (comm.startsWith("/") || comm.equals("*")) { if (comm.startsWith("/") || comm.equals("*")) {
if (comm.contains("_")) { if (comm.contains("_")) {
comm = comm.replace("_", " "); comm = comm.replace("_", " ");
@ -302,9 +299,9 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} }
} else { } else {
// BoosChat.sendMessageToCommandSender(sender, BoosChat.sendMessageToCommandSender(sender,
// "&6[" + pdfFile.getName() + "]&e" "&6[" + pdfFile.getName() + "]&e"
// + " Invalid command or access denied!"); + " Invalid command or access denied!");
return false; return false;
} }
} }
@ -327,7 +324,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
@Override @Override
public void onEnable() { public void onEnable() {
pdfFile = this.getDescription(); pdfFile = this.getDescription();
PluginDescriptionFile pdfFile = this.getDescription(); final PluginDescriptionFile pdfFile = this.getDescription();
log.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " by " + pdfFile.getAuthors() + " is enabled!"); log.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " by " + pdfFile.getAuthors() + " is enabled!");
this.saveDefaultConfig(); this.saveDefaultConfig();
new BoosConfigManager(this); new BoosConfigManager(this);
@ -337,7 +334,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
registerListeners(); registerListeners();
initializeVault(); initializeVault();
hookPlayerPoints(); hookPlayerPoints();
BukkitScheduler scheduler = this.getServer().getScheduler(); final BukkitScheduler scheduler = this.getServer().getScheduler();
startLimitResetTimersGlobal(); startLimitResetTimersGlobal();
if (BoosConfigManager.getAutoSave()) { if (BoosConfigManager.getAutoSave()) {
scheduler.scheduleSyncRepeatingTask(this, scheduler.scheduleSyncRepeatingTask(this,
@ -350,22 +347,11 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
BoosConfigManager.clear(); BoosConfigManager.clear();
} }
try { try {
MetricsLite metrics = new MetricsLite(this); final MetricsLite metrics = new MetricsLite(this);
metrics.start(); metrics.start();
} catch (IOException e) { } catch (final IOException e) {
// Failed to submit the stats :-( // Failed to submit the stats :-(
} }
NMSSetupResponse nmsSetupResponse = JSON.setup(this);
if (nmsSetupResponse.isCompatible()) {
getLogger().info("[" + pdfFile.getName() + "]" + " Hooked server version " + nmsSetupResponse.getVersion());
} else {
getLogger().warning("[" + pdfFile.getName() + "]" + " Your server version (" + (nmsSetupResponse.getVersion() == null ? "UNKNOWN" : nmsSetupResponse
.getVersion()) + ") is not compatible with this plugin!");
getServer().getPluginManager().disablePlugin(this);
return;
}
} }
private void registerListeners() { private void registerListeners() {
@ -412,7 +398,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
private boolean setupEconomy() { private boolean setupEconomy() {
if (usingVault) { if (usingVault) {
RegisteredServiceProvider<Economy> economyProvider = getServer() final RegisteredServiceProvider<Economy> economyProvider = getServer()
.getServicesManager() .getServicesManager()
.getRegistration(net.milkbowl.vault.economy.Economy.class); .getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) { if (economyProvider != null) {
@ -425,9 +411,9 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
private boolean hookPlayerPoints() { private boolean hookPlayerPoints() {
if (BoosConfigManager.getPlayerPointsEnabled()) { if (BoosConfigManager.getPlayerPointsEnabled()) {
Plugin x = pm.getPlugin("PlayerPoints"); final Plugin x = pm.getPlugin("PlayerPoints");
if (x != null && x instanceof PlayerPoints) { if (x != null && x instanceof PlayerPoints) {
RegisteredServiceProvider<PlayerPoints> playerPointsProvider = getServer() final RegisteredServiceProvider<PlayerPoints> playerPointsProvider = getServer()
.getServicesManager() .getServicesManager()
.getRegistration(org.black_ixx.playerpoints.PlayerPoints.class); .getRegistration(org.black_ixx.playerpoints.PlayerPoints.class);
if (playerPointsProvider != null) { if (playerPointsProvider != null) {

View File

@ -39,20 +39,21 @@ public class BoosCoolDownListener implements Listener {
public static Map<String, Boolean> commandQueue = new ConcurrentHashMap<>(); public static Map<String, Boolean> commandQueue = new ConcurrentHashMap<>();
private static BoosCoolDown plugin; private static BoosCoolDown plugin;
BoosCoolDownListener(BoosCoolDown instance) { BoosCoolDownListener(final BoosCoolDown instance) {
plugin = instance; plugin = instance;
} }
private void checkRestrictions(PlayerCommandPreprocessEvent event, private void checkRestrictions(
Player player, String regexCommad, String originalCommand, final PlayerCommandPreprocessEvent event,
int warmupTime, int cooldownTime, double price, String item, final Player player, final String regexCommad, final String originalCommand,
int count, String name, List<String> lore, List<String> enchants, int limit, int xpPrice, final int warmupTime, final int cooldownTime, final double price, final String item,
int xpRequirement, int playerPoints) { final int count, final String name, final List<String> lore, final List<String> enchants, final int limit, final int xpPrice,
final int xpRequirement, final int playerPoints) {
boolean blocked = false; boolean blocked = false;
String perm = BoosConfigManager.getPermission(player, regexCommad); final String perm = BoosConfigManager.getPermission(player, regexCommad);
if (!(perm == null)) { if (!(perm == null)) {
if (!player.hasPermission(perm)) { if (!player.hasPermission(perm)) {
String msg = BoosConfigManager.getPermissionMessage(player, regexCommad); final String msg = BoosConfigManager.getPermissionMessage(player, regexCommad);
if (!(msg == null)) { if (!(msg == null)) {
BoosChat.sendMessageToPlayer(player, msg); BoosChat.sendMessageToPlayer(player, msg);
} }
@ -103,8 +104,8 @@ public class BoosCoolDownListener implements Listener {
regexCommad, originalCommand, playerPoints); regexCommad, originalCommand, playerPoints);
} }
} else { } else {
boolean warmupInProgress = BoosWarmUpManager.isWarmUpProcess(player, regexCommad); final boolean warmupInProgress = BoosWarmUpManager.isWarmUpProcess(player, regexCommad);
boolean cooldownInProgress = BoosCoolDownManager.isCoolingdown(player, regexCommad, cooldownTime); final boolean cooldownInProgress = BoosCoolDownManager.isCoolingdown(player, regexCommad, cooldownTime);
if (!BoosPriceManager.has(player, price) if (!BoosPriceManager.has(player, price)
&& !warmupInProgress && !cooldownInProgress) { && !warmupInProgress && !cooldownInProgress) {
String msg; String msg;
@ -121,7 +122,7 @@ public class BoosCoolDownListener implements Listener {
&& !warmupInProgress && !cooldownInProgress) { && !warmupInProgress && !cooldownInProgress) {
String msg; String msg;
msg = BoosConfigManager.getInsufficientItemsMessage(); msg = BoosConfigManager.getInsufficientItemsMessage();
JSON json = getItemStackJson(1, item, count, name, lore, enchants); final JSON json = getItemStackJson(1, item, count, name, lore, enchants);
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
BoosChat.sendMessageToPlayer(player, msg); BoosChat.sendMessageToPlayer(player, msg);
json.send(player); json.send(player);
@ -156,7 +157,7 @@ public class BoosCoolDownListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
if (!event.isCancelled()) { if (!event.isCancelled()) {
String msg = BoosConfigManager.getMessage( final String msg = BoosConfigManager.getMessage(
regexCommad, player); regexCommad, player);
if (!msg.equals("")) { if (!msg.equals("")) {
BoosChat.sendMessageToPlayer(player, msg); BoosChat.sendMessageToPlayer(player, msg);
@ -166,13 +167,13 @@ public class BoosCoolDownListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
if (!event.isCancelled()) { if (!event.isCancelled()) {
List<String> linkGroup = BoosConfigManager.getSharedLimits( final List<String> linkGroup = BoosConfigManager.getSharedLimits(
regexCommad, player); regexCommad, player);
if (linkGroup.isEmpty()) { if (linkGroup.isEmpty()) {
BoosLimitManager.setUses(player, regexCommad); BoosLimitManager.setUses(player, regexCommad);
} else { } else {
BoosLimitManager.setUses(player, regexCommad); BoosLimitManager.setUses(player, regexCommad);
for (String a : linkGroup) { for (final String a : linkGroup) {
BoosLimitManager.setUses(player, a); BoosLimitManager.setUses(player, a);
} }
} }
@ -180,7 +181,7 @@ public class BoosCoolDownListener implements Listener {
BoosCoolDown.commandLogger(player.getName(), originalCommand); BoosCoolDown.commandLogger(player.getName(), originalCommand);
} }
} }
for (String key : commandQueue.keySet()) { for (final String key : commandQueue.keySet()) {
if (key.startsWith(String.valueOf(player.getUniqueId()))) { if (key.startsWith(String.valueOf(player.getUniqueId()))) {
commandQueue.remove(key); commandQueue.remove(key);
} }
@ -188,13 +189,13 @@ public class BoosCoolDownListener implements Listener {
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { private void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer(); final Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
if (BoosConfigManager.getSyntaxBlocker() && !player.isOp() && !player.hasPermission("booscooldowns.syntaxblockerexception")) { if (BoosConfigManager.getSyntaxBlocker() && !player.isOp() && !player.hasPermission("booscooldowns.syntaxblockerexception")) {
if (event.getMessage().contains(":")) { if (event.getMessage().contains(":")) {
Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):"); final Pattern p = Pattern.compile("^/([a-zA-Z0-9_]+):");
Matcher m = p.matcher(event.getMessage()); final Matcher m = p.matcher(event.getMessage());
if (m.find()) { if (m.find()) {
{ {
BoosChat.sendMessageToPlayer(player, BoosConfigManager BoosChat.sendMessageToPlayer(player, BoosConfigManager
@ -206,8 +207,8 @@ public class BoosCoolDownListener implements Listener {
} }
} }
if (BoosConfigManager.getConfirmCommandEnabled(player)) { if (BoosConfigManager.getConfirmCommandEnabled(player)) {
for (String key : commandQueue.keySet()) { for (final String key : commandQueue.keySet()) {
String[] keyList = key.split("@"); final String[] keyList = key.split("@");
if (keyList[0].equals(String.valueOf(uuid))) { if (keyList[0].equals(String.valueOf(uuid))) {
if (!keyList[1].equals(event.getMessage())) { if (!keyList[1].equals(event.getMessage())) {
commandQueue.remove(key); commandQueue.remove(key);
@ -225,9 +226,9 @@ public class BoosCoolDownListener implements Listener {
originalCommand = originalCommand.replace("$", "SdollarS"); originalCommand = originalCommand.replace("$", "SdollarS");
originalCommand = originalCommand.trim().replaceAll(" +", " "); originalCommand = originalCommand.trim().replaceAll(" +", " ");
String regexCommad = ""; String regexCommad = "";
Set<String> aliases = BoosConfigManager.getAliases(); final Set<String> aliases = BoosConfigManager.getAliases();
Set<String> commands = BoosConfigManager.getCommands(player); final Set<String> commands = BoosConfigManager.getCommands(player);
boolean on; final boolean on;
String item = ""; String item = "";
String name = ""; String name = "";
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
@ -247,8 +248,8 @@ public class BoosCoolDownListener implements Listener {
event.setMessage(originalCommand); event.setMessage(originalCommand);
} }
if (on && commands != null) { if (on && commands != null) {
for (String group : commands) { for (final String group : commands) {
String group2 = group.replace("*", ".*"); final String group2 = group.replace("*", ".*");
if (originalCommand.matches("(?i)" + group2)) { if (originalCommand.matches("(?i)" + group2)) {
regexCommad = group; regexCommad = group;
if (BoosConfigManager.getWarmupEnabled()) { if (BoosConfigManager.getWarmupEnabled()) {
@ -290,8 +291,7 @@ public class BoosCoolDownListener implements Listener {
} }
} }
if (!BoosConfigManager.getConfirmCommandEnabled(player) || (commandQueue if (!BoosConfigManager.getConfirmCommandEnabled(player) || (commandQueue
.keySet() .containsKey(uuid + "@" + originalCommand) && commandQueue.get(uuid + "@" + originalCommand))) {
.contains(uuid + "@" + originalCommand) && commandQueue.get(uuid + "@" + originalCommand))) {
this.checkRestrictions(event, player, regexCommad, originalCommand, this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, name, lore, enchants, limit, warmupTime, cooldownTime, price, item, count, name, lore, enchants, limit,
xpPrice, xpRequirement, playerPoints); xpPrice, xpRequirement, playerPoints);
@ -333,30 +333,30 @@ public class BoosCoolDownListener implements Listener {
if (count > 0) { if (count > 0) {
String itemMessage = BoosConfigManager.getItsItemCostMessage(); String itemMessage = BoosConfigManager.getItsItemCostMessage();
itemMessage = itemMessage.replace("&itemprice&", "").replace("&itemname&", ""); itemMessage = itemMessage.replace("&itemprice&", "").replace("&itemname&", "");
JSON json = getItemStackJson(2, item, count, name, lore, enchants); final JSON json = getItemStackJson(2, item, count, name, lore, enchants);
BoosChat.sendMessageToPlayer(player, " " + itemMessage); BoosChat.sendMessageToPlayer(player, " " + itemMessage);
json.send(player); json.send(player);
} }
if (limit > 0) { if (limit > 0) {
int uses = BoosLimitManager.getUses(player, regexCommad); final int uses = BoosLimitManager.getUses(player, regexCommad);
String limitMessage = BoosConfigManager.getItsLimitMessage(); String limitMessage = BoosConfigManager.getItsLimitMessage();
limitMessage = limitMessage.replace("&limit&", String.valueOf(limit)) limitMessage = limitMessage.replace("&limit&", String.valueOf(limit))
.replace("&uses&", String.valueOf(limit - uses)); .replace("&uses&", String.valueOf(limit - uses));
BoosChat.sendMessageToPlayer(player, " " + limitMessage); BoosChat.sendMessageToPlayer(player, " " + limitMessage);
} }
String yesString = BoosConfigManager.getConfirmCommandMessage(); final String yesString = BoosConfigManager.getConfirmCommandMessage();
JSONClickAction yesClick = new JSONClickAction.RunCommand(yesString); final JSONClickAction yesClick = new JSONClickAction.RunCommand(yesString);
JSONHoverAction yesHover = new JSONHoverAction.ShowStringText(BoosConfigManager.getConfirmCommandHint()); final JSONHoverAction yesHover = new JSONHoverAction.ShowStringText(BoosConfigManager.getConfirmCommandHint());
JSONComponent yes = new JSONComponent(" " + yesString); final JSONComponent yes = new JSONComponent(" " + yesString);
yes.setColor(JSONColor.GREEN).setBold(true); yes.setColor(JSONColor.GREEN).setBold(true);
yes.setClickAction(yesClick); yes.setClickAction(yesClick);
yes.setHoverAction(yesHover); yes.setHoverAction(yesHover);
yes.send(player); yes.send(player);
String noString = BoosConfigManager.getCancelCommandMessage(); final String noString = BoosConfigManager.getCancelCommandMessage();
JSONClickAction noClick = new JSONClickAction.RunCommand(noString); final JSONClickAction noClick = new JSONClickAction.RunCommand(noString);
JSONHoverAction noHover = new JSONHoverAction.ShowStringText(BoosConfigManager.getCancelCommandHint()); final JSONHoverAction noHover = new JSONHoverAction.ShowStringText(BoosConfigManager.getCancelCommandHint());
JSONComponent no = new JSONComponent(" " + noString); final JSONComponent no = new JSONComponent(" " + noString);
no.setColor(JSONColor.RED).setBold(true); no.setColor(JSONColor.RED).setBold(true);
no.setClickAction(noClick); no.setClickAction(noClick);
no.setHoverAction(noHover); no.setHoverAction(noHover);
@ -376,11 +376,11 @@ public class BoosCoolDownListener implements Listener {
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
private void onPlayerChatEvent(AsyncPlayerChatEvent event) { private void onPlayerChatEvent(final AsyncPlayerChatEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
if (BoosConfigManager.getConfirmCommandEnabled(player)) { if (BoosConfigManager.getConfirmCommandEnabled(player)) {
for (String key : commandQueue.keySet()) { for (final String key : commandQueue.keySet()) {
final String[] keyList = key.split("@"); final String[] keyList = key.split("@");
if (keyList[0].equals(String.valueOf(uuid))) { if (keyList[0].equals(String.valueOf(uuid))) {
if (event.getMessage().equalsIgnoreCase(BoosConfigManager.getConfirmCommandMessage())) { if (event.getMessage().equalsIgnoreCase(BoosConfigManager.getConfirmCommandMessage())) {
@ -404,9 +404,10 @@ public class BoosCoolDownListener implements Listener {
} }
} }
private void start(PlayerCommandPreprocessEvent event, Player player, private void start(
String regexCommad, String originalCommand, int warmupTime, final PlayerCommandPreprocessEvent event, final Player player,
int cooldownTime) { final String regexCommad, final String originalCommand, final int warmupTime,
final int cooldownTime) {
if (!BoosWarmUpManager.checkWarmUpOK(player, regexCommad)) { if (!BoosWarmUpManager.checkWarmUpOK(player, regexCommad)) {
if (BoosCoolDownManager.checkCoolDownOK(player, regexCommad, if (BoosCoolDownManager.checkCoolDownOK(player, regexCommad,
originalCommand, cooldownTime)) { originalCommand, cooldownTime)) {

View File

@ -14,10 +14,10 @@ import util.BoosChat;
public class BoosEntityDamageListener implements Listener { public class BoosEntityDamageListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onEntityDamage(EntityDamageEvent event) { private void onEntityDamage(final EntityDamageEvent event) {
Entity entity = event.getEntity(); final Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) { if (entity != null && entity instanceof Player) {
Player player = (Player) entity; final Player player = (Player) entity;
if (!player.hasPermission("booscooldowns.nocancel.damage")) { if (!player.hasPermission("booscooldowns.nocancel.damage")) {
if (BoosWarmUpManager.hasWarmUps(player)) { if (BoosWarmUpManager.hasWarmUps(player)) {
BoosChat.sendMessageToPlayer(player, BoosConfigManager BoosChat.sendMessageToPlayer(player, BoosConfigManager

View File

@ -13,17 +13,17 @@ import cz.boosik.boosCooldown.Managers.BoosCoolDownManager;
public class BoosPlayerDeathListener implements Listener { public class BoosPlayerDeathListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) { private void onPlayerDeath(final PlayerDeathEvent event) {
Entity entity = event.getEntity(); final Entity entity = event.getEntity();
if (entity != null) { if (entity != null) {
Player player = (Player) entity; final Player player = (Player) entity;
clearCooldownsOnDeath(player); clearCooldownsOnDeath(player);
clearUsesOnDeath(player); clearUsesOnDeath(player);
startCooldownsOnDeath(player); startCooldownsOnDeath(player);
} }
} }
private void startCooldownsOnDeath(Player player) { private void startCooldownsOnDeath(final Player player) {
if (player != null) { if (player != null) {
if (BoosConfigManager.getStartCooldownsOnDeath()) { if (BoosConfigManager.getStartCooldownsOnDeath()) {
BoosCoolDownManager.startAllCooldowns(player, ""); BoosCoolDownManager.startAllCooldowns(player, "");
@ -31,7 +31,7 @@ public class BoosPlayerDeathListener implements Listener {
} }
} }
private void clearUsesOnDeath(Player player) { private void clearUsesOnDeath(final Player player) {
if (player != null if (player != null
&& player.hasPermission("booscooldowns.clear.uses.death")) { && player.hasPermission("booscooldowns.clear.uses.death")) {
if (BoosConfigManager.getCleanUsesOnDeath()) { if (BoosConfigManager.getCleanUsesOnDeath()) {
@ -40,7 +40,7 @@ public class BoosPlayerDeathListener implements Listener {
} }
} }
private void clearCooldownsOnDeath(Player player) { private void clearCooldownsOnDeath(final Player player) {
if (player != null if (player != null
&& player.hasPermission("booscooldowns.clear.cooldowns.death")) { && player.hasPermission("booscooldowns.clear.cooldowns.death")) {
if (BoosConfigManager.getCleanCooldownsOnDeath()) { if (BoosConfigManager.getCleanCooldownsOnDeath()) {

View File

@ -14,10 +14,10 @@ import util.BoosChat;
public class BoosPlayerGameModeChangeListener implements Listener { public class BoosPlayerGameModeChangeListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerGameModeChange(PlayerGameModeChangeEvent event) { private void onPlayerGameModeChange(final PlayerGameModeChangeEvent event) {
Entity entity = event.getPlayer(); final Entity entity = event.getPlayer();
if (entity != null) { if (entity != null) {
Player player = (Player) entity; final Player player = (Player) entity;
if (!player if (!player
.hasPermission("booscooldowns.nocancel.gamemodechange")) { .hasPermission("booscooldowns.nocancel.gamemodechange")) {
if (BoosWarmUpManager.hasWarmUps(player)) { if (BoosWarmUpManager.hasWarmUps(player)) {

View File

@ -14,10 +14,10 @@ import util.BoosChat;
public class BoosPlayerInteractListener implements Listener { public class BoosPlayerInteractListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerInteract(PlayerInteractEvent event) { private void onPlayerInteract(final PlayerInteractEvent event) {
Entity entity = event.getPlayer(); final Entity entity = event.getPlayer();
if (entity != null) { if (entity != null) {
Player player = (Player) entity; final Player player = (Player) entity;
if (!player if (!player
.hasPermission("booscooldowns.dontblock.interact")) { .hasPermission("booscooldowns.dontblock.interact")) {
if (BoosWarmUpManager.hasWarmUps(player)) { if (BoosWarmUpManager.hasWarmUps(player)) {

View File

@ -14,12 +14,12 @@ public class BoosPlayerMoveListener implements Listener {
private int tempTimer = 0; private int tempTimer = 0;
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerMove(PlayerMoveEvent event) { private void onPlayerMove(final PlayerMoveEvent event) {
if (tempTimer < 10) { if (tempTimer < 10) {
tempTimer = tempTimer + 1; tempTimer = tempTimer + 1;
} else { } else {
Player player = event.getPlayer(); final Player player = event.getPlayer();
if (player != null if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) { && !player.hasPermission("booscooldowns.nocancel.move")) {
if (BoosWarmUpManager.hasWarmUps(player) && (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event if (BoosWarmUpManager.hasWarmUps(player) && (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event

View File

@ -13,8 +13,8 @@ import util.BoosChat;
public class BoosPlayerToggleSneakListener implements Listener { public class BoosPlayerToggleSneakListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerToggleSneak(PlayerToggleSneakEvent event) { private void onPlayerToggleSneak(final PlayerToggleSneakEvent event) {
Player player = event.getPlayer(); final Player player = event.getPlayer();
if (player != null if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sneak")) { && !player.hasPermission("booscooldowns.nocancel.sneak")) {
if (BoosWarmUpManager.hasWarmUps(player)) { if (BoosWarmUpManager.hasWarmUps(player)) {

View File

@ -13,8 +13,8 @@ import util.BoosChat;
public class BoosPlayerToggleSprintListener implements Listener { public class BoosPlayerToggleSprintListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerToggleSprint(PlayerToggleSprintEvent event) { private void onPlayerToggleSprint(final PlayerToggleSprintEvent event) {
Player player = event.getPlayer(); final Player player = event.getPlayer();
if (player != null if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sprint")) { && !player.hasPermission("booscooldowns.nocancel.sprint")) {
if (BoosWarmUpManager.hasWarmUps(player)) { if (BoosWarmUpManager.hasWarmUps(player)) {

View File

@ -12,10 +12,10 @@ import util.BoosChat;
public class BoosSignChangeListener implements Listener { public class BoosSignChangeListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onSignChange(SignChangeEvent event) { private void onSignChange(final SignChangeEvent event) {
Player player = event.getPlayer(); final Player player = event.getPlayer();
String line1 = event.getLine(0); final String line1 = event.getLine(0);
String line2 = event.getLine(1); final String line2 = event.getLine(1);
if (line1.equals("[boosCooldowns]")) { if (line1.equals("[boosCooldowns]")) {
if (line2.equals("player") if (line2.equals("player")
&& !player && !player

View File

@ -16,12 +16,12 @@ import util.BoosChat;
public class BoosSignInteractListener implements Listener { public class BoosSignInteractListener implements Listener {
private final BoosCoolDown plugin; private final BoosCoolDown plugin;
public BoosSignInteractListener(BoosCoolDown instance) { public BoosSignInteractListener(final BoosCoolDown instance) {
plugin = instance; plugin = instance;
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onSignInteract(PlayerInteractEvent event) { private void onSignInteract(final PlayerInteractEvent event) {
String msg; String msg;
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
@ -49,12 +49,12 @@ public class BoosSignInteractListener implements Listener {
|| event.getClickedBlock().getType() == Material.BIRCH_SIGN || event.getClickedBlock().getType() == Material.BIRCH_SIGN
|| event.getClickedBlock().getType() == Material.BIRCH_WALL_SIGN) { || event.getClickedBlock().getType() == Material.BIRCH_WALL_SIGN) {
Sign s = (Sign) event.getClickedBlock().getState(); final Sign s = (Sign) event.getClickedBlock().getState();
String line1 = s.getLine(0); final String line1 = s.getLine(0);
String line2 = s.getLine(1); final String line2 = s.getLine(1);
String line3 = s.getLine(2); final String line3 = s.getLine(2);
String line4 = s.getLine(3); final String line4 = s.getLine(3);
Player player = event.getPlayer(); final Player player = event.getPlayer();
if (line1.equals("[boosCooldowns]")) { if (line1.equals("[boosCooldowns]")) {
if (line2.equals("player") if (line2.equals("player")
&& player && player

View File

@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
public class BoosAliasManager { public class BoosAliasManager {
public static String checkCommandAlias(String originalCommand, public static String checkCommandAlias(String originalCommand,
Set<String> aliases, Player player) { final Set<String> aliases, final Player player) {
String[] splitCommand = originalCommand.split(" ", 4); final String[] splitCommand = originalCommand.split(" ", 4);
String one = ""; String one = "";
String two = ""; String two = "";
String three = ""; String three = "";
@ -21,8 +21,8 @@ public class BoosAliasManager {
} }
} }
} }
for (String alias : aliases) { for (final String alias : aliases) {
String alias2 = alias.replace("*", ".+"); final String alias2 = alias.replace("*", ".+");
if (originalCommand.matches("(?i)" + alias2)) { if (originalCommand.matches("(?i)" + alias2)) {
originalCommand = BoosConfigManager.getAlias(alias); originalCommand = BoosConfigManager.getAlias(alias);
if (originalCommand.contains("$1")) { if (originalCommand.contains("$1")) {

View File

@ -25,7 +25,7 @@ public class BoosConfigManager {
private static File confusersFile; private static File confusersFile;
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public BoosConfigManager(BoosCoolDown boosCoolDown) { public BoosConfigManager(final BoosCoolDown boosCoolDown) {
confFile = new File(boosCoolDown.getDataFolder(), "config.yml"); confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
if (confFile.exists()) { if (confFile.exists()) {
conf = new YamlConfiguration(); conf = new YamlConfiguration();
@ -44,7 +44,7 @@ public class BoosConfigManager {
} else { } else {
try { try {
confusersFile.createNewFile(); confusersFile.createNewFile();
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Could not save storage file!"); BoosCoolDown.getLog().severe("[boosCooldowns] Could not save storage file!");
} }
@ -52,22 +52,22 @@ public class BoosConfigManager {
} }
public static void clear() { public static void clear() {
ConfigurationSection userSection = confusers.getConfigurationSection("users"); final ConfigurationSection userSection = confusers.getConfigurationSection("users");
if (userSection == null) { if (userSection == null) {
return; return;
} }
for (String user : userSection.getKeys(false)) { for (final String user : userSection.getKeys(false)) {
ConfigurationSection cooldown = confusers.getConfigurationSection("users." + user + ".cooldown"); final ConfigurationSection cooldown = confusers.getConfigurationSection("users." + user + ".cooldown");
if (cooldown != null) { if (cooldown != null) {
for (String key : cooldown.getKeys(false)) { for (final String key : cooldown.getKeys(false)) {
confusers.set("users." + user + ".cooldown." + key, null); confusers.set("users." + user + ".cooldown." + key, null);
} }
} }
confusers.set("users." + user + ".cooldown", null); confusers.set("users." + user + ".cooldown", null);
ConfigurationSection warmup = confusers.getConfigurationSection("users." + user + ".warmup"); final ConfigurationSection warmup = confusers.getConfigurationSection("users." + user + ".warmup");
if (warmup != null) { if (warmup != null) {
for (String key : warmup.getKeys(false)) { for (final String key : warmup.getKeys(false)) {
confusers.set("users." + user + ".warmup." + key, null); confusers.set("users." + user + ".warmup." + key, null);
} }
} }
@ -79,8 +79,8 @@ public class BoosConfigManager {
loadConfusers(); loadConfusers();
} }
public static void clearSomething(String co, UUID uuid) { public static void clearSomething(final String co, final UUID uuid) {
ConfigurationSection userSection = confusers.getConfigurationSection("users." + uuid + "." + co); final ConfigurationSection userSection = confusers.getConfigurationSection("users." + uuid + "." + co);
if (userSection == null) { if (userSection == null) {
return; return;
} }
@ -89,20 +89,20 @@ public class BoosConfigManager {
loadConfusers(); loadConfusers();
} }
public static void clearSomething(String co, UUID uuid, String command) { public static void clearSomething(final String co, final UUID uuid, final String command) {
int pre2 = command.toLowerCase().hashCode(); final int pre2 = command.toLowerCase().hashCode();
confusers.set("users." + uuid + "." + co + "." + pre2, 0); confusers.set("users." + uuid + "." + co + "." + pre2, 0);
saveConfusers(); saveConfusers();
loadConfusers(); loadConfusers();
} }
static String getAlias(String message) { static String getAlias(final String message) {
return conf.getString("commands.aliases." + message); return conf.getString("commands.aliases." + message);
} }
public static Set<String> getAliases() { public static Set<String> getAliases() {
Set<String> aliases = null; Set<String> aliases = null;
ConfigurationSection aliasesSection = conf.getConfigurationSection("commands.aliases"); final ConfigurationSection aliasesSection = conf.getConfigurationSection("commands.aliases");
if (aliasesSection != null) { if (aliasesSection != null) {
aliases = conf.getConfigurationSection("commands.aliases").getKeys(false); aliases = conf.getConfigurationSection("commands.aliases").getKeys(false);
} }
@ -166,15 +166,15 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.clear_on_restart", false); return conf.getBoolean("options.options.clear_on_restart", false);
} }
static String getCommandBlockedMessage() { public static String getCommandBlockedMessage() {
return conf.getString("options.messages.limit_achieved", "&6You cannot use this command anymore!&f"); return conf.getString("options.messages.limit_achieved", "&6You cannot use this command anymore!&f");
} }
private static String getCommandGroup(Player player) { private static String getCommandGroup(final Player player) {
String cmdGroup = "default"; String cmdGroup = "default";
Set<String> groups = getCommandGroups(); final Set<String> groups = getCommandGroups();
if (groups != null) { if (groups != null) {
for (String group : groups) { for (final String group : groups) {
if (player.hasPermission("booscooldowns." + group)) { if (player.hasPermission("booscooldowns." + group)) {
cmdGroup = group; cmdGroup = group;
} }
@ -184,7 +184,7 @@ public class BoosConfigManager {
} }
private static Set<String> getCommandGroups() { private static Set<String> getCommandGroups() {
ConfigurationSection groupsSection = conf.getConfigurationSection("commands.groups"); final ConfigurationSection groupsSection = conf.getConfigurationSection("commands.groups");
Set<String> groups = null; Set<String> groups = null;
if (groupsSection != null) { if (groupsSection != null) {
groups = groupsSection.getKeys(false); groups = groupsSection.getKeys(false);
@ -196,10 +196,10 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.command_logging", false); return conf.getBoolean("options.options.command_logging", false);
} }
public static Set<String> getCommands(Player player) { public static Set<String> getCommands(final Player player) {
String group = getCommandGroup(player); final String group = getCommandGroup(player);
Set<String> commands = null; Set<String> commands = null;
ConfigurationSection commandsSection = conf.getConfigurationSection("commands.groups." + group); final ConfigurationSection commandsSection = conf.getConfigurationSection("commands.groups." + group);
if (commandsSection != null) { if (commandsSection != null) {
commands = commandsSection.getKeys(false); commands = commandsSection.getKeys(false);
} }
@ -210,10 +210,10 @@ public class BoosConfigManager {
return confusers; return confusers;
} }
public static int getCoolDown(String regexCommand, Player player) { public static int getCoolDown(final String regexCommand, final Player player) {
int coolDown; final int coolDown;
String coolDownString = ""; String coolDownString = "";
String group = getCommandGroup(player); final String group = getCommandGroup(player);
coolDownString = conf.getString("commands.groups." + group + "." + regexCommand + ".cooldown", "0"); coolDownString = conf.getString("commands.groups." + group + "." + regexCommand + ".cooldown", "0");
coolDown = parseTime(coolDownString); coolDown = parseTime(coolDownString);
return coolDown; return coolDown;
@ -227,8 +227,8 @@ public class BoosConfigManager {
return conf.getString("options.messages.cooling_down", "&6Wait&e &seconds& seconds&6 before you can use command&e &command& &6again.&f"); return conf.getString("options.messages.cooling_down", "&6Wait&e &seconds& seconds&6 before you can use command&e &command& &6again.&f");
} }
static Set<String> getCooldowns(Player player) { static Set<String> getCooldowns(final Player player) {
String cool = getCommandGroup(player); final String cool = getCommandGroup(player);
return conf.getConfigurationSection("commands.groups." + cool).getKeys(false); return conf.getConfigurationSection("commands.groups." + cool).getKeys(false);
} }
@ -241,29 +241,29 @@ public class BoosConfigManager {
return conf.getString("options.messages.interact_blocked_during_warmup", "&6You can't do this when command is warming-up!&f"); return conf.getString("options.messages.interact_blocked_during_warmup", "&6You can't do this when command is warming-up!&f");
} }
public static List<String> getItemCostLore(String regexCommand, Player player) { public static List<String> getItemCostLore(final String regexCommand, final Player player) {
return conf.getStringList("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.lore"); return conf.getStringList("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.lore");
} }
public static List<String> getItemCostEnchants(String regexCommand, Player player) { public static List<String> getItemCostEnchants(final String regexCommand, final Player player) {
return conf.getStringList("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.enchants"); return conf.getStringList("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.enchants");
} }
public static String getItemCostName(String regexCommand, Player player) { public static String getItemCostName(final String regexCommand, final Player player) {
return conf.getString("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.name", ""); return conf.getString("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.name", "");
} }
public static String getItemCostItem(String regexCommand, Player player) { public static String getItemCostItem(final String regexCommand, final Player player) {
return conf.getString("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.item", ""); return conf.getString("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.item", "");
} }
public static int getItemCostCount(String regexCommand, Player player) { public static int getItemCostCount(final String regexCommand, final Player player) {
return conf.getInt("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.count", 0); return conf.getInt("commands.groups." + getCommandGroup(player) + "." + regexCommand + ".itemcost.count", 0);
} }
public static int getLimit(String regexCommand, Player player) { public static int getLimit(final String regexCommand, final Player player) {
int limit; final int limit;
String group = getCommandGroup(player); final String group = getCommandGroup(player);
limit = conf.getInt("commands.groups." + group + "." + regexCommand + ".limit", -1); limit = conf.getInt("commands.groups." + group + "." + regexCommand + ".limit", -1);
return limit; return limit;
} }
@ -282,27 +282,27 @@ public class BoosConfigManager {
} }
static Set<String> getAllPlayers() { static Set<String> getAllPlayers() {
ConfigurationSection users = confusers.getConfigurationSection("users"); final ConfigurationSection users = confusers.getConfigurationSection("users");
return users.getKeys(false); return users.getKeys(false);
} }
static List<String> getSharedCooldowns(String pre, Player player) { static List<String> getSharedCooldowns(final String pre, final Player player) {
List<String> sharedCooldowns; final List<String> sharedCooldowns;
String group = getCommandGroup(player); final String group = getCommandGroup(player);
sharedCooldowns = conf.getStringList("commands.groups." + group + "." + pre + ".shared_cooldown"); sharedCooldowns = conf.getStringList("commands.groups." + group + "." + pre + ".shared_cooldown");
return sharedCooldowns; return sharedCooldowns;
} }
public static List<String> getSharedLimits(String pre, Player player) { public static List<String> getSharedLimits(final String pre, final Player player) {
List<String> sharedLimits; final List<String> sharedLimits;
String group = getCommandGroup(player); final String group = getCommandGroup(player);
sharedLimits = conf.getStringList("commands.groups." + group + "." + pre + ".shared_limit"); sharedLimits = conf.getStringList("commands.groups." + group + "." + pre + ".shared_limit");
return sharedLimits; return sharedLimits;
} }
public static String getMessage(String regexCommand, Player player) { public static String getMessage(final String regexCommand, final Player player) {
String message = ""; String message = "";
String group = getCommandGroup(player); final String group = getCommandGroup(player);
message = conf.getString("commands.groups." + group + "." + regexCommand + ".message", ""); message = conf.getString("commands.groups." + group + "." + regexCommand + ".message", "");
return message; return message;
} }
@ -315,8 +315,8 @@ public class BoosConfigManager {
return conf.getString("options.messages.paid_for_command", "Price of &command& was %s and you now have %s"); return conf.getString("options.messages.paid_for_command", "Price of &command& was %s and you now have %s");
} }
static List<String> getPotionEffects(String regexCommand, Player player) { static List<String> getPotionEffects(final String regexCommand, final Player player) {
String group = getCommandGroup(player); final String group = getCommandGroup(player);
return conf.getStringList("commands.groups." + group + "." + regexCommand + ".potion"); return conf.getStringList("commands.groups." + group + "." + regexCommand + ".potion");
} }
@ -324,9 +324,9 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.cancel_potions_on_warmup_cancel", false); return conf.getBoolean("options.options.cancel_potions_on_warmup_cancel", false);
} }
public static double getPrice(String regexCommand, Player player) { public static double getPrice(final String regexCommand, final Player player) {
double price; final double price;
String group = getCommandGroup(player); final String group = getCommandGroup(player);
price = conf.getDouble("commands.groups." + group + "." + regexCommand + ".price", 0.0); price = conf.getDouble("commands.groups." + group + "." + regexCommand + ".price", 0.0);
return price; return price;
} }
@ -359,10 +359,10 @@ public class BoosConfigManager {
return conf.getString("options.units.seconds", "seconds"); return conf.getString("options.units.seconds", "seconds");
} }
public static int getWarmUp(String regexCommand, Player player) { public static int getWarmUp(final String regexCommand, final Player player) {
int warmUp; final int warmUp;
String warmUpString = ""; String warmUpString = "";
String group = getCommandGroup(player); final String group = getCommandGroup(player);
warmUpString = conf.getString("commands.groups." + group + "." + regexCommand + ".warmup", "0"); warmUpString = conf.getString("commands.groups." + group + "." + regexCommand + ".warmup", "0");
warmUp = parseTime(warmUpString); warmUp = parseTime(warmUpString);
return warmUp; return warmUp;
@ -391,13 +391,13 @@ public class BoosConfigManager {
public static void load() { public static void load() {
try { try {
conf.load(confFile); conf.load(confFile);
} catch (FileNotFoundException e) { } catch (final FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Configuration file not found!"); BoosCoolDown.getLog().severe("[boosCooldowns] Configuration file not found!");
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Could not read configuration file!"); BoosCoolDown.getLog().severe("[boosCooldowns] Could not read configuration file!");
} catch (InvalidConfigurationException e) { } catch (final InvalidConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Configuration file is invalid!"); BoosCoolDown.getLog().severe("[boosCooldowns] Configuration file is invalid!");
} }
@ -406,13 +406,13 @@ public class BoosConfigManager {
public static void loadConfusers() { public static void loadConfusers() {
try { try {
confusers.load(confusersFile); confusers.load(confusersFile);
} catch (FileNotFoundException e) { } catch (final FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Storage file not found!"); BoosCoolDown.getLog().severe("[boosCooldowns] Storage file not found!");
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Could not read storage file!"); BoosCoolDown.getLog().severe("[boosCooldowns] Could not read storage file!");
} catch (InvalidConfigurationException e) { } catch (final InvalidConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Storage file is invalid!"); BoosCoolDown.getLog().severe("[boosCooldowns] Storage file is invalid!");
} }
@ -427,35 +427,35 @@ public class BoosConfigManager {
try { try {
confFile.createNewFile(); confFile.createNewFile();
confusers.save(confusersFile); confusers.save(confusersFile);
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
BoosCoolDown.getLog().severe("[boosCooldowns] Could not save storage file!"); BoosCoolDown.getLog().severe("[boosCooldowns] Could not save storage file!");
} }
} }
public static void setAddToConfigFile(String group, String command, String what, String value) { public static void setAddToConfigFile(String group, String command, final String what, final String value) {
group = group.toLowerCase(); group = group.toLowerCase();
command = command.toLowerCase(); command = command.toLowerCase();
int value2; final int value2;
try { try {
value2 = Integer.parseInt(value); value2 = Integer.parseInt(value);
reload(); reload();
conf.set("commands.groups." + group + "." + command + "." + what, value2); conf.set("commands.groups." + group + "." + command + "." + what, value2);
} catch (NumberFormatException e1) { } catch (final NumberFormatException e1) {
reload(); reload();
conf.set("commands.groups." + group + "." + command + "." + what, value); conf.set("commands.groups." + group + "." + command + "." + what, value);
} }
try { try {
conf.save(confFile); conf.save(confFile);
} catch (IOException e) { } catch (final IOException e) {
BoosCoolDown.getLog().severe("[boosCooldowns] Could not save configuration file!"); BoosCoolDown.getLog().severe("[boosCooldowns] Could not save configuration file!");
} }
reload(); reload();
} }
public static void toggleConfirmations(Player player) { public static void toggleConfirmations(final Player player) {
Boolean def = confusers.getBoolean("users." + player.getUniqueId() + ".confirmations", getConfirmCommandEnabled(player)); final Boolean def = confusers.getBoolean("users." + player.getUniqueId() + ".confirmations", getConfirmCommandEnabled(player));
confusers.set("users." + player.getUniqueId() + ".confirmations", !def); confusers.set("users." + player.getUniqueId() + ".confirmations", !def);
if (def) { if (def) {
BoosChat.sendMessageToPlayer(player, "&6[boosCooldowns]&e " + getConfirmToggleMessageFalse()); BoosChat.sendMessageToPlayer(player, "&6[boosCooldowns]&e " + getConfirmToggleMessageFalse());
@ -466,7 +466,7 @@ public class BoosConfigManager {
loadConfusers(); loadConfusers();
} }
public static Boolean getConfirmationsPlayer(Player player) { public static Boolean getConfirmationsPlayer(final Player player) {
return (Boolean) confusers.get("users." + player.getUniqueId() + ".confirmations", null); return (Boolean) confusers.get("users." + player.getUniqueId() + ".confirmations", null);
} }
@ -479,7 +479,7 @@ public class BoosConfigManager {
} }
public static String getInsufficientItemsMessage() { public static String getInsufficientItemsMessage() {
return conf.getString("options.messages.insufficient_items", "&6You have not enough items!&e &command& &6needs &e%s"); return conf.getString("options.messages.insufficient_items", "&6You have not enough items!&e &command& &6needs");
} }
public static boolean getItemCostEnabled() { public static boolean getItemCostEnabled() {
@ -490,9 +490,9 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.player_points_prices_enabled", true); return conf.getBoolean("options.options.player_points_prices_enabled", true);
} }
public static int getPlayerPointsPrice(String regexCommand, Player player) { public static int getPlayerPointsPrice(final String regexCommand, final Player player) {
int price; final int price;
String group = getCommandGroup(player); final String group = getCommandGroup(player);
price = conf.getInt("commands.groups." + group + "." + regexCommand + ".playerpoints", 0); price = conf.getInt("commands.groups." + group + "." + regexCommand + ".playerpoints", 0);
return price; return price;
} }
@ -501,16 +501,16 @@ public class BoosConfigManager {
return conf.getString("options.messages.paid_xp_for_command", "&6Price of&e &command& &6was &e%s"); return conf.getString("options.messages.paid_xp_for_command", "&6Price of&e &command& &6was &e%s");
} }
public static int getXpPrice(String regexCommand, Player player) { public static int getXpPrice(final String regexCommand, final Player player) {
int price; final int price;
String group = getCommandGroup(player); final String group = getCommandGroup(player);
price = conf.getInt("commands.groups." + group + "." + regexCommand + ".xpcost", 0); price = conf.getInt("commands.groups." + group + "." + regexCommand + ".xpcost", 0);
return price; return price;
} }
public static int getXpRequirement(String regexCommand, Player player) { public static int getXpRequirement(final String regexCommand, final Player player) {
int price; final int price;
String group = getCommandGroup(player); final String group = getCommandGroup(player);
price = conf.getInt("commands.groups." + group + "." + regexCommand + ".xprequirement", 0); price = conf.getInt("commands.groups." + group + "." + regexCommand + ".xprequirement", 0);
return price; return price;
} }
@ -535,10 +535,10 @@ public class BoosConfigManager {
return conf.getString("options.messages.invalid_command_syntax", "&6You are not allowed to use command syntax /<pluginname>:<command>!"); return conf.getString("options.messages.invalid_command_syntax", "&6You are not allowed to use command syntax /<pluginname>:<command>!");
} }
static long getLimitResetDelay(String regexCommand, Player player) { static long getLimitResetDelay(final String regexCommand, final Player player) {
long limitreset; final long limitreset;
String limitResetString = ""; String limitResetString = "";
String group = getCommandGroup(player); final String group = getCommandGroup(player);
limitResetString = conf.getString("commands.groups." + group + "." + regexCommand + ".limit_reset_delay", "0"); limitResetString = conf.getString("commands.groups." + group + "." + regexCommand + ".limit_reset_delay", "0");
limitreset = parseTime(limitResetString); limitreset = parseTime(limitResetString);
return limitreset; return limitreset;
@ -549,11 +549,11 @@ public class BoosConfigManager {
"&6Wait&e &seconds& &unit&&6 before your limit for command&e &command& &6is reset.&f"); "&6Wait&e &seconds& &unit&&6 before your limit for command&e &command& &6is reset.&f");
} }
static void clearSomething2(String co, String uuid, int hashedCommand) { static void clearSomething2(final String co, final String uuid, final int hashedCommand) {
confusers.set("users." + uuid + "." + co + "." + hashedCommand, 0); confusers.set("users." + uuid + "." + co + "." + hashedCommand, 0);
} }
public static long getLimitResetDelayGlobal(String command) { public static long getLimitResetDelayGlobal(final String command) {
long delay = 0; long delay = 0;
String delayString = ""; String delayString = "";
delayString = conf.getString("global." + command + ".limit_reset_delay", "0"); delayString = conf.getString("global." + command + ".limit_reset_delay", "0");
@ -565,15 +565,15 @@ public class BoosConfigManager {
return conf.getConfigurationSection("global").getKeys(false); return conf.getConfigurationSection("global").getKeys(false);
} }
private static int parseTime(String time) { private static int parseTime(final String time) {
String[] timeString = time.split(" ", 2); final String[] timeString = time.split(" ", 2);
if (timeString[0].equals("cancel")) { if (timeString[0].equals("cancel")) {
return -65535; return -65535;
} }
int timeNumber = Integer.valueOf(timeString[0]); final int timeNumber = Integer.valueOf(timeString[0]);
int timeMultiplier = 1; int timeMultiplier = 1;
if (timeString.length > 1) { if (timeString.length > 1) {
String timeUnit = timeString[1]; final String timeUnit = timeString[1];
switch (timeUnit) { switch (timeUnit) {
case "minute": case "minute":
case "minutes": case "minutes":
@ -607,13 +607,13 @@ public class BoosConfigManager {
return conf.getString("options.messages.limit_reset_now", "&6Reseting limits for command&e &command& &6now.&f"); return conf.getString("options.messages.limit_reset_now", "&6Reseting limits for command&e &command& &6now.&f");
} }
public static String getPermission(Player player, String regexCommad) { public static String getPermission(final Player player, final String regexCommad) {
String group = getCommandGroup(player); final String group = getCommandGroup(player);
return conf.getString("commands.groups." + group + "." + regexCommad + ".permission"); return conf.getString("commands.groups." + group + "." + regexCommad + ".permission");
} }
public static String getPermissionMessage(Player player, String regexCommad) { public static String getPermissionMessage(final Player player, final String regexCommad) {
String group = getCommandGroup(player); final String group = getCommandGroup(player);
return conf.getString("commands.groups." + group + "." + regexCommad + ".denied_message"); return conf.getString("commands.groups." + group + "." + regexCommad + ".denied_message");
} }
@ -674,8 +674,8 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.syntax_blocker_enabled", true); return conf.getBoolean("options.options.syntax_blocker_enabled", true);
} }
public static boolean getConfirmCommandEnabled(Player player) { public static boolean getConfirmCommandEnabled(final Player player) {
Boolean playersChoice = getConfirmationsPlayer(player); final Boolean playersChoice = getConfirmationsPlayer(player);
if (playersChoice != null) { if (playersChoice != null) {
return playersChoice; return playersChoice;
} else { } else {

View File

@ -12,68 +12,66 @@ import util.BoosChat;
public class BoosCoolDownManager { public class BoosCoolDownManager {
static void cancelCooldown(Player player, String regexCommand) { static void cancelCooldown(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".cooldown." + pre2, null); "users." + player.getUniqueId() + ".cooldown." + pre2, null);
} }
public static boolean isCoolingdown(Player player, String regexCommand, int time) { public static boolean isCoolingdown(final Player player, final String regexCommand, final int time) {
Date lastTime = getTime(player, regexCommand); final Date lastTime = getTime(player, regexCommand);
if (lastTime == null) { if (lastTime == null) {
return false; return false;
} }
Calendar calcurrTime = Calendar.getInstance(); final Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(getCurrTime()); calcurrTime.setTime(getCurrTime());
Calendar callastTime = Calendar.getInstance(); final Calendar callastTime = Calendar.getInstance();
callastTime.setTime(lastTime); callastTime.setTime(lastTime);
long secondsBetween = secondsBetween(callastTime, calcurrTime); final long secondsBetween = secondsBetween(callastTime, calcurrTime);
if ((secondsBetween > time) || secondsBetween == 0) { return (secondsBetween <= time) && secondsBetween != 0;
return false;
}
return true;
} }
private static boolean cd(Player player, String regexCommand, private static boolean cd(
String originalCommand, int coolDownSeconds) { final Player player, final String regexCommand,
Date lastTime = getTime(player, regexCommand); final String originalCommand, final int coolDownSeconds) {
List<String> linkGroup = BoosConfigManager.getSharedCooldowns( final Date lastTime = getTime(player, regexCommand);
final List<String> linkGroup = BoosConfigManager.getSharedCooldowns(
regexCommand, player); regexCommand, player);
if (lastTime == null) { if (lastTime == null) {
if (linkGroup.isEmpty()) { if (linkGroup.isEmpty()) {
setTime(player, regexCommand); setTime(player, regexCommand);
} else { } else {
setTime(player, regexCommand); setTime(player, regexCommand);
for (String a : linkGroup) { for (final String a : linkGroup) {
setTime(player, a); setTime(player, a);
} }
} }
return false; return false;
} else { } else {
Calendar calcurrTime = Calendar.getInstance(); final Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(getCurrTime()); calcurrTime.setTime(getCurrTime());
Calendar callastTime = Calendar.getInstance(); final Calendar callastTime = Calendar.getInstance();
callastTime.setTime(lastTime); callastTime.setTime(lastTime);
long secondsBetween = secondsBetween(callastTime, calcurrTime); final long secondsBetween = secondsBetween(callastTime, calcurrTime);
long waitSeconds = coolDownSeconds - secondsBetween; long waitSeconds = coolDownSeconds - secondsBetween;
long waitMinutes = (long) Math.floor(waitSeconds / 60.0); long waitMinutes = (long) Math.floor(waitSeconds / 60.0);
long waitHours = (long) Math.floor(waitMinutes / 60.0); final long waitHours = (long) Math.floor(waitMinutes / 60.0);
if (secondsBetween > coolDownSeconds) { if (secondsBetween > coolDownSeconds) {
if (linkGroup.isEmpty()) { if (linkGroup.isEmpty()) {
setTime(player, regexCommand); setTime(player, regexCommand);
} else { } else {
setTime(player, regexCommand); setTime(player, regexCommand);
for (String a : linkGroup) { for (final String a : linkGroup) {
setTime(player, a); setTime(player, a);
} }
} }
return false; return false;
} else { } else {
String msg = BoosConfigManager.getCoolDownMessage(); String msg = BoosConfigManager.getCoolDownMessage();
StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 3600) { if (waitSeconds >= 3600) {
stringBuilder.append(Long.toString(waitHours)); stringBuilder.append(waitHours);
stringBuilder.append(" "); stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitHoursMessage()); stringBuilder.append(BoosConfigManager.getUnitHoursMessage());
stringBuilder.append(", "); stringBuilder.append(", ");
@ -81,7 +79,7 @@ public class BoosCoolDownManager {
} }
if (waitSeconds >= 60) { if (waitSeconds >= 60) {
waitMinutes = waitMinutes - (waitHours * 60); waitMinutes = waitMinutes - (waitHours * 60);
stringBuilder.append(Long.toString(waitMinutes)); stringBuilder.append(waitMinutes);
stringBuilder.append(" "); stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitMinutesMessage()); stringBuilder.append(BoosConfigManager.getUnitMinutesMessage());
stringBuilder.append(", "); stringBuilder.append(", ");
@ -105,8 +103,9 @@ public class BoosCoolDownManager {
} }
} }
public static boolean coolDown(Player player, String regexCommand, public static boolean coolDown(
String originalCommand, int time) { final Player player, String regexCommand,
final String originalCommand, final int time) {
regexCommand = regexCommand.toLowerCase(); regexCommand = regexCommand.toLowerCase();
return time > 0 && !player.hasPermission("booscooldowns.nocooldown") && !player.hasPermission("booscooldowns.nocooldown." + originalCommand) && cd( return time > 0 && !player.hasPermission("booscooldowns.nocooldown") && !player.hasPermission("booscooldowns.nocooldown." + originalCommand) && cd(
player, player,
@ -117,63 +116,64 @@ public class BoosCoolDownManager {
private static Date getCurrTime() { private static Date getCurrTime() {
String currTime = ""; String currTime = "";
Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime()); currTime = sdf.format(cal.getTime());
Date time = null; Date time = null;
try { try {
time = sdf.parse(currTime); time = sdf.parse(currTime);
return time; return time;
} catch (ParseException e) { } catch (final ParseException e) {
return null; return null;
} }
} }
private static Date getTime(Player player, String regexCommand) { private static Date getTime(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = ""; String confTime = "";
confTime = BoosConfigManager.getConfusers().getString( confTime = BoosConfigManager.getConfusers().getString(
"users." + player.getUniqueId() + ".cooldown." + pre2, null); "users." + player.getUniqueId() + ".cooldown." + pre2, null);
if (confTime != null && !confTime.equals("")) { if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null; Date lastDate = null;
try { try {
lastDate = sdf.parse(confTime); lastDate = sdf.parse(confTime);
return lastDate; return lastDate;
} catch (ParseException e) { } catch (final ParseException e) {
return null; return null;
} }
} }
return null; return null;
} }
public static boolean checkCoolDownOK(Player player, String regexCommand, public static boolean checkCoolDownOK(
String originalCommand, int time) { final Player player, String regexCommand,
final String originalCommand, final int time) {
regexCommand = regexCommand.toLowerCase(); regexCommand = regexCommand.toLowerCase();
if (time > 0) { if (time > 0) {
Date lastTime = getTime(player, regexCommand); final Date lastTime = getTime(player, regexCommand);
if (lastTime == null) { if (lastTime == null) {
return true; return true;
} else { } else {
Calendar calcurrTime = Calendar.getInstance(); final Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(getCurrTime()); calcurrTime.setTime(getCurrTime());
Calendar callastTime = Calendar.getInstance(); final Calendar callastTime = Calendar.getInstance();
callastTime.setTime(lastTime); callastTime.setTime(lastTime);
long secondsBetween = secondsBetween(callastTime, calcurrTime); final long secondsBetween = secondsBetween(callastTime, calcurrTime);
long waitSeconds = time - secondsBetween; long waitSeconds = time - secondsBetween;
long waitMinutes = (long) Math.floor(waitSeconds / 60.0); long waitMinutes = (long) Math.floor(waitSeconds / 60.0);
long waitHours = (long) Math.floor(waitMinutes / 60.0); final long waitHours = (long) Math.floor(waitMinutes / 60.0);
if (secondsBetween > time) { if (secondsBetween > time) {
return true; return true;
} else { } else {
String msg = BoosConfigManager.getCoolDownMessage(); String msg = BoosConfigManager.getCoolDownMessage();
StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 3600) { if (waitSeconds >= 3600) {
stringBuilder.append(Long.toString(waitHours)); stringBuilder.append(waitHours);
stringBuilder.append(" "); stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitHoursMessage()); stringBuilder.append(BoosConfigManager.getUnitHoursMessage());
stringBuilder.append(", "); stringBuilder.append(", ");
@ -181,7 +181,7 @@ public class BoosCoolDownManager {
} }
if (waitSeconds >= 60) { if (waitSeconds >= 60) {
waitMinutes = waitMinutes - (waitHours * 60); waitMinutes = waitMinutes - (waitHours * 60);
stringBuilder.append(Long.toString(waitMinutes)); stringBuilder.append(waitMinutes);
stringBuilder.append(" "); stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitMinutesMessage()); stringBuilder.append(BoosConfigManager.getUnitMinutesMessage());
stringBuilder.append(", "); stringBuilder.append(", ");
@ -207,27 +207,27 @@ public class BoosCoolDownManager {
return true; return true;
} }
private static long secondsBetween(Calendar startDate, Calendar endDate) { private static long secondsBetween(final Calendar startDate, final Calendar endDate) {
long secondsBetween = 0; long secondsBetween = 0;
secondsBetween = (endDate.getTimeInMillis() - startDate secondsBetween = (endDate.getTimeInMillis() - startDate
.getTimeInMillis()) / 1000; .getTimeInMillis()) / 1000;
return secondsBetween; return secondsBetween;
} }
private static void setTime(Player player, String regexCommand) { private static void setTime(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
String currTime = ""; String currTime = "";
Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime()); currTime = sdf.format(cal.getTime());
BoosConfigManager.getConfusers() BoosConfigManager.getConfusers()
.set("users." + player.getUniqueId() + ".cooldown." + pre2, .set("users." + player.getUniqueId() + ".cooldown." + pre2,
currTime); currTime);
} }
public static void startAllCooldowns(Player player, String message) { public static void startAllCooldowns(final Player player, final String message) {
for (String a : BoosConfigManager.getCooldowns(player)) { for (final String a : BoosConfigManager.getCooldowns(player)) {
int cooldownTime = BoosConfigManager.getCoolDown(a, player); final int cooldownTime = BoosConfigManager.getCoolDown(a, player);
coolDown(player, a, message, cooldownTime); coolDown(player, a, message, cooldownTime);
} }

View File

@ -18,13 +18,14 @@ import util.BoosChat;
public class BoosItemCostManager { public class BoosItemCostManager {
private static boolean payItemForCommand(Player player, private static boolean payItemForCommand(
String originalCommand, String item, int count, String name, List<String> lore, List<String> enchants) { final Player player,
final String originalCommand, final String item, final int count, final String name, final List<String> lore, final List<String> enchants) {
ItemStack itemStack = createItemStack(item, count, name, lore, enchants); final ItemStack itemStack = createItemStack(item, count, name, lore, enchants);
ItemStack itemStackSingle = createItemStack(item, 1, name, lore, enchants); final ItemStack itemStackSingle = createItemStack(item, 1, name, lore, enchants);
Inventory inventory = player.getInventory(); final Inventory inventory = player.getInventory();
Boolean trans = false; Boolean trans = false;
if (inventory.containsAtLeast(itemStackSingle, count)) { if (inventory.containsAtLeast(itemStackSingle, count)) {
inventory.removeItem(itemStack); inventory.removeItem(itemStack);
@ -33,7 +34,7 @@ public class BoosItemCostManager {
if (trans) { if (trans) {
String msg = String.format( String msg = String.format(
BoosConfigManager.getPaidItemsForCommandMessage(), ""); BoosConfigManager.getPaidItemsForCommandMessage(), "");
JSON json = getItemStackJson(1, item, count, name, lore, enchants); final JSON json = getItemStackJson(1, item, count, name, lore, enchants);
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
BoosChat.sendMessageToPlayer(player, msg); BoosChat.sendMessageToPlayer(player, msg);
json.send(player); json.send(player);
@ -43,9 +44,10 @@ public class BoosItemCostManager {
} }
} }
public static void payItemForCommand(PlayerCommandPreprocessEvent event, public static void payItemForCommand(
Player player, String regexCommand, String originalCommand, final PlayerCommandPreprocessEvent event,
String item, int count, String name, List<String> lore, List<String> enchants) { final Player player, final String regexCommand, final String originalCommand,
final String item, final int count, final String name, final List<String> lore, final List<String> enchants) {
if (count > 0) { if (count > 0) {
if (!player.hasPermission("booscooldowns.noitemcost") if (!player.hasPermission("booscooldowns.noitemcost")
&& !player.hasPermission("booscooldowns.noitemcost." && !player.hasPermission("booscooldowns.noitemcost."
@ -59,21 +61,21 @@ public class BoosItemCostManager {
} }
} }
public static boolean has(Player player, String item, int count, String name, List<String> lore, List<String> enchants) { public static boolean has(final Player player, final String item, final int count, final String name, final List<String> lore, final List<String> enchants) {
if (item.equals("")) { if (item.equals("")) {
return true; return true;
} }
if (count <= 0) { if (count <= 0) {
return true; return true;
} }
ItemStack itemStack = createItemStack(item, 1, name, lore, enchants); final ItemStack itemStack = createItemStack(item, 1, name, lore, enchants);
Inventory inventory = player.getInventory(); final Inventory inventory = player.getInventory();
return inventory.containsAtLeast(itemStack, count); return inventory.containsAtLeast(itemStack, count);
} }
public static ItemStack createItemStack(String item, int count, String name, List<String> lore, List<String> enchants) { public static ItemStack createItemStack(final String item, final int count, final String name, final List<String> lore, final List<String> enchants) {
ItemStack itemStack = new ItemStack(Material.getMaterial(item), count); final ItemStack itemStack = new ItemStack(Material.getMaterial(item), count);
ItemMeta itemMeta = itemStack.getItemMeta(); final ItemMeta itemMeta = itemStack.getItemMeta();
if (name != null) { if (name != null) {
itemMeta.setDisplayName(name); itemMeta.setDisplayName(name);
} }
@ -81,9 +83,9 @@ public class BoosItemCostManager {
itemMeta.setLore(lore); itemMeta.setLore(lore);
} }
if (!enchants.isEmpty()) { if (!enchants.isEmpty()) {
for (String enchantString : enchants) { for (final String enchantString : enchants) {
String[] enchantArray = enchantString.split(","); final String[] enchantArray = enchantString.split(",");
Enchantment enchant = Enchantment.getByName(enchantArray[0]); final Enchantment enchant = Enchantment.getByName(enchantArray[0]);
itemMeta.addEnchant(enchant, Integer.valueOf(enchantArray[1]), true); itemMeta.addEnchant(enchant, Integer.valueOf(enchantArray[1]), true);
} }
} }
@ -91,8 +93,8 @@ public class BoosItemCostManager {
return itemStack; return itemStack;
} }
public static JSON getItemStackJson(int indent, String item, int count, String name, List<String> lore, List<String> enchants) { public static JSON getItemStackJson(final int indent, final String item, final int count, final String name, final List<String> lore, final List<String> enchants) {
ItemStack itemStack = createItemStack(item, count, name, lore, enchants); final ItemStack itemStack = createItemStack(item, count, name, lore, enchants);
JSONColor itemColor; JSONColor itemColor;
if (itemStack.getItemMeta().hasEnchants()) { if (itemStack.getItemMeta().hasEnchants()) {
itemColor = JSONColor.fromString("&b"); itemColor = JSONColor.fromString("&b");
@ -104,17 +106,17 @@ public class BoosItemCostManager {
for (int i = 0; i < indent; i++) { for (int i = 0; i < indent; i++) {
indentation += " "; indentation += " ";
} }
JSONComponent comp1 = new JSONComponent(indentation); final JSONComponent comp1 = new JSONComponent(indentation);
JSONComponent comp2 = new JSONComponent(String.valueOf(count) + "x "); final JSONComponent comp2 = new JSONComponent(count + "x ");
comp2.setColor(JSONColor.YELLOW); comp2.setColor(JSONColor.YELLOW);
JSONComponent comp3 = new JSONComponent("["); final JSONComponent comp3 = new JSONComponent("[");
comp3.setColor(itemColor); comp3.setColor(itemColor);
JSONComponent comp4 = new JSONComponent(name == null || name.equals("") ? toTitleCase(itemStack final JSONComponent comp4 = new JSONComponent(name == null || name.equals("") ? toTitleCase(itemStack
.getType() .getType()
.toString() .toString()
.toLowerCase()) : name); .toLowerCase()) : name);
comp4.setColor(itemColor); comp4.setColor(itemColor);
JSONComponent comp5 = new JSONComponent("]"); final JSONComponent comp5 = new JSONComponent("]");
comp5.setColor(itemColor); comp5.setColor(itemColor);
comp3.setHoverAction(new JSONHoverAction.ShowItemStack(itemStack)); comp3.setHoverAction(new JSONHoverAction.ShowItemStack(itemStack));
comp4.setHoverAction(new JSONHoverAction.ShowItemStack(itemStack)); comp4.setHoverAction(new JSONHoverAction.ShowItemStack(itemStack));
@ -122,12 +124,12 @@ public class BoosItemCostManager {
return new JSON(comp1, comp2, comp3, comp4, comp5); return new JSON(comp1, comp2, comp3, comp4, comp5);
} }
public static String toTitleCase(String givenString) { public static String toTitleCase(final String givenString) {
if (givenString == null || "".equals(givenString)) { if (givenString == null || "".equals(givenString)) {
return ""; return "";
} }
String[] arr = givenString.split(" "); final String[] arr = givenString.split(" ");
StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
sb.append(Character.toUpperCase(arr[i].charAt(0))) sb.append(Character.toUpperCase(arr[i].charAt(0)))

View File

@ -13,18 +13,19 @@ import util.BoosChat;
public class BoosLimitManager { public class BoosLimitManager {
public static boolean blocked(Player player, String regexCommand, public static boolean blocked(
String originalCommand, int limit) { final Player player, final String regexCommand,
final String originalCommand, final int limit) {
Date time = getTime(player, regexCommand); Date time = getTime(player, regexCommand);
Date confTime = getTime(regexCommand); final Date confTime = getTime(regexCommand);
Calendar calcurrTime = Calendar.getInstance(); final Calendar calcurrTime = Calendar.getInstance();
calcurrTime.setTime(getCurrTime()); calcurrTime.setTime(getCurrTime());
Calendar callastTime = Calendar.getInstance(); final Calendar callastTime = Calendar.getInstance();
Calendar callastTimeGlobal = Calendar.getInstance(); final Calendar callastTimeGlobal = Calendar.getInstance();
int uses = getUses(player, regexCommand); int uses = getUses(player, regexCommand);
long limitResetDelay = BoosConfigManager.getLimitResetDelay( final long limitResetDelay = BoosConfigManager.getLimitResetDelay(
regexCommand, player); regexCommand, player);
long limitResetDelayGlobal = BoosConfigManager final long limitResetDelayGlobal = BoosConfigManager
.getLimitResetDelayGlobal(regexCommand); .getLimitResetDelayGlobal(regexCommand);
if (time != null) { if (time != null) {
callastTime.setTime(time); callastTime.setTime(time);
@ -53,10 +54,10 @@ public class BoosLimitManager {
return false; return false;
} else if (limit <= uses) { } else if (limit <= uses) {
if (limitResetDelay > 0) { if (limitResetDelay > 0) {
long waitSeconds = secondsBetween(callastTime, final long waitSeconds = secondsBetween(callastTime,
calcurrTime, limitResetDelay); calcurrTime, limitResetDelay);
long waitMinutes = Math.round(waitSeconds / 60) + 1; final long waitMinutes = Math.round(waitSeconds / 60) + 1;
long waitHours = Math.round(waitMinutes / 60) + 1; final long waitHours = Math.round(waitMinutes / 60) + 1;
String msg = BoosConfigManager.getLimitResetMessage(); String msg = BoosConfigManager.getLimitResetMessage();
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 60 && 3600 >= waitSeconds) { if (waitSeconds >= 60 && 3600 >= waitSeconds) {
@ -79,10 +80,10 @@ public class BoosLimitManager {
} else if (limitResetDelayGlobal > 0) { } else if (limitResetDelayGlobal > 0) {
if (confTime != null) { if (confTime != null) {
callastTimeGlobal.setTime(confTime); callastTimeGlobal.setTime(confTime);
long waitSeconds = secondsBetween(callastTimeGlobal, final long waitSeconds = secondsBetween(callastTimeGlobal,
calcurrTime, limitResetDelayGlobal); calcurrTime, limitResetDelayGlobal);
long waitMinutes = (long) Math.ceil(waitSeconds / 60.0); final long waitMinutes = (long) Math.ceil(waitSeconds / 60.0);
long waitHours = (long) Math.ceil(waitMinutes / 60.0); final long waitHours = (long) Math.ceil(waitMinutes / 60.0);
String msg = BoosConfigManager.getLimitResetMessage(); String msg = BoosConfigManager.getLimitResetMessage();
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
if (waitSeconds >= 60 && 3600 >= waitSeconds) { if (waitSeconds >= 60 && 3600 >= waitSeconds) {
@ -104,7 +105,7 @@ public class BoosLimitManager {
BoosChat.sendMessageToPlayer(player, msg); BoosChat.sendMessageToPlayer(player, msg);
} }
} else { } else {
String msg = String.format(BoosConfigManager final String msg = String.format(BoosConfigManager
.getCommandBlockedMessage()); .getCommandBlockedMessage());
BoosChat.sendMessageToPlayer(player, msg); BoosChat.sendMessageToPlayer(player, msg);
} }
@ -114,8 +115,8 @@ public class BoosLimitManager {
return false; return false;
} }
public static int getUses(Player player, String regexCommand) { public static int getUses(final Player player, final String regexCommand) {
int regexCommand2 = regexCommand.toLowerCase().hashCode(); final int regexCommand2 = regexCommand.toLowerCase().hashCode();
int uses = 0; int uses = 0;
uses = BoosConfigManager.getConfusers().getInt( uses = BoosConfigManager.getConfusers().getInt(
"users." + player.getUniqueId() + ".uses." + regexCommand2, "users." + player.getUniqueId() + ".uses." + regexCommand2,
@ -123,17 +124,17 @@ public class BoosLimitManager {
return uses; return uses;
} }
public static void setUses(Player player, String regexCommand) { public static void setUses(final Player player, final String regexCommand) {
if (BoosConfigManager.getLimitsEnabled()) { if (BoosConfigManager.getLimitsEnabled()) {
if (BoosConfigManager.getCommands(player).contains(regexCommand)) { if (BoosConfigManager.getCommands(player).contains(regexCommand)) {
int regexCommand2 = regexCommand.toLowerCase().hashCode(); final int regexCommand2 = regexCommand.toLowerCase().hashCode();
int uses = getUses(player, regexCommand); int uses = getUses(player, regexCommand);
uses = uses + 1; uses = uses + 1;
try { try {
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".uses." "users." + player.getUniqueId() + ".uses."
+ regexCommand2, uses); + regexCommand2, uses);
} catch (IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
BoosCoolDown BoosCoolDown
.getLog() .getLog()
.warning( .warning(
@ -145,9 +146,9 @@ public class BoosLimitManager {
} }
} }
public static void getLimitListMessages(Player send, String comm, int lim) { public static void getLimitListMessages(final Player send, final String comm, final int lim) {
if (lim != -1) { if (lim != -1) {
int uses = getUses(send, comm); final int uses = getUses(send, comm);
String message = BoosConfigManager.getLimitListMessage(); String message = BoosConfigManager.getLimitListMessage();
int num = lim - uses; int num = lim - uses;
if (num < 0) { if (num < 0) {
@ -163,80 +164,81 @@ public class BoosLimitManager {
private static Date getCurrTime() { private static Date getCurrTime() {
String currTime = ""; String currTime = "";
Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime()); currTime = sdf.format(cal.getTime());
Date time = null; Date time = null;
try { try {
time = sdf.parse(currTime); time = sdf.parse(currTime);
return time; return time;
} catch (ParseException e) { } catch (final ParseException e) {
return null; return null;
} }
} }
private static Date getTime(Player player, String regexCommand) { private static Date getTime(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
String confTime = ""; String confTime = "";
confTime = BoosConfigManager.getConfusers().getString( confTime = BoosConfigManager.getConfusers().getString(
"users." + player.getUniqueId() + ".lastused." + pre2, null); "users." + player.getUniqueId() + ".lastused." + pre2, null);
if (confTime != null && !confTime.equals("")) { if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null; Date lastDate = null;
try { try {
lastDate = sdf.parse(confTime); lastDate = sdf.parse(confTime);
return lastDate; return lastDate;
} catch (ParseException e) { } catch (final ParseException e) {
return null; return null;
} }
} }
return null; return null;
} }
private static Date getTime(String regexCommand) { private static Date getTime(final String regexCommand) {
String confTime = ""; String confTime = "";
confTime = BoosConfigManager.getConfusers().getString( confTime = BoosConfigManager.getConfusers().getString(
"global." + regexCommand + ".reset", null); "global." + regexCommand + ".reset", null);
if (confTime != null && !confTime.equals("")) { if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null; Date lastDate = null;
try { try {
lastDate = sdf.parse(confTime); lastDate = sdf.parse(confTime);
return lastDate; return lastDate;
} catch (ParseException e) { } catch (final ParseException e) {
return null; return null;
} }
} }
return null; return null;
} }
private static void setTime(Player player, String regexCommand) { private static void setTime(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
String currTime = ""; String currTime = "";
Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime()); currTime = sdf.format(cal.getTime());
BoosConfigManager.getConfusers() BoosConfigManager.getConfusers()
.set("users." + player.getUniqueId() + ".lastused." + pre2, .set("users." + player.getUniqueId() + ".lastused." + pre2,
currTime); currTime);
} }
private static long secondsBetween(Calendar startDate, Calendar endDate, private static long secondsBetween(
long limitResetDelay) { final Calendar startDate, final Calendar endDate,
final long limitResetDelay) {
long secondsBetween = 0; long secondsBetween = 0;
secondsBetween = ((startDate.getTimeInMillis() - endDate secondsBetween = ((startDate.getTimeInMillis() - endDate
.getTimeInMillis()) / 1000) + limitResetDelay; .getTimeInMillis()) / 1000) + limitResetDelay;
return secondsBetween; return secondsBetween;
} }
public static void clearAllLimits(int hashedCommand) { public static void clearAllLimits(final int hashedCommand) {
Set<String> players = BoosConfigManager.getAllPlayers(); final Set<String> players = BoosConfigManager.getAllPlayers();
for (String player : players) { for (final String player : players) {
BoosConfigManager.clearSomething2("uses", player, hashedCommand); BoosConfigManager.clearSomething2("uses", player, hashedCommand);
} }
BoosConfigManager.saveConfusers(); BoosConfigManager.saveConfusers();
@ -244,7 +246,7 @@ public class BoosLimitManager {
} }
public static void setGlobalLimitResetDate() { public static void setGlobalLimitResetDate() {
for (String command : BoosConfigManager.getLimitResetCommandsGlobal()) { for (final String command : BoosConfigManager.getLimitResetCommandsGlobal()) {
if (BoosConfigManager.getLimitResetDelayGlobal(command) == -65535) { if (BoosConfigManager.getLimitResetDelayGlobal(command) == -65535) {
BoosConfigManager.getConfusers().set("global." + command, null); BoosConfigManager.getConfusers().set("global." + command, null);
} else { } else {
@ -255,16 +257,16 @@ public class BoosLimitManager {
BoosConfigManager.loadConfusers(); BoosConfigManager.loadConfusers();
} }
public static void setGlobalLimitResetDate(String command) { public static void setGlobalLimitResetDate(final String command) {
setTime(command); setTime(command);
BoosConfigManager.saveConfusers(); BoosConfigManager.saveConfusers();
BoosConfigManager.loadConfusers(); BoosConfigManager.loadConfusers();
} }
private static void setTime(String command) { private static void setTime(final String command) {
String currTime = ""; String currTime = "";
Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime()); currTime = sdf.format(cal.getTime());
BoosConfigManager.getConfusers().set("global." + command + ".reset", BoosConfigManager.getConfusers().set("global." + command + ".reset",
currTime); currTime);

View File

@ -10,8 +10,9 @@ import util.BoosChat;
public class BoosPlayerPointsManager { public class BoosPlayerPointsManager {
private static final PlayerPoints playerPoints = BoosCoolDown.getPlayerPoints(); private static final PlayerPoints playerPoints = BoosCoolDown.getPlayerPoints();
private static boolean payForCommand(Player player, private static boolean payForCommand(
String originalCommand, int price) { final Player player,
final String originalCommand, final int price) {
if (playerPoints == null) { if (playerPoints == null) {
return true; return true;
} }
@ -30,9 +31,10 @@ public class BoosPlayerPointsManager {
} }
} }
public static void payForCommand(PlayerCommandPreprocessEvent event, public static void payForCommand(
Player player, String regexCommand, String originalCommand, final PlayerCommandPreprocessEvent event,
int price) { final Player player, final String regexCommand, final String originalCommand,
final int price) {
if (price > 0) { if (price > 0) {
if (!player.hasPermission("booscooldowns.noplayerpoints") if (!player.hasPermission("booscooldowns.noplayerpoints")
&& !player.hasPermission("booscooldowns.noplayerpoints." && !player.hasPermission("booscooldowns.noplayerpoints."
@ -45,7 +47,7 @@ public class BoosPlayerPointsManager {
} }
} }
public static boolean has(Player player, int price) { public static boolean has(final Player player, final int price) {
return playerPoints == null || price <= 0 || playerPoints.getAPI().look(player.getUniqueId()) >= price; return playerPoints == null || price <= 0 || playerPoints.getAPI().look(player.getUniqueId()) >= price;
} }
} }

View File

@ -11,12 +11,13 @@ import util.BoosChat;
public class BoosPriceManager { public class BoosPriceManager {
private static final Economy economy = BoosCoolDown.getEconomy(); private static final Economy economy = BoosCoolDown.getEconomy();
private static boolean payForCommand(Player player, private static boolean payForCommand(
String originalCommand, double price) { final Player player,
final String originalCommand, final double price) {
if (economy == null) { if (economy == null) {
return true; return true;
} }
EconomyResponse r = economy.withdrawPlayer(player, price); final EconomyResponse r = economy.withdrawPlayer(player, price);
String msg = ""; String msg = "";
if (r.transactionSuccess()) { if (r.transactionSuccess()) {
msg = String.format(BoosConfigManager.getPaidForCommandMessage(), msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
@ -32,9 +33,10 @@ public class BoosPriceManager {
} }
} }
public static void payForCommand(PlayerCommandPreprocessEvent event, public static void payForCommand(
Player player, String regexCommand, String originalCommand, final PlayerCommandPreprocessEvent event,
double price) { final Player player, final String regexCommand, final String originalCommand,
final double price) {
if (price > 0) { if (price > 0) {
if (!player.hasPermission("booscooldowns.noprice") if (!player.hasPermission("booscooldowns.noprice")
&& !player.hasPermission("booscooldowns.noprice." && !player.hasPermission("booscooldowns.noprice."
@ -47,7 +49,7 @@ public class BoosPriceManager {
} }
} }
public static boolean has(Player player, double price) { public static boolean has(final Player player, final double price) {
return economy == null || price <= 0 || economy.has(player, price); return economy == null || price <= 0 || economy.has(player, price);
} }
} }

View File

@ -17,22 +17,22 @@ public class BoosWarmUpManager {
private static final ConcurrentHashMap<String, BoosWarmUpTimer> playercommands = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, BoosWarmUpTimer> playercommands = new ConcurrentHashMap<>();
private static void applyPotionEffect(Player player, String regexCommand, int warmUpSeconds) { private static void applyPotionEffect(final Player player, final String regexCommand, final int warmUpSeconds) {
for (String potionUnparsed : BoosConfigManager.getPotionEffects(regexCommand, player)) { for (final String potionUnparsed : BoosConfigManager.getPotionEffects(regexCommand, player)) {
String[] potionParsed = potionUnparsed.split(","); final String[] potionParsed = potionUnparsed.split(",");
PotionEffectType type = PotionEffectType.getByName(potionParsed[0]); final PotionEffectType type = PotionEffectType.getByName(potionParsed[0]);
final int duration = potionParsed.length == 3 ? Integer.valueOf(potionParsed[2]) * 20 : warmUpSeconds * 20; final int duration = potionParsed.length == 3 ? Integer.valueOf(potionParsed[2]) * 20 : warmUpSeconds * 20;
player.addPotionEffect(new PotionEffect(type, duration, Integer.valueOf(potionParsed[1]) - 1), true); player.addPotionEffect(new PotionEffect(type, duration, Integer.valueOf(potionParsed[1]) - 1), true);
} }
} }
public static void cancelWarmUps(Player player) { public static void cancelWarmUps(final Player player) {
Iterator<String> iter = ((Map<String, BoosWarmUpTimer>) playercommands).keySet().iterator(); final Iterator<String> iter = ((Map<String, BoosWarmUpTimer>) playercommands).keySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
final String key = iter.next(); final String key = iter.next();
if (key.startsWith(player.getUniqueId() + "@")) { if (key.startsWith(player.getUniqueId() + "@")) {
if (BoosConfigManager.getCancelPotionsOnWarmupCancel()) { if (BoosConfigManager.getCancelPotionsOnWarmupCancel()) {
for (String potionUnparsed : BoosConfigManager.getPotionEffects(playercommands.get(key).getRegexCommand(), player)) { for (final String potionUnparsed : BoosConfigManager.getPotionEffects(playercommands.get(key).getRegexCommand(), player)) {
player.removePotionEffect(PotionEffectType.getByName(potionUnparsed.split(",")[0])); player.removePotionEffect(PotionEffectType.getByName(potionUnparsed.split(",")[0]));
} }
} }
@ -42,8 +42,8 @@ public class BoosWarmUpManager {
} }
} }
public static boolean hasWarmUps(Player player) { public static boolean hasWarmUps(final Player player) {
for (String key : ((Map<String, BoosWarmUpTimer>) playercommands).keySet()) { for (final String key : ((Map<String, BoosWarmUpTimer>) playercommands).keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) { if (key.startsWith(player.getUniqueId() + "@")) {
return true; return true;
} }
@ -51,63 +51,64 @@ public class BoosWarmUpManager {
return false; return false;
} }
public static boolean checkWarmUpOK(Player player, String regexCommand) { public static boolean checkWarmUpOK(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
int ok = 0; int ok = 0;
ok = BoosConfigManager.getConfusers().getInt( ok = BoosConfigManager.getConfusers().getInt(
"users." + player.getUniqueId() + ".warmup." + pre2, ok); "users." + player.getUniqueId() + ".warmup." + pre2, ok);
return ok == 1; return ok == 1;
} }
public static boolean isWarmUpProcess(Player player, String regexCommand) { public static boolean isWarmUpProcess(final Player player, String regexCommand) {
regexCommand = regexCommand.toLowerCase(); regexCommand = regexCommand.toLowerCase();
return playercommands.containsKey(player.getUniqueId() + "@" return playercommands.containsKey(player.getUniqueId() + "@"
+ regexCommand); + regexCommand);
} }
private static void killTimer(Player player) { private static void killTimer(final Player player) {
for (String key : ((Map<String, BoosWarmUpTimer>) playercommands).keySet()) { for (final String key : ((Map<String, BoosWarmUpTimer>) playercommands).keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) { if (key.startsWith(player.getUniqueId() + "@")) {
playercommands.get(key).cancel(); playercommands.get(key).cancel();
} }
} }
} }
public static void removeWarmUp(Player player, String regexCommand) { public static void removeWarmUp(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, null); "users." + player.getUniqueId() + ".warmup." + pre2, null);
} }
public static void removeWarmUpOK(Player player, String regexCommand) { public static void removeWarmUpOK(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, null); "users." + player.getUniqueId() + ".warmup." + pre2, null);
} }
public static void removeWarmUpProcess(String tag) { public static void removeWarmUpProcess(final String tag) {
BoosWarmUpManager.playercommands.remove(tag); BoosWarmUpManager.playercommands.remove(tag);
} }
public static void setWarmUpOK(Player player, String regexCommand) { public static void setWarmUpOK(final Player player, final String regexCommand) {
int pre2 = regexCommand.toLowerCase().hashCode(); final int pre2 = regexCommand.toLowerCase().hashCode();
BoosConfigManager.getConfusers().set( BoosConfigManager.getConfusers().set(
"users." + player.getUniqueId() + ".warmup." + pre2, 1); "users." + player.getUniqueId() + ".warmup." + pre2, 1);
} }
public static void startWarmUp(BoosCoolDown bCoolDown, Player player, public static void startWarmUp(
String regexCommand, String originalCommand, int warmUpSeconds) { final BoosCoolDown bCoolDown, final Player player,
String regexCommand, final String originalCommand, int warmUpSeconds) {
regexCommand = regexCommand.toLowerCase(); regexCommand = regexCommand.toLowerCase();
int warmUpSecondsTem = warmUpSeconds; final int warmUpSecondsTem = warmUpSeconds;
long warmUpMinutes = (long) Math.floor(warmUpSeconds / 60.0); long warmUpMinutes = (long) Math.floor(warmUpSeconds / 60.0);
long warmUpHours = (long) Math.floor(warmUpMinutes / 60.0); final long warmUpHours = (long) Math.floor(warmUpMinutes / 60.0);
if (!isWarmUpProcess(player, regexCommand)) { if (!isWarmUpProcess(player, regexCommand)) {
BoosWarmUpManager.removeWarmUpOK(player, regexCommand); BoosWarmUpManager.removeWarmUpOK(player, regexCommand);
String msg = BoosConfigManager.getWarmUpMessage(); String msg = BoosConfigManager.getWarmUpMessage();
StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
msg = msg.replaceAll("&command&", originalCommand); msg = msg.replaceAll("&command&", originalCommand);
if (warmUpSeconds >= 3600) { if (warmUpSeconds >= 3600) {
stringBuilder.append(Long.toString(warmUpHours)); stringBuilder.append(warmUpHours);
stringBuilder.append(" "); stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitHoursMessage()); stringBuilder.append(BoosConfigManager.getUnitHoursMessage());
stringBuilder.append(", "); stringBuilder.append(", ");
@ -115,7 +116,7 @@ public class BoosWarmUpManager {
} }
if (warmUpSeconds >= 60) { if (warmUpSeconds >= 60) {
warmUpMinutes = warmUpMinutes - (warmUpHours * 60); warmUpMinutes = warmUpMinutes - (warmUpHours * 60);
stringBuilder.append(Long.toString(warmUpMinutes)); stringBuilder.append(warmUpMinutes);
stringBuilder.append(" "); stringBuilder.append(" ");
stringBuilder.append(BoosConfigManager.getUnitMinutesMessage()); stringBuilder.append(BoosConfigManager.getUnitMinutesMessage());
stringBuilder.append(", "); stringBuilder.append(", ");
@ -135,8 +136,8 @@ public class BoosWarmUpManager {
BoosChat.sendMessageToPlayer(player, msg); BoosChat.sendMessageToPlayer(player, msg);
Timer scheduler = new Timer(); final Timer scheduler = new Timer();
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, player, regexCommand, originalCommand); final BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, player, regexCommand, originalCommand);
playercommands.put(player.getUniqueId() + "@" + regexCommand, playercommands.put(player.getUniqueId() + "@" + regexCommand,
scheduleMe); scheduleMe);
scheduler.schedule(scheduleMe, warmUpSecondsTem * 1000); scheduler.schedule(scheduleMe, warmUpSecondsTem * 1000);

View File

@ -7,9 +7,10 @@ import util.BoosChat;
public class BoosXpCostManager { public class BoosXpCostManager {
private static boolean payXPForCommand(Player player, private static boolean payXPForCommand(
String originalCommand, int xpPrice) { final Player player,
int xp = player.getLevel(); final String originalCommand, final int xpPrice) {
final int xp = player.getLevel();
Boolean trans = false; Boolean trans = false;
if (xp >= xpPrice) { if (xp >= xpPrice) {
player.setLevel(xp - xpPrice); player.setLevel(xp - xpPrice);
@ -26,9 +27,10 @@ public class BoosXpCostManager {
} }
} }
public static void payXPForCommand(PlayerCommandPreprocessEvent event, public static void payXPForCommand(
Player player, String regexCommand, String originalCommand, final PlayerCommandPreprocessEvent event,
int xpPrice) { final Player player, final String regexCommand, final String originalCommand,
final int xpPrice) {
if (xpPrice > 0) { if (xpPrice > 0) {
if (!player.hasPermission("booscooldowns.noxpcost") if (!player.hasPermission("booscooldowns.noxpcost")
&& !player.hasPermission("booscooldowns.noxpcost." && !player.hasPermission("booscooldowns.noxpcost."
@ -42,11 +44,11 @@ public class BoosXpCostManager {
} }
} }
public static boolean has(Player player, int xpPrice) { public static boolean has(final Player player, final int xpPrice) {
if (xpPrice <= 0) { if (xpPrice <= 0) {
return true; return true;
} }
int xp = player.getLevel(); final int xp = player.getLevel();
return xp >= xpPrice; return xp >= xpPrice;
} }
} }

View File

@ -10,7 +10,7 @@ public class BoosGlobalLimitResetRunnable implements Runnable {
private final String command; private final String command;
public BoosGlobalLimitResetRunnable(String key) { public BoosGlobalLimitResetRunnable(final String key) {
this.command = key; this.command = key;
} }

View File

@ -15,8 +15,9 @@ public class BoosWarmUpTimer extends TimerTask {
private final String originalCommand; private final String originalCommand;
private final String regexCommand; private final String regexCommand;
public BoosWarmUpTimer(BoosCoolDown bCoolDown, Player player, public BoosWarmUpTimer(
String regexCommand, String originalCommand) { final BoosCoolDown bCoolDown, final Player player,
final String regexCommand, final String originalCommand) {
this.bCoolDown = bCoolDown; this.bCoolDown = bCoolDown;
this.player = player; this.player = player;
this.regexCommand = regexCommand; this.regexCommand = regexCommand;

View File

@ -1,28 +0,0 @@
package nms;
import org.bukkit.entity.Player;
/**
* All rights reserved.
*
* @author ColoredCarrot
*/
public interface INMSHook {
/**
* Sends a JSON message to a player.
*
* @param json (String) - the plain JSON
* @param player (Player) - the player
*/
void sendJSON(String json, Player player);
/**
* Sends an actionbar to a player.
*
* @param json (String) - the plain JSON
* @param player (Player) - the player
*/
void sendActionBar(String json, Player player);
}

View File

@ -1,77 +0,0 @@
package nms;
import org.bukkit.plugin.Plugin;
/**
* All rights reserved.
*
* @author ColoredCarrot
*/
public class NMS {
private static INMSHook hook;
private static String version;
private static boolean compatible = true;
/**
* Gets the server version and adjusts this API accordingly.
*
* @param pl (Plugin) - the instance of your plugin
* @return (NMSSetupResponse) - the setup response.
*/
public static NMSSetupResponse setup(Plugin pl) {
String version;
try {
version = pl.getServer().getClass().getPackage().getName().replace('.', ',').split(",")[3];
} catch (ArrayIndexOutOfBoundsException e) {
return new NMSSetupResponse(null, false);
}
try {
hook = new NMSHook();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return new NMSSetupResponse(version, true);
}
/**
* Gets the NMS hook, if NMS is hooked.
*
* @return (INMSHook) - the INMSHook.
* @throws NMSNotHookedException if NMS is not hooked (by using {@link #setup(Plugin)})
*/
public static INMSHook getHook()
throws NMSNotHookedException {
if (!compatible) {
throw new NMSNotHookedException();
}
return hook;
}
/**
* Gets the found server version.
*
* @return (String) - the server version in form of "v1_9_R1" or null
*/
public static String getVersion() {
return version;
}
/**
* Checks whether this API is compatible with the found server version.
*
* @return
*/
public static boolean isCompatibleVersionFound() {
return compatible;
}
}

View File

@ -1,84 +0,0 @@
package nms;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
* All rights reserved.
*
* @author ColoredCarrot
*/
public class NMSHook
implements INMSHook {
private String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
private Class<?> chatSerializer = version.startsWith("v1_7")
? Class.forName("net.minecraft.server." + version + ".ChatSerializer")
: Class.forName("net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer");
private Class<?> chatComponent = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent");
private Class<?> packet = Class.forName("net.minecraft.server." + version + ".PacketPlayOutChat");
public NMSHook() throws ClassNotFoundException {
}
public void sendJSON(String json, Player player) {
try {
Object nmsPlayer = getNmsPlayer(player);
Object connection = getConnection(nmsPlayer);
Constructor constructor = packet.getConstructor(chatComponent);
Object text = getText(json);
Object packetFinal = constructor.newInstance(text);
sendPacket(packetFinal, text, connection);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void sendActionBar(String json, Player player) {
try {
Object nmsPlayer = getNmsPlayer(player);
Object connection = getConnection(nmsPlayer);
Constructor constructor = packet.getConstructor(chatComponent, byte.class);
Object text = getText(json);
Object packetFinal = constructor.newInstance(text, (byte) 2);
sendPacket(packetFinal, text, connection);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void sendPacket(Object packetFinal, Object text, Object connection) throws IllegalAccessException, NoSuchFieldException,
ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
Field field = packetFinal.getClass().getDeclaredField("a");
field.setAccessible(true);
field.set(packetFinal, text);
connection
.getClass()
.getMethod("sendPacket", Class.forName("net.minecraft.server." + version + ".Packet"))
.invoke(connection, packetFinal);
}
private Object getNmsPlayer(Player player) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
return player.getClass().getMethod("getHandle").invoke(player);
}
private Object getConnection(Object nmsPlayer) throws NoSuchFieldException, IllegalAccessException {
return nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
}
private Object getText(String json) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
return chatSerializer.getMethod("a", String.class).invoke(chatSerializer, json);
}
}

View File

@ -1,20 +0,0 @@
package nms;
/**
* All rights reserved.
*
* @author ColoredCarrot
*/
public class NMSNotHookedException
extends Exception {
/**
*
*/
private static final long serialVersionUID = -1482736539139159745L;
public NMSNotHookedException() {
super("NMS not hooked!");
}
}

View File

@ -1,36 +0,0 @@
package nms;
/**
* All rights reserved.
*
* @author ColoredCarrot
*/
public class NMSSetupResponse {
private String version;
private boolean compatible;
protected NMSSetupResponse(String version, boolean compatible) {
this.version = version;
this.compatible = compatible;
}
/**
* Gets the found server version in form of "v1_9_R1".
*
* @return (String) - the server version or null if it's not found.
*/
public String getVersion() {
return version;
}
/**
* Gets if the found server version is compatible with this API.
*
* @return
*/
public boolean isCompatible() {
return compatible;
}
}

View File

@ -40,6 +40,7 @@ import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
@ -110,7 +111,7 @@ public class MetricsLite {
*/ */
private volatile BukkitTask task = null; private volatile BukkitTask task = null;
public MetricsLite(Plugin plugin) throws IOException { public MetricsLite(final Plugin plugin) throws IOException {
if (plugin == null) { if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null"); throw new IllegalArgumentException("Plugin cannot be null");
} }
@ -143,19 +144,19 @@ public class MetricsLite {
* @param input * @param input
* @return * @return
*/ */
public static byte[] gzip(String input) { public static byte[] gzip(final String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null; GZIPOutputStream gzos = null;
try { try {
gzos = new GZIPOutputStream(baos); gzos = new GZIPOutputStream(baos);
gzos.write(input.getBytes("UTF-8")); gzos.write(input.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (gzos != null) try { if (gzos != null) try {
gzos.close(); gzos.close();
} catch (IOException ignore) { } catch (final IOException ignore) {
} }
} }
@ -170,7 +171,7 @@ public class MetricsLite {
* @param value * @param value
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false; boolean isValueNumeric = false;
try { try {
@ -178,7 +179,7 @@ public class MetricsLite {
Double.parseDouble(value); Double.parseDouble(value);
isValueNumeric = true; isValueNumeric = true;
} }
} catch (NumberFormatException e) { } catch (final NumberFormatException e) {
isValueNumeric = false; isValueNumeric = false;
} }
@ -202,12 +203,12 @@ public class MetricsLite {
* @param text * @param text
* @return * @return
*/ */
private static String escapeJSON(String text) { private static String escapeJSON(final String text) {
StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
builder.append('"'); builder.append('"');
for (int index = 0; index < text.length(); index++) { for (int index = 0; index < text.length(); index++) {
char chr = text.charAt(index); final char chr = text.charAt(index);
switch (chr) { switch (chr) {
case '"': case '"':
@ -229,7 +230,7 @@ public class MetricsLite {
break; break;
default: default:
if (chr < ' ') { if (chr < ' ') {
String t = "000" + Integer.toHexString(chr); final String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4)); builder.append("\\u" + t.substring(t.length() - 4));
} else { } else {
builder.append(chr); builder.append(chr);
@ -295,7 +296,7 @@ public class MetricsLite {
// After the first post we set firstPost to false // After the first post we set firstPost to false
// Each post thereafter will be a ping // Each post thereafter will be a ping
firstPost = false; firstPost = false;
} catch (IOException e) { } catch (final IOException e) {
if (debug) { if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
} }
@ -317,12 +318,12 @@ public class MetricsLite {
try { try {
// Reload the metrics file // Reload the metrics file
configuration.load(getConfigFile()); configuration.load(getConfigFile());
} catch (IOException ex) { } catch (final IOException ex) {
if (debug) { if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
} }
return true; return true;
} catch (InvalidConfigurationException ex) { } catch (final InvalidConfigurationException ex) {
if (debug) { if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
} }
@ -386,7 +387,7 @@ public class MetricsLite {
// plugin.getDataFolder() => base/plugins/PluginA/ // plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/ // pluginsFolder => base/plugins/
// The base is not necessarily relative to the startup directory. // The base is not necessarily relative to the startup directory.
File pluginsFolder = plugin.getDataFolder().getParentFile(); final File pluginsFolder = plugin.getDataFolder().getParentFile();
// return => base/plugins/PluginMetrics/config.yml // return => base/plugins/PluginMetrics/config.yml
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
@ -399,13 +400,13 @@ public class MetricsLite {
*/ */
private int getOnlinePlayers() { private int getOnlinePlayers() {
try { try {
Method onlinePlayerMethod = Bukkit.class.getMethod("getOnlinePlayers"); final Method onlinePlayerMethod = Bukkit.class.getMethod("getOnlinePlayers");
if (onlinePlayerMethod.getReturnType().equals(Collection.class)) { if (onlinePlayerMethod.getReturnType().equals(Collection.class)) {
return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.class)).size(); return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.class)).size();
} else { } else {
return ((Player[]) onlinePlayerMethod.invoke(Bukkit.class)).length; return ((Player[]) onlinePlayerMethod.invoke(Bukkit.class)).length;
} }
} catch (Exception ex) { } catch (final Exception ex) {
if (debug) { if (debug) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
} }
@ -417,19 +418,19 @@ public class MetricsLite {
/** /**
* Generic method that posts a plugin to the metrics website * Generic method that posts a plugin to the metrics website
*/ */
private void postPlugin(boolean isPing) throws IOException { private void postPlugin(final boolean isPing) throws IOException {
// Server software specific section // Server software specific section
PluginDescriptionFile description = plugin.getDescription(); final PluginDescriptionFile description = plugin.getDescription();
String pluginName = description.getName(); final String pluginName = description.getName();
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled final boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
String pluginVersion = description.getVersion(); final String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion(); final String serverVersion = Bukkit.getVersion();
int playersOnline = this.getOnlinePlayers(); final int playersOnline = this.getOnlinePlayers();
// END server software specific section -- all code below does not use any code outside of this class / Java // END server software specific section -- all code below does not use any code outside of this class / Java
// Construct the post data // Construct the post data
StringBuilder json = new StringBuilder(1024); final StringBuilder json = new StringBuilder(1024);
json.append('{'); json.append('{');
// The plugin's description file containg all of the plugin data such as name, version, author, etc // The plugin's description file containg all of the plugin data such as name, version, author, etc
@ -439,11 +440,11 @@ public class MetricsLite {
appendJSONPair(json, "players_online", Integer.toString(playersOnline)); appendJSONPair(json, "players_online", Integer.toString(playersOnline));
// New data as of R6 // New data as of R6
String osname = System.getProperty("os.name"); final String osname = System.getProperty("os.name");
String osarch = System.getProperty("os.arch"); String osarch = System.getProperty("os.arch");
String osversion = System.getProperty("os.version"); final String osversion = System.getProperty("os.version");
String java_version = System.getProperty("java.version"); final String java_version = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors(); final int coreCount = Runtime.getRuntime().availableProcessors();
// normalize os arch .. amd64 -> x86_64 // normalize os arch .. amd64 -> x86_64
if (osarch.equals("amd64")) { if (osarch.equals("amd64")) {
@ -466,10 +467,10 @@ public class MetricsLite {
json.append('}'); json.append('}');
// Create the url // Create the url
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName))); final URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
// Connect to the website // Connect to the website
URLConnection connection; final URLConnection connection;
// Mineshafter creates a socks proxy, so we can safely bypass it // Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it // It does not reroute POST requests so we need to go around it
@ -480,8 +481,8 @@ public class MetricsLite {
} }
byte[] uncompressed = json.toString().getBytes(); final byte[] uncompressed = json.toString().getBytes();
byte[] compressed = gzip(json.toString()); final byte[] compressed = gzip(json.toString());
// Headers // Headers
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
@ -499,7 +500,7 @@ public class MetricsLite {
} }
// Write the data // Write the data
OutputStream os = connection.getOutputStream(); final OutputStream os = connection.getOutputStream();
os.write(compressed); os.write(compressed);
os.flush(); os.flush();
@ -531,7 +532,7 @@ public class MetricsLite {
try { try {
Class.forName("mineshafter.MineServer"); Class.forName("mineshafter.MineServer");
return true; return true;
} catch (Exception e) { } catch (final Exception e) {
return false; return false;
} }
} }

View File

@ -74,7 +74,7 @@ options:
paid_items_for_command: '&6Price of&e &command& &6was &e%s' paid_items_for_command: '&6Price of&e &command& &6was &e%s'
paid_xp_for_command: '&6Price of&e &command& &6was &e%s levels' paid_xp_for_command: '&6Price of&e &command& &6was &e%s levels'
paid_player_points_for_command: '&6Price of&e &command& &6was &e%s PlayerPoints &6and you now have&e %s PlayerPoints' paid_player_points_for_command: '&6Price of&e &command& &6was &e%s PlayerPoints &6and you now have&e %s PlayerPoints'
insufficient_items: '&6You have not enough items!&e &command& &6needs &e%s' insufficient_items: '&6You have not enough items!&e &command& &6needs'
insufficient_xp: '&6You have not enough XP!&e &command& &6needs &e%s' insufficient_xp: '&6You have not enough XP!&e &command& &6needs &e%s'
insufficient_xp_requirement: '&6Your level is too low to use this!&e &command& &6needs &e%s' insufficient_xp_requirement: '&6Your level is too low to use this!&e &command& &6needs &e%s'
insufficient_player_points: '&6You have not enough PlayerPoints!&e &command& &6needs &e%s' insufficient_player_points: '&6You have not enough PlayerPoints!&e &command& &6needs &e%s'

View File

@ -1,6 +1,6 @@
name: boosCooldowns name: boosCooldowns
main: cz.boosik.boosCooldown.BoosCoolDown main: cz.boosik.boosCooldown.BoosCoolDown
version: 3.16.0 version: 3.16.1
authors: [LordBoos (boosik)] authors: [LordBoos (boosik)]
softdepend: [Vault, PlayerPoints] softdepend: [Vault, PlayerPoints]
description: > description: >

View File

@ -11,12 +11,11 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>
<boosCooldowns.version>3.16.0</boosCooldowns.version> <boosCooldowns.version>3.16.1</boosCooldowns.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<minecraft.version>1.16.1</minecraft.version> <minecraft.version>1.16.1</minecraft.version>
<bukkit.version>R0.1</bukkit.version> <bukkit.version>R0.1</bukkit.version>
<bukkit.packet>v1_16_R1</bukkit.packet>
</properties> </properties>
<pluginRepositories> <pluginRepositories>
<pluginRepository> <pluginRepository>