Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tr 9 #18

Merged
merged 20 commits into from
Sep 2, 2021
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand All @@ -22,16 +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, 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:
> `<br/><span style="font-weight:bold;">Resources&colon; %town_resources%</span>`
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.
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
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.townyadvanced</groupId>
<artifactId>TownyResources</artifactId>
<version>0.0.7</version>
<version>0.0.8</version>
<name>townyresources</name> <!-- Leave lower-cased -->

<properties>
Expand Down Expand Up @@ -51,6 +51,12 @@
<version>2.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-15</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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.townyadvanced.townyresources.commands.TownyResourcesAdminCommand;
Expand All @@ -25,6 +24,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() {
Expand Down Expand Up @@ -57,6 +57,7 @@ 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());
Expand Down Expand Up @@ -165,10 +166,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();
Expand All @@ -188,9 +193,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 slimeFun = Bukkit.getPluginManager().getPlugin("Slimefun");
slimeFunInstalled = slimeFun != null;
if(slimeFunInstalled)
info("Slimefun Integration Enabled");
else
info("Slimefun Integration Not Enabled");

Plugin languageUtils = Bukkit.getPluginManager().getPlugin("LangUtils");
languageUtilsInstalled = languageUtils!= null;
languageUtilsInstalled = languageUtils != null;
if(languageUtilsInstalled)
info("LanguageUtils Integration Enabled");
else
info("LanguageUtils Integration Not Enabled");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Material> discoveredResources = TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town);
List<String> discoveredResources = TownyResourcesGovernmentMetaDataController.getDiscoveredAsList(town);
List<Integer> costPerResourceLevel = TownyResourcesSettings.getSurveyCostsPerResourceLevel();
List<Integer> requiredNumTownblocksPerResourceLevel = TownyResourcesSettings.getSurveyNumTownblocksRequirementsPerResourceLevel();
if(discoveredResources.size() >= costPerResourceLevel.size())
Expand Down Expand Up @@ -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<Material, Integer> availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(town);
Map<String, Integer> availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(town);
if(availableForCollection.isEmpty())
throw new TownyException(TownyResourcesTranslation.of("msg_err_cannot_towncollect_no_resources_available"));

