!Added unidentification and soulbound chance to mmocore drop items

This commit is contained in:
Indyuce 2020-08-12 12:57:12 +02:00
parent ab9eec1412
commit 9470f35cc9
11 changed files with 88 additions and 106 deletions

View File

@ -27,7 +27,6 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.version.VersionMaterial;
public class MMOUtils { public class MMOUtils {
public static String getSkullTextureURL(ItemStack item) { public static String getSkullTextureURL(ItemStack item) {
@ -250,18 +249,19 @@ public class MMOUtils {
return format; return format;
} }
@Deprecated // @Deprecated
public static boolean areSimilar(ItemStack item1, ItemStack iitem2) { // public static boolean areSimilar(ItemStack item1, ItemStack iitem2) {
if (item1.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && iitem2.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) { // if (item1.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() &&
ItemMeta meta1 = item1.getItemMeta(); // iitem2.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
ItemMeta meta2 = iitem2.getItemMeta(); // ItemMeta meta1 = item1.getItemMeta();
// ItemMeta meta2 = iitem2.getItemMeta();
if (meta1.hasDisplayName() && meta2.hasDisplayName()) //
return meta1.getDisplayName().equalsIgnoreCase(meta2.getDisplayName()); // if (meta1.hasDisplayName() && meta2.hasDisplayName())
} // return meta1.getDisplayName().equalsIgnoreCase(meta2.getDisplayName());
// }
return item1.isSimilar(iitem2); //
} // return item1.isSimilar(iitem2);
// }
public static double truncation(double x, int n) { public static double truncation(double x, int n) {
double pow = Math.pow(10.0, n); double pow = Math.pow(10.0, n);

View File

@ -22,8 +22,6 @@ import net.Indyuce.mmoitems.comp.mmocore.crafting.ExperienceCraftingTrigger;
import net.Indyuce.mmoitems.comp.mmocore.crafting.ProfessionCondition; import net.Indyuce.mmoitems.comp.mmocore.crafting.ProfessionCondition;
import net.Indyuce.mmoitems.comp.mmocore.load.GetMMOItemObjective; import net.Indyuce.mmoitems.comp.mmocore.load.GetMMOItemObjective;
import net.Indyuce.mmoitems.comp.mmocore.load.ItemTemplateDropItem; import net.Indyuce.mmoitems.comp.mmocore.load.ItemTemplateDropItem;
//import net.Indyuce.mmoitems.comp.mmocore.load.ItemTemplateDropItem;
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemDropItem;
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemTrigger; import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemTrigger;
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemsBlockType; import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemsBlockType;
import net.Indyuce.mmoitems.comp.mmocore.load.MineMIBlockExperienceSource; import net.Indyuce.mmoitems.comp.mmocore.load.MineMIBlockExperienceSource;
@ -91,10 +89,7 @@ public class MMOCoreMMOLoader extends MMOLoader {
@Override @Override
public DropItem loadDropItem(MMOLineConfig config) { public DropItem loadDropItem(MMOLineConfig config) {
if (config.getKey().equals("mmoitem")) if (config.getKey().equals("mmoitem") || config.getKey().equals("mmoitemtemplate"))
return new MMOItemDropItem(config);
if (config.getKey().equals("gentemplate"))
return new ItemTemplateDropItem(config); return new ItemTemplateDropItem(config);
if (config.getKey().equals("miloot")) if (config.getKey().equals("miloot"))

View File

@ -1,10 +1,12 @@
package net.Indyuce.mmoitems.comp.mmocore.load; package net.Indyuce.mmoitems.comp.mmocore.load;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier; import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.api.MMOLineConfig;
public abstract class ItemGenerationDropItem extends DropItem { public abstract class ItemGenerationDropItem extends DropItem {
@ -12,6 +14,9 @@ public abstract class ItemGenerationDropItem extends DropItem {
protected final int level; protected final int level;
protected final ItemTier tier; protected final ItemTier tier;
// chance to get one of these two modifiers
private final double unidentified, soulbound;
public ItemGenerationDropItem(MMOLineConfig config) { public ItemGenerationDropItem(MMOLineConfig config) {
super(config); super(config);
@ -24,5 +29,17 @@ public abstract class ItemGenerationDropItem extends DropItem {
tier = MMOItems.plugin.getTiers().get(format); tier = MMOItems.plugin.getTiers().get(format);
} else } else
tier = null; tier = null;
unidentified = config.getDouble("unidentified", 0);
soulbound = config.getDouble("soulbound", 0);
}
public ItemStack rollUnidentification(MMOItem mmoitem) {
return random.nextDouble() < unidentified ? mmoitem.getType().getUnidentifiedTemplate().newBuilder(mmoitem.newBuilder().buildNBT()).build()
: mmoitem.newBuilder().build();
}
public boolean rollSoulbound() {
return random.nextDouble() < soulbound;
} }
} }

View File

@ -1,13 +1,17 @@
package net.Indyuce.mmoitems.comp.mmocore.load; package net.Indyuce.mmoitems.comp.mmocore.load;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.api.loot.LootBuilder; import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier; import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.data.SoulboundData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.api.MMOLineConfig;
public class ItemTemplateDropItem extends ItemGenerationDropItem { public class ItemTemplateDropItem extends ItemGenerationDropItem {
@ -34,6 +38,13 @@ public class ItemTemplateDropItem extends ItemGenerationDropItem {
int itemLevel = MMOItems.plugin.getTemplates().rollLevel(matchLevel ? rpgPlayer.getLevel() : this.level); int itemLevel = MMOItems.plugin.getTemplates().rollLevel(matchLevel ? rpgPlayer.getLevel() : this.level);
ItemTier itemTier = this.tier != null ? this.tier : MMOItems.plugin.getTemplates().rollTier(); ItemTier itemTier = this.tier != null ? this.tier : MMOItems.plugin.getTemplates().rollTier();
builder.addLoot(template.newBuilder(itemLevel, itemTier).build().newBuilder().build()); MMOItem mmoitem = template.newBuilder(itemLevel, itemTier).build();
if (rollSoulbound())
mmoitem.setData(ItemStat.SOULBOUND, new SoulboundData(rpgPlayer.getPlayer(), 1));
ItemStack stack = rollUnidentification(mmoitem);
stack.setAmount(rollAmount());
builder.addLoot(stack);
} }
} }

View File

@ -1,40 +0,0 @@
package net.Indyuce.mmoitems.comp.mmocore.load;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.mmogroup.mmolib.api.MMOLineConfig;
public class MMOItemDropItem extends DropItem {
private final Type type;
private final String id;
public MMOItemDropItem(MMOLineConfig config) {
super(config);
config.validate("type", "id");
String type = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_");
Validate.isTrue(MMOItems.plugin.getTypes().has(type), "Could not find item type " + type);
this.type = MMOItems.plugin.getTypes().get(type);
this.id = config.getString("id").toUpperCase().replace("-", "_").replace(" ", "_");
}
@Override
public void collect(LootBuilder builder) {
if (!MMOItems.plugin.getTemplates().hasTemplate(type, id))
return;
ItemStack item = MMOItems.plugin.getItem(type, id, builder.getEntity().getMMOPlayerData().getMMOItems());
if (item != null && item.getType() != Material.AIR) {
item.setAmount(rollAmount());
builder.addLoot(item);
}
}
}

View File

@ -1,19 +1,18 @@
package net.Indyuce.mmoitems.comp.mmocore.load; package net.Indyuce.mmoitems.comp.mmocore.load;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.api.util.SmartGive; import net.mmogroup.mmolib.api.util.SmartGive;
public class MMOItemTrigger extends Trigger { public class MMOItemTrigger extends Trigger {
private final Type type; private final MMOItemTemplate template;
private final String id;
private final int amount; private final int amount;
public MMOItemTrigger(MMOLineConfig config) { public MMOItemTrigger(MMOLineConfig config) {
@ -22,25 +21,20 @@ public class MMOItemTrigger extends Trigger {
config.validate("type", "id"); config.validate("type", "id");
String format = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"); String format = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_");
Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type " + format); Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type with ID '" + format + "'");
type = MMOItems.plugin.getTypes().get(format); Type type = MMOItems.plugin.getTypes().get(format);
String id = config.getString("id").replace("-", "_").toUpperCase();
Validate.isTrue(MMOItems.plugin.getTemplates().hasTemplate(type, id), "Could not find MMOItem with ID '" + id + "'");
template = MMOItems.plugin.getTemplates().getTemplate(type, id);
id = config.getString("id").replace("-", "_").toUpperCase();
amount = config.args().length > 0 ? Math.max(1, Integer.parseInt(config.args()[0])) : 1; amount = config.args().length > 0 ? Math.max(1, Integer.parseInt(config.args()[0])) : 1;
Validate.isTrue(type.getConfigFile().getConfig().contains(id), "Could not find item id " + id);
} }
@Override @Override
public void apply(PlayerData player) { public void apply(PlayerData player) {
if (!MMOItems.plugin.getTemplates().hasTemplate(type, id)) ItemStack item = template.newBuilder(player.getMMOPlayerData().getMMOItems().getRPG()).build().newBuilder().build();
return;
ItemStack item = MMOItems.plugin.getItem(type, id, player.getMMOPlayerData().getMMOItems());
if (item == null || item.getType() == Material.AIR)
return;
item.setAmount(amount); item.setAmount(amount);
if (item != null && item.getType() != Material.AIR) new SmartGive(player.getPlayer()).give(item);
new SmartGive(player.getPlayer()).give(item);
} }
} }

View File

@ -11,6 +11,8 @@ import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.template.loot.ClassFilter; import net.Indyuce.mmoitems.api.item.template.loot.ClassFilter;
import net.Indyuce.mmoitems.api.item.template.loot.TypeFilter; import net.Indyuce.mmoitems.api.item.template.loot.TypeFilter;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.data.SoulboundData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.api.MMOLineConfig;
public class RandomItemDropItem extends ItemGenerationDropItem { public class RandomItemDropItem extends ItemGenerationDropItem {
@ -41,7 +43,8 @@ public class RandomItemDropItem extends ItemGenerationDropItem {
int itemLevel = MMOItems.plugin.getTemplates().rollLevel(matchLevel ? rpgPlayer.getLevel() : this.level); int itemLevel = MMOItems.plugin.getTemplates().rollLevel(matchLevel ? rpgPlayer.getLevel() : this.level);
ItemTier itemTier = this.tier != null ? this.tier : MMOItems.plugin.getTemplates().rollTier(); ItemTier itemTier = this.tier != null ? this.tier : MMOItems.plugin.getTemplates().rollTier();
net.Indyuce.mmoitems.api.item.template.loot.LootBuilder loot = new net.Indyuce.mmoitems.api.item.template.loot.LootBuilder(itemLevel, itemTier); net.Indyuce.mmoitems.api.item.template.loot.LootBuilder loot = new net.Indyuce.mmoitems.api.item.template.loot.LootBuilder(itemLevel,
itemTier);
if (matchClass) if (matchClass)
loot.applyFilter(new ClassFilter(rpgPlayer)); loot.applyFilter(new ClassFilter(rpgPlayer));
@ -55,8 +58,11 @@ public class RandomItemDropItem extends ItemGenerationDropItem {
if (rolled == null) if (rolled == null)
return; return;
ItemStack gen = rolled.newBuilder().build(); if (rollSoulbound())
gen.setAmount(rollAmount()); rolled.setData(ItemStat.SOULBOUND, new SoulboundData(rpgPlayer.getPlayer(), 1));
builder.addLoot(gen);
ItemStack stack = rollUnidentification(rolled);
stack.setAmount(rollAmount());
builder.addLoot(stack);
} }
} }

View File

@ -40,22 +40,23 @@ public class CraftingStationPreview extends PluginInventory {
public Inventory getInventory() { public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, 45, Message.RECIPE_PREVIEW.formatRaw(ChatColor.RESET)); Inventory inv = Bukkit.createInventory(this, 45, Message.RECIPE_PREVIEW.formatRaw(ChatColor.RESET));
ingredients.clear(); ingredients.clear();
for(CheckedIngredient ing : recipe.getIngredients()) { for (CheckedIngredient ing : recipe.getIngredients()) {
if(ing.getIngredient().getAmount() > 64) { if (ing.getIngredient().getAmount() > 64) {
ItemStack sample = ing.getIngredient().generateItemStack(playerData.getRPG()); ItemStack sample = ing.getIngredient().generateItemStack(playerData.getRPG());
sample.setAmount(64); sample.setAmount(64);
int amount = ing.getIngredient().getAmount(); int amount = ing.getIngredient().getAmount();
//calculate how many full stacks there are // calculate how many full stacks there are
int stacks = (int) Math.floor(amount / 64); int stacks = (int) Math.floor(amount / 64);
//check for remainders // check for remainders
if((stacks % 64) == 0) if ((stacks % 64) == 0)
//simply add the desired amount of ingredients // simply add the desired amount of ingredients
for(int i = 0; i < stacks; i++) for (int i = 0; i < stacks; i++)
ingredients.add(sample.clone()); ingredients.add(sample.clone());
else else
//iterate stacks + 1 for the final one // iterate stacks + 1 for the final one
for(int i = 0; i < (stacks + 1); i++) { for (int i = 0; i < (stacks + 1); i++) {
if(i == stacks) sample.setAmount(amount - (stacks * 64)); if (i == stacks)
sample.setAmount(amount - (stacks * 64));
ingredients.add(sample.clone()); ingredients.add(sample.clone());
} }
} else } else
@ -64,7 +65,8 @@ public class CraftingStationPreview extends PluginInventory {
int min = (page - 1) * slots.length, max = page * slots.length; int min = (page - 1) * slots.length, max = page * slots.length;
for (int j = min; j < max; j++) { for (int j = min; j < max; j++) {
if (j >= ingredients.size()) break; if (j >= ingredients.size())
break;
inv.setItem(slots[j - min], ingredients.get(j)); inv.setItem(slots[j - min], ingredients.get(j));
} }
@ -103,7 +105,6 @@ public class CraftingStationPreview extends PluginInventory {
return inv; return inv;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void whenClicked(InventoryClickEvent event) { public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true); event.setCancelled(true);
@ -111,25 +112,25 @@ public class CraftingStationPreview extends PluginInventory {
if (!MMOUtils.isMetaItem(event.getCurrentItem(), false)) if (!MMOUtils.isMetaItem(event.getCurrentItem(), false))
return; return;
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.CONFIRM.getItem())) { if (event.getCurrentItem().isSimilar(ConfigItem.CONFIRM.getItem())) {
previous.processRecipe(recipe); previous.processRecipe(recipe);
previous.open(); previous.open();
return; return;
} }
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.PREVIOUS_PAGE.getItem())) { if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_PAGE.getItem())) {
page--; page--;
open(); open();
return; return;
} }
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.NEXT_PAGE.getItem())) { if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_PAGE.getItem())) {
page++; page++;
open(); open();
return; return;
} }
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.BACK.getItem())) if (event.getCurrentItem().isSimilar(ConfigItem.BACK.getItem()))
previous.open(); previous.open();
} }
} }

View File

@ -131,7 +131,6 @@ public class CraftingStationView extends PluginInventory {
return inv; return inv;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void whenClicked(InventoryClickEvent event) { public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true); event.setCancelled(true);
@ -139,25 +138,25 @@ public class CraftingStationView extends PluginInventory {
if (!MMOUtils.isMetaItem(event.getCurrentItem(), false)) if (!MMOUtils.isMetaItem(event.getCurrentItem(), false))
return; return;
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.PREVIOUS_IN_QUEUE.getItem())) { if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_IN_QUEUE.getItem())) {
queueOffset--; queueOffset--;
open(); open();
return; return;
} }
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.NEXT_IN_QUEUE.getItem())) { if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_IN_QUEUE.getItem())) {
queueOffset++; queueOffset++;
open(); open();
return; return;
} }
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.NEXT_PAGE.getItem())) { if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_PAGE.getItem())) {
page++; page++;
open(); open();
return; return;
} }
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.PREVIOUS_PAGE.getItem())) { if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_PAGE.getItem())) {
page--; page--;
open(); open();
return; return;

View File

@ -17,7 +17,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.UpdaterData; import net.Indyuce.mmoitems.api.UpdaterData;
@ -81,7 +80,6 @@ public class UpdaterManager implements Listener {
/** /**
* Updates inventory item when an item is clicked in a player's inventory * Updates inventory item when an item is clicked in a player's inventory
*/ */
@SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void updateOnClick(InventoryClickEvent event) { public void updateOnClick(InventoryClickEvent event) {
ItemStack item = event.getCurrentItem(); ItemStack item = event.getCurrentItem();
@ -89,7 +87,7 @@ public class UpdaterManager implements Listener {
return; return;
ItemStack newItem = getUpdated(item); ItemStack newItem = getUpdated(item);
if (!MMOUtils.areSimilar(newItem, item)) if (!newItem.equals(item))
event.setCurrentItem(newItem); event.setCurrentItem(newItem);
} }
@ -117,7 +115,7 @@ public class UpdaterManager implements Listener {
public ItemStack getUpdated(NBTItem item) { public ItemStack getUpdated(NBTItem item) {
/* /*
* if the item type is null, then it is not an mmoitem and it does not * If the item type is null, then it is not an mmoitem and it does not
* need to be updated * need to be updated
*/ */
Type type = item.getType(); Type type = item.getType();

View File

@ -2,8 +2,9 @@ package net.Indyuce.mmoitems.stat.data;
import java.util.UUID; import java.util.UUID;
import org.bukkit.entity.Player;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.sk89q.worldedit.entity.Player;
import net.Indyuce.mmoitems.stat.data.type.StatData; import net.Indyuce.mmoitems.stat.data.type.StatData;