Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tradetag villager_xp and price_multiplier
- Loading branch information
1 parent
5ab2395
commit 02b4c7f
Showing
5 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...rc/main/java/com/denizenscript/denizen/objects/properties/trade/TradePriceMultiplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.denizenscript.denizen.objects.properties.trade; | ||
|
||
import com.denizenscript.denizen.objects.TradeTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
|
||
public class TradePriceMultiplier implements Property { | ||
|
||
public static boolean describes(ObjectTag recipe) { | ||
return recipe instanceof TradeTag; | ||
} | ||
|
||
public static TradePriceMultiplier getFrom(ObjectTag recipe) { | ||
if (!describes(recipe)) { | ||
return null; | ||
} | ||
return new TradePriceMultiplier((TradeTag) recipe); | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"price_multiplier" | ||
}; | ||
|
||
private TradeTag recipe; | ||
|
||
public TradePriceMultiplier(TradeTag recipe) { | ||
this.recipe = recipe; | ||
} | ||
|
||
public String getPropertyString() { | ||
if (recipe.getRecipe() == null) { | ||
return null; | ||
} | ||
return String.valueOf(recipe.getRecipe().getPriceMultiplier()); | ||
} | ||
|
||
public String getPropertyId() { | ||
return "price_multiplier"; | ||
} | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <TradeTag.price_multiplier> | ||
// @returns ElementTag(Decimal) | ||
// @mechanism TradeTag.price_multiplier | ||
// @description | ||
// Returns the price multiplier for this trade. | ||
// --> | ||
PropertyParser.<TradePriceMultiplier>registerTag("price_multiplier", (attribute, recipe) -> { | ||
return new ElementTag(recipe.recipe.getRecipe().getPriceMultiplier()); | ||
}); | ||
} | ||
|
||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object TradeTag | ||
// @name price_multiplier | ||
// @input ElementTag(Decimal) | ||
// @description | ||
// Sets the price multiplier for this trade. | ||
// @tags | ||
// <TradeTag.price_multiplier> | ||
// --> | ||
if (mechanism.matches("price_multiplier") && mechanism.requireFloat()) { | ||
recipe.getRecipe().setPriceMultiplier(mechanism.getValue().asFloat()); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
plugin/src/main/java/com/denizenscript/denizen/objects/properties/trade/TradeVillagerXP.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.denizenscript.denizen.objects.properties.trade; | ||
|
||
import com.denizenscript.denizen.objects.TradeTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
|
||
public class TradeVillagerXP implements Property { | ||
|
||
public static boolean describes(ObjectTag recipe) { | ||
return recipe instanceof TradeTag; | ||
} | ||
|
||
public static TradeVillagerXP getFrom(ObjectTag recipe) { | ||
if (!describes(recipe)) { | ||
return null; | ||
} | ||
return new TradeVillagerXP((TradeTag) recipe); | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"villager_xp" | ||
}; | ||
|
||
private TradeTag recipe; | ||
|
||
public TradeVillagerXP(TradeTag recipe) { | ||
this.recipe = recipe; | ||
} | ||
|
||
public String getPropertyString() { | ||
if (recipe.getRecipe() == null) { | ||
return null; | ||
} | ||
return String.valueOf(recipe.getRecipe().getVillagerExperience()); | ||
} | ||
|
||
public String getPropertyId() { | ||
return "villager_xp"; | ||
} | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <TradeTag.villager_xp> | ||
// @returns ElementTag(Number) | ||
// @mechanism TradeTag.villager_xp | ||
// @description | ||
// Returns the amount of experience a villager gains from this trade. | ||
// --> | ||
PropertyParser.<TradeVillagerXP>registerTag("villager_xp", (attribute, recipe) -> { | ||
return new ElementTag(recipe.recipe.getRecipe().getVillagerExperience()); | ||
}); | ||
} | ||
|
||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object TradeTag | ||
// @name villager_xp | ||
// @input ElementTag(Number) | ||
// @description | ||
// Sets the amount of experience a villager gains from this trade. | ||
// @tags | ||
// <TradeTag.villager_xp> | ||
// --> | ||
if (mechanism.matches("villager_xp") && mechanism.requireInteger()) { | ||
recipe.getRecipe().setVillagerExperience(mechanism.getValue().asInt()); | ||
} | ||
} | ||
} |