Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package functions;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.annotation.Nullable;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.World;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- public class Channel {
- private String name;
- private char channelchar;
- private boolean worldSpecific;
- @Nullable
- private String world;
- private ChatColor prefixcolor;
- public Channel(String name, char cchar, boolean worldSpecific, @Nullable String world, ChatColor color) {
- this.name = name;
- this.channelchar = cchar;
- this.worldSpecific = worldSpecific;
- this.world = world;
- this.prefixcolor = color;
- }
- public Channel(String name, char cchar, ChatColor color) {
- this.name = name;
- this.channelchar = cchar;
- this.worldSpecific = false;
- this.world = null;
- this.prefixcolor = color;
- }
- public void sendMessage(String msg, Player sender) {
- for (Player a : Bukkit.getOnlinePlayers()) {
- if (this.worldSpecific) {
- if (a.getWorld().getName().equalsIgnoreCase(world)) {
- if (a.hasPermission("core.channels." + name)) {
- a.sendMessage(prefixcolor + "[" + name + "] " + util.formatMsg(sender, msg));
- }
- }
- } else {
- a.sendMessage(prefixcolor + "[" + name + "] " + util.formatMsg(sender, msg));
- }
- }
- }
- public void saveFile() throws IOException {
- File f = new File("plugins/channels/" + name + ".yml");
- YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
- if (!f.exists()) {
- f.createNewFile();
- }
- yml.set("name", name);
- yml.set("char", channelchar);
- yml.set("specific", this.worldSpecific);
- yml.set("world", world);
- yml.set("color", prefixcolor.getChar());
- yml.save(f);
- }
- public boolean isSaved() {
- File f = new File("plugins/channels/" + name + ".yml");
- return f.exists() ? true : false;
- }
- public void loadSaved() {
- File f = new File("plugins/channels/" + name + ".yml");
- YamlConfiguration yml = YamlConfiguration.loadConfiguration(f);
- if (!f.exists()) {
- util.log("Error: Channel not saved as file", LogType.WARNING, new Date());
- return;
- }
- name = yml.getString("name");
- this.channelchar = (char) yml.get("char");
- this.worldSpecific = yml.getBoolean("specific");
- world = yml.getString("world");
- this.prefixcolor = ChatColor.getByChar((char) yml.get("color"));
- }
- public boolean canReceive(Player p) {
- if (this.worldSpecific) {
- if (p.hasPermission("core.channels." + name) && p.getWorld().getName().equalsIgnoreCase(world)) {
- return true;
- } else {
- if (p.hasPermission("core.channels" + name)) {
- return true;
- }
- }
- }
- return false;
- }
- public String getName() {
- return name;
- }
- public char getChar() {
- return this.channelchar;
- }
- public boolean getSpecific() {
- return this.worldSpecific;
- }
- public String getWorldName() {
- return this.world;
- }
- public ChatColor getPrefixColor() {
- return this.prefixcolor;
- }
- public World getWorld() {
- return Bukkit.getWorld(this.getWorldName());
- }
- public List<Player> getRecipients() {
- List<Player> var = new ArrayList<>();
- for (Player a : Bukkit.getOnlinePlayers()) {
- if (this.worldSpecific) {
- if (a.hasPermission("core.channels." + name) && a.getWorld().getName().equalsIgnoreCase(this.getWorldName())) {
- var.add(a);
- }
- } else {
- if (a.hasPermission("core.channels." + name)) {
- var.add(a);
- }
- }
- }
- return var;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setChar(char car) {
- this.channelchar = car;
- }
- public void setSpecific(boolean specific, World world) {
- this.worldSpecific = specific;
- this.world = world.getName();
- }
- public void setWorld(World world) {
- this.world = world.getName();
- }
- public void setColor(ChatColor color) {
- this.prefixcolor = color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement