Skip to content

Commit

Permalink
improvement to artefact stacking (#596)
Browse files Browse the repository at this point in the history
authored-by: goosius1 <=>
  • Loading branch information
Goosius1 authored May 19, 2022
1 parent 82a25cb commit 4bed582
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 37 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.time.LocalTime;

import com.gmail.goosius.siegewar.SiegeWar;
import com.gmail.goosius.siegewar.objects.ArtefactOffer;
import com.palmergames.bukkit.towny.exceptions.TownyException;

import com.palmergames.bukkit.towny.object.Translatable;
Expand All @@ -42,7 +41,7 @@ public class SiegeWarSettings {
private static EnumSet<Material> cachedWallBreachingDestroyBlocksBlacklist = null;
@SuppressWarnings("unused")
private static Boolean cachedWallBreachingDestroyEntityBlacklist = null;
private static Map<Integer, List<ArtefactOffer>> cachedDominationAwardsArtefactOffers = null;
private static Map<Integer, List<ItemStack>> cachedDominationAwardsArtefactOffers = null;

protected static void resetCachedSettings() {
siegeZoneWildernessForbiddenBlockMaterials = null;
Expand Down Expand Up @@ -673,8 +672,8 @@ public static List<List<Integer>> getDominationAwardsGlobalGrantedOffers() {
*
* @return the artefact offers
*/
private static List<ArtefactOffer> getDominationAwardsArtefactOffers(ConfigNodes configNode, int tier) {
List<ArtefactOffer> result = new ArrayList<>();
private static List<ItemStack> getDominationAwardsArtefactOffers(ConfigNodes configNode, int tier) {
List<ItemStack> result = new ArrayList<>();

for(String offerAsString: Settings.getListOfCurlyBracketedItems(configNode)) {
//Create convenience variables
Expand All @@ -688,15 +687,14 @@ private static List<ArtefactOffer> getDominationAwardsArtefactOffers(ConfigNodes
Material material = Material.matchMaterial("minecraft:" + specificationFields[2]);
//Create artefact
ItemStack artefact = new ItemStack(material);
artefact.setAmount(quantity);
ItemMeta itemMeta = artefact.getItemMeta();
itemMeta.setDisplayName(name);
itemMeta.setLore(lore);
artefact.setItemMeta(itemMeta);
addSpecialEffects(artefact, specificationFields);

//Create offer and add to map
ArtefactOffer artefactOffer = new ArtefactOffer(artefact, quantity);
result.add(artefactOffer);
//Add artefact to result
result.add(artefact);
}
return result;
}
Expand All @@ -711,17 +709,17 @@ private static List<ArtefactOffer> getDominationAwardsArtefactOffers(ConfigNodes
* The returned offers should considered as "templates"
* Thus make sure to clone any of the items before granting.
*/
public static Map<Integer, List<ArtefactOffer>> getDominationAwardsArtefactOffers() {
public static Map<Integer, List<ItemStack>> getDominationAwardsArtefactOffers() {
return cachedDominationAwardsArtefactOffers;
}

/**
* Loads the indicated list into cache
*/
public static void loadDominationAwardsArtefactOffers() {
Map<Integer, List<ArtefactOffer>> result = new HashMap<>();
Map<Integer, List<ItemStack>> result = new HashMap<>();

List<ArtefactOffer> offersInTier = new ArrayList<>();
List<ItemStack> offersInTier = new ArrayList<>();
offersInTier.addAll(getDominationAwardsArtefactOffers(ConfigNodes.DOMINATION_AWARDS_ARTEFACT_OFFERS_CUSTOM_TIER1,0));
offersInTier.addAll(getDominationAwardsArtefactOffers(ConfigNodes.DOMINATION_AWARDS_ARTEFACT_OFFERS_DEFAULT_TIER1,0));
result.put(0, offersInTier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.gmail.goosius.siegewar.SiegeWar;
import com.gmail.goosius.siegewar.events.GlobalDominationAwardsEvent;
import com.gmail.goosius.siegewar.metadata.NationMetaDataController;
import com.gmail.goosius.siegewar.objects.ArtefactOffer;
import com.gmail.goosius.siegewar.settings.SiegeWarSettings;
import com.palmergames.bukkit.towny.TownyEconomyHandler;
import com.palmergames.bukkit.towny.TownyMessaging;
Expand Down Expand Up @@ -110,6 +109,7 @@ private static void grantGlobalDominationAwardsNow(GlobalDominationAwardsEvent e
Map<Nation, Integer> moneyAwards = event.getMoneyAwards();
Map<Nation, List<ItemStack>> artefactAwards = event.getArtefactAwards();
int moneyToGrant;
int numArtefacts;
String moneyText;
String artefactText;
List<ItemStack> artefactsToGrant;
Expand All @@ -129,7 +129,11 @@ private static void grantGlobalDominationAwardsNow(GlobalDominationAwardsEvent e
//Gib Artefacts
artefactsToGrant = artefactAwards.get(nation);
grantArtefactsToNation(nation, artefactsToGrant);
artefactText = Integer.toString(artefactsToGrant.size());
numArtefacts = 0;
for(ItemStack artefact: artefactsToGrant) {
numArtefacts += artefact.getAmount();
}
artefactText = Integer.toString(numArtefacts);
//Add to Global message
readableNationPosition++;
globalMessageLines.add(Translatable.of("msg_global_domination_awards_line", readableNationPosition, nation.getName(), moneyText, artefactText));
Expand Down Expand Up @@ -272,19 +276,17 @@ private static List<ItemStack> generateArtefacts(List<Integer> numberOfArtefacts

private static List<ItemStack> generateArtefacts(int tier, int numOffers) {
List<ItemStack> result = new ArrayList<>();
List<ArtefactOffer> offersInTier = SiegeWarSettings.getDominationAwardsArtefactOffers().get(tier);
List<ItemStack> offersInTier = SiegeWarSettings.getDominationAwardsArtefactOffers().get(tier);
for(int i = 0; i < numOffers; i++) {
//Identify Random offer
ArtefactOffer offer = offersInTier.get((int)(Math.random() * offersInTier.size()));
//Generate the artefacts specified by that offer
for(int ii = 0; ii < offer.quantity; ii++) {
ItemStack artefact = offer.artefactTemplate.clone();
ItemMeta itemMeta = artefact.getItemMeta();
long expirationTime = System.currentTimeMillis() + (long)(SiegeWarSettings.getDominationAwardsArtefactExpiryLifetimeDays() * 864500000);
itemMeta.getPersistentDataContainer().set(EXPIRATION_TIME_KEY, EXPIRATION_TIME_KEY_TYPE, expirationTime);
artefact.setItemMeta(itemMeta);
result.add(artefact);
}
ItemStack offer = offersInTier.get((int)(Math.random() * offersInTier.size()));
//Generate the artefact(s) specified by that offer
ItemStack artefact = offer.clone();
ItemMeta itemMeta = artefact.getItemMeta();
long expirationTime = System.currentTimeMillis() + (long)(SiegeWarSettings.getDominationAwardsArtefactExpiryLifetimeDays() * 864500000);
itemMeta.getPersistentDataContainer().set(EXPIRATION_TIME_KEY, EXPIRATION_TIME_KEY_TYPE, expirationTime);
artefact.setItemMeta(itemMeta);
result.add(artefact);
}
return result;
}
Expand Down

0 comments on commit 4bed582

Please sign in to comment.