From 06633a977c96ce1dba148675592b9566aa10a98a Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 10:28:31 +0100 Subject: [PATCH 01/19] TR-9 added some slimefun integration --- pom.xml | 6 +++ .../townyresources/TownyResources.java | 37 +++++++++++++++++-- .../TownResourceCollectionController.java | 19 ++++++++++ src/main/resources/plugin.yml | 2 +- 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9be6102..b04ce0d 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,12 @@ 2.3-SNAPSHOT provided + + com.github.TheBusyBiscuit + Slimefun4 + RC-15 + provided + diff --git a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java index 15d00f7..959a5dd 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java +++ b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java @@ -3,6 +3,7 @@ import com.gmail.goosius.siegewar.settings.SiegeWarSettings; import com.palmergames.bukkit.towny.exceptions.TownyException; import com.palmergames.bukkit.util.Version; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.townyadvanced.townyresources.commands.TownyResourcesAdminCommand; import io.github.townyadvanced.townyresources.commands.TownyResourcesCommand; import io.github.townyadvanced.townyresources.controllers.PlayerExtractionLimitsController; @@ -11,7 +12,11 @@ import io.github.townyadvanced.townyresources.listeners.*; import io.github.townyadvanced.townyresources.settings.TownyResourcesSettings; import io.github.townyadvanced.townyresources.settings.TownyResourcesTranslation; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.api.Slimefun; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import org.bukkit.Bukkit; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -25,6 +30,7 @@ public class TownyResources extends JavaPlugin { private static boolean siegeWarInstalled; private static boolean dynmapTownyInstalled; private static boolean languageUtilsInstalled; + private static boolean slimeFunInstalled; @Override public void onEnable() { @@ -165,10 +171,14 @@ public boolean isDynmapTownyInstalled() { public boolean isSiegeWarInstalled() { return siegeWarInstalled; } - + public boolean isLanguageUtilsInstalled() { return languageUtilsInstalled; } + + public boolean isSlimeFunInstalled() { + return slimeFunInstalled; + } private String getTownyVersion() { return Bukkit.getPluginManager().getPlugin("Towny").getDescription().getVersion(); @@ -188,9 +198,30 @@ private void setupIntegrationsWithOtherPlugins() { //Determine if other plugins are installed Plugin siegeWar = Bukkit.getPluginManager().getPlugin("SiegeWar"); siegeWarInstalled = siegeWar != null; + if(siegeWarInstalled) + info("SiegeWar Integration Enabled"); + else + info("SiegeWar Integration Not Enabled"); + Plugin dynmapTowny = Bukkit.getPluginManager().getPlugin("Dynmap-Towny"); - dynmapTownyInstalled = dynmapTowny!= null; + dynmapTownyInstalled = dynmapTowny != null; + if(dynmapTownyInstalled) + info("DynmapTowny Integration Enabled"); + else + info("DynmapTowny Integration Not Enabled"); + Plugin languageUtils = Bukkit.getPluginManager().getPlugin("LanguageUtils"); - languageUtilsInstalled = languageUtils!= null; + languageUtilsInstalled = languageUtils != null; + if(languageUtilsInstalled) + info("LanguageUtils Integration Enabled"); + else + info("LanguageUtils Integration Not Enabled"); + + Plugin slimeFun = Bukkit.getPluginManager().getPlugin("slimefun"); + slimeFunInstalled = slimeFun != null; + if(slimeFunInstalled) + info("Slimefun Integration Enabled"); + else + info("Slimefun Integration Not Enabled"); } } diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java index 7e38bb2..c685274 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java @@ -4,9 +4,11 @@ import com.palmergames.bukkit.towny.object.Government; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; +import io.github.townyadvanced.townyresources.TownyResources; import io.github.townyadvanced.townyresources.metadata.TownyResourcesGovernmentMetaDataController; import io.github.townyadvanced.townyresources.settings.TownyResourcesTranslation; import io.github.townyadvanced.townyresources.util.TownyResourcesMessagingUtil; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -20,6 +22,23 @@ public class TownResourceCollectionController { public static synchronized void collectAvailableTownResources(Player player, Town town, Map availableForCollection) { + + if(TownyResources.getPlugin().isSlimeFunInstalled()) { + SlimefunItem slimeFunItem = SlimefunItem.getByID("OIL_BUCKET"); + //If null, return + //Create the stack to drop + ItemStack itemStack = slimeFunItem.getRecipeOutput(); + //Set the amount + itemStack.setAmount(1); + //Drop stuff near player + Towny.getPlugin().getServer().getScheduler().runTask(Towny.getPlugin(), new Runnable() { + public void run() { + Location location = player.getLocation(); + player.getWorld().dropItemNaturally(location, itemStack); + } + }); + } + //Collect resources collectAvailableGovernmentResources(player, town, availableForCollection); //Notify Player diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7be4cac..799136e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,7 +6,7 @@ author: Goosius website: 'https://github.com/TownyAdvanced/TownyResources' prefix: ${project.artifactId} depend: [Towny] -softdepend: [SiegeWar,Dynmap-Towny,LanguageUtils] +softdepend: [SiegeWar,Dynmap-Towny,LanguageUtils,Slimefun] loadbefore: [SiegeWar] description: This is an add-on plugin for Towny, which gives each town a unique set of automatically-extracted resources, and then protects the economic value of those resources with moderate limits to player resource extraction. From 5baef09b75023960baaf63adff916740445ad483 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 10:33:38 +0100 Subject: [PATCH 02/19] TR-9 typo fix --- .../townyadvanced/townyresources/TownyResources.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java index 959a5dd..84f1e4d 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java +++ b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java @@ -1,9 +1,7 @@ package io.github.townyadvanced.townyresources; -import com.gmail.goosius.siegewar.settings.SiegeWarSettings; import com.palmergames.bukkit.towny.exceptions.TownyException; import com.palmergames.bukkit.util.Version; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.townyadvanced.townyresources.commands.TownyResourcesAdminCommand; import io.github.townyadvanced.townyresources.commands.TownyResourcesCommand; import io.github.townyadvanced.townyresources.controllers.PlayerExtractionLimitsController; @@ -12,11 +10,7 @@ import io.github.townyadvanced.townyresources.listeners.*; import io.github.townyadvanced.townyresources.settings.TownyResourcesSettings; import io.github.townyadvanced.townyresources.settings.TownyResourcesTranslation; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.api.Slimefun; -import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import org.bukkit.Bukkit; -import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -217,7 +211,7 @@ private void setupIntegrationsWithOtherPlugins() { else info("LanguageUtils Integration Not Enabled"); - Plugin slimeFun = Bukkit.getPluginManager().getPlugin("slimefun"); + Plugin slimeFun = Bukkit.getPluginManager().getPlugin("Slimefun"); slimeFunInstalled = slimeFun != null; if(slimeFunInstalled) info("Slimefun Integration Enabled"); From 32fb021e05113e1501981f723e48e61a7a5d5fdf Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 11:35:19 +0100 Subject: [PATCH 03/19] Added full slimefun support --- .../townyresources/TownyResources.java | 21 +++++----- .../commands/TownyResourcesCommand.java | 6 +-- .../TownResourceCollectionController.java | 42 +++++++++++++------ .../TownResourceDiscoveryController.java | 8 ++-- .../TownResourceOffersController.java | 6 +-- .../TownResourceProductionController.java | 36 ++++++++-------- ...ResourcesGovernmentMetaDataController.java | 32 +++++++------- .../objects/ResourceOfferCategory.java | 6 +-- .../settings/TownyResourcesSettings.java | 25 ++++++++--- .../util/TownyResourcesMessagingUtil.java | 30 ++++++++----- 10 files changed, 125 insertions(+), 87 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java index 84f1e4d..0c3df6e 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java +++ b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java @@ -57,7 +57,6 @@ public boolean loadAll() { try { printSickASCIIArt(); townyVersionCheck(); - setupIntegrationsWithOtherPlugins(); //Load settings and languages TownyResourcesSettings.loadConfig(this.getDataFolder().getPath() + File.separator + "config.yml", getVersion()); TownyResourcesTranslation.loadLanguage(this.getDataFolder().getPath() + File.separator , "english.yml"); @@ -68,6 +67,8 @@ public boolean loadAll() { //Load commands and listeners registerCommands(); registerListeners(); + //Setup integrations with other plugins + setupIntegrationsWithOtherPlugins(); } catch (TownyException te) { severe(te.getMessage()); severe("TownyResources failed to load! Disabling!"); @@ -203,19 +204,19 @@ private void setupIntegrationsWithOtherPlugins() { info("DynmapTowny Integration Enabled"); else info("DynmapTowny Integration Not Enabled"); - - Plugin languageUtils = Bukkit.getPluginManager().getPlugin("LanguageUtils"); - languageUtilsInstalled = languageUtils != null; - if(languageUtilsInstalled) - info("LanguageUtils Integration Enabled"); - else - info("LanguageUtils Integration Not Enabled"); - + Plugin slimeFun = Bukkit.getPluginManager().getPlugin("Slimefun"); slimeFunInstalled = slimeFun != null; if(slimeFunInstalled) info("Slimefun Integration Enabled"); else - info("Slimefun Integration Not Enabled"); + info("Slimefun Integration Not Enabled"); + + Plugin languageUtils = Bukkit.getPluginManager().getPlugin("LanguageUtils"); + languageUtilsInstalled = languageUtils != null; + if(languageUtilsInstalled) + info("LanguageUtils Integration Enabled"); + else + info("LanguageUtils Integration Not Enabled"); } } diff --git a/src/main/java/io/github/townyadvanced/townyresources/commands/TownyResourcesCommand.java b/src/main/java/io/github/townyadvanced/townyresources/commands/TownyResourcesCommand.java index cc0fdd4..96cae57 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/commands/TownyResourcesCommand.java +++ b/src/main/java/io/github/townyadvanced/townyresources/commands/TownyResourcesCommand.java @@ -98,7 +98,7 @@ private void parseSurveyCommand(Player player) throws TownyException{ //Check if there are resources left to discover at the town Town town = playerWorldCoord.getTownBlock().getTown(); - List discoveredResources = TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town); + List discoveredResources = TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town); List costPerResourceLevel = TownyResourcesSettings.getSurveyCostsPerResourceLevel(); List requiredNumTownblocksPerResourceLevel = TownyResourcesSettings.getSurveyNumTownblocksRequirementsPerResourceLevel(); if(discoveredResources.size() >= costPerResourceLevel.size()) @@ -145,7 +145,7 @@ private static void parseTownCollectCommand(Player player) throws TownyException throw new TownyException(TownyResourcesTranslation.of("msg_err_cannot_towncollect_not_in_own_town")); //Ensure some resources are available - Map availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(town); + Map availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(town); if(availableForCollection.isEmpty()) throw new TownyException(TownyResourcesTranslation.of("msg_err_cannot_towncollect_no_resources_available")); @@ -175,7 +175,7 @@ private static void parseNationCollectCommand(Player player) throws TownyExcepti throw new TownyException(TownyResourcesTranslation.of("msg_err_cannot_nationcollect_not_in_capital")); //Ensure some resources are available - Map availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(nation); + Map availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(nation); if(availableForCollection.isEmpty()) throw new TownyException(TownyResourcesTranslation.of("msg_err_cannot_nationcollect_no_resources_available")); diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java index c685274..1fce54a 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java @@ -4,6 +4,7 @@ import com.palmergames.bukkit.towny.object.Government; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.townyadvanced.townyresources.TownyResources; import io.github.townyadvanced.townyresources.metadata.TownyResourcesGovernmentMetaDataController; import io.github.townyadvanced.townyresources.settings.TownyResourcesTranslation; @@ -21,10 +22,10 @@ public class TownResourceCollectionController { - public static synchronized void collectAvailableTownResources(Player player, Town town, Map availableForCollection) { + public static synchronized void collectAvailableTownResources(Player player, Town town, Map availableForCollection) { if(TownyResources.getPlugin().isSlimeFunInstalled()) { - SlimefunItem slimeFunItem = SlimefunItem.getByID("OIL_BUCKET"); + SlimefunItem slimeFunItem = SlimefunItem.getByID("BUCKET_OF_OIL"); //If null, return //Create the stack to drop ItemStack itemStack = slimeFunItem.getRecipeOutput(); @@ -45,7 +46,7 @@ public void run() { TownyResourcesMessagingUtil.sendMsg(player, TownyResourcesTranslation.of("resource.towncollect.success")); } - public static synchronized void collectAvailableNationResources(Player player, Nation nation, Map availableForCollection) { + public static synchronized void collectAvailableNationResources(Player player, Nation nation, Map availableForCollection) { //Collect resources collectAvailableGovernmentResources(player, nation, availableForCollection); //Notify Player @@ -61,25 +62,40 @@ public static synchronized void collectAvailableNationResources(Player player, N * @param government the government * @param availableForCollection the list of currently available resources */ - private static synchronized void collectAvailableGovernmentResources(Player player, Government government, Map availableForCollection) { + private static synchronized void collectAvailableGovernmentResources(Player player, Government government, Map availableForCollection) { List itemStackList = new ArrayList<>(); //Calculate stuff to give player + String materialName; Material material; int amount; ItemStack itemStack; - for(Map.Entry mapEntry: availableForCollection.entrySet()) { - material = mapEntry.getKey(); - if(material == null) { - TownyResourcesMessagingUtil.sendErrorMsg(player, TownyResourcesTranslation.of("msg_err_cannot_collect_unknown_material", material)); - continue; - } + for(Map.Entry mapEntry: availableForCollection.entrySet()) { + materialName = mapEntry.getKey(); amount = mapEntry.getValue(); - itemStack = new ItemStack(material, amount); - itemStackList.add(itemStack); + + //Try creating a regular MC itemstack + material = Material.getMaterial(materialName); + if(material != null) { + itemStack = new ItemStack(material, amount); + itemStackList.add(itemStack); + } + + //Try creating a slimefun itemstack + if(TownyResources.getPlugin().isSlimeFunInstalled()) { + SlimefunItem slimeFunItem = SlimefunItem.getByID(materialName); + if(slimeFunItem != null) { + itemStack = slimeFunItem.getRecipeOutput(); + itemStack.setAmount(amount); + itemStackList.add(itemStack); + } + } + + //Unknown material. Send error message + TownyResourcesMessagingUtil.sendErrorMsg(player, TownyResourcesTranslation.of("msg_err_cannot_collect_unknown_material", material)); } - //Drop stuff near player + //Drop all collected itemstacks near player Towny.getPlugin().getServer().getScheduler().runTask(Towny.getPlugin(), new Runnable() { public void run() { Location location = player.getLocation(); diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java index b0b6d5c..fb3c0f6 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java @@ -29,7 +29,7 @@ public class TownResourceDiscoveryController { * @param alreadyDiscoveredMaterials list of the town's already-discovered materials * @throws TownyException */ - public static void discoverNewResource(Resident resident, Town town, List alreadyDiscoveredMaterials) throws TownyException{ + public static void discoverNewResource(Resident resident, Town town, List alreadyDiscoveredMaterials) throws TownyException{ /* * Generate a list of candidate categories * This list will be comprised of all resource offer categories, except those of already discovered materials @@ -38,7 +38,7 @@ public static void discoverNewResource(Resident resident, Town town, List discoveredMaterials = new ArrayList<>(alreadyDiscoveredMaterials); + List discoveredMaterials = new ArrayList<>(alreadyDiscoveredMaterials); discoveredMaterials.add(winningMaterial); TownyResourcesGovernmentMetaDataController.setDiscovered(town, discoveredMaterials); town.save(); diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceOffersController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceOffersController.java index aa6f185..6bbda24 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceOffersController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceOffersController.java @@ -14,7 +14,7 @@ public class TownResourceOffersController { private static List resourceOfferCategoryList = new ArrayList<>(); - private static Map materialToResourceOfferCategoryMap = new HashMap<>(); + private static Map materialToResourceOfferCategoryMap = new HashMap<>(); public static void loadAllResourceOfferCategories() throws TownyException { //Load all categories @@ -23,7 +23,7 @@ public static void loadAllResourceOfferCategories() throws TownyException { materialToResourceOfferCategoryMap.clear(); //Put each material on the map for(ResourceOfferCategory category: resourceOfferCategoryList) { - for(Material material: category.getMaterialsInCategory()) { + for(String material: category.getMaterialsInCategory()) { materialToResourceOfferCategoryMap.put(material, category); } } @@ -34,7 +34,7 @@ public static List getResourceOfferCategoryList() { return resourceOfferCategoryList; } - public static Map getMaterialToResourceOfferCategoryMap() { + public static Map getMaterialToResourceOfferCategoryMap() { return materialToResourceOfferCategoryMap; } } diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceProductionController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceProductionController.java index cc150bf..1d985c6 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceProductionController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceProductionController.java @@ -51,12 +51,12 @@ private static void recalculateProductionForAllTowns() { static void recalculateProductionForOneTown(Town town) { try { //Get discovered resources - List discoveredResources = new ArrayList<>(TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town)); + List discoveredResources = new ArrayList<>(TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town)); //Remove any discovered resources which are no longer on offer - Map allOffers = TownResourceOffersController.getMaterialToResourceOfferCategoryMap(); - List resourcesToRemove = new ArrayList<>(); - for(Material resource: discoveredResources) { + Map allOffers = TownResourceOffersController.getMaterialToResourceOfferCategoryMap(); + List resourcesToRemove = new ArrayList<>(); + for(String resource: discoveredResources) { if(!allOffers.containsKey(resource)) { resourcesToRemove.add(resource); } @@ -71,7 +71,7 @@ static void recalculateProductionForOneTown(Town town) { double townCutNormalized = calculateTownCutNormalized(town); //Build the town production map - Map townProduction = calculateProduction(town, townCutNormalized); + Map townProduction = calculateProduction(town, townCutNormalized); //Save data TownyResourcesGovernmentMetaDataController.setDailyProduction(town, townProduction); @@ -133,15 +133,15 @@ static void recalculateProductionForOneNation(Nation nation) { //Take resources from towns and give to nation double nationCutNormalized = TownyResourcesSettings.getTownResourcesProductionNationTaxNormalized(); - Map nationProduction = new HashMap<>(); - Map resourcesTakenFromTown; - Material takenResource; + Map nationProduction = new HashMap<>(); + Map resourcesTakenFromTown; + String takenResource; int takenQuantity; for(Town town: townsToTakeFrom) { //Take resources from town resourcesTakenFromTown = calculateProduction(town, nationCutNormalized); //Add resources to nation - for(Map.Entry resourceTakenFromTown: resourcesTakenFromTown.entrySet()) { + for(Map.Entry resourceTakenFromTown: resourcesTakenFromTown.entrySet()) { takenResource = resourceTakenFromTown.getKey(); takenQuantity = resourceTakenFromTown.getValue(); if(nationProduction.containsKey(takenResource)) { @@ -167,19 +167,19 @@ static void recalculateProductionForOneNation(Nation nation) { * @param cutNormalized the cut of the resource to return * @return the production as a map, with each value multiplied by the given cutNormalized value */ - private static Map calculateProduction(Town town, double cutNormalized) { + private static Map calculateProduction(Town town, double cutNormalized) { //Get all offers - Map allOffers = TownResourceOffersController.getMaterialToResourceOfferCategoryMap(); + Map allOffers = TownResourceOffersController.getMaterialToResourceOfferCategoryMap(); //Get discovered resources - List discoveredResources = new ArrayList<>(TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town)); + List discoveredResources = new ArrayList<>(TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town)); //Get configured resource level bonuses List normalizedBonusesPerResourceLevel = TownyResourcesSettings.getNormalizedProductionBonusesPerResourceLevel(); //Calculate the production - Map production = new HashMap<>(); - Material material; + Map production = new HashMap<>(); + String material; double baseProducedAmount; int finalProducedAmount; @@ -237,23 +237,23 @@ private static void produceAllResourcesForAllNations() { private static boolean produceResourcesForOneGovernment(Government government) { try { //Get daily production - Map townDailyProduction = TownyResourcesGovernmentMetaDataController.getDailyProductionAsMap(government); + Map townDailyProduction = TownyResourcesGovernmentMetaDataController.getDailyProductionAsMap(government); if(townDailyProduction.isEmpty()) return false; //Get the list of resources which are already available for collection - Map availableResources = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(government); + Map availableResources = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(government); //Get storage Limit modifier int storageLimitModifier = TownyResourcesSettings.getStorageLimitModifier(); //Produce resources - Material resource; + String resource; int quantityToProduce; int currentQuantity; int storageLimit; - for(Map.Entry townProductionEntry: townDailyProduction.entrySet()) { + for(Map.Entry townProductionEntry: townDailyProduction.entrySet()) { resource = townProductionEntry.getKey(); quantityToProduce =townProductionEntry.getValue(); if(availableResources.containsKey(resource)) { diff --git a/src/main/java/io/github/townyadvanced/townyresources/metadata/TownyResourcesGovernmentMetaDataController.java b/src/main/java/io/github/townyadvanced/townyresources/metadata/TownyResourcesGovernmentMetaDataController.java index 74c8378..a6c3bdd 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/metadata/TownyResourcesGovernmentMetaDataController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/metadata/TownyResourcesGovernmentMetaDataController.java @@ -47,16 +47,14 @@ public static String getDiscovered(Government government) { * @param town the town * @return the town's discovered resources, as an IMMUTABLE list */ - public static List getDiscoveredAsList(Town town) { + public static List getDiscoveredAsList(Town town) { String discoveredMaterialsString = getDiscovered(town); if(discoveredMaterialsString.isEmpty()) { return Collections.emptyList(); } else { String[] discoveredMaterialsArray = discoveredMaterialsString.split(","); - List result = new ArrayList<>(); - for(String discoveredMaterial: discoveredMaterialsArray) { - result.add(Material.getMaterial(discoveredMaterial)); - } + List result = new ArrayList<>(); + result.addAll(Arrays.asList(discoveredMaterialsArray)); return result; } } @@ -96,13 +94,13 @@ public static List getDiscoveredResources(Town town) { */ - public static void setDiscovered(Government government, List discoveredResources) { + public static void setDiscovered(Government government, List discoveredResources) { //Convert materials list to single string StringBuilder metadataStringBuilder = new StringBuilder(); for(int i= 0; i < discoveredResources.size();i++) { if(i !=0) metadataStringBuilder.append(", "); - metadataStringBuilder.append(discoveredResources.get(i).toString()); //TODO nice format pls + metadataStringBuilder.append(discoveredResources.get(i)); } setDiscovered(government, metadataStringBuilder.toString()); } @@ -119,16 +117,16 @@ public static String getAvailableForCollection(Government government) { return MetaDataUtil.getSdf(government, availableForCollectionMetadataKey).replaceAll(" ",""); } - public static Map getDailyProductionAsMap(Government town) { + public static Map getDailyProductionAsMap(Government town) { return getResourceQuantitiesStringAsMap(getDailyProduction(town)); } - public static Map getAvailableForCollectionAsMap(Government town) { + public static Map getAvailableForCollectionAsMap(Government town) { return getResourceQuantitiesStringAsMap(getAvailableForCollection(town)); } - private static Map getResourceQuantitiesStringAsMap(String resourceQuantitiesString) { - Map result = new HashMap<>(); + private static Map getResourceQuantitiesStringAsMap(String resourceQuantitiesString) { + Map result = new HashMap<>(); if(!resourceQuantitiesString.isEmpty()) { String[] resourceQuantitiesArray = resourceQuantitiesString.split(","); String[] resourceQuantityPair; @@ -138,23 +136,23 @@ private static Map getResourceQuantitiesStringAsMap(String re resourceQuantityPair = resourceQuantityString.split("-"); amount = Integer.parseInt(resourceQuantityPair[0]); resource = resourceQuantityPair[1]; - result.put(Material.getMaterial(resource), amount); + result.put(resource, amount); } } return result; } - public static void setAvailableForCollection(Government government, Map availableForCollection) { + public static void setAvailableForCollection(Government government, Map availableForCollection) { setResourceQuantitiesString(government, availableForCollectionMetadataKey, availableForCollection); } - public static void setDailyProduction(Government government, Map dailyProduction) { + public static void setDailyProduction(Government government, Map dailyProduction) { setResourceQuantitiesString(government, dailyProductionMetadataKey, dailyProduction); } - private static void setResourceQuantitiesString(Government government, String metadataKey, Map resourceQuantitiesMap) { + private static void setResourceQuantitiesString(Government government, String metadataKey, Map resourceQuantitiesMap) { //Order map by descending values - Map sortedResourceQuantitiesMap = resourceQuantitiesMap.entrySet().stream() + Map sortedResourceQuantitiesMap = resourceQuantitiesMap.entrySet().stream() .sorted(Comparator.comparingInt(e -> -e.getValue())) .collect(Collectors.toMap( Map.Entry::getKey, @@ -165,7 +163,7 @@ private static void setResourceQuantitiesString(Government government, String me //Create list List resourceQuantitiesList = new ArrayList<>(); - for(Map.Entry resourceQuantity: sortedResourceQuantitiesMap.entrySet()) { + for(Map.Entry resourceQuantity: sortedResourceQuantitiesMap.entrySet()) { resourceQuantitiesList.add(resourceQuantity.getValue() + "-" + resourceQuantity.getKey()); } setResourceQuantitiesString(government, metadataKey, resourceQuantitiesList); diff --git a/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java b/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java index d2091f1..0eded24 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java +++ b/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java @@ -8,9 +8,9 @@ public class ResourceOfferCategory { private final String name; private final int discoveryWeight; private final int baseAmountItems; - private final List materialsInCategory; + private final List materialsInCategory; - public ResourceOfferCategory(String name, int discoveryWeight, int baseOfferItems, List materialsInCategory) { + public ResourceOfferCategory(String name, int discoveryWeight, int baseOfferItems, List materialsInCategory) { this.name = name; this.discoveryWeight = discoveryWeight; this.baseAmountItems = baseOfferItems; @@ -25,7 +25,7 @@ public int getBaseAmountItems() { return baseAmountItems; } - public List getMaterialsInCategory() { + public List getMaterialsInCategory() { return materialsInCategory; } diff --git a/src/main/java/io/github/townyadvanced/townyresources/settings/TownyResourcesSettings.java b/src/main/java/io/github/townyadvanced/townyresources/settings/TownyResourcesSettings.java index 1ab1172..63d86cb 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/settings/TownyResourcesSettings.java +++ b/src/main/java/io/github/townyadvanced/townyresources/settings/TownyResourcesSettings.java @@ -11,7 +11,9 @@ import io.github.townyadvanced.townyresources.objects.ResourceOffer; import io.github.townyadvanced.townyresources.objects.ResourceOfferCategory; import io.github.townyadvanced.townyresources.util.FileMgmt; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; public class TownyResourcesSettings { private static CommentedConfiguration config, newConfig; @@ -175,7 +177,8 @@ public static List getResourceOfferCategories() throws To double categoryBaseAmountStacks; int categoryBaseAmountItems; Material material; - List materialsInCategory = new ArrayList<>(); + List materialsInCategory; + String materialName; ResourceOfferCategory resourceOfferCategory; while (matcher.find()) { @@ -202,13 +205,13 @@ public static List getResourceOfferCategories() throws To //Read Materials materialsInCategory = new ArrayList<>(); for(int i = 3; i < categoryAsArray.length; i++) { - material = Material.getMaterial(categoryAsArray[i].trim()); - if(material == null) { + materialName = categoryAsArray[i].trim(); + if(!isValidMaterial(materialName)) { TownyResources.severe("Unknown material in offer category. Category: " + categoryName + ". Material: " + categoryAsArray[i]); problemLoadingCategories = true; - continue; + continue; } - materialsInCategory.add(material); + materialsInCategory.add(materialName); } //Construct ResourceExtractionCategory object @@ -226,6 +229,18 @@ public static List getResourceOfferCategories() throws To } } + private static boolean isValidMaterial(String materialName) { + Material material = Material.getMaterial(materialName); + if(material != null) + return true; //Known material + if(TownyResources.getPlugin().isSlimeFunInstalled()) { + SlimefunItem slimeFunItem = SlimefunItem.getByID(materialName); + if(slimeFunItem != null) + return true; //Known material + } + return false; //Unknown material + } + public static void loadConfig(String filepath, String version) throws TownyException{ if (FileMgmt.checkOrCreateFile(filepath)) { File file = new File(filepath); diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index a7d2f91..8121480 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -2,6 +2,7 @@ import com.meowj.langutils.lang.LanguageHelper; import io.github.townyadvanced.townyresources.settings.TownyResourcesSettings; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -75,11 +76,9 @@ public static String formatProductionStringForDynmapTownyDisplay(String resource if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { List resourcesAsFormattedList = new ArrayList<>(); String[] resourcesAsArray = resourcesAsString.replaceAll("\\d+-", "").split(","); - Material material; String translatedMaterialName; for(String resourceAsString: resourcesAsArray) { - material = Material.getMaterial(resourceAsString); - translatedMaterialName = getTranslatedMaterialName(material); + translatedMaterialName = getTranslatedMaterialName(resourceAsString); resourcesAsFormattedList.add(translatedMaterialName); } return Arrays.toString(resourcesAsFormattedList.toArray()).replace("[","").replace("]",""); @@ -95,11 +94,11 @@ public static String formatProductionStringForDynmapTownyDisplay(String resource * @param material the material * @return the formatted material name */ - public static String formatMaterialForDisplay(Material material) { + public static String formatMaterialForDisplay(String material) { if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { return getTranslatedMaterialName(material); } else { - return WordUtils.capitalizeFully(material.toString().replaceAll("_", " ")); + return WordUtils.capitalizeFully(material.replaceAll("_", " ")); } } @@ -125,8 +124,7 @@ private static String[] convertResourceAmountsStringToFormattedArray(String reso amountAndMaterialName = resourceAsString.split("-"); amount = amountAndMaterialName[0]; materialName = amountAndMaterialName[1]; - material = Material.getMaterial(materialName); - translatedMaterialName = getTranslatedMaterialName(material); + translatedMaterialName = getTranslatedMaterialName(materialName); resourcesAsFormattedList.add(amount + " " + translatedMaterialName); } return resourcesAsFormattedList.toArray(new String[0]); @@ -140,9 +138,19 @@ private static String[] convertResourceAmountsStringToFormattedArray(String reso } } - private static String getTranslatedMaterialName(Material material) { - ItemStack fakeItemStack = new ItemStack(material); - String translatedMaterialName = LanguageHelper.getItemDisplayName(fakeItemStack, TownyResourcesSettings.getMaterialsDisplayLanguage()); - return translatedMaterialName; + private static String getTranslatedMaterialName(String materialName) { + Material material = Material.getMaterial(materialName); + if(material == null) { + if(TownyResources.getPlugin().isSlimeFunInstalled()) { + SlimefunItem slimefunItem = SlimefunItem.getByID(materialName); + return slimefunItem.getItemName(); + } else { + return materialName; //Shouldn't get here, but handled as failsafe + } + } else { + ItemStack fakeItemStack = new ItemStack(material); + String translatedMaterialName = LanguageHelper.getItemDisplayName(fakeItemStack, TownyResourcesSettings.getMaterialsDisplayLanguage()); + return translatedMaterialName; + } } } From 468912f710eeaddd187309e84663498321e75ce9 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 11:43:01 +0100 Subject: [PATCH 04/19] TR-9 removed dev artefact --- .../TownResourceCollectionController.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java index 1fce54a..43900d7 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java @@ -23,23 +23,6 @@ public class TownResourceCollectionController { public static synchronized void collectAvailableTownResources(Player player, Town town, Map availableForCollection) { - - if(TownyResources.getPlugin().isSlimeFunInstalled()) { - SlimefunItem slimeFunItem = SlimefunItem.getByID("BUCKET_OF_OIL"); - //If null, return - //Create the stack to drop - ItemStack itemStack = slimeFunItem.getRecipeOutput(); - //Set the amount - itemStack.setAmount(1); - //Drop stuff near player - Towny.getPlugin().getServer().getScheduler().runTask(Towny.getPlugin(), new Runnable() { - public void run() { - Location location = player.getLocation(); - player.getWorld().dropItemNaturally(location, itemStack); - } - }); - } - //Collect resources collectAvailableGovernmentResources(player, town, availableForCollection); //Notify Player From fd086af4d471d33033723a8e9de25c07fbd4fa89 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 13:19:13 +0100 Subject: [PATCH 05/19] TR-9 added a translation pattern for slimefun --- .../PlayerExtractionLimitsController.java | 3 +-- .../TownResourceDiscoveryController.java | 3 +-- .../objects/CategoryExtractionRecord.java | 4 +--- .../objects/ResourceExtractionCategory.java | 19 ++++++++++++++++++- .../objects/ResourceOfferCategory.java | 19 ++++++++++++++++++- .../settings/TownyResourcesTranslation.java | 4 ++++ .../util/TownyResourcesMessagingUtil.java | 4 ++-- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java index 09b3394..692722e 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java @@ -387,8 +387,7 @@ private static CategoryExtractionRecord getCategoryExtractionRecord(Map categoryExtractionRecord.getNextLimitWarningTime()) { - String categoryName = categoryExtractionRecord.getResourceExtractionCategory().getCategoryName(); - String translatedCategoryName = TownyResourcesTranslation.of("resource_category_" + categoryName).split(",")[0]; + String translatedCategoryName = categoryExtractionRecord.getResourceExtractionCategory().getTranslatedName(); int categoryExtractionLimit = categoryExtractionRecord.getResourceExtractionCategory().getCategoryExtractionLimitItems(); String errorString = TownyResourcesTranslation.of("msg_error_daily_extraction_limit_reached", translatedCategoryName, categoryExtractionLimit); //Send temporary action bar message diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java index fb3c0f6..4ce2072 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java @@ -94,8 +94,7 @@ public static void discoverNewResource(Resident resident, Town town, List Date: Thu, 2 Sep 2021 13:21:04 +0100 Subject: [PATCH 06/19] Updated version to 008 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b04ce0d..bd6f820 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.github.townyadvanced TownyResources - 0.0.7 + 0.0.8 townyresources From 7e247028893588c45c094c0ac9328a08df11a52a Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 13:26:26 +0100 Subject: [PATCH 07/19] Fix --- .../github/townyadvanced/townyresources/TownyResources.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java index bd79df7..422382c 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java +++ b/src/main/java/io/github/townyadvanced/townyresources/TownyResources.java @@ -57,6 +57,8 @@ public boolean loadAll() { try { printSickASCIIArt(); townyVersionCheck(); + //Setup integrations with other plugins + setupIntegrationsWithOtherPlugins(); //Load settings and languages TownyResourcesSettings.loadConfig(this.getDataFolder().getPath() + File.separator + "config.yml", getVersion()); TownyResourcesTranslation.loadLanguage(this.getDataFolder().getPath() + File.separator , "english.yml"); @@ -67,8 +69,6 @@ public boolean loadAll() { //Load commands and listeners registerCommands(); registerListeners(); - //Setup integrations with other plugins - setupIntegrationsWithOtherPlugins(); } catch (TownyException te) { severe(te.getMessage()); severe("TownyResources failed to load! Disabling!"); From 23433f940cf1764d9c0b40697f9266e621f0a595 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 13:42:13 +0100 Subject: [PATCH 08/19] Fix --- .../util/TownyResourcesMessagingUtil.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index 66654e8..eafdfa7 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -144,13 +144,15 @@ public static String getTranslatedMaterialName(String materialName) { if(TownyResources.getPlugin().isSlimeFunInstalled()) { SlimefunItem slimefunItem = SlimefunItem.getByID(materialName); return slimefunItem.getItemName(); - } else { - return materialName; //No material found. Return untranslated name + } + } else { + if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { + ItemStack fakeItemStack = new ItemStack(material); + String translatedMaterialName = LanguageHelper.getItemDisplayName(fakeItemStack, TownyResourcesSettings.getMaterialsDisplayLanguage()); + return translatedMaterialName; } - } else { - ItemStack fakeItemStack = new ItemStack(material); - String translatedMaterialName = LanguageHelper.getItemDisplayName(fakeItemStack, TownyResourcesSettings.getMaterialsDisplayLanguage()); - return translatedMaterialName; } + //Couldn't find a translation. Return un-translated material name + return materialName; } } From 1331611636d4bb88ea2ceee463f72b64b2deb835 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 13:48:33 +0100 Subject: [PATCH 09/19] TR-9 fixed some bgs --- .../controllers/TownResourceCollectionController.java | 4 +++- src/main/resources/english.yml | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java index 43900d7..78419df 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceCollectionController.java @@ -61,7 +61,8 @@ private static synchronized void collectAvailableGovernmentResources(Player play material = Material.getMaterial(materialName); if(material != null) { itemStack = new ItemStack(material, amount); - itemStackList.add(itemStack); + itemStackList.add(itemStack); + continue; } //Try creating a slimefun itemstack @@ -71,6 +72,7 @@ private static synchronized void collectAvailableGovernmentResources(Player play itemStack = slimeFunItem.getRecipeOutput(); itemStack.setAmount(amount); itemStackList.add(itemStack); + continue; } } diff --git a/src/main/resources/english.yml b/src/main/resources/english.yml index d459cf6..77e7047 100644 --- a/src/main/resources/english.yml +++ b/src/main/resources/english.yml @@ -1,5 +1,5 @@ name: TownyResources -version: 0.02 +version: 0.03 language: english author: Goosius website: 'https://github.com/TownyAdvanced/TownyResources' @@ -43,7 +43,6 @@ nation.screen.available.for.collection: '&2 > Available For Collection &a[%s]&2: ### Surveys help_survey: 'Survey the town at your current location, to discover new resources.' -discovery.success: "&b%s has discovered %s at %s!. Daily Production: %d %s." msg_err_survey_no_town: "&cThere is no town here to survey." msg_err_survey_all_resources_already_discovered: "&cAll the resources of this town have already been discovered." @@ -142,3 +141,5 @@ resource_category_chickens: 'Chicken, a flock of chickens' resource_category_eggs: 'Eggs, a flock of hens' resource_category_ender_pearls: 'Ender Pearls, a nest of endermen' +#Added in 0.03 +discovery.success: "&b%s has discovered %s &bat %s!. Daily Production: %d %s." \ No newline at end of file From b6cf204f05c8a06c7cc18e1ca502223f51558ecf Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 14:16:40 +0100 Subject: [PATCH 10/19] TR-9 translation fixes --- .../PlayerExtractionLimitsController.java | 4 +- .../TownResourceDiscoveryController.java | 6 +-- ...nyResourcesResidentMetaDataController.java | 2 +- .../objects/ResourceExtractionCategory.java | 18 +------- .../objects/ResourceOfferCategory.java | 16 ------- .../util/TownyResourcesMessagingUtil.java | 42 +++++++++++-------- src/main/resources/english.yml | 5 +-- 7 files changed, 33 insertions(+), 60 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java index 692722e..e81209e 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/PlayerExtractionLimitsController.java @@ -387,7 +387,7 @@ private static CategoryExtractionRecord getCategoryExtractionRecord(Map categoryExtractionRecord.getNextLimitWarningTime()) { - String translatedCategoryName = categoryExtractionRecord.getResourceExtractionCategory().getTranslatedName(); + String translatedCategoryName = TownyResourcesMessagingUtil.formatExtractionCategoryNameForDisplay(categoryExtractionRecord.getResourceExtractionCategory()); int categoryExtractionLimit = categoryExtractionRecord.getResourceExtractionCategory().getCategoryExtractionLimitItems(); String errorString = TownyResourcesTranslation.of("msg_error_daily_extraction_limit_reached", translatedCategoryName, categoryExtractionLimit); //Send temporary action bar message @@ -400,7 +400,7 @@ private static void sendLimitReachedWarningMessage(Player player, CategoryExtrac public static ResourceExtractionCategory getResourceExtractionCategory(String givenCategoryName) { for(ResourceExtractionCategory resourceExtractionCategory: resourceExtractionCategories) { - if(resourceExtractionCategory.getCategoryName().equals(givenCategoryName)) { + if(resourceExtractionCategory.getName().equals(givenCategoryName)) { return resourceExtractionCategory; } } diff --git a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java index 4ce2072..7ee6901 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java +++ b/src/main/java/io/github/townyadvanced/townyresources/controllers/TownResourceDiscoveryController.java @@ -94,8 +94,8 @@ public static void discoverNewResource(Resident resident, Town town, List Available For Collection &a[%s]&2: ### Surveys help_survey: 'Survey the town at your current location, to discover new resources.' +discovery.success: "&b%s has discovered %s at %s!. Daily Production: %d %s." msg_err_survey_no_town: "&cThere is no town here to survey." msg_err_survey_all_resources_already_discovered: "&cAll the resources of this town have already been discovered." @@ -141,5 +142,3 @@ resource_category_chickens: 'Chicken, a flock of chickens' resource_category_eggs: 'Eggs, a flock of hens' resource_category_ender_pearls: 'Ender Pearls, a nest of endermen' -#Added in 0.03 -discovery.success: "&b%s has discovered %s &bat %s!. Daily Production: %d %s." \ No newline at end of file From f8b8abfec7d690eeaa6a765f738f7acccdd9dd0a Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 14:53:33 +0100 Subject: [PATCH 11/19] TR-9 formatting fix --- .../townyresources/util/TownyResourcesMessagingUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index f2c3c6c..06363e9 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -149,7 +149,7 @@ public static String formatMaterialNameForDisplay(String materialName) { if(material == null) { if(TownyResources.getPlugin().isSlimeFunInstalled()) { SlimefunItem slimefunItem = SlimefunItem.getByID(materialName); - return slimefunItem.getItemName(); + return slimefunItem.getItemName().replaceAll("&.",""); } } else { if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { From e54b4a6e7e8f811a66746584191b1bb92519c43f Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 15:05:36 +0100 Subject: [PATCH 12/19] TR-9 formatting fix --- .../townyresources/util/TownyResourcesMessagingUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index 06363e9..624e641 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -149,7 +149,7 @@ public static String formatMaterialNameForDisplay(String materialName) { if(material == null) { if(TownyResources.getPlugin().isSlimeFunInstalled()) { SlimefunItem slimefunItem = SlimefunItem.getByID(materialName); - return slimefunItem.getItemName().replaceAll("&.",""); + return slimefunItem.getItemName().replaceAll("\\W",""); } } else { if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { From 027cbf1d2d50b9f556b5bbec0d215cfd6ba80c82 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 15:12:53 +0100 Subject: [PATCH 13/19] TR-9 formatting fix --- .../townyresources/util/TownyResourcesMessagingUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index 624e641..056d926 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -149,7 +149,7 @@ public static String formatMaterialNameForDisplay(String materialName) { if(material == null) { if(TownyResources.getPlugin().isSlimeFunInstalled()) { SlimefunItem slimefunItem = SlimefunItem.getByID(materialName); - return slimefunItem.getItemName().replaceAll("\\W",""); + return slimefunItem.getItemName().replaceAll("[\\W\\S]\\w",""); } } else { if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { From 42abf3ecda3d96bf37df8896c641e90541c5b571 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 15:20:41 +0100 Subject: [PATCH 14/19] TR-9 formatting fix --- .../townyresources/util/TownyResourcesMessagingUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index 056d926..20001b9 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -149,7 +149,7 @@ public static String formatMaterialNameForDisplay(String materialName) { if(material == null) { if(TownyResources.getPlugin().isSlimeFunInstalled()) { SlimefunItem slimefunItem = SlimefunItem.getByID(materialName); - return slimefunItem.getItemName().replaceAll("[\\W\\S]\\w",""); + return slimefunItem.getItemName().replaceAll("[^\\w\\s]\\w",""); } } else { if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { From cdd7d8725df3df6788a6bc274ca3ea876d3e9b5e Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 15:42:10 +0100 Subject: [PATCH 15/19] TR-9 fixed things --- .../townyresources/util/TownyResourcesMessagingUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index 20001b9..5042524 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -128,7 +128,7 @@ private static String[] convertResourceAmountsStringToFormattedArray(String reso public static String formatExtractionCategoryNameForDisplay(ResourceExtractionCategory resourceExtractionCategory) { String categoryName = resourceExtractionCategory.getName(); - if(TownyResourcesTranslation.hasKey(categoryName)) { + if(TownyResourcesTranslation.hasKey("resource_category_" + categoryName)) { return TownyResourcesTranslation.of("resource_category_" + categoryName).split(",")[0]; } else { return formatMaterialNameForDisplay(categoryName); @@ -137,7 +137,7 @@ public static String formatExtractionCategoryNameForDisplay(ResourceExtractionCa public static String formatOfferCategoryNameForDisplay(ResourceOfferCategory resourceOfferCategory) { String categoryName = resourceOfferCategory.getName(); - if(TownyResourcesTranslation.hasKey(categoryName)) { + if(TownyResourcesTranslation.hasKey("resource_category_"+ categoryName)) { return TownyResourcesTranslation.of("resource_category_" + categoryName).split(",")[1].trim(); } else { return formatMaterialNameForDisplay(categoryName); From 503005369b7adcefbffb08d60111d01e99ff00f8 Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 15:48:24 +0100 Subject: [PATCH 16/19] TR-9 mebbe final fix --- .../townyresources/util/TownyResourcesMessagingUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java index 5042524..5cfd40a 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java +++ b/src/main/java/io/github/townyadvanced/townyresources/util/TownyResourcesMessagingUtil.java @@ -149,7 +149,9 @@ public static String formatMaterialNameForDisplay(String materialName) { if(material == null) { if(TownyResources.getPlugin().isSlimeFunInstalled()) { SlimefunItem slimefunItem = SlimefunItem.getByID(materialName); - return slimefunItem.getItemName().replaceAll("[^\\w\\s]\\w",""); + if(slimefunItem != null) { + return slimefunItem.getItemName().replaceAll("[^\\w\\s]\\w",""); + } } } else { if(TownyResources.getPlugin().isLanguageUtilsInstalled()) { From 4aa863079180f69ec177103e3138abb4822bcd0e Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 16:14:49 +0100 Subject: [PATCH 17/19] TR-9 Readme file update --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8fba583..59a3d77 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,11 @@ Key Benefits: ``` - townyresources.admin.command.* ``` -4. If you have the *TownyDynmap* plugin installed, add this to the 'infowindow' section of your Dynmap-Towny config file +4. If you have the *TownyDynmap* plugin installed ([download](https://github.com/TownyAdvanced/Dynmap-Towny/releases)), add this to the 'infowindow' section of your Dynmap-Towny config file: > `
Resources: %town_resources%` -5. If you want to translate Material names to a Non-English language, click [here](https://github.com/NyaaCat/LanguageUtils/releases) to download the Jar for the *LanguageUtils* plugin, and drop it into your plugins folder. The language is configured in the *TownyResources* Config.yml file. +5. If you have the *Slimefun* plugin installed ([download](https://github.com/Slimefun/Slimefun4/releases)), you can add slimefun items to the **offers** list by using Slimefun item ID's. Example: + > `...{BUCKET_OF_OIL, 100, 1 BUCKET_OF_OIL}...{TIN_DUST, 100, 1, TIN_DUST}...` +5. If you have the *LangUtils* plugin installed ([download](https://ci.nyaacat.com/job/LanguageUtils/job/1.17/)), set your preferred Material language in the *TownyResources* Config.yml file. 6. Stop your server. 7. Download the latest TownyResources jar from [here](https://github.com/TownyAdvanced/TownyResources/releases). 8. Drop the TownyResources jar into your plugins folder. From bf06ccdd6a1fa187203897b47fddb93ca662ca7d Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 16:19:53 +0100 Subject: [PATCH 18/19] TR-9 readme file update --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 59a3d77..eaafcf4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Key Benefits: (*details in the FAQ section below*) # Installation Guide -1. Ensure you have *Towny* 0.97.1.0 +. +1. Ensure you have *Towny* version 0.97.1.0 +. 2. Edit your townyperms.yml file, and add the following perms: - Mayor / Assistant / Treasurer: ``` @@ -22,18 +22,18 @@ Key Benefits: ``` - townyresources.command.nationcollect ``` -3. Using your permissions plugin, give this to any admins who are not already op: +3. Using your permissions plugin, give this to any admins who are not already OP: ``` - townyresources.admin.command.* ``` -4. If you have the *TownyDynmap* plugin installed ([download](https://github.com/TownyAdvanced/Dynmap-Towny/releases)), add this to the 'infowindow' section of your Dynmap-Towny config file: +4. If you have the *Dynmap-Towny* plugin installed ([download](https://github.com/TownyAdvanced/Dynmap-Towny/releases)), add this to the 'infowindow' section of your *Dynmap-Towny* config file: > `
Resources: %town_resources%` -5. If you have the *Slimefun* plugin installed ([download](https://github.com/Slimefun/Slimefun4/releases)), you can add slimefun items to the **offers** list by using Slimefun item ID's. Example: +5. If you have the *Slimefun* plugin installed ([download](https://github.com/Slimefun/Slimefun4/releases)), you can add slimefun items to the **offers** list by using *Slimefun* item ID's. Example: > `...{BUCKET_OF_OIL, 100, 1 BUCKET_OF_OIL}...{TIN_DUST, 100, 1, TIN_DUST}...` 5. If you have the *LangUtils* plugin installed ([download](https://ci.nyaacat.com/job/LanguageUtils/job/1.17/)), set your preferred Material language in the *TownyResources* Config.yml file. 6. Stop your server. -7. Download the latest TownyResources jar from [here](https://github.com/TownyAdvanced/TownyResources/releases). -8. Drop the TownyResources jar into your plugins folder. +7. Download the latest *TownyResources* Jar from [here](https://github.com/TownyAdvanced/TownyResources/releases). +8. Drop the *TownyResources* Jar into your plugins folder. 9. Start yor server. # Player Guide From 92aeb0dc3b6f79a8facaa3db32c73103fac827bd Mon Sep 17 00:00:00 2001 From: goosius1 Date: Thu, 2 Sep 2021 16:30:40 +0100 Subject: [PATCH 19/19] TR-9 imports cleanup --- .../townyresources/objects/ResourceExtractionCategory.java | 2 -- .../townyresources/objects/ResourceOfferCategory.java | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceExtractionCategory.java b/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceExtractionCategory.java index 24e8c86..c536be3 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceExtractionCategory.java +++ b/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceExtractionCategory.java @@ -1,7 +1,5 @@ package io.github.townyadvanced.townyresources.objects; -import io.github.townyadvanced.townyresources.settings.TownyResourcesTranslation; -import io.github.townyadvanced.townyresources.util.TownyResourcesMessagingUtil; import org.bukkit.Material; import java.util.List; diff --git a/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java b/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java index 38a0123..a5065d6 100644 --- a/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java +++ b/src/main/java/io/github/townyadvanced/townyresources/objects/ResourceOfferCategory.java @@ -1,8 +1,5 @@ package io.github.townyadvanced.townyresources.objects; -import io.github.townyadvanced.townyresources.settings.TownyResourcesTranslation; -import io.github.townyadvanced.townyresources.util.TownyResourcesMessagingUtil; - import java.util.List; public class ResourceOfferCategory {