This commit is contained in:
Indyuce 2022-08-16 12:39:43 +02:00
parent 32ca996871
commit 706ddf6f1f
729 changed files with 10108 additions and 9881 deletions

351
MMOItems-API/pom.xml Normal file
View File

@ -0,0 +1,351 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>MMOItems</artifactId>
<groupId>net.Indyuce</groupId>
<version>${revision}</version>
</parent>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>MMOItems-API</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<finalName>${project.name}-${project.version}</finalName>
<defaultGoal>clean package install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--
This flattens the pom.xml from the API module as well so that it can be uploaded
to Nexus. For plugins which have no API/Bukkit differenciation like MythicLib we
can just use the main plugin pom.xml file.
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>package</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>mojang</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>inventive-repo</id>
<url>https://repo.inventivetalent.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<!-- Repository used to fetch all Spigot builds -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- AdvancedEnchants -->
<repository>
<id>egg82-ninja</id>
<url>https://www.myget.org/F/egg82-java/maven/</url>
</repository>
<!-- HolographicDisplays -->
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
</repositories>
<!--
Order of dependencies matters in Maven because
the first wins when multiple classpaths match
-->
<dependencies>
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-clean-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore-API</artifactId>
<version>1.9.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicEnchants</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.RednedEpic</groupId>
<artifactId>PhatLoots</artifactId>
<version>4.2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.lumine</groupId>
<artifactId>Mythic-Dist</artifactId>
<version>5.1.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<!-- Local dependencies -->
<dependency>
<groupId>com.github.Eniripsa96</groupId>
<artifactId>SkillAPI</artifactId>
<version>master</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>n3kas</groupId>
<artifactId>ae.api</artifactId>
<version>5.7.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.black_ixx</groupId>
<artifactId>BossShop</artifactId>
<version>2.0.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bekvon.bukkit.residence</groupId>
<artifactId>Residence</artifactId>
<version>4.8.7.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.herocraftonline</groupId>
<artifactId>Heroes</artifactId>
<version>1.9.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.nossr50</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.104</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>us.eunoians</groupId>
<artifactId>McRPG</artifactId>
<version>1.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.baks</groupId>
<artifactId>rpl</artifactId>
<version>3.9.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.leothepro555</groupId>
<artifactId>skills</artifactId>
<version>12.3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.skills.main</groupId>
<artifactId>SkillsPro</artifactId>
<version>18.9.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.robin</groupId>
<artifactId>BattleLevels</artifactId>
<version>6.9.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.arasple.mc</groupId>
<artifactId>TrHologram</artifactId>
<version>1.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.tobiyas</groupId>
<artifactId>RacesAndClasses</artifactId>
<version>1.2.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ru.endlesscode</groupId>
<artifactId>rpginventory</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sainttx.holograms</groupId>
<artifactId>Holograms</artifactId>
<version>2.9.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.archyx</groupId>
<artifactId>AureliumSkills</artifactId>
<version>1.2.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.badbones69</groupId>
<artifactId>crazyenchantments</artifactId>
<version>1.8-db9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>Citizens</artifactId>
<version>2.0.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.inventivetalent</groupId>
<artifactId>glowapi</artifactId>
<version>1.4.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.denizenscript</groupId>
<artifactId>denizen</artifactId>
<version>1.2.1-b1744-REL</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.denizenscript</groupId>
<artifactId>depenizen</artifactId>
<version>2.0.0-b709</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -3,11 +3,9 @@ package net.Indyuce.mmoitems;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.comp.target.InteractionType;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import net.Indyuce.mmoitems.api.Type;
import org.apache.commons.codec.binary.Base64;
@ -48,22 +46,54 @@ public class MMOUtils {
}
}
public static int getPickaxePower(Player player) {
ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && item.getType() != Material.AIR) {
NBTItem nbt = NBTItem.get(item);
if (nbt.hasType())
return nbt.getInteger("MMOITEMS_PICKAXE_POWER");
else {
switch (item.getType().name()) {
case "WOODEN_PICKAXE":
case "WOOD_PICKAXE":
return 5;
case "STONE_PICKAXE":
return 10;
case "GOLDEN_PICKAXE":
case "GOLD_PICKAXE":
return 15;
case "IRON_PICKAXE":
return 20;
case "DIAMOND_PICKAXE":
return 25;
case "NETHERITE_PICKAXE":
return 30;
default:
return 0;
}
}
}
return 0;
}
/**
* @param name The trigger name that may be in old format
* @return The trigger type this represents
* @throws IllegalArgumentException If this does not match any trigger type
*/
@NotNull
public static TriggerType backwardsCompatibleTriggerType(@Nullable String name) throws IllegalArgumentException {
if (name == null) { throw new IllegalArgumentException("Trigger cannot be null"); }
public static TriggerType backwardsCompatibleTriggerType(@NotNull String name) throws IllegalArgumentException {
if (name == null)
throw new IllegalArgumentException("Trigger cannot be null");
switch (name) {
case "ON_HIT": return TriggerType.ATTACK;
case "WHEN_HIT": return TriggerType.DAMAGED;
case "ON_HIT":
return TriggerType.ATTACK;
case "WHEN_HIT":
return TriggerType.DAMAGED;
default:
TriggerType trigger = TriggerType.valueOf(name);
return trigger;
return TriggerType.valueOf(name);
}
}

View File

@ -1,187 +1,187 @@
package net.Indyuce.mmoitems.api;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.util.message.FFPMMOItems;
import net.Indyuce.mmoitems.stat.Enchants;
import net.Indyuce.mmoitems.stat.data.UpgradeData;
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.Upgradable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class UpgradeTemplate {
@NotNull
private final String id;
@NotNull
private final Map<ItemStat, UpgradeInfo> perStatUpgradeInfos = new HashMap<>();
/**
* Loads an Upgrade Template directly from the YML file. Neat!
*/
public UpgradeTemplate(@NotNull ConfigurationSection config) {
Validate.notNull(config, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "You must specify a config section."));
// Build ID
id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-");
// Feedback
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
ffp.activatePrefix(true, "Upgrade Template $i&o" + config.getName());
// For ever stat
for (String key : config.getKeys(false)) {
//UPGRD//MMOItems. Log("\u00a7a>>> \u00a77Stat \u00a72" + key);
// Get internal stat ID
String statFormat = key.toUpperCase().replace("-", "_");
// Attempt to find stat
ItemStat stat = MMOItems.plugin.getStats().get(statFormat);
if (stat == null) { ffp.log(FriendlyFeedbackCategory.ERROR, "Stat '$r{0}$b' $fnot found$b.", statFormat); continue; }
if (!(stat instanceof Upgradable)) { ffp.log(FriendlyFeedbackCategory.ERROR, "Stat $r{0}$b is $fnot upgradeable$b.", stat.getId()); continue; }
if (!(stat.getClearStatData() instanceof Mergeable)) { ffp.log(FriendlyFeedbackCategory.ERROR, "Stat Data used by $r{0}$b is $fnot mergeable$b, and thus it cannot be upgradeable. Contact the dev of this ItemStat.", stat.getId()); continue; }
// Attempt to parse Upgrade Info
try {
// Parsed correctly? Add
perStatUpgradeInfos.put(stat, ((Upgradable) stat).loadUpgradeInfo(config.get(key)));
// Somethings up, generate exception ig
} catch (IllegalArgumentException exception) {
// Log
ffp.log(FriendlyFeedbackCategory.ERROR, exception.getMessage());
}
}
// Print all failures
ffp.sendTo(FriendlyFeedbackCategory.ERROR, MMOItems.getConsole());
}
/**
* Get the internal ID of this template.
* <p></p>
* In the format: <code><b>upgrade-template-name</b></code>
* <p>(No spaces nor underscores, lowercase)</p>
*/
@NotNull public String getId() {
return id;
}
/**
* Get the <code>ItemStat</code>s that this template has <code>UpgradeInfo</code> about.
*/
@NotNull public Set<ItemStat> getKeys() {
return perStatUpgradeInfos.keySet();
}
/**
* Get the <code>UpgradeInfo</code> associated with this stat.
*/
@Nullable public UpgradeInfo getUpgradeInfo(@NotNull ItemStat stat) {
return perStatUpgradeInfos.get(stat);
}
/**
* Upgrades this MMOItem by 1 level
*/
public void upgrade(@NotNull MMOItem mmoitem) {
// Yes
upgradeTo(mmoitem, mmoitem.getUpgradeLevel() + 1);
}
/**
* Upgrades this MMOItem's stats and sets the level.
* @param level Target level, which may even be negative!
*/
public void upgradeTo(@NotNull MMOItem mmoitem, int level) {
// Make sure to not overwrite player's enchantments when upgrading.
Enchants.separateEnchantments(mmoitem);
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Separated enchantments");
// Set the items level
UpgradeData dat;
if (mmoitem.hasData(ItemStats.UPGRADE)) {
dat = (UpgradeData) mmoitem.getData(ItemStats.UPGRADE);
} else { dat = new UpgradeData(null, null, false, false, 0, 0, 100); }
dat.setLevel(level);
mmoitem.setData(ItemStats.UPGRADE, dat);
//UPGR//MMOItems.log("\u00a76>\u00a73>\u00a7a> \u00a77Upgrading to level \u00a7e" + dat.getLevel());
// For every Stat-UpgradeInfo pair
for (ItemStat stat : perStatUpgradeInfos.keySet()) {
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Upgrading stat \u00a7e" + stat.getId());
// Preprocess
((Upgradable) stat).preprocess(mmoitem);
// Initializes Stat History
StatHistory hist = StatHistory.from(mmoitem, stat);
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Stat History Initialized");
// Midprocess
((Upgradable) stat).midprocess(mmoitem);
// The Stat History now manages applying upgrades.
//HSY//MMOItems.log(" \u00a73-\u00a7a- \u00a77Upgrade Recalculation \u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-");
mmoitem.setData(stat, hist.recalculate(level));
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Recalculated");
// Postprocess
((Upgradable) stat).postprocess(mmoitem);
}
}
/**
* @return If the user has set in the config that the stats should display how the item's upgrades have affected them.
*/
public static boolean isDisplayingUpgrades() { return MMOItems.plugin.getConfig().getBoolean("item-upgrading.display-stat-changes", false); }
/**
* The user may define how to display stat changes due to upgrades,
* as well as 'negative' and 'positive' colours.
*
* @return A string ready to just have its colors parsed and inserted into lore.
* @param value The <code>toString()</code> of this will replace all instances of <code>#stat#</code> the user specifies in the config.
* @param isNegative Should 'negative' coloration be used instead of positive? The user uses the placeholder <code><b>< p ></b></code> in this place.
*/
@NotNull public static String getUpgradeChangeSuffix(@NotNull String value, boolean isNegative) {
// Get the base
String base = Objects.requireNonNull(MMOItems.plugin.getConfig().getString("item-upgrading.stat-change-suffix", " &8(<p>#stat#&8)"));
String succ = Objects.requireNonNull(MMOItems.plugin.getConfig().getString("item-upgrading.stat-change-positive", "&a"));
String fauc = Objects.requireNonNull(MMOItems.plugin.getConfig().getString("item-upgrading.stat-change-negative", "&c"));
// Parse ig
if (isNegative) {
// Failure-colored
return base.replace("<p>", fauc).replace("#stat#", value);
// Its a positive upgrade-yo
} else {
// Success-coloreds
return base.replace("<p>", succ).replace("#stat#", value);
}
}
}
package net.Indyuce.mmoitems.api;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.util.message.FFPMMOItems;
import net.Indyuce.mmoitems.stat.Enchants;
import net.Indyuce.mmoitems.stat.data.UpgradeData;
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.Upgradable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class UpgradeTemplate {
@NotNull
private final String id;
@NotNull
private final Map<ItemStat, UpgradeInfo> perStatUpgradeInfos = new HashMap<>();
/**
* Loads an Upgrade Template directly from the YML file. Neat!
*/
public UpgradeTemplate(@NotNull ConfigurationSection config) {
Validate.notNull(config, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "You must specify a config section."));
// Build ID
id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-");
// Feedback
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
ffp.activatePrefix(true, "Upgrade Template $i&o" + config.getName());
// For ever stat
for (String key : config.getKeys(false)) {
//UPGRD//MMOItems. Log("\u00a7a>>> \u00a77Stat \u00a72" + key);
// Get internal stat ID
String statFormat = key.toUpperCase().replace("-", "_");
// Attempt to find stat
ItemStat stat = MMOItems.plugin.getStats().get(statFormat);
if (stat == null) { ffp.log(FriendlyFeedbackCategory.ERROR, "Stat '$r{0}$b' $fnot found$b.", statFormat); continue; }
if (!(stat instanceof Upgradable)) { ffp.log(FriendlyFeedbackCategory.ERROR, "Stat $r{0}$b is $fnot upgradeable$b.", stat.getId()); continue; }
if (!(stat.getClearStatData() instanceof Mergeable)) { ffp.log(FriendlyFeedbackCategory.ERROR, "Stat Data used by $r{0}$b is $fnot mergeable$b, and thus it cannot be upgradeable. Contact the dev of this ItemStat.", stat.getId()); continue; }
// Attempt to parse Upgrade Info
try {
// Parsed correctly? Add
perStatUpgradeInfos.put(stat, ((Upgradable) stat).loadUpgradeInfo(config.get(key)));
// Somethings up, generate exception ig
} catch (IllegalArgumentException exception) {
// Log
ffp.log(FriendlyFeedbackCategory.ERROR, exception.getMessage());
}
}
// Print all failures
ffp.sendTo(FriendlyFeedbackCategory.ERROR, MMOItems.getConsole());
}
/**
* Get the internal ID of this template.
* <p></p>
* In the format: <code><b>upgrade-template-name</b></code>
* <p>(No spaces nor underscores, lowercase)</p>
*/
@NotNull public String getId() {
return id;
}
/**
* Get the <code>ItemStat</code>s that this template has <code>UpgradeInfo</code> about.
*/
@NotNull public Set<ItemStat> getKeys() {
return perStatUpgradeInfos.keySet();
}
/**
* Get the <code>UpgradeInfo</code> associated with this stat.
*/
@Nullable public UpgradeInfo getUpgradeInfo(@NotNull ItemStat stat) {
return perStatUpgradeInfos.get(stat);
}
/**
* Upgrades this MMOItem by 1 level
*/
public void upgrade(@NotNull MMOItem mmoitem) {
// Yes
upgradeTo(mmoitem, mmoitem.getUpgradeLevel() + 1);
}
/**
* Upgrades this MMOItem's stats and sets the level.
* @param level Target level, which may even be negative!
*/
public void upgradeTo(@NotNull MMOItem mmoitem, int level) {
// Make sure to not overwrite player's enchantments when upgrading.
Enchants.separateEnchantments(mmoitem);
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Separated enchantments");
// Set the items level
UpgradeData dat;
if (mmoitem.hasData(ItemStats.UPGRADE)) {
dat = (UpgradeData) mmoitem.getData(ItemStats.UPGRADE);
} else { dat = new UpgradeData(null, null, false, false, 0, 0, 100); }
dat.setLevel(level);
mmoitem.setData(ItemStats.UPGRADE, dat);
//UPGR//MMOItems.log("\u00a76>\u00a73>\u00a7a> \u00a77Upgrading to level \u00a7e" + dat.getLevel());
// For every Stat-UpgradeInfo pair
for (ItemStat stat : perStatUpgradeInfos.keySet()) {
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Upgrading stat \u00a7e" + stat.getId());
// Preprocess
((Upgradable) stat).preprocess(mmoitem);
// Initializes Stat History
StatHistory hist = StatHistory.from(mmoitem, stat);
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Stat History Initialized");
// Midprocess
((Upgradable) stat).midprocess(mmoitem);
// The Stat History now manages applying upgrades.
//HSY//MMOItems.log(" \u00a73-\u00a7a- \u00a77Upgrade Recalculation \u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-");
mmoitem.setData(stat, hist.recalculate(level));
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Recalculated");
// Postprocess
((Upgradable) stat).postprocess(mmoitem);
}
}
/**
* @return If the user has set in the config that the stats should display how the item's upgrades have affected them.
*/
public static boolean isDisplayingUpgrades() { return MMOItems.plugin.getConfig().getBoolean("item-upgrading.display-stat-changes", false); }
/**
* The user may define how to display stat changes due to upgrades,
* as well as 'negative' and 'positive' colours.
*
* @return A string ready to just have its colors parsed and inserted into lore.
* @param value The <code>toString()</code> of this will replace all instances of <code>#stat#</code> the user specifies in the config.
* @param isNegative Should 'negative' coloration be used instead of positive? The user uses the placeholder <code><b>< p ></b></code> in this place.
*/
@NotNull public static String getUpgradeChangeSuffix(@NotNull String value, boolean isNegative) {
// Get the base
String base = Objects.requireNonNull(MMOItems.plugin.getConfig().getString("item-upgrading.stat-change-suffix", " &8(<p>#stat#&8)"));
String succ = Objects.requireNonNull(MMOItems.plugin.getConfig().getString("item-upgrading.stat-change-positive", "&a"));
String fauc = Objects.requireNonNull(MMOItems.plugin.getConfig().getString("item-upgrading.stat-change-negative", "&c"));
// Parse ig
if (isNegative) {
// Failure-colored
return base.replace("<p>", fauc).replace("#stat#", value);
// Its a positive upgrade-yo
} else {
// Success-coloreds
return base.replace("<p>", succ).replace("#stat#", value);
}
}
}

