Added configuration conversion!

This commit is contained in:
BuildTools 2019-09-12 15:53:52 -05:00
parent a25e134f20
commit 8ede39413c
4 changed files with 297 additions and 129 deletions

View File

@ -0,0 +1,27 @@
package com.massivecraft.factions.cmd.config;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdConvertConfig extends FCommand {
public CmdConvertConfig() {
super();
this.aliases.add("convertconfig");
this.permission = Permission.CONVERTCONFIG.node;
this.disableOnLock = false;
senderMustBePlayer = true;
}
@Override
public void perform() {
ConvertConfigHandler.convertconfig(fme.getPlayer());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CONVERTCONFIG_DESCRIPTION;
}
}

View File

@ -0,0 +1,137 @@
package com.massivecraft.factions.cmd.config;
import com.massivecraft.factions.P;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class ConvertConfigHandler {
static File savageConfigFile = new File("plugins/Factions/SavageFactions/config.yml");
static FileConfiguration sv = YamlConfiguration.loadConfiguration(savageConfigFile);
static File configFile = new File("plugins/Factions/config.yml");
static FileConfiguration sb = YamlConfiguration.loadConfiguration(configFile);
public static void setString(String s){
sb.set(s, sv.getString(s));
}
public static void setInt(String s){
sb.set(s, sv.getInt(s));
}
public static void setConfigSec(String s){
ConfigurationSection cs = sv.getConfigurationSection(s);
sb.set(s, cs);
}
static JavaPlugin plugin = JavaPlugin.getProvidingPlugin(P.class);
public static void setBoolean(String s){
sb.set(s, sv.getBoolean(s));
}
public static void convertconfig(Player player) {
if (new File("plugins/Factions/SavageFactions/config.yml").exists()) {
BukkitScheduler scheduler = plugin.getServer().getScheduler();
scheduler.scheduleAsyncDelayedTask(plugin, () -> {
File savageConfigFile = new File("plugins/Factions/SavageFactions/config.yml");
FileConfiguration sv = YamlConfiguration.loadConfiguration(savageConfigFile);
File configFile = new File("plugins/Factions/config.yml");
FileConfiguration sb = YamlConfiguration.loadConfiguration(configFile);
sb.set("ConfigConvertedFromSavageFactions", true);
sb.set("debug", sv.getBoolean("debug"));
ConfigurationSection ffe = sv.getConfigurationSection("findfactionsexploit");
sb.set("findfactionsexploit", ffe);
setString("default-relation");
ConfigurationSection pC = sv.getConfigurationSection("portals");
sb.set("portals", pC);
sb.set("maxwarps", sv.getInt("maxwarps"));
setConfigSec("warp-cost");
setBoolean("enable-faction-flight");
setBoolean("ffly.AutoEnable");
setInt("fly-falldamage-cooldown");
setBoolean("disable-pistons-in-territory");
setConfigSec("tooltips");
setConfigSec("scoreboard");
sb.set("scoreboard.also-send-chat", true);
setConfigSec("warmups");
setConfigSec("max-relations");
setInt("world-border.buffer");
setConfigSec("hcf");
sb.set("show", sv.getStringList("show"));
setBoolean("show-exempt");
sb.set("map", sv.getStringList("map"));
setConfigSec("list");
setBoolean("use-old-help");
setConfigSec("help");
setConfigSec("fperm-gui");
sb.set("fperm-gui.action.slots.check", 50);
setConfigSec("fwarp-gui");
setBoolean("faction-creation-broadcast");
setBoolean("faction-disband-broadcast");
setBoolean("See-Invisible-Faction-Members");
setConfigSec("frules");
setConfigSec("ftnt");
setBoolean("fpaypal.Enabled");
setBoolean("checkpoints.Enabled");
setConfigSec("fnear");
setConfigSec("ffocus");
setConfigSec("fvualt");
sb.set("fupgrades.MainMenu.DummyItem.slots", sv.getStringList("fupgrades.MainMenu.DummyItem.slots"));
setConfigSec("fupgrades.MainMenu.Crops.Crop-Boost");
setConfigSec("fupgrades.MainMenu.Crops.Cost");
sb.set("fupgrades.MainMenu.Crops.CropItem", sv.getConfigurationSection("fupgrades.MainMenu.Crops.DisplayItem"));
setConfigSec("fupgrades.MainMenu.EXP.EXP-Boost");
setConfigSec("fupgrades.MainMenu.EXP.Cost");
sb.set("fupgrades.MainMenu.EXP.EXPItem", sv.getConfigurationSection("fupgrades.MainMenu.EXP.DisplayItem"));
setConfigSec("fupgrades.MainMenu.Power.Power-Boost");
setConfigSec("fupgrades.MainMenu.Power.Cost");
sb.set("fupgrades.MainMenu.Power.PowerItem", sv.getConfigurationSection("fupgrades.MainMenu.Power.DisplayItem"));
List<Integer> p = new ArrayList();
p.add(sv.getInt("fupgrades.MainMenu.Power.DisplayItem.Slot"));
sb.set("fupgrades.MainMenu.Power.PowerItem.slots", p);
sb.set("fupgrades.MainMenu.Power.PowerItem.Amount", 1);
sb.set("fupgrades.MainMenu.Power.PowerItem.Damage", 0);
sb.set("fupgrades.MainMenu.Power.PowerItem.Slot", null);
sb.set("fupgrades.MainMenu.Members.Members-Limit", sv.getConfigurationSection("fupgrades.MainMenu.Members.Members-Boost"));
setConfigSec("fupgrades.MainMenu.Spawners.Spawner-Boost");
setConfigSec("fupgrades.MainMenu.Spawners.Cost");
sb.set("fupgrades.MainMenu.Spawners.SpawnerItem", sv.getConfigurationSection("fupgrades.MainMenu.Spawners.DisplayItem"));
setConfigSec("fupgrades.MainMenu.Chest.Chest-Size");
setConfigSec("fupgrades.MainMenu.Chest.Cost");
sb.set("fupgrades.MainMenu.Chest.ChestItem", sv.getConfigurationSection("fupgrades.MainMenu.Chest.DisplayItem"));
setConfigSec("fupgrades.MainMenu.Members.Cost");
sb.set("fupgrades.MainMenu.Members.MembersItem", sv.getConfigurationSection("fupgrades.MainMenu.Members.DisplayItem"));
sb.set("fupgrades.MainMenu.Members.MembersItem.Amount", 1);
sb.set("fupgrades.MainMenu.Members.MembersItem.Damage", 0);
if (sv.getString("fupgrades.MainMenu.Members.DisplayItem.Type").equalsIgnoreCase("PLAYER_HEAD"))
sb.set("fupgrades.MainMenu.Members.MembersItem.Type", "PAPER");
List<Integer> x = new ArrayList();
x.add(sv.getInt("fupgrades.MainMenu.Members.DisplayItem.Slot"));
sb.set("fupgrades.MainMenu.Members.MembersItem.slots", x);
sb.set("fupgrades.MainMenu.Members.MembersItem.Slot", null);
sb.set("fupgrades.MainMenu.Members.Members-Limit", sv.getConfigurationSection("fupgrades.MainMenu.Members.Members-Boost"));
setConfigSec("fbanners");
setConfigSec("Title");
setConfigSec("see-chunk");
setConfigSec("Tntfill");
try {
sb.save(configFile);
P.p.reloadConfig();
} catch (IOException e) {
player.sendMessage(TL.COMMAND_CONVERTCONFIG_FAIL.toString());
Bukkit.getLogger().log(Level.SEVERE, e.getStackTrace().toString());
}
player.sendMessage(TL.COMMAND_CONVERTCONFIG_SUCCESS.toString());
}, 0L);
} else {
player.sendMessage(TL.COMMAND_CONVERTCONFIG_FAILCONFIGMISSING.toString());
}
}
}

