Created
July 21, 2019 23:14
-
-
Save boxbeam/8f4a11878ec8d172d83bef38cd5058e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Tag { | |
private static FileConfiguration config = Main.plugin.getConfig(); | |
private String name; | |
public static List<Tag> getTags() { | |
return config.getKeys(false).stream().map(Tag::new).collect(Collectors.toList()); | |
} | |
public static List<Tag> getTags(Player player) { | |
return config.getKeys(false).stream().map(Tag::new).filter(t -> !t.getPermission().equals("") && player.hasPermission(t.getPermission())).collect(Collectors.toList()); | |
} | |
public static Tag getTag(String name) { | |
Optional<String> found = config.getKeys(false).stream().filter(t -> t.equalsIgnoreCase(name)).findFirst(); | |
return found.isPresent() ? new Tag(found.get()) : null; | |
} | |
public static Tag create(String name, ItemStack item, String command) { | |
return new Tag(name, item, command); | |
} | |
public static void setGUIName(String name) { | |
config.set("guiname", ChatColor.translateAlternateColorCodes('&', name)); | |
} | |
public static String getGUIName() { | |
return config.getString("guiname", ChatColor.GRAY + "Tags"); | |
} | |
private Tag(String name, ItemStack item, String command) { | |
this.name = name; | |
if (config.get(name) != null) { | |
throw new IllegalArgumentException("A tag by this name already exists"); | |
} | |
config.set(name + ".item", item); | |
config.set(name + ".permission", ""); | |
config.set(name + ".command", command); | |
} | |
private Tag(String name) { | |
this.name = name; | |
} | |
public void setPermission(String permission) { | |
config.set(name + ".permission", permission); | |
} | |
public String getPermission() { | |
return config.getString(name + ".permission"); | |
} | |
public void setMessage(String message) { | |
config.set(name + ".message", ChatColor.translateAlternateColorCodes('&', message)); | |
} | |
public String getMessage() { | |
return config.getString(name + ".message", ChatColor.GRAY + "Activated " + getName()); | |
} | |
public String getName() { | |
return name; | |
} | |
public ItemStack getItem() { | |
return config.getItemStack(name + ".item"); | |
} | |
public String getCommand() { | |
return config.getString(name + ".command"); | |
} | |
public void remove() { | |
config.set(name, null); | |
} | |
public void setItem(ItemStack item) { | |
config.set(name + ".item", item); | |
} | |
public void setCommand(String command) { | |
config.set(name + ".command", command); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment