mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-23 14:51:21 +01:00
Fixed item drop events
This commit is contained in:
parent
4f9e789690
commit
852e62057b
@ -1,40 +0,0 @@
|
||||
package net.Indyuce.mmoitems.api.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.api.block.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
|
||||
public class CustomBlockDropEvent extends PlayerDataEvent {
|
||||
private final CustomBlock block;
|
||||
private final List<ItemStack> drops;
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public CustomBlockDropEvent(PlayerData playerData, CustomBlock block, List<ItemStack> drops) {
|
||||
super(playerData);
|
||||
|
||||
this.block = block;
|
||||
this.drops = drops;
|
||||
}
|
||||
|
||||
public CustomBlock getCustomBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public List<ItemStack> getDrops() {
|
||||
return drops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package net.Indyuce.mmoitems.api.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.Indyuce.mmoitems.api.block.CustomBlock;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -10,32 +9,68 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemDropEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
private boolean cancelled;
|
||||
private final DropCause cause;
|
||||
private final List<ItemStack> drops;
|
||||
private final LivingEntity player;
|
||||
|
||||
// data that depends on drop cause
|
||||
// Data that depends on drop cause
|
||||
private final Block block;
|
||||
private final Entity entity;
|
||||
private final String mythicMobName;
|
||||
private final CustomBlock customBlock;
|
||||
|
||||
public ItemDropEvent(LivingEntity player, List<ItemStack> drops, DropCause cause, Block block) {
|
||||
this(player, drops, cause, block, null, null);
|
||||
/**
|
||||
* When an item drops from a custom block
|
||||
*
|
||||
* @param player Player dropping the item
|
||||
* @param drops Item drops
|
||||
* @param customBlock Custom block broken
|
||||
*/
|
||||
public ItemDropEvent(LivingEntity player, List<ItemStack> drops, CustomBlock customBlock) {
|
||||
this(player, drops, DropCause.CUSTOM_BLOCK, null, null, null, customBlock);
|
||||
}
|
||||
|
||||
public ItemDropEvent(LivingEntity player, List<ItemStack> drops, DropCause cause, Entity entity) {
|
||||
this(player, drops, cause, null, entity, null);
|
||||
/**
|
||||
* When an item drops from a normal block
|
||||
*
|
||||
* @param player Player dropping the item
|
||||
* @param drops Item drops
|
||||
* @param block Normal block broken
|
||||
*/
|
||||
public ItemDropEvent(LivingEntity player, List<ItemStack> drops, Block block) {
|
||||
this(player, drops, DropCause.NORMAL_BLOCK, block, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* When an item drops from a dying entity
|
||||
*
|
||||
* @param player Player dropping the item
|
||||
* @param drops Item drops
|
||||
* @param entity Entity being killed
|
||||
*/
|
||||
public ItemDropEvent(LivingEntity player, List<ItemStack> drops, Entity entity) {
|
||||
this(player, drops, DropCause.NORMAL_MONSTER, null, entity, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* When an item drops from a MythicMobs mob
|
||||
*
|
||||
* @param player Player dropping the item
|
||||
* @param drops Item drops
|
||||
* @param mythicMobName Internal id of the mythic mob
|
||||
*/
|
||||
@Deprecated
|
||||
public ItemDropEvent(LivingEntity player, List<ItemStack> drops, DropCause cause, String mythicMobName) {
|
||||
this(player, drops, cause, null, null, mythicMobName);
|
||||
this(player, drops, DropCause.MYTHIC_MOB, null, null, mythicMobName, null);
|
||||
}
|
||||
|
||||
public ItemDropEvent(LivingEntity player, List<ItemStack> drops, DropCause cause, Block block, Entity entity, String mythicMobName) {
|
||||
private ItemDropEvent(LivingEntity player, List<ItemStack> drops, DropCause cause, Block block, Entity entity, String mythicMobName, CustomBlock customBlock) {
|
||||
this.player = player;
|
||||
this.cause = cause;
|
||||
this.drops = drops;
|
||||
@ -43,6 +78,7 @@ public class ItemDropEvent extends Event implements Cancellable {
|
||||
this.block = block;
|
||||
this.entity = entity;
|
||||
this.mythicMobName = mythicMobName;
|
||||
this.customBlock = customBlock;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
@ -86,8 +122,26 @@ public class ItemDropEvent extends Event implements Cancellable {
|
||||
}
|
||||
|
||||
public enum DropCause {
|
||||
BLOCK,
|
||||
MONSTER,
|
||||
MYTHIC_MOB
|
||||
|
||||
/**
|
||||
* Item dropped from a non custom block
|
||||
*/
|
||||
NORMAL_BLOCK,
|
||||
|
||||
/**
|
||||
* Item dropped from a non MythicMobs mob
|
||||
*/
|
||||
NORMAL_MONSTER,
|
||||
|
||||
/**
|
||||
* Item dropped from a MythicMobs mob
|
||||
*/
|
||||
@Deprecated
|
||||
MYTHIC_MOB,
|
||||
|
||||
/**
|
||||
* Item dropped from a custom block
|
||||
*/
|
||||
CUSTOM_BLOCK;
|
||||
}
|
||||
}
|
||||
|
@ -75,10 +75,8 @@ public class MMOItemBuilder {
|
||||
capacity -= modifier.getWeight();
|
||||
if (modifier.hasNameModifier()) { addModifier(modifier.getNameModifier(), modUUID); }
|
||||
|
||||
for (ItemStat stat : modifier.getItemData().keySet()) {
|
||||
|
||||
for (ItemStat stat : modifier.getItemData().keySet())
|
||||
addModifierData(stat, modifier.getItemData().get(stat).randomize(this), modUUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,19 @@
|
||||
package net.Indyuce.mmoitems.api.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.stat.data.random.UpdatableRandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.DoubleData;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.random.UpdatableRandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* That Gaussian spread distribution thing that no one understands.
|
||||
@ -166,29 +164,25 @@ public class NumericStatFormula implements RandomStatData, UpdatableRandomStatDa
|
||||
|
||||
if (useRelativeSpread) {
|
||||
//SPRD//if (spread > 0) MMOItems.log("\u00a7c༺\u00a77 Using \u00a7eRelative\u00a77 spread formula: \u00a76μ=" + (base + scale * levelScalingFactor) + "\u00a77, \u00a73σ=" + (spread * (base + scale * levelScalingFactor) + "\u00a7b=" + spread + "×" + (base + scale * levelScalingFactor)) + " \u00a7c@" + random + "\u00a7e = " + (base + scale * levelScalingFactor) * (1 + Math.min(Math.max(random * spread, -maxSpread), maxSpread)));
|
||||
return (base + scale * levelScalingFactor) * (1 + Math.min(Math.max(random * spread, -maxSpread), maxSpread)); }
|
||||
return (base + scale * levelScalingFactor) * (1 + Math.min(Math.max(random * spread, -maxSpread), maxSpread));
|
||||
}
|
||||
|
||||
/*
|
||||
* The mean, the center of the distribution
|
||||
*/
|
||||
double actualBase = (base + (scale * levelScalingFactor));
|
||||
// The mean, the center of the distribution
|
||||
double actualBase = base + (scale * levelScalingFactor);
|
||||
|
||||
/*
|
||||
* This is one pick from a gaussian distribution
|
||||
* at mean 0, and standard deviation 1, multiplied
|
||||
* by the spread chosen.
|
||||
*/
|
||||
double gaussSpread = random * spread;
|
||||
double flatSpread = random * spread;
|
||||
|
||||
/*
|
||||
* Does it exceed the max spread (positive or negative)? Not anymore!
|
||||
*/
|
||||
if (gaussSpread < (-getMaxSpread())) { gaussSpread = -getMaxSpread(); } else
|
||||
if (gaussSpread > (getMaxSpread())) { gaussSpread = getMaxSpread(); }
|
||||
// Does it exceed the max spread (positive or negative)? Not anymore!
|
||||
flatSpread = Math.min(Math.max(flatSpread, -maxSpread), maxSpread);
|
||||
|
||||
// That's it
|
||||
//SPRD//if (spread > 0) MMOItems.log("\u00a7c༺\u00a77 Using \u00a7aAdditive\u00a77 spread formula, \u00a76μ=" + (base + scale * levelScalingFactor) + "\u00a77, \u00a73σ=" + (spread) + " \u00a7c@" + random + "\u00a7e = " + (actualBase + gaussSpread));
|
||||
return actualBase + gaussSpread;
|
||||
return actualBase + flatSpread;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -295,5 +289,4 @@ public class NumericStatFormula implements RandomStatData, UpdatableRandomStatDa
|
||||
*/
|
||||
NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.block.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.droptable.DropTable;
|
||||
import net.Indyuce.mmoitems.api.event.CustomBlockDropEvent;
|
||||
import net.Indyuce.mmoitems.api.event.ItemDropEvent;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.listener.CustomBlockListener;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -83,8 +83,15 @@ public class DropTableManager implements Listener, Reloadable {
|
||||
if (killer != null && killer.hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
if (monsters.containsKey(entity.getType()))
|
||||
event.getDrops().addAll(monsters.get(entity.getType()).read(killer != null ? PlayerData.get(killer) : null, false));
|
||||
if (monsters.containsKey(entity.getType())) {
|
||||
List<ItemStack> drops = monsters.get(entity.getType()).read(killer != null ? PlayerData.get(killer) : null, false);
|
||||
ItemDropEvent called = new ItemDropEvent(killer, drops, entity);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return;
|
||||
|
||||
event.getDrops().addAll(drops);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
@ -95,32 +102,41 @@ public class DropTableManager implements Listener, Reloadable {
|
||||
|
||||
Block block = event.getBlock();
|
||||
Optional<CustomBlock> opt = MMOItems.plugin.getCustomBlocks().getFromBlock(block.getBlockData());
|
||||
|
||||
// Custom block
|
||||
if (opt.isPresent()) {
|
||||
CustomBlock customBlock = opt.get();
|
||||
|
||||
/*
|
||||
* check if corresponding custom block has a drop table registered,
|
||||
* and only reads corresponding drop table if the tool has enough
|
||||
* power
|
||||
* Check if corresponding custom block has a drop table registered,
|
||||
* and only reads corresponding drop table if the tool has enough power
|
||||
*/
|
||||
if (customBlocks.containsKey(customBlock.getId()) && CustomBlockListener.getPickaxePower(player) >= customBlock.getRequiredPower())
|
||||
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
List<ItemStack> drops = customBlocks.get(customBlock.getId()).read(playerData, hasSilkTouchTool(player));
|
||||
CustomBlockDropEvent called = new CustomBlockDropEvent(playerData, customBlock, drops);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return;
|
||||
if (customBlocks.containsKey(customBlock.getId()) && CustomBlockListener.getPickaxePower(player) >= customBlock.getRequiredPower()) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
List<ItemStack> drops = customBlocks.get(customBlock.getId()).read(playerData, hasSilkTouchTool(player));
|
||||
ItemDropEvent called = new ItemDropEvent(player, drops, customBlock);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
|
||||
for (ItemStack drop : drops)
|
||||
UtilityMethods.dropItemNaturally(block.getLocation(), drop);
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Normal block
|
||||
else if (blocks.containsKey(block.getType())) {
|
||||
final Material type = block.getType();
|
||||
Material type = block.getType();
|
||||
List<ItemStack> drops = blocks.get(type).read(PlayerData.get(player), hasSilkTouchTool(player));
|
||||
ItemDropEvent called = new ItemDropEvent(player, drops, block);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return;
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
|
||||
for (ItemStack drop : blocks.get(type).read(PlayerData.get(player), hasSilkTouchTool(player)))
|
||||
for (ItemStack drop : drops)
|
||||
UtilityMethods.dropItemNaturally(block.getLocation(), drop);
|
||||
}, 2);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ locked-skins: true
|
||||
# off-hand like tomes!
|
||||
disable-abilities-in-offhand: false
|
||||
|
||||
# enable/disable the automatic equip feature
|
||||
# Enable/disable the automatic equip feature.
|
||||
# By right clicking with a piece of armor, the plugin will
|
||||
# check if your currently equipped armor's "Equip Priority" stat
|
||||
# is lower/higher than the one you're currently right clicking with, if
|
||||
|
Loading…
Reference in New Issue
Block a user