Expand Down Expand Up @@ -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<Material, Integer> availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(nation);
Map<String, Integer> availableForCollection = TownyResourcesGovernmentMetaDataController.getAvailableForCollectionAsMap(nation);
if(availableForCollection.isEmpty())
throw new TownyException(TownyResourcesTranslation.of("msg_err_cannot_nationcollect_no_resources_available"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ private static CategoryExtractionRecord getCategoryExtractionRecord(Map<Material

private static void sendLimitReachedWarningMessage(Player player, CategoryExtractionRecord categoryExtractionRecord) {
if(System.currentTimeMillis() > categoryExtractionRecord.getNextLimitWarningTime()) {
String categoryName = categoryExtractionRecord.getResourceExtractionCategory().getCategoryName();
String translatedCategoryName = TownyResourcesTranslation.of("resource_category_" + categoryName).split(",")[0];
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
Expand All @@ -401,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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
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;
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;
Expand All @@ -19,14 +22,14 @@

public class TownResourceCollectionController {

public static synchronized void collectAvailableTownResources(Player player, Town town, Map<Material,Integer> availableForCollection) {
public static synchronized void collectAvailableTownResources(Player player, Town town, Map<String,Integer> availableForCollection) {
//Collect resources
collectAvailableGovernmentResources(player, town, availableForCollection);
//Notify Player
TownyResourcesMessagingUtil.sendMsg(player, TownyResourcesTranslation.of("resource.towncollect.success"));
}

public static synchronized void collectAvailableNationResources(Player player, Nation nation, Map<Material,Integer> availableForCollection) {
public static synchronized void collectAvailableNationResources(Player player, Nation nation, Map<String,Integer> availableForCollection) {
//Collect resources
collectAvailableGovernmentResources(player, nation, availableForCollection);
//Notify Player
Expand All @@ -42,25 +45,42 @@ 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<Material,Integer> availableForCollection) {
private static synchronized void collectAvailableGovernmentResources(Player player, Government government, Map<String,Integer> availableForCollection) {
List<ItemStack> itemStackList = new ArrayList<>();

//Calculate stuff to give player
String materialName;
Material material;
int amount;
ItemStack itemStack;
for(Map.Entry<Material,Integer> 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<String,Integer> 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);
continue;
}

//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);
continue;
}
}

//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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Material> alreadyDiscoveredMaterials) throws TownyException{
public static void discoverNewResource(Resident resident, Town town, List<String> 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
Expand All @@ -38,7 +38,7 @@ public static void discoverNewResource(Resident resident, Town town, List<Materi
CATEGORY_LOOP:
for(ResourceOfferCategory category: TownResourceOffersController.getResourceOfferCategoryList()) {
//Skip category if we have already discovered something in it
for(Material material: alreadyDiscoveredMaterials) {
for(String material: alreadyDiscoveredMaterials) {
if(category.getMaterialsInCategory().contains(material))
continue CATEGORY_LOOP;
}
Expand Down Expand Up @@ -72,10 +72,10 @@ public static void discoverNewResource(Resident resident, Town town, List<Materi

//Determine the winning material
winningNumber = (int)((Math.random() * winningCategory.getMaterialsInCategory().size()));
Material winningMaterial = winningCategory.getMaterialsInCategory().get(winningNumber);
String winningMaterial = winningCategory.getMaterialsInCategory().get(winningNumber);

//Discover the resource
List<Material> discoveredMaterials = new ArrayList<>(alreadyDiscoveredMaterials);
List<String> discoveredMaterials = new ArrayList<>(alreadyDiscoveredMaterials);
discoveredMaterials.add(winningMaterial);
TownyResourcesGovernmentMetaDataController.setDiscovered(town, discoveredMaterials);
town.save();
Expand All @@ -94,9 +94,8 @@ public static void discoverNewResource(Resident resident, Town town, List<Materi
int levelOfNewResource = discoveredMaterials.size();
double productivityModifierNormalized = (double)TownyResourcesSettings.getProductionPercentagesPerResourceLevel().get(levelOfNewResource-1) / 100;
int preTaxProduction = (int)((winningCategory.getBaseAmountItems() * productivityModifierNormalized) + 0.5);
String categoryName = winningCategory.getName();
String translatedCategoryName = TownyResourcesTranslation.of("resource_category_" + categoryName).split(",")[1].trim();
String materialName = TownyResourcesMessagingUtil.formatMaterialForDisplay(winningMaterial);
TownyResourcesMessagingUtil.sendGlobalMessage(TownyResourcesTranslation.of("discovery.success", resident.getName(), translatedCategoryName, town.getName(), preTaxProduction, materialName));
String categoryName = TownyResourcesMessagingUtil.formatOfferCategoryNameForDisplay(winningCategory);
String materialName = TownyResourcesMessagingUtil.formatMaterialNameForDisplay(winningMaterial);
TownyResourcesMessagingUtil.sendGlobalMessage(TownyResourcesTranslation.of("discovery.success", resident.getName(), categoryName, town.getName(), preTaxProduction, materialName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class TownResourceOffersController {

private static List<ResourceOfferCategory> resourceOfferCategoryList = new ArrayList<>();
private static Map<Material, ResourceOfferCategory> materialToResourceOfferCategoryMap = new HashMap<>();
private static Map<String, ResourceOfferCategory> materialToResourceOfferCategoryMap = new HashMap<>();

public static void loadAllResourceOfferCategories() throws TownyException {
//Load all categories
Expand All @@ -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);
}
}
Expand All @@ -34,7 +34,7 @@ public static List<ResourceOfferCategory> getResourceOfferCategoryList() {
return resourceOfferCategoryList;
}

public static Map<Material, ResourceOfferCategory> getMaterialToResourceOfferCategoryMap() {
public static Map<String, ResourceOfferCategory> getMaterialToResourceOfferCategoryMap() {
return materialToResourceOfferCategoryMap;
}
}
Loading