2018-02-20 23:06:09 +01:00
|
|
|
package us.tastybento.bskyblock.api.flags;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
2018-02-25 17:09:46 +01:00
|
|
|
import org.bukkit.Material;
|
2018-02-20 23:06:09 +01:00
|
|
|
import org.bukkit.event.Listener;
|
2018-02-25 17:09:46 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2018-02-26 03:21:42 +01:00
|
|
|
|
2018-02-20 23:06:09 +01:00
|
|
|
import us.tastybento.bskyblock.api.panels.PanelItem;
|
2018-02-25 17:09:46 +01:00
|
|
|
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
2018-03-11 23:59:03 +01:00
|
|
|
import us.tastybento.bskyblock.api.user.User;
|
2018-02-20 23:06:09 +01:00
|
|
|
|
2018-02-26 04:48:01 +01:00
|
|
|
public class Flag implements Comparable<Flag> {
|
2018-02-20 23:06:09 +01:00
|
|
|
|
|
|
|
public enum Type {
|
|
|
|
PROTECTION,
|
|
|
|
SETTING
|
|
|
|
}
|
|
|
|
|
|
|
|
private final String id;
|
2018-02-25 17:09:46 +01:00
|
|
|
private final Material icon;
|
2018-02-20 23:06:09 +01:00
|
|
|
private final Listener listener;
|
|
|
|
private final Type type;
|
|
|
|
private boolean defaultSetting;
|
|
|
|
|
2018-02-25 17:09:46 +01:00
|
|
|
Flag(String id, Material icon, Listener listener, boolean defaultSetting, Type type) {
|
|
|
|
this.id = id;
|
2018-02-20 23:06:09 +01:00
|
|
|
this.icon = icon;
|
|
|
|
this.listener = listener;
|
2018-02-25 17:09:46 +01:00
|
|
|
this.defaultSetting = defaultSetting;
|
2018-02-20 23:06:09 +01:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getID() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-02-25 17:09:46 +01:00
|
|
|
public Material getIcon() {
|
2018-02-20 23:06:09 +01:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Optional<Listener> getListener() {
|
|
|
|
return Optional.ofNullable(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return - true means it is allowed. false means it is not allowed
|
|
|
|
*/
|
|
|
|
public boolean isDefaultSetting() {
|
|
|
|
return defaultSetting;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the status of this flag for locations outside of island spaces
|
|
|
|
* @param defaultSetting - true means it is allowed. false means it is not allowed
|
|
|
|
*/
|
|
|
|
public void setDefaultSetting(boolean defaultSetting) {
|
|
|
|
this.defaultSetting = defaultSetting;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the type
|
|
|
|
*/
|
|
|
|
public Type getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see java.lang.Object#hashCode()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
final int prime = 31;
|
|
|
|
int result = 1;
|
|
|
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
|
|
|
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see java.lang.Object#equals(java.lang.Object)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (obj == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-25 16:01:30 +01:00
|
|
|
if (!(obj instanceof Flag)) {
|
2018-02-20 23:06:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-02-25 16:01:30 +01:00
|
|
|
Flag other = (Flag) obj;
|
2018-02-20 23:06:09 +01:00
|
|
|
if (id == null) {
|
|
|
|
if (other.id != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!id.equals(other.id)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-25 13:48:58 +02:00
|
|
|
|
|
|
|
return type == other.type;
|
2018-02-20 23:06:09 +01:00
|
|
|
}
|
|
|
|
|
2018-02-25 17:09:46 +01:00
|
|
|
public PanelItem toPanelItem(User user) {
|
|
|
|
return new PanelItemBuilder()
|
|
|
|
.icon(new ItemStack(icon))
|
2018-02-26 20:18:09 +01:00
|
|
|
.name(user.getTranslation("protection.panel.flag-item.name-layout", "[name]", user.getTranslation("protection.flags." + id + ".name")))
|
|
|
|
.description(user.getTranslation("protection.panel.flag-item.description-layout",
|
|
|
|
"[description]", user.getTranslation("protection.flags." + id + ".description"),
|
|
|
|
"[rank]", "Owner"))
|
2018-02-25 17:09:46 +01:00
|
|
|
.clickHandler((clicker, click) -> {
|
|
|
|
clicker.sendRawMessage("You clicked on : " + id);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
.build();
|
|
|
|
}
|
2018-02-26 04:48:01 +01:00
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see java.lang.Object#toString()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "Flag [id=" + id + ", icon=" + icon + ", type=" + type + ", defaultSetting=" + defaultSetting + "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(Flag o) {
|
|
|
|
return getID().compareTo(o.getID());
|
|
|
|
}
|
2018-02-20 23:06:09 +01:00
|
|
|
}
|