View File

@ -1,75 +1,75 @@
package net.Indyuce.mmoitems.api.block;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.util.MushroomState;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import org.bukkit.inventory.ItemStack;
public class CustomBlock {
private final int id;
private final MushroomState state;
private final MMOItem mmoitem;
private final WorldGenTemplate template;
private final int minExp, maxExp, requiredPower;
private final boolean requirePowerToBreak;
public CustomBlock(MushroomState state, MMOItem mmoitem) {
this.mmoitem = mmoitem;
this.id = (mmoitem.hasData(ItemStats.BLOCK_ID)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.BLOCK_ID)).getValue() : 0;
this.state = state;
this.minExp = (mmoitem.hasData(ItemStats.MIN_XP)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.MIN_XP)).getValue() : 0;
this.maxExp = (mmoitem.hasData(ItemStats.MAX_XP)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.MAX_XP)).getValue() : 0;
this.requiredPower = (mmoitem.hasData(ItemStats.REQUIRED_POWER)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.REQUIRED_POWER)).getValue()
: 0;
this.requirePowerToBreak = (mmoitem.hasData(ItemStats.REQUIRE_POWER_TO_BREAK)) ? (boolean) ((BooleanData) mmoitem.getData(ItemStats.REQUIRE_POWER_TO_BREAK)).isEnabled() : false;
this.template = (mmoitem.hasData(ItemStats.GEN_TEMPLATE))
? MMOItems.plugin.getWorldGen().getOrThrow((mmoitem.getData(ItemStats.GEN_TEMPLATE)).toString())
: null;
}
public int getId() {
return id;
}
public MushroomState getState() {
return state;
}
public boolean hasGenTemplate() {
return template != null;
}
public WorldGenTemplate getGenTemplate() {
return template;
}
public int getMinExpDrop() {
return minExp;
}
public int getMaxExpDrop() {
return maxExp;
}
public int getRequiredPower() {
return requiredPower;
}
public ItemStack getItem() {
return mmoitem.newBuilder().build();
}
public boolean requirePowerToBreak() {
return requirePowerToBreak;
}
}
package net.Indyuce.mmoitems.api.block;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.util.MushroomState;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import org.bukkit.inventory.ItemStack;
public class CustomBlock {
private final int id;
private final MushroomState state;
private final MMOItem mmoitem;
private final WorldGenTemplate template;
private final int minExp, maxExp, requiredPower;
private final boolean requirePowerToBreak;
public CustomBlock(MushroomState state, MMOItem mmoitem) {
this.mmoitem = mmoitem;
this.id = (mmoitem.hasData(ItemStats.BLOCK_ID)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.BLOCK_ID)).getValue() : 0;
this.state = state;
this.minExp = (mmoitem.hasData(ItemStats.MIN_XP)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.MIN_XP)).getValue() : 0;
this.maxExp = (mmoitem.hasData(ItemStats.MAX_XP)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.MAX_XP)).getValue() : 0;
this.requiredPower = (mmoitem.hasData(ItemStats.REQUIRED_POWER)) ? (int) ((DoubleData) mmoitem.getData(ItemStats.REQUIRED_POWER)).getValue()
: 0;
this.requirePowerToBreak = (mmoitem.hasData(ItemStats.REQUIRE_POWER_TO_BREAK)) ? (boolean) ((BooleanData) mmoitem.getData(ItemStats.REQUIRE_POWER_TO_BREAK)).isEnabled() : false;
this.template = (mmoitem.hasData(ItemStats.GEN_TEMPLATE))
? MMOItems.plugin.getWorldGen().getOrThrow((mmoitem.getData(ItemStats.GEN_TEMPLATE)).toString())
: null;
}
public int getId() {
return id;
}
public MushroomState getState() {
return state;
}
public boolean hasGenTemplate() {
return template != null;
}
public WorldGenTemplate getGenTemplate() {
return template;
}
public int getMinExpDrop() {
return minExp;
}
public int getMaxExpDrop() {
return maxExp;
}
public int getRequiredPower() {
return requiredPower;
}
public ItemStack getItem() {
return mmoitem.newBuilder().build();
}
public boolean requirePowerToBreak() {
return requirePowerToBreak;
}
}

