remove debug options and unused code
This commit is contained in:
parent
25a9e511c5
commit
a1bfac4cd6
|
|
@ -44,10 +44,8 @@ public class CustomMOTD extends JavaPlugin {
|
|||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// TODO Insert logic to be performed when the plugin is enabled
|
||||
try {
|
||||
CustomMOTD = this;
|
||||
//getLogger().info("Altitude Custom MOTD starting");
|
||||
|
||||
loadConfig();
|
||||
reloadConfig();
|
||||
|
|
@ -72,17 +70,13 @@ public class CustomMOTD extends JavaPlugin {
|
|||
counterfile = new MOTDConfig(this, "counter.yml", "counter.yml");
|
||||
counter = counterfile.getInt("counter");
|
||||
|
||||
//motd = motdfile.getStringList("MOTD");
|
||||
setmotd(motdfile.getString("MOTD"));
|
||||
//getLogger().info("setting motd to - " + motdfile.getString("MOTD"));
|
||||
//getLogger().info("setting Counter to - " + counter);
|
||||
for(String line : this.getConfig().getKeys(false)) {
|
||||
if(!line.equalsIgnoreCase("mcmmo")) {
|
||||
Options += line + " ";
|
||||
}
|
||||
}
|
||||
useproxyonlinecount = motdfile.getBoolean("useproxyonline", false);
|
||||
//getLogger().info(Options);
|
||||
}
|
||||
|
||||
public void reloadsettings() {
|
||||
|
|
@ -93,8 +87,6 @@ public class CustomMOTD extends JavaPlugin {
|
|||
counter = 0;
|
||||
counter = counterfile.getInt("counter");
|
||||
loadmotd(motdfile.getString("MOTD"));
|
||||
//getLogger().info("setting MOTD to - " + motdfile.getString("MOTD"));
|
||||
//getLogger().info("setting Counter to - " + counter);
|
||||
Options = "";
|
||||
|
||||
for(String line : this.getConfig().getKeys(false)) {
|
||||
|
|
@ -154,13 +146,10 @@ public class CustomMOTD extends JavaPlugin {
|
|||
|
||||
public void setmotd(String motdname) {
|
||||
if(motdname.equalsIgnoreCase("default") || motdname.equalsIgnoreCase("mcmmo")) {
|
||||
//getLogger().info("MOTD - Checking for MCMMO counter: " + counter);
|
||||
if(counter > 0) {
|
||||
getLogger().info(" - Activating mcmmo MOTD");
|
||||
List<String> lines = this.colorList(this.getConfig().getStringList("mcmmo"));
|
||||
//getLogger().info(lines.get(0) + "\n" + lines.get(1));
|
||||
motd = lines;
|
||||
//motd = this.getConfig().getStringList(motd + ".LINES");
|
||||
motdfile.set("MOTD", "default");
|
||||
motdfile.save();
|
||||
motdfile.reload();
|
||||
|
|
@ -168,9 +157,7 @@ public class CustomMOTD extends JavaPlugin {
|
|||
}
|
||||
else {
|
||||
List<String> lines = this.colorList(this.getConfig().getStringList(motdname));
|
||||
//getLogger().info(lines.get(0) + "\n" + lines.get(1));
|
||||
motd = lines;
|
||||
//motd = this.getConfig().getStringList(motd + ".LINES");
|
||||
motdfile.set("MOTD", "default");
|
||||
motdfile.save();
|
||||
motdfile.reload();
|
||||
|
|
@ -179,9 +166,7 @@ public class CustomMOTD extends JavaPlugin {
|
|||
}
|
||||
else {
|
||||
List<String> lines = this.colorList(this.getConfig().getStringList(motdname));
|
||||
//getLogger().info(lines.get(0) + "\n" + lines.get(1));
|
||||
motd = lines;
|
||||
//motd = this.getConfig().getStringList(motd + ".LINES");
|
||||
motdfile.set("MOTD", motdname);
|
||||
motdfile.save();
|
||||
motdfile.reload();
|
||||
|
|
@ -227,6 +212,6 @@ public class CustomMOTD extends JavaPlugin {
|
|||
private void registerCommands() {
|
||||
// TODO add all commands
|
||||
getCommand("custommotd").setExecutor(new custommotdCommand());
|
||||
//getCommand("customicon").setExecutor(new customIconCommand());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -74,30 +74,4 @@ public class custommotdCommand implements CommandExecutor/*, TabCompleter*/ {
|
|||
return false;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
if(args.length == 1) {
|
||||
commands.add("set");
|
||||
commands.add("reload");
|
||||
commands.add("counter");
|
||||
StringUtil.copyPartialMatches(args[0], commands, completions);
|
||||
}
|
||||
if(args.length == 2) {
|
||||
if (args[0].equals("set")) {
|
||||
completions = CustomMOTD.getmotdlist().stream()
|
||||
.filter(wrapper -> !wrapper.isRestricted())
|
||||
.map(wrapper -> wrapper.getTitle())
|
||||
.collect(Collectors.toList());
|
||||
} else if (args[0].equals("counter")) {
|
||||
commands.add("up");
|
||||
commands.add("down");
|
||||
StringUtil.copyPartialMatches(args[1], commands, completions);
|
||||
}
|
||||
}
|
||||
return completions;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package com.alttd.destro174.custommotd.listener;
|
||||
|
||||
import com.alttd.destro174.custommotd.CustomMOTD;
|
||||
import com.alttd.destro174.custommotd.MotdWrapper;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
|
|
@ -16,64 +14,4 @@ public class PingListener implements Listener {
|
|||
event.setMotd(CustomMOTD.motd.get(0) + "\n" + CustomMOTD.motd.get(1));
|
||||
}
|
||||
|
||||
/*private List<String> colorList(List<String> list){
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
for (String s : list) {
|
||||
lines.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||
}
|
||||
|
||||
return lines;
|
||||
}*/
|
||||
|
||||
/*@EventHandler
|
||||
public void onPing(ServerListPingEvent event) {
|
||||
//event.setMotd(instance.getActiveMotd());
|
||||
for(MotdWrapper wrapper : CustomMOTD.getmotdlist()) {
|
||||
if(wrapper.getTitle().equalsIgnoreCase("default")) {
|
||||
event.setMotd(ChatColor.translateAlternateColorCodes('&',
|
||||
centerText(wrapper.getLine1(), 60)
|
||||
+ "\n" + centerText(wrapper.getLine2(), 60)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
// lineLength = 80 (Chat Length)
|
||||
// lineLength = 45 (MOTD Length)
|
||||
public String centerText(String text, int lineLength) {
|
||||
char[] chars = text.toCharArray(); // Get a list of all characters in text
|
||||
boolean isBold = false;
|
||||
double length = 0;
|
||||
ChatColor pholder = null;
|
||||
for (int i = 0; i < chars.length; i++) { // Loop through all characters
|
||||
// Check if the character is a ColorCode..
|
||||
if (chars[i] == '&' && chars.length != (i + 1) && (pholder = ChatColor.getByChar(chars[i + 1])) != null) {
|
||||
if (pholder != ChatColor.UNDERLINE && pholder != ChatColor.ITALIC
|
||||
&& pholder != ChatColor.STRIKETHROUGH && pholder != ChatColor.MAGIC) {
|
||||
isBold = (chars[i + 1] == 'l'); // Setting bold to true or false, depending on if the ChatColor is Bold.
|
||||
length--; // Removing one from the length, of the string, because we don't wanna count color codes.
|
||||
i += isBold ? 1 : 0;
|
||||
}
|
||||
} else {
|
||||
// If the character is not a color code:
|
||||
length++; // Adding a space
|
||||
length += (isBold ? (chars[i] != ' ' ? 0.1555555555555556 : 0) : 0); // Adding 0.156 spaces if the character is bold.
|
||||
}
|
||||
}
|
||||
|
||||
double spaces = (lineLength - length) / 3; // Getting the spaces to add by (max line length - length) / 2
|
||||
|
||||
// Adding the spaces
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < spaces; i++) {
|
||||
builder.append(' ');
|
||||
}
|
||||
String copy = builder.toString();
|
||||
builder.append(text).append(copy);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user