mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
!Added event for gem stone application
This commit is contained in:
parent
35c435456b
commit
940d898980
@ -12,8 +12,6 @@ public class AbilityUseEvent extends PlayerDataEvent {
|
||||
private final AbilityData ability;
|
||||
private final LivingEntity target;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
public AbilityUseEvent(PlayerData playerData, AbilityData ability) {
|
||||
this(playerData, ability, null);
|
||||
}
|
||||
@ -32,16 +30,6 @@ public class AbilityUseEvent extends PlayerDataEvent {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean bool) {
|
||||
cancelled = bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
package net.Indyuce.mmoitems.api.event;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
|
||||
public class GemStoneAppliedEvent extends PlayerDataEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final MMOItem gemStone, targetItem;
|
||||
|
||||
/**
|
||||
* Called when a player tries to apply a gem stone onto an item
|
||||
*
|
||||
* @param playerData
|
||||
* Player applying the gem stone
|
||||
* @param gemStone
|
||||
* Gem stone being applied
|
||||
* @param target
|
||||
* Item on which the gem is being applied
|
||||
*/
|
||||
public GemStoneAppliedEvent(PlayerData playerData, MMOItem gemStone, MMOItem targetItem) {
|
||||
super(playerData);
|
||||
|
||||
this.gemStone = gemStone;
|
||||
this.targetItem = targetItem;
|
||||
}
|
||||
|
||||
public MMOItem getGemStone() {
|
||||
return gemStone;
|
||||
}
|
||||
|
||||
public MMOItem getTargetItem() {
|
||||
return targetItem;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmoitems.api.interaction;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -7,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.event.GemStoneAppliedEvent;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
@ -27,7 +29,8 @@ public class GemStone extends UseItem {
|
||||
public ApplyResult applyOntoItem(NBTItem target, Type targetType) {
|
||||
|
||||
/*
|
||||
* loads all stats and calculates EVERY piece of the lore again.
|
||||
* Entirely loads the MMOItem and checks if it has the required empty
|
||||
* socket for the gem
|
||||
*/
|
||||
MMOItem targetMMO = new LiveMMOItem(target);
|
||||
if (!targetMMO.hasData(ItemStat.GEM_SOCKETS))
|
||||
@ -40,7 +43,7 @@ public class GemStone extends UseItem {
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
|
||||
/*
|
||||
* checks if the gem supports the item type, or the item set, or a
|
||||
* Checks if the gem supports the item type, or the item set, or a
|
||||
* weapon
|
||||
*/
|
||||
String appliableTypes = getNBTItem().getString("MMOITEMS_ITEM_TYPE_RESTRICTION");
|
||||
@ -50,17 +53,21 @@ public class GemStone extends UseItem {
|
||||
|
||||
// check for success rate
|
||||
double successRate = getNBTItem().getStat(ItemStat.SUCCESS_RATE);
|
||||
if (successRate != 0)
|
||||
if (random.nextDouble() < 1 - successRate / 100) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||
Message.GEM_STONE_BROKE
|
||||
.format(ChatColor.RED, "#gem#", MMOUtils.getDisplayName(getItem()), "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||
.send(player);
|
||||
return new ApplyResult(ResultType.FAILURE);
|
||||
}
|
||||
if (successRate != 0 && random.nextDouble() > successRate / 100) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
|
||||
Message.GEM_STONE_BROKE
|
||||
.format(ChatColor.RED, "#gem#", MMOUtils.getDisplayName(getItem()), "#item#", MMOUtils.getDisplayName(target.getItem()))
|
||||
.send(player);
|
||||
return new ApplyResult(ResultType.FAILURE);
|
||||
}
|
||||
|
||||
GemStoneAppliedEvent called = new GemStoneAppliedEvent(playerData, mmoitem, targetMMO);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return new ApplyResult(ResultType.NONE);
|
||||
|
||||
/*
|
||||
* gem stone can be successfully applied. apply stats then abilities and
|
||||
* Gem stone can be successfully applied. apply stats then abilities and
|
||||
* permanent effects. also REGISTER gem stone in the item gem stone
|
||||
* list.
|
||||
*/
|
||||
@ -68,7 +75,7 @@ public class GemStone extends UseItem {
|
||||
sockets.apply(gemType, gemData);
|
||||
|
||||
/*
|
||||
* only applies NON PROPER and MERGEABLE item stats
|
||||
* Only applies NON PROPER and MERGEABLE item stats
|
||||
*/
|
||||
for (ItemStat stat : mmoitem.getStats())
|
||||
if (!(stat instanceof ProperStat)) {
|
||||
|
Loading…
Reference in New Issue
Block a user