View File

@ -1,171 +1,171 @@
package net.Indyuce.mmoitems.api.block;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.ConfigurationSection;
public class WorldGenTemplate {
private final String id;
private final double chunkChance;
private final int minDepth, maxDepth, veinSize, veinCount;
private final List<Material> replaceable = new ArrayList<>();
private final List<Material> bordering = new ArrayList<>();
private final List<Material> notBordering = new ArrayList<>();
private final List<String> worldWhitelist = new ArrayList<>(), worldBlacklist = new ArrayList<>();
private final List<String> biomeWhitelist = new ArrayList<>(), biomeBlacklist = new ArrayList<>();
private final boolean slimeChunk;
public WorldGenTemplate(ConfigurationSection config) {
Validate.notNull(config, "Could not read gen template config");
id = config.getName().toLowerCase().replace(" ", "-").replace("_", "-");
config.getStringList("replace").forEach(str -> replaceable.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
config.getStringList("bordering").forEach(str -> bordering.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
config.getStringList("not-bordering").forEach(str -> notBordering.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
for (String world : config.getStringList("worlds")) {
(world.startsWith("!") ? worldBlacklist : worldWhitelist).add(world.toLowerCase().replace("_", "-"));
}
for (String biome : config.getStringList("biomes")) {
(biome.startsWith("!") ? biomeBlacklist : biomeWhitelist).add(biome.toUpperCase().replace("-", "_").replace(" ", "_"));
}
chunkChance = config.getDouble("chunk-chance");
slimeChunk = config.getBoolean("slime-chunk", false);
String[] depth = config.getString("depth").split("=");
minDepth = Integer.parseInt(depth[0]);
maxDepth = Integer.parseInt(depth[1]);
//Validate.isTrue(minDepth >= 0, "Min depth must be greater than 0");
//Validate.isTrue(maxDepth < 256, "Max depth must be at most 255");
veinSize = config.getInt("vein-size");
veinCount = config.getInt("vein-count");
Validate.isTrue(veinSize > 0 && veinCount > 0, "Vein size and count must be at least 1");
}
public String getId() {
return id;
}
public double getChunkChance() {
return chunkChance;
}
public int getVeinSize() {
return veinSize;
}
public int getVeinCount() {
return veinCount;
}
public int getMinDepth() {
return minDepth;
}
public int getMaxDepth() {
return maxDepth;
}
public boolean canGenerateInWorld(World w) {
// check world list
String world = w.getName().toLowerCase().replace("_", "-");
if (!worldWhitelist.isEmpty() && !worldWhitelist.contains(world)) {
return false;
}
if (!worldBlacklist.isEmpty() && worldBlacklist.contains(world)) {
return false;
}
return true;
}
public boolean canGenerate(Location pos) {
// check biome list
Biome biome = pos.getWorld().getBiome(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
if (!biomeWhitelist.isEmpty() && !biomeWhitelist.contains(biome.name())) {
return false;
}
if (!biomeBlacklist.isEmpty() && biomeBlacklist.contains(biome.name())) {
return false;
}
// check extra options
if (slimeChunk && !pos.getChunk().isSlimeChunk()) {
return false;
}
if(!bordering.isEmpty()) {
if(!checkIfBorderingBlocks(pos)) {
return false;
}
}
if(!notBordering.isEmpty()) {
return checkIfNotBorderingBlocks(pos);
}
// can generate if no restrictions applied
return true;
}
public boolean canReplace(Material type) {
return replaceable.isEmpty() || replaceable.contains(type);
}
public boolean canBorder(Material type) {
return bordering.isEmpty() || bordering.contains(type);
}
public boolean checkIfBorderingBlocks(Location pos) {
if(!canBorder(pos.getBlock().getRelative(BlockFace.NORTH).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.EAST).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.SOUTH).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.WEST).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.UP).getType())) {
return false;
}
return canBorder(pos.getBlock().getRelative(BlockFace.DOWN).getType());
}
public boolean canNotBorder(Material type) {
return !notBordering.isEmpty() && notBordering.contains(type);
}
public boolean checkIfNotBorderingBlocks(Location pos) {
if(canNotBorder(pos.getBlock().getRelative(BlockFace.NORTH).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.EAST).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.SOUTH).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.WEST).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.UP).getType())) {
return false;
}
return !canNotBorder(pos.getBlock().getRelative(BlockFace.DOWN).getType());
}
}
package net.Indyuce.mmoitems.api.block;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.ConfigurationSection;
public class WorldGenTemplate {
private final String id;
private final double chunkChance;
private final int minDepth, maxDepth, veinSize, veinCount;
private final List<Material> replaceable = new ArrayList<>();
private final List<Material> bordering = new ArrayList<>();
private final List<Material> notBordering = new ArrayList<>();
private final List<String> worldWhitelist = new ArrayList<>(), worldBlacklist = new ArrayList<>();
private final List<String> biomeWhitelist = new ArrayList<>(), biomeBlacklist = new ArrayList<>();
private final boolean slimeChunk;
public WorldGenTemplate(ConfigurationSection config) {
Validate.notNull(config, "Could not read gen template config");
id = config.getName().toLowerCase().replace(" ", "-").replace("_", "-");
config.getStringList("replace").forEach(str -> replaceable.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
config.getStringList("bordering").forEach(str -> bordering.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
config.getStringList("not-bordering").forEach(str -> notBordering.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
for (String world : config.getStringList("worlds")) {
(world.startsWith("!") ? worldBlacklist : worldWhitelist).add(world.toLowerCase().replace("_", "-"));
}
for (String biome : config.getStringList("biomes")) {
(biome.startsWith("!") ? biomeBlacklist : biomeWhitelist).add(biome.toUpperCase().replace("-", "_").replace(" ", "_"));
}
chunkChance = config.getDouble("chunk-chance");
slimeChunk = config.getBoolean("slime-chunk", false);
String[] depth = config.getString("depth").split("=");
minDepth = Integer.parseInt(depth[0]);
maxDepth = Integer.parseInt(depth[1]);
//Validate.isTrue(minDepth >= 0, "Min depth must be greater than 0");
//Validate.isTrue(maxDepth < 256, "Max depth must be at most 255");
veinSize = config.getInt("vein-size");
veinCount = config.getInt("vein-count");
Validate.isTrue(veinSize > 0 && veinCount > 0, "Vein size and count must be at least 1");
}
public String getId() {
return id;
}
public double getChunkChance() {
return chunkChance;
}
public int getVeinSize() {
return veinSize;
}
public int getVeinCount() {
return veinCount;
}
public int getMinDepth() {
return minDepth;
}
public int getMaxDepth() {
return maxDepth;
}
public boolean canGenerateInWorld(World w) {
// check world list
String world = w.getName().toLowerCase().replace("_", "-");
if (!worldWhitelist.isEmpty() && !worldWhitelist.contains(world)) {
return false;
}
if (!worldBlacklist.isEmpty() && worldBlacklist.contains(world)) {
return false;
}
return true;
}
public boolean canGenerate(Location pos) {
// check biome list
Biome biome = pos.getWorld().getBiome(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
if (!biomeWhitelist.isEmpty() && !biomeWhitelist.contains(biome.name())) {
return false;
}
if (!biomeBlacklist.isEmpty() && biomeBlacklist.contains(biome.name())) {
return false;
}
// check extra options
if (slimeChunk && !pos.getChunk().isSlimeChunk()) {
return false;
}
if(!bordering.isEmpty()) {
if(!checkIfBorderingBlocks(pos)) {
return false;
}
}
if(!notBordering.isEmpty()) {
return checkIfNotBorderingBlocks(pos);
}
// can generate if no restrictions applied
return true;
}
public boolean canReplace(Material type) {
return replaceable.isEmpty() || replaceable.contains(type);
}
public boolean canBorder(Material type) {
return bordering.isEmpty() || bordering.contains(type);
}
public boolean checkIfBorderingBlocks(Location pos) {
if(!canBorder(pos.getBlock().getRelative(BlockFace.NORTH).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.EAST).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.SOUTH).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.WEST).getType())) {
return false;
}
if(!canBorder(pos.getBlock().getRelative(BlockFace.UP).getType())) {
return false;
}
return canBorder(pos.getBlock().getRelative(BlockFace.DOWN).getType());
}
public boolean canNotBorder(Material type) {
return !notBordering.isEmpty() && notBordering.contains(type);
}
public boolean checkIfNotBorderingBlocks(Location pos) {
if(canNotBorder(pos.getBlock().getRelative(BlockFace.NORTH).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.EAST).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.SOUTH).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.WEST).getType())) {
return false;
}
if(canNotBorder(pos.getBlock().getRelative(BlockFace.UP).getType())) {
return false;
}
return !canNotBorder(pos.getBlock().getRelative(BlockFace.DOWN).getType());
}
}