View File

@ -4,137 +4,136 @@ import com.massivecraft.factions.P;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public enum Permission { public enum Permission {
MANAGE_SAFE_ZONE("managesafezone"), MANAGE_SAFE_ZONE("managesafezone"),
MANAGE_WAR_ZONE("managewarzone"), MANAGE_WAR_ZONE("managewarzone"),
OWNERSHIP_BYPASS("ownershipbypass"), OWNERSHIP_BYPASS("ownershipbypass"),
ADMIN("admin"), ADMIN("admin"),
ALTS("alts"), ALTS("alts"),
ADMIN_ANY("admin.any"), ADMIN_ANY("admin.any"),
AHOME("ahome"), AHOME("ahome"),
ANNOUNCE("announce"), ANNOUNCE("announce"),
AUTOCLAIM("autoclaim"), AUTOCLAIM("autoclaim"),
AUTO_LEAVE_BYPASS("autoleavebypass"), AUTO_LEAVE_BYPASS("autoleavebypass"),
BAN("ban"), BAN("ban"),
BYPASS("bypass"), BYPASS("bypass"),
CHAT("chat"), CHAT("chat"),
CHATSPY("chatspy"), CHATSPY("chatspy"),
CHECK("check"), CLAIM("claim"),
CLAIM("claim"), CLAIMAT("claimat"),
CLAIMAT("claimat"), CLAIM_LINE("claim.line"),
CLAIM_LINE("claim.line"), CLAIM_RADIUS("claim.radius"),
CLAIM_RADIUS("claim.radius"), CONFIG("config"),
CONFIG("config"), CONVERT("convert"),
CONVERT("convert"), CREATE("create"),
CREATE("create"), CORNER("corner"),
CORNER("corner"), DEFAULTRANK("defaultrank"),
DEFAULTRANK("defaultrank"), DEINVITE("deinvite"),
DEINVITE("deinvite"), DESCRIPTION("description"),
DELHOME("delhome"), DISBAND("disband"),
DESCRIPTION("description"), DISBAND_ANY("disband.any"),
DISBAND("disband"), FLY("fly"),
DISBAND_ANY("disband.any"), FOCUS("focus"),
FLY("fly"), GRACE("grace"),
FOCUS("focus"), HELP("help"),
GRACE("grace"), HOME("home"),
HELP("help"), INVITE("invite"),
HOME("home"), INVSEE("invsee"),
INVITE("invite"), JOIN("join"),
INVSEE("invsee"), JOIN_ANY("join.any"),
JOIN("join"), JOIN_OTHERS("join.others"),
JOIN_ANY("join.any"), KICK("kick"),
JOIN_OTHERS("join.others"), KICK_ANY("kick.any"),
KICK("kick"), LEAVE("leave"),
KICK_ANY("kick.any"), LIST("list"),
LEAVE("leave"), LOCK("lock"),
LIST("list"), LOGOUT("logout"),
LOCK("lock"), MAP("map"),
LOGOUT("logout"), MAPHEIGHT("mapheight"),
MAP("map"), MOD("mod"),
MAPHEIGHT("mapheight"), COLEADER("coleader"),
MOD("mod"), MOD_ANY("mod.any"),
COLEADER("coleader"), COLEADER_ANY("coleader.any"),
MOD_ANY("mod.any"), MISSIONS("missions"),
COLEADER_ANY("coleader.any"), MODIFY_POWER("modifypower"),
MISSIONS("missions"), MONEY_BALANCE("money.balance"),
MODIFY_POWER("modifypower"), MONEY_BALANCE_ANY("money.balance.any"),
MONEY_BALANCE("money.balance"), MONEY_DEPOSIT("money.deposit"),
MONEY_BALANCE_ANY("money.balance.any"), MONEY_WITHDRAW("money.withdraw"),
MONEY_DEPOSIT("money.deposit"), MONEY_WITHDRAW_ANY("money.withdraw.any"),
MONEY_WITHDRAW("money.withdraw"), MONEY_F2F("money.f2f"),
MONEY_WITHDRAW_ANY("money.withdraw.any"), MONEY_F2P("money.f2p"),
MONEY_F2F("money.f2f"), MONEY_P2F("money.p2f"),
MONEY_F2P("money.f2p"), MONITOR_LOGINS("monitorlogins"),
MONEY_P2F("money.p2f"), NO_BOOM("noboom"),
MONITOR_LOGINS("monitorlogins"), OPEN("open"),
NO_BOOM("noboom"), OWNER("owner"),
OPEN("open"), OWNERLIST("ownerlist"),
OWNER("owner"), SET_PEACEFUL("setpeaceful"),
OWNERLIST("ownerlist"), SET_PERMANENT("setpermanent"),
SET_PEACEFUL("setpeaceful"), SET_PERMANENTPOWER("setpermanentpower"),
SET_PERMANENT("setpermanent"), SHOW_INVITES("showinvites"),
SET_PERMANENTPOWER("setpermanentpower"), PAYPAL("paypal"),
SHOW_INVITES("showinvites"), PAYPALSET("setpaypal"),
PAYPAL("paypal"), PERMISSIONS("permissions"),
PAYPALSET("setpaypal"), POWERBOOST("powerboost"),
PERMISSIONS("permissions"), POWER("power"),
POWERBOOST("powerboost"), POWER_ANY("power.any"),
POWER("power"), PROMOTE("promote"),
POWER_ANY("power.any"), RELATION("relation"),
PROMOTE("promote"), RELOAD("reload"),
RELATION("relation"), SAVE("save"),
RELOAD("reload"), SPAM("spam"),
SAVE("save"), SETHOME("sethome"),
SPAM("spam"), SETHOME_ANY("sethome.any"),
SETHOME("sethome"), SETSTRIKES("setstrikes"),
SETHOME_ANY("sethome.any"), SHOW("show"),
SETSTRIKES("setstrikes"), STATUS("status"),
SHOW("show"), STEALTH("stealth"),
STATUS("status"), STUCK("stuck"),
STEALTH("stealth"), TAG("tag"),
STUCK("stuck"), TNT("tnt"),
TAG("tag"), TITLE("title"),
TNT("tnt"), TITLE_COLOR("title.color"),
TITLE("title"), TOGGLE_ALLIANCE_CHAT("togglealliancechat"),
TITLE_COLOR("title.color"), UNCLAIM("unclaim"),
TOGGLE_ALLIANCE_CHAT("togglealliancechat"), UNCLAIM_ALL("unclaimall"),
UNCLAIM("unclaim"), VERSION("version"),
UNCLAIM_ALL("unclaimall"), SCOREBOARD("scoreboard"),
VERSION("version"), SEECHUNK("seechunk"),
SCOREBOARD("scoreboard"), SETWARP("setwarp"),
SEECHUNK("seechunk"), TOP("top"),
SETWARP("setwarp"), VIEWCHEST("viewchest"),
TOP("top"), ADDPOINTS("addpoints"),
VIEWCHEST("viewchest"), REMOVEPOINTS("removepoints"),
ADDPOINTS("addpoints"), SETPOINTS("setpoints"),
REMOVEPOINTS("removepoints"), VAULT("vault"),
SETPOINTS("setpoints"), GETVAULT("getvault"),
VAULT("vault"), SETMAXVAULTS("setmaxvaults"),
GETVAULT("getvault"), RULES("rules"),
SETMAXVAULTS("setmaxvaults"), CHECKPOINT("checkpoint"),
RULES("rules"), UPGRADES("upgrades"),
CHECKPOINT("checkpoint"), BANNER("banner"),
UPGRADES("upgrades"), TPBANNER("tpbanner"),
BANNER("banner"), KILLHOLOS("killholos"),
TPBANNER("tpbanner"), INSPECT("inspect"),
KILLHOLOS("killholos"), TNTFILL("tntfill"),
INSPECT("inspect"), COORD("coords"),
TNTFILL("tntfill"), SHOWCLAIMS("showclaims"),
COORD("coords"), WARP("warp"),
SHOWCLAIMS("showclaims"), CHEST("chest"),
WARP("warp"), CONVERTCONFIG("convertconfig");
CHEST("chest");
public final String node; public final String node;
Permission(final String node) { Permission(final String node) {
this.node = "factions." + node; this.node = "factions." + node;
} }
public boolean has(CommandSender sender, boolean informSenderIfNot) { public boolean has(CommandSender sender, boolean informSenderIfNot) {
return P.p.perm.has(sender, this.node, informSenderIfNot); return P.p.perm.has(sender, this.node, informSenderIfNot);
} }
public boolean has(CommandSender sender) { public boolean has(CommandSender sender) {
return has(sender, false); return has(sender, false);
} }
} }

View File

@ -889,6 +889,11 @@ public enum TL {
COMMAND_RULES_SET_SUCCESS("&cRule set successfully!"), COMMAND_RULES_SET_SUCCESS("&cRule set successfully!"),
COMMAND_RULES_CLEAR_SUCCESS("&cRule cleared successfully!"), COMMAND_RULES_CLEAR_SUCCESS("&cRule cleared successfully!"),
COMMAND_CONVERTCONFIG_DESCRIPTION("Convert your SavageFactions config to SaberFactions"),
COMMAND_CONVERTCONFIG_SUCCESS("&cConfiguration successfully converted"),
COMMAND_CONVERTCONFIG_FAIL("&cConfiguration conversion failed!"),
COMMAND_CONVERTCONFIG_FAILCONFIGMISSING("&cPlease ensure you have placed SavageFactions files in a folder called SavageFactions"),
// F Global \\ // F Global \\
COMMAND_F_GLOBAL_TOGGLE("&c&l[!] &7You have &b%1$s &7Global Chat"), COMMAND_F_GLOBAL_TOGGLE("&c&l[!] &7You have &b%1$s &7Global Chat"),
COMMAND_F_GLOBAL_DESCRIPTION("Toggle global chat and only allow factions based chats"), COMMAND_F_GLOBAL_DESCRIPTION("Toggle global chat and only allow factions based chats"),