From bd77c8266c36b4961f6f4f4c8bd55df446980a87 Mon Sep 17 00:00:00 2001 From: DroppingAnvil Date: Thu, 14 Nov 2019 02:27:29 -0600 Subject: [PATCH] Small bug fix + Code added to run randomized missions Signed-off-by: DroppingAnvil --- .../massivecraft/factions/cmd/CmdHome.java | 4 ++ .../factions/missions/MissionGUI.java | 62 ++++++++++++++++++- .../massivecraft/factions/util/Updater.java | 23 ++++++- .../massivecraft/factions/zcore/util/TL.java | 3 +- src/main/resources/config.yml | 17 ++++- 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index 24a31544..f5fba376 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -48,6 +48,10 @@ public class CmdHome extends FCommand { if (context.args.size() == 1) { Faction faction = context.argAsFaction(0); if (faction == null) return; + if (faction.getAccess(context.fPlayer, PermissableAction.HOME) != Access.ALLOW) { + context.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home"); + return; + } context.faction = faction; } diff --git a/src/main/java/com/massivecraft/factions/missions/MissionGUI.java b/src/main/java/com/massivecraft/factions/missions/MissionGUI.java index 29ad38b6..ad6c0b8f 100644 --- a/src/main/java/com/massivecraft/factions/missions/MissionGUI.java +++ b/src/main/java/com/massivecraft/factions/missions/MissionGUI.java @@ -13,7 +13,6 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; - import java.util.*; public class MissionGUI implements FactionGUI { @@ -44,6 +43,9 @@ public class MissionGUI implements FactionGUI { if (missionName == null) { return; } + //if (missionName.equals(plugin.color(FactionsPlugin.getInstance().getConfig().getString("Randomization.Start-Item.Disallowed.Name")))) { + //return; + //} if (fPlayer.getFaction().getMissions().containsKey(missionName)) { fPlayer.msg(TL.MISSION_MISSION_ACTIVE); return; @@ -63,6 +65,24 @@ public class MissionGUI implements FactionGUI { if (missionSection == null) { return; } + //Coming soon (: + //if (missionName.equals(plugin.color(FactionsPlugin.getInstance().getConfig().getString("Randomization.Start-Item.Allowed.Name")))) { + //Mission pickedMission = null; + //Set keys = plugin.getConfig().getConfigurationSection("Missions").getKeys(false); + //while (pickedMission == null) { + //Random r = new Random(); + //int pick = r.nextInt(keys.size() - 1); + //if (!keys.toArray()[pick].toString().equals("FillItem")) { + //missionName = keys.toArray()[pick].toString(); + //pickedMission = new Mission(missionName, plugin.getConfig().getString("Missions." + missionName + ".Mission.Type")); + //fPlayer.getFaction().getMissions().put(missionName, pickedMission); + //fPlayer.msg(TL.MISSION_MISSION_STARTED, fPlayer.describeTo(fPlayer.getFaction()), plugin.color(plugin.getConfig().getString("Missions." + missionName + ".Name"))); + //build(); + //fPlayer.getPlayer().openInventory(inventory); + //return; + //} + //} + //} Mission mission = new Mission(missionName, missionSection.getString("Type")); fPlayer.getFaction().getMissions().put(missionName, mission); fPlayer.msg(TL.MISSION_MISSION_STARTED, fPlayer.describeTo(fPlayer.getFaction()), plugin.color(section.getString("Name"))); @@ -110,6 +130,46 @@ public class MissionGUI implements FactionGUI { slots.put(slot, key); } } + if (plugin.getConfig().getBoolean("Randomization.Enabled")) { + ItemStack start = null; + ItemMeta meta; + start = XMaterial.matchXMaterial(plugin.getConfig().getString("Randomization.Start-Item.Allowed.Material")).parseItem(); + meta = start.getItemMeta(); + meta.setDisplayName(plugin.color(plugin.getConfig().getString("Randomization.Start-Item.Allowed.Name"))); + List loree = meta.getLore(); + loree.clear(); + for (String string : plugin.getConfig().getStringList("Randomization.Start-Item.Allowed.Lore")) { + loree.add(plugin.color(string)); + } + meta.setLore(loree); + start.setItemMeta(meta); + if (fPlayer.getFaction().getCompletedMissions().size() >= configurationSection.getKeys(false).size() - 1 && plugin.getConfig().getBoolean("DenyMissionsMoreThenOnce")) { + start = XMaterial.matchXMaterial(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Material")).parseItem(); + meta = start.getItemMeta(); + meta.setDisplayName(plugin.color(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Name"))); + List lore = meta.getLore(); + lore.clear(); + for (String string : plugin.getConfig().getStringList("Randomization.Start-Item.Disallowed.Lore")) { + lore.add(plugin.color(string).replace("%reason%", TL.MISSION_MISSION_ALL_COMPLETED.toString())); + } + meta.setLore(lore); + start.setItemMeta(meta); + } + if (fPlayer.getFaction().getMissions().size() >= plugin.getConfig().getInt("MaximumMissionsAllowedAtOnce")) { + start = XMaterial.matchXMaterial(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Material")).parseItem(); + meta = start.getItemMeta(); + meta.setDisplayName(plugin.color(plugin.getConfig().getString("Randomization.Start-Item.Disallowed.Name"))); + List lore = meta.getLore(); + lore.clear(); + for (String string : plugin.getConfig().getStringList("Randomization.Start-Item.Disallowed.Lore")) { + lore.add(plugin.color(string).replace("%reason%", FactionsPlugin.getInstance().txt.parse(TL.MISSION_MISSION_MAX_ALLOWED.toString(), plugin.getConfig().getInt("MaximumMissionsAllowedAtOnce")))); + } + meta.setLore(lore); + start.setItemMeta(meta); + } + inventory.setItem(plugin.getConfig().getInt("Randomization.Start-Item.Slot"), start); + slots.put(plugin.getConfig().getInt("Randomization.Start-Item.Slot"), start.getItemMeta().getDisplayName()); + } } public Inventory getInventory() { diff --git a/src/main/java/com/massivecraft/factions/util/Updater.java b/src/main/java/com/massivecraft/factions/util/Updater.java index f1fc065c..95678a8e 100644 --- a/src/main/java/com/massivecraft/factions/util/Updater.java +++ b/src/main/java/com/massivecraft/factions/util/Updater.java @@ -5,9 +5,11 @@ import org.bukkit.configuration.file.FileConfiguration; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public class Updater { - public static double currentVersion = 1.0; + public static double currentVersion = 1.1; public static void updateIfNeeded(FileConfiguration conf) { double version = conf.getDouble("Config-Version", 0); //Previous version @@ -17,6 +19,25 @@ public class Updater { conf.set("Config-Version", 1.0); version = 1.0; } + if (version == 1.0) { + FactionsPlugin.getInstance().log("Updating config from version 1.0 to 1.1"); + FactionsPlugin.getInstance().log("Adding randomization support for f missions..."); + conf.set("Randomization.Enabled", false); + conf.set("Randomization.Start-Item.Allowed.Name", "&aStart!"); + conf.set("Randomization.Start-Item.Allowed.Material", "GREEN_STAINED_GLASS_PANE"); + List lore = new ArrayList<>(); + lore.add("&aStart a new mission!"); + conf.set("Randomization.Start-Item.Allowed.Lore", lore); + conf.set("Randomization.Start-Item.Disallowed.Name", "&4Cannot start new mission"); + conf.set("Randomization.Start-Item.Disallowed.Material", "GRAY_STAINED_GLASS_PANE"); + lore.clear(); + lore.add("&4%reason%"); + conf.set("Randomization.Start-Item.Disallowed.Lore", lore); + conf.set("Randomization.Start-Item.Slot", 23); + conf.set("Config-Version", 1.1); + version = 1.1; + + } //End with save + reload try { conf.save(new File("plugins/Factions/config.yml")); diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index fdea58b2..a066685a 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -1036,7 +1036,8 @@ public enum TL { MISSION_MISSION_STARTED("&f%1$s &dstarted the %2$s &fmission"), MISSION_ALREAD_COMPLETED("&c&l[!] &7You may not restart a mission you have already completed"), MISSION_MISSION_ACTIVE("&c&l[!] &7This mission is currently active!"), - MISSION_MISSION_MAX_ALLOWED("&c&l[!] &7You may not have more then &b%1$s &7missions active at once."), + MISSION_MISSION_MAX_ALLOWED("&c&l[!] &7You may not have more than &b%1$s &7missions active at once."), + MISSION_MISSION_ALL_COMPLETED("&c&l[!] &7Your faction has completed all available missions."), MISSION_MISSION_FINISHED("&c&l[!] &7Your faction has successfully completed %1$s mission!"), COMMAND_MISSION_DESCRIPTION("Opens missions gui"), // F Global \\ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3c7a2f2e..8992309b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,4 @@ -Config-Version: 1.0 +Config-Version: 1.1 # SaberFactions by Driftay # Report issues: https://github.com/Driftay/Saber-Factions/issues/new # Live support: https://discord.gg/TFxWKeX @@ -753,6 +753,21 @@ Missions-Enabled: true Missions-GUI-Title: '&8&lFaction Missions' MaximumMissionsAllowedAtOnce: 1 Mission-Progress-Format: '&b&lProgression: &f{progress}&7/&e{total}' +Randomization: + Enabled: false + Start-Item: + # Allowed means that they are under maximum allowed missions at one AND if applicable they have not completed every mission more than once + Allowed: + Name: "&aStart!" + Material: GREEN_STAINED_GLASS_PANE + Lore: "&2Start a new mission!" + Disallowed: + # Placeholder %reason% supported throughout this section + Name: "&4Cannot start new mission" + Material: GRAY_STAINED_GLASS_PANE + Lore: + - '&4%reason%' + Slot: 23 DenyMissionsMoreThenOnce: true #this setting to true, means that if they complete a mission they cannot redo the same mission #Mission Types: KILL, MINE, PLACE, FISH, TAME, ENCHANT, CONSUME