View File

@ -1,32 +1,32 @@
package net.Indyuce.mmoitems.api.crafting.condition;
import java.util.Arrays;
import java.util.List;
import net.Indyuce.mmoitems.api.player.PlayerData;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class ClassCondition extends Condition {
private final List<String> classes;
public ClassCondition(MMOLineConfig config) {
super("class");
config.validate("list");
classes = Arrays.asList(config.getString("list").split(","));
}
@Override
public boolean isMet(PlayerData data) {
return classes.contains(data.getRPG().getClassName());
}
@Override
public String formatDisplay(String string) {
return string.replace("#class#", String.join(", ", classes));
}
@Override
public void whenCrafting(PlayerData data) {
}
}
package net.Indyuce.mmoitems.api.crafting.condition;
import java.util.Arrays;
import java.util.List;
import net.Indyuce.mmoitems.api.player.PlayerData;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class ClassCondition extends Condition {
private final List<String> classes;
public ClassCondition(MMOLineConfig config) {
super("class");
config.validate("list");
classes = Arrays.asList(config.getString("list").split(","));
}
@Override
public boolean isMet(PlayerData data) {
return classes.contains(data.getRPG().getClassName());
}
@Override
public String formatDisplay(String string) {
return string.replace("#class#", String.join(", ", classes));
}
@Override
public void whenCrafting(PlayerData data) {
}
}

View File

@ -1,30 +1,30 @@
package net.Indyuce.mmoitems.api.crafting.condition;
import java.util.Arrays;
import java.util.List;
import net.Indyuce.mmoitems.api.player.PlayerData;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class PermissionCondition extends GenericCondition {
private final List<String> permissions;
public PermissionCondition(MMOLineConfig config) {
super("permission", config);
config.validate("list");
permissions = Arrays.asList(config.getString("list").split(","));
}
@Override
public boolean isMet(PlayerData data) {
for (String permission : permissions)
if (!data.getPlayer().hasPermission(permission))
return false;
return true;
}
@Override
public void whenCrafting(PlayerData data) {
}
}
package net.Indyuce.mmoitems.api.crafting.condition;
import java.util.Arrays;
import java.util.List;
import net.Indyuce.mmoitems.api.player.PlayerData;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class PermissionCondition extends GenericCondition {
private final List<String> permissions;
public PermissionCondition(MMOLineConfig config) {
super("permission", config);
config.validate("list");
permissions = Arrays.asList(config.getString("list").split(","));
}
@Override
public boolean isMet(PlayerData data) {
for (String permission : permissions)
if (!data.getPlayer().hasPermission(permission))
return false;
return true;
}
@Override
public void whenCrafting(PlayerData data) {
}
}

View File

@ -1,30 +1,30 @@
package net.Indyuce.mmoitems.api.droptable.item;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.PlayerData;
public class BlockDropItem extends DropItem {
private final int blockId;
public BlockDropItem(int blockId, String info) {
super(info);
this.blockId = blockId;
}
public int getBlockId() {
return blockId;
}
@Override
public ItemStack getItem(PlayerData player, int amount) {
return MMOItems.plugin.getCustomBlocks().getBlock(blockId).getItem();
}
@Override
public String getKey() {
return "block." + getBlockId();
}
}
package net.Indyuce.mmoitems.api.droptable.item;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.PlayerData;
public class BlockDropItem extends DropItem {
private final int blockId;
public BlockDropItem(int blockId, String info) {
super(info);
this.blockId = blockId;
}
public int getBlockId() {
return blockId;
}
@Override
public ItemStack getItem(PlayerData player, int amount) {
return MMOItems.plugin.getCustomBlocks().getBlock(blockId).getItem();
}
@Override
public String getKey() {
return "block." + getBlockId();
}
}

View File

@ -1,74 +1,74 @@
package net.Indyuce.mmoitems.api.droptable.item;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.RandomAmount;
import io.lumine.mythic.lib.api.item.NBTItem;
public class MMOItemDropItem extends DropItem {
private final Type type;
private final String id;
private final double unidentification;
public MMOItemDropItem(Type type, String id, double drop, double unidentification, RandomAmount amount) {
this(type, id, drop, unidentification, amount.getMin(), amount.getMax());
}
public MMOItemDropItem(Type type, String id, double drop, double unidentification, int min, int max) {
super(drop, min, max);
this.type = type;
this.id = id;
this.unidentification = unidentification;
}
public MMOItemDropItem(Type type, String id, String info) {
super(info);
this.type = type;
this.id = id;
String[] argSplit = info.split(",");
unidentification = Double.parseDouble(argSplit[2]) / 100;
}
public Type getType() {
return type;
}
public String getId() {
return id;
}
public boolean rollIdentification() {
return random.nextDouble() < unidentification;
}
@Override
public ItemStack getItem(PlayerData player, int amount) {
if (!MMOItems.plugin.getTemplates().hasTemplate(type, id))
return null;
ItemStack item = player == null ? MMOItems.plugin.getItem(type, id) : MMOItems.plugin.getItem(type, id, player);
if (item == null || item.getType() == Material.AIR)
return null;
/*
* Apply unidentification before editing the item amount
*/
if (rollIdentification())
item = type.getUnidentifiedTemplate().newBuilder(NBTItem.get(item)).build();
item.setAmount(amount);
return item;
}
@Override
public String getKey() {
return type.getId() + "." + id;
}
}
package net.Indyuce.mmoitems.api.droptable.item;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.RandomAmount;
import io.lumine.mythic.lib.api.item.NBTItem;
public class MMOItemDropItem extends DropItem {
private final Type type;
private final String id;
private final double unidentification;
public MMOItemDropItem(Type type, String id, double drop, double unidentification, RandomAmount amount) {
this(type, id, drop, unidentification, amount.getMin(), amount.getMax());
}
public MMOItemDropItem(Type type, String id, double drop, double unidentification, int min, int max) {
super(drop, min, max);
this.type = type;
this.id = id;
this.unidentification = unidentification;
}
public MMOItemDropItem(Type type, String id, String info) {
super(info);
this.type = type;
this.id = id;
String[] argSplit = info.split(",");
unidentification = Double.parseDouble(argSplit[2]) / 100;
}
public Type getType() {
return type;
}
public String getId() {
return id;
}
public boolean rollIdentification() {
return random.nextDouble() < unidentification;
}
@Override
public ItemStack getItem(PlayerData player, int amount) {
if (!MMOItems.plugin.getTemplates().hasTemplate(type, id))
return null;
ItemStack item = player == null ? MMOItems.plugin.getItem(type, id) : MMOItems.plugin.getItem(type, id, player);
if (item == null || item.getType() == Material.AIR)
return null;
/*
* Apply unidentification before editing the item amount
*/
if (rollIdentification())
item = type.getUnidentifiedTemplate().newBuilder(NBTItem.get(item)).build();
item.setAmount(amount);
return item;
}
@Override
public String getKey() {
return type.getId() + "." + id;
}
}

View File

@ -1,33 +1,33 @@
package net.Indyuce.mmoitems.api.edition;
import net.Indyuce.mmoitems.gui.PluginInventory;
public interface Edition {
/**
* Processes the player input.
*
* @param input Current player input
* @return False if it should continue listening to player input
*/
boolean processInput(String input);
/**
* @return The inventory used to edit some data, which also contains info
* about the player currently editing
*/
PluginInventory getInventory();
/**
* Called when edition is opened.
*
* @param message Message which should be sent to the player
*/
void enable(String... message);
/**
* @return If the previously opened GUI should be opened right after edition
* ends or if it should be ignored
*/
boolean shouldGoBack();
}
package net.Indyuce.mmoitems.api.edition;
import net.Indyuce.mmoitems.gui.PluginInventory;
public interface Edition {
/**
* Processes the player input.
*
* @param input Current player input
* @return False if it should continue listening to player input
*/
boolean processInput(String input);
/**
* @return The inventory used to edit some data, which also contains info
* about the player currently editing
*/
PluginInventory getInventory();
/**
* Called when edition is opened.
*
* @param message Message which should be sent to the player
*/
void enable(String... message);
/**
* @return If the previously opened GUI should be opened right after edition
* ends or if it should be ignored
*/
boolean shouldGoBack();
}

View File

@ -1,45 +1,45 @@
package net.Indyuce.mmoitems.api.edition.input;
import org.bukkit.entity.Player;
import net.Indyuce.mmoitems.api.edition.Edition;
public abstract class PlayerInputHandler {
/**
* Saves the last inventory opened, the item data, and the last opened page;
* allows for a much easier access to this data
*/
private final Edition edition;
/**
* Abstract class which lists all possible ways to retrieve player input
*
* @param edition The edition object
*/
public PlayerInputHandler(Edition edition) {
this.edition = edition;
}
public Player getPlayer() {
return edition.getInventory().getPlayer();
}
/**
* Processes the player input, closes the edition process if needed and
* opens the previously opened GUI if needed. This method is protected
* because it should only be ran by edition process classes
*
* @param input Player input
*/
protected void registerInput(String input) {
if (!edition.processInput(input))
return;
if (edition.shouldGoBack())
edition.getInventory().open();
close();
}
public abstract void close();
}
package net.Indyuce.mmoitems.api.edition.input;
import org.bukkit.entity.Player;
import net.Indyuce.mmoitems.api.edition.Edition;
public abstract class PlayerInputHandler {
/**
* Saves the last inventory opened, the item data, and the last opened page;
* allows for a much easier access to this data
*/
private final Edition edition;
/**
* Abstract class which lists all possible ways to retrieve player input
*
* @param edition The edition object
*/
public PlayerInputHandler(Edition edition) {
this.edition = edition;
}
public Player getPlayer() {
return edition.getInventory().getPlayer();
}
/**
* Processes the player input, closes the edition process if needed and
* opens the previously opened GUI if needed. This method is protected
* because it should only be ran by edition process classes
*
* @param input Player input
*/
protected void registerInput(String input) {
if (!edition.processInput(input))
return;
if (edition.shouldGoBack())
edition.getInventory().open();
close();
}
public abstract void close();
}

Some files were not shown because too many files have changed in this diff Show More