Last active
December 27, 2015 06:49
-
-
Save Dinner1111/7284278 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package io.github.Dinner1111.ServerUtils; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.logging.Level; | |
import org.bukkit.configuration.file.FileConfiguration; | |
import org.bukkit.configuration.file.YamlConfiguration; | |
import org.bukkit.plugin.Plugin; | |
public class ConfigMethods { | |
private FileConfiguration customConfig = null; | |
private File customConfigFile = null; | |
private Plugin plg; | |
private String fileName; | |
private String path; | |
public ConfigMethods(String name, String path, Plugin pl){ | |
plg = pl; | |
fileName = name; | |
this.path = path; | |
} | |
public void reloadConfig() { | |
if (customConfigFile == null) { | |
customConfigFile = new File(plg.getDataFolder(), path); | |
if(!customConfigFile.exists()) { | |
try { | |
customConfigFile.createNewFile(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
customConfig = YamlConfiguration.loadConfiguration(customConfigFile); | |
InputStream defConfigStream = plg.getResource(fileName); | |
if (defConfigStream != null) { | |
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); | |
customConfig.setDefaults(defConfig); | |
} | |
} | |
public FileConfiguration getConfig() { | |
if (customConfig == null) { | |
reloadConfig(); | |
} | |
return customConfig; | |
} | |
public void saveConfig() { | |
if (customConfig == null || customConfigFile == null) { | |
return; | |
} | |
try { getConfig().save(customConfigFile); } catch (IOException ex) { | |
plg.getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex); | |
} | |
} | |
public void saveDefaultConfig() { | |
if (customConfigFile == null) { | |
try { | |
customConfigFile = new File(plg.getDataFolder(), path); | |
} catch (NullPointerException e) { | |
e.printStackTrace(); | |
} | |
if(!customConfigFile.exists()) { | |
try { | |
customConfigFile.createNewFile(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
if (!customConfigFile.exists()) { | |
plg.saveResource(fileName, false); | |
} | |
} | |
} |
This file contains hidden or 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
package io.github.Dinner1111.ServerUtils; | |
import java.util.List; | |
import org.bukkit.Bukkit; | |
import org.bukkit.ChatColor; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.player.AsyncPlayerChatEvent; | |
import org.bukkit.plugin.Plugin; | |
import com.google.common.collect.Lists; | |
public class MuteListener implements Listener { | |
Plugin pl; | |
SharedVariables sv; | |
Startup start; | |
ConfigMethods cm; | |
public MuteListener(Plugin plg, SharedVariables shared, Startup s, ConfigMethods c) { | |
pl = plg; | |
sv = shared; | |
start = s; | |
cm = c; | |
} | |
@EventHandler | |
public void playerFormat(AsyncPlayerChatEvent e) { | |
start.splitter(true, true, true, true); | |
if (sv.getIsMuted() == true) { | |
if (!e.getPlayer().isOp()) { | |
e.setCancelled(true); | |
} | |
} | |
if (sv.getIsBroadcasting() == true) { | |
if (e.getPlayer().isOp()) { | |
e.setCancelled(true); | |
Bukkit.broadcastMessage(ChatColor.DARK_GRAY + "[" + ChatColor.BLUE + "Broadcast" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY + e.getMessage()); | |
} else { | |
e.setCancelled(true); | |
} | |
} | |
if (!pl.getConfig().getConfigurationSection("worlds").getKeys(false).contains(e.getPlayer().getWorld().getName())) { | |
pl.getConfig().createSection("worlds." + e.getPlayer().getWorld().getName()); | |
pl.saveConfig(); | |
} | |
String message = e.getMessage(); | |
if (message.contains("%")) { | |
message = message.replace("%", "%%"); | |
} | |
if (message.contains("`")) { | |
if (e.getPlayer().hasPermission("Utils.Chat.Color")) { | |
List<String> colors = Lists.newArrayList("1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "l", "o", "k", "m", "n", "r"); | |
try { | |
if (colors.contains(message.charAt(message.indexOf("`") + 1) + "".toString()) && (message.indexOf("`") + 2) < message.length()) { | |
message = message.replace("`", "§"); | |
} | |
} catch (Exception exc) { } | |
} | |
} | |
String format = ChatColor.DARK_GRAY + "["; | |
if (!(pl.getConfig().getString("worlds." + e.getPlayer().getWorld().getName()) + ".color").equals("")) { | |
format += ChatColor.valueOf(pl.getConfig().getString("worlds." + e.getPlayer().getWorld().getName() + ".color").toUpperCase()); | |
} else { | |
format += ChatColor.GRAY; | |
} | |
if (!(pl.getConfig().getString("worlds." + e.getPlayer().getWorld().getName()) + ".alias").equals("")) { | |
format += pl.getConfig().getString("worlds." + e.getPlayer().getWorld().getName() + ".alias"); | |
} else { | |
format += e.getPlayer().getWorld().getName(); | |
} | |
format += ChatColor.DARK_GRAY + "] "; | |
if (!cm.getConfig().getString("players." + e.getPlayer().getName() + ".prefix-color").equals("") && !cm.getConfig().getString("players." + e.getPlayer().getName() + ".prefix").equals("")) { | |
format += ChatColor.valueOf(cm.getConfig().getString("players." + e.getPlayer().getName() + ".prefix-color").toUpperCase()) + cm.getConfig().getString("players." + e.getPlayer().getName() + ".prefix"); | |
} | |
if (!cm.getConfig().getString("players." + e.getPlayer().getName() + ".display-color").equals("")) { | |
format += ChatColor.valueOf(cm.getConfig().getString("players." + e.getPlayer().getName() + ".display-color").toUpperCase()) + e.getPlayer().getName(); | |
} else { | |
format += ChatColor.DARK_GRAY + e.getPlayer().getName(); | |
} | |
format += ChatColor.GRAY + ": " + ChatColor.WHITE; | |
e.setFormat(format + e.getMessage()); | |
} | |
} |
This file contains hidden or 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
package io.github.Dinner1111.ServerUtils; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.Plugin; | |
public class Startup { | |
Plugin plg; | |
ConfigMethods cm; | |
public Startup(Plugin pl, ConfigMethods c) { | |
plg = pl; | |
cm = c; | |
} | |
public void splitter(boolean admins, boolean ops, boolean builders, boolean guests) { | |
for (Player p : Bukkit.getOnlinePlayers()) { | |
if (admins) { | |
if (!(plg.getConfig().getStringList("admins") == null)) { | |
if (plg.getConfig().getStringList("admins").contains(p.getName())) { | |
this.admins(p); | |
} | |
} | |
} | |
if (ops) { | |
if (!(plg.getConfig().getStringList("ops") == null)) { | |
if (plg.getConfig().getStringList("ops").contains(p.getName())) { | |
this.ops(p); | |
} | |
} | |
} | |
if (builders) { | |
if (!(plg.getConfig().getStringList("builders") == null)) { | |
if (plg.getConfig().getStringList("builders").contains(p.getName())) { | |
this.builders(p); | |
} | |
} | |
} | |
if (guests) { | |
if (!(plg.getConfig().getStringList("guests") == null)) { | |
if (plg.getConfig().getStringList("guests").contains(p.getName())) { | |
this.guests(p); | |
} | |
} | |
} | |
} | |
} | |
public void admins(Player p) { | |
switch (p.getName()) { | |
case "dinner1111": | |
cm.getConfig().set("players." + p.getName() + ".display-color", "LIGHT_PURPLE"); | |
cm.getConfig().set("players." + p.getName() + ".prefix", "\u269D"); | |
cm.getConfig().set("players." + p.getName() + ".prefix-color", "GOLD"); | |
cm.getConfig().set("players." + p.getName() + ".op-override", false); | |
cm.getConfig().set("players." + p.getName() + ".deop-override", true); | |
break; | |
case "pepsidawg00": | |
cm.getConfig().set("players." + p.getName() + ".display-color", "AQUA"); | |
cm.getConfig().set("players." + p.getName() + ".prefix", "\u269D"); | |
cm.getConfig().set("players." + p.getName() + ".prefix-color", "GOLD"); | |
cm.getConfig().set("players." + p.getName() + ".op-override", false); | |
cm.getConfig().set("players." + p.getName() + ".deop-override", true); | |
break; | |
case "xannallax33": | |
cm.getConfig().set("players." + p.getName() + ".display-color", "RED"); | |
cm.getConfig().set("players." + p.getName() + ".prefix", "\u269D"); | |
cm.getConfig().set("players." + p.getName() + ".prefix-color", "GOLD"); | |
cm.getConfig().set("players." + p.getName() + ".op-override", false); | |
cm.getConfig().set("players." + p.getName() + ".deop-override", true); | |
break; | |
} | |
} | |
public void ops(Player p) { | |
cm.getConfig().set("players." + p.getName() + ".display-color", "RED"); | |
cm.getConfig().set("players." + p.getName() + ".prefix", "\u269D"); | |
cm.getConfig().set("players." + p.getName() + ".prefix-color", "DARK_RED"); | |
cm.getConfig().set("players." + p.getName() + ".deop-override", true); | |
} | |
public void builders(Player p) { | |
cm.getConfig().set("players." + p.getName() + ".display-color", "BLUE"); | |
cm.getConfig().set("players." + p.getName() + ".prefix", "\u2692"); | |
cm.getConfig().set("players." + p.getName() + ".prefix-color", "GRAY"); | |
} | |
public void guests(Player p) { | |
cm.getConfig().set("players." + p.getName() + ".display-color", "DARK_GRAY"); | |
cm.getConfig().set("players." + p.getName() + ".op-override", true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment