mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-09 07:37:34 +01:00
!Added unidentification and soulbound chance to mmocore drop items
This commit is contained in:
parent
ab9eec1412
commit
9470f35cc9
@ -27,7 +27,6 @@ import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
|
||||
public class MMOUtils {
|
||||
public static String getSkullTextureURL(ItemStack item) {
|
||||
@ -250,18 +249,19 @@ public class MMOUtils {
|
||||
return format;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean areSimilar(ItemStack item1, ItemStack iitem2) {
|
||||
if (item1.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && iitem2.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||
ItemMeta meta1 = item1.getItemMeta();
|
||||
ItemMeta meta2 = iitem2.getItemMeta();
|
||||
|
||||
if (meta1.hasDisplayName() && meta2.hasDisplayName())
|
||||
return meta1.getDisplayName().equalsIgnoreCase(meta2.getDisplayName());
|
||||
}
|
||||
|
||||
return item1.isSimilar(iitem2);
|
||||
}
|
||||
// @Deprecated
|
||||
// public static boolean areSimilar(ItemStack item1, ItemStack iitem2) {
|
||||
// if (item1.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() &&
|
||||
// iitem2.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||
// ItemMeta meta1 = item1.getItemMeta();
|
||||
// ItemMeta meta2 = iitem2.getItemMeta();
|
||||
//
|
||||
// if (meta1.hasDisplayName() && meta2.hasDisplayName())
|
||||
// return meta1.getDisplayName().equalsIgnoreCase(meta2.getDisplayName());
|
||||
// }
|
||||
//
|
||||
// return item1.isSimilar(iitem2);
|
||||
// }
|
||||
|
||||
public static double truncation(double x, int n) {
|
||||
double pow = Math.pow(10.0, n);
|
||||
|
@ -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.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.MMOItemDropItem;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemTrigger;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemsBlockType;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.MineMIBlockExperienceSource;
|
||||
@ -91,10 +89,7 @@ public class MMOCoreMMOLoader extends MMOLoader {
|
||||
@Override
|
||||
public DropItem loadDropItem(MMOLineConfig config) {
|
||||
|
||||
if (config.getKey().equals("mmoitem"))
|
||||
return new MMOItemDropItem(config);
|
||||
|
||||
if (config.getKey().equals("gentemplate"))
|
||||
if (config.getKey().equals("mmoitem") || config.getKey().equals("mmoitemtemplate"))
|
||||
return new ItemTemplateDropItem(config);
|
||||
|
||||
if (config.getKey().equals("miloot"))
|
||||
|
@ -1,10 +1,12 @@
|
||||
package net.Indyuce.mmoitems.comp.mmocore.load;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
|
||||
public abstract class ItemGenerationDropItem extends DropItem {
|
||||
@ -12,6 +14,9 @@ public abstract class ItemGenerationDropItem extends DropItem {
|
||||
protected final int level;
|
||||
protected final ItemTier tier;
|
||||
|
||||
// chance to get one of these two modifiers
|
||||
private final double unidentified, soulbound;
|
||||
|
||||
public ItemGenerationDropItem(MMOLineConfig config) {
|
||||
super(config);
|
||||
|
||||
@ -24,5 +29,17 @@ public abstract class ItemGenerationDropItem extends DropItem {
|
||||
tier = MMOItems.plugin.getTiers().get(format);
|
||||
} else
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
package net.Indyuce.mmoitems.comp.mmocore.load;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
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.player.RPGPlayer;
|
||||
import net.Indyuce.mmoitems.stat.data.SoulboundData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +1,18 @@
|
||||
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.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
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.util.SmartGive;
|
||||
|
||||
public class MMOItemTrigger extends Trigger {
|
||||
private final Type type;
|
||||
private final String id;
|
||||
private final MMOItemTemplate template;
|
||||
private final int amount;
|
||||
|
||||
public MMOItemTrigger(MMOLineConfig config) {
|
||||
@ -22,25 +21,20 @@ public class MMOItemTrigger extends Trigger {
|
||||
config.validate("type", "id");
|
||||
|
||||
String format = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type " + format);
|
||||
type = MMOItems.plugin.getTypes().get(format);
|
||||
Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type with ID '" + 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;
|
||||
Validate.isTrue(type.getConfigFile().getConfig().contains(id), "Could not find item id " + id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(PlayerData player) {
|
||||
if (!MMOItems.plugin.getTemplates().hasTemplate(type, id))
|
||||
return;
|
||||
|
||||
ItemStack item = MMOItems.plugin.getItem(type, id, player.getMMOPlayerData().getMMOItems());
|
||||
if (item == null || item.getType() == Material.AIR)
|
||||
return;
|
||||
|
||||
ItemStack item = template.newBuilder(player.getMMOPlayerData().getMMOItems().getRPG()).build().newBuilder().build();
|
||||
item.setAmount(amount);
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
new SmartGive(player.getPlayer()).give(item);
|
||||
new SmartGive(player.getPlayer()).give(item);
|
||||
}
|
||||
}
|
||||
|
@ -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.TypeFilter;
|
||||
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;
|
||||
|
||||
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);
|
||||
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)
|
||||
loot.applyFilter(new ClassFilter(rpgPlayer));
|
||||
@ -55,8 +58,11 @@ public class RandomItemDropItem extends ItemGenerationDropItem {
|
||||
if (rolled == null)
|
||||
return;
|
||||
|
||||
ItemStack gen = rolled.newBuilder().build();
|
||||
gen.setAmount(rollAmount());
|
||||
builder.addLoot(gen);
|
||||
if (rollSoulbound())
|
||||
rolled.setData(ItemStat.SOULBOUND, new SoulboundData(rpgPlayer.getPlayer(), 1));
|
||||
|
||||
ItemStack stack = rollUnidentification(rolled);
|
||||
stack.setAmount(rollAmount());
|
||||
builder.addLoot(stack);
|
||||
}
|
||||
}
|
||||
|
@ -40,22 +40,23 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, 45, Message.RECIPE_PREVIEW.formatRaw(ChatColor.RESET));
|
||||
ingredients.clear();
|
||||
for(CheckedIngredient ing : recipe.getIngredients()) {
|
||||
if(ing.getIngredient().getAmount() > 64) {
|
||||
for (CheckedIngredient ing : recipe.getIngredients()) {
|
||||
if (ing.getIngredient().getAmount() > 64) {
|
||||
ItemStack sample = ing.getIngredient().generateItemStack(playerData.getRPG());
|
||||
sample.setAmount(64);
|
||||
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);
|
||||
//check for remainders
|
||||
if((stacks % 64) == 0)
|
||||
//simply add the desired amount of ingredients
|
||||
for(int i = 0; i < stacks; i++)
|
||||
// check for remainders
|
||||
if ((stacks % 64) == 0)
|
||||
// simply add the desired amount of ingredients
|
||||
for (int i = 0; i < stacks; i++)
|
||||
ingredients.add(sample.clone());
|
||||
else
|
||||
//iterate stacks + 1 for the final one
|
||||
for(int i = 0; i < (stacks + 1); i++) {
|
||||
if(i == stacks) sample.setAmount(amount - (stacks * 64));
|
||||
// iterate stacks + 1 for the final one
|
||||
for (int i = 0; i < (stacks + 1); i++) {
|
||||
if (i == stacks)
|
||||
sample.setAmount(amount - (stacks * 64));
|
||||
ingredients.add(sample.clone());
|
||||
}
|
||||
} else
|
||||
@ -64,7 +65,8 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
|
||||
int min = (page - 1) * slots.length, max = page * slots.length;
|
||||
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));
|
||||
}
|
||||
|
||||
@ -103,7 +105,6 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
@ -111,25 +112,25 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
if (!MMOUtils.isMetaItem(event.getCurrentItem(), false))
|
||||
return;
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.CONFIRM.getItem())) {
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.CONFIRM.getItem())) {
|
||||
previous.processRecipe(recipe);
|
||||
previous.open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.PREVIOUS_PAGE.getItem())) {
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_PAGE.getItem())) {
|
||||
page--;
|
||||
open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.NEXT_PAGE.getItem())) {
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_PAGE.getItem())) {
|
||||
page++;
|
||||
open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.BACK.getItem()))
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.BACK.getItem()))
|
||||
previous.open();
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,6 @@ public class CraftingStationView extends PluginInventory {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
@ -139,25 +138,25 @@ public class CraftingStationView extends PluginInventory {
|
||||
if (!MMOUtils.isMetaItem(event.getCurrentItem(), false))
|
||||
return;
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.PREVIOUS_IN_QUEUE.getItem())) {
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_IN_QUEUE.getItem())) {
|
||||
queueOffset--;
|
||||
open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.NEXT_IN_QUEUE.getItem())) {
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_IN_QUEUE.getItem())) {
|
||||
queueOffset++;
|
||||
open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.NEXT_PAGE.getItem())) {
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.NEXT_PAGE.getItem())) {
|
||||
page++;
|
||||
open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.PREVIOUS_PAGE.getItem())) {
|
||||
if (event.getCurrentItem().isSimilar(ConfigItem.PREVIOUS_PAGE.getItem())) {
|
||||
page--;
|
||||
open();
|
||||
return;
|
||||
|
@ -17,7 +17,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
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
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void updateOnClick(InventoryClickEvent event) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
@ -89,7 +87,7 @@ public class UpdaterManager implements Listener {
|
||||
return;
|
||||
|
||||
ItemStack newItem = getUpdated(item);
|
||||
if (!MMOUtils.areSimilar(newItem, item))
|
||||
if (!newItem.equals(item))
|
||||
event.setCurrentItem(newItem);
|
||||
}
|
||||
|
||||
@ -117,7 +115,7 @@ public class UpdaterManager implements Listener {
|
||||
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
|
||||
*/
|
||||
Type type = item.getType();
|
||||
|
@ -2,8 +2,9 @@ package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user