mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-22 09:31:20 +01:00
push build
This commit is contained in:
commit
d369875449
Binary file not shown.
@ -147,7 +147,7 @@ public class MMOItems extends JavaPlugin {
|
||||
abilityManager.stopRegistration();
|
||||
|
||||
configManager = new ConfigManager();
|
||||
itemManager = new ItemManager();
|
||||
itemManager = new ItemManager(getConfig().getBoolean("use-item-caching"));
|
||||
tierManager = new TierManager();
|
||||
setManager = new SetManager();
|
||||
upgradeManager = new UpgradeManager();
|
||||
|
@ -49,12 +49,10 @@ public class MMOUtils {
|
||||
/*
|
||||
* used by many plugin abilities and mecanisms. sometimes vector cannot be
|
||||
* normalized because its length is equal to 0 (normalizing a vector just
|
||||
* divides the vector coordinates by its length) however you cannot divide
|
||||
* by 0. just return vec if its null. lengthSquared better for performance
|
||||
* because it has no square root
|
||||
* divides the vector coordinates by its length), return vec if null length
|
||||
*/
|
||||
public static Vector normalize(Vector vector) {
|
||||
return vector.lengthSquared() == 0 ? vector : vector.normalize();
|
||||
return vector.getX() == 0 && vector.getY() == 0 ? vector : vector.normalize();
|
||||
}
|
||||
|
||||
public static String getProgressBar(double ratio, int n, String barChar) {
|
||||
|
@ -21,7 +21,7 @@ import net.Indyuce.mmoitems.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.version.nms.ItemTag;
|
||||
|
||||
public class MMOItemBuilder {
|
||||
private MMOItem mmoitem;
|
||||
private final MMOItem mmoitem;
|
||||
|
||||
private ItemStack item = new ItemStack(VersionMaterial.NETHER_WART.toMaterial());
|
||||
private ItemMeta meta;
|
||||
|
@ -22,13 +22,19 @@ public class RealDualWieldHook implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void a(PlayerDamageEntityWithOffhandEvent event) {
|
||||
|
||||
// check for npc
|
||||
// safety checks
|
||||
if (event.getEntity().hasMetadata("NPC") || !(event.getEntity() instanceof LivingEntity) || event.getDamage() == 0)
|
||||
/*
|
||||
* Citizens and Sentinels NPC support; damage = 0 check to ignore safety
|
||||
* checks; check for entity attack
|
||||
*/
|
||||
if (event.getDamage() == 0 || !(event.getEntity() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC"))
|
||||
return;
|
||||
|
||||
// custom damage check
|
||||
LivingEntity target = (LivingEntity) event.getEntity();
|
||||
Player player = (Player) event.getPlayer();
|
||||
if (MMOItems.plugin.getDamage().findInfo(target) != null)
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
TemporaryStats stats = null;
|
||||
|
||||
/*
|
||||
@ -36,8 +42,10 @@ public class RealDualWieldHook implements Listener {
|
||||
* be cancelled before anything is applied
|
||||
*/
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
NBTItem item = MMOItems.plugin.getNMS().getNBTItem(event.getItemInOffhand());
|
||||
NBTItem item = MMOItems.plugin.getNMS().getNBTItem(player.getInventory().getItemInMainHand());
|
||||
NBTItem offhandItem = MMOItems.plugin.getNMS().getNBTItem(player.getInventory().getItemInOffHand());
|
||||
AttackResult result = new AttackResult(event.getDamage(), DamageType.WEAPON, DamageType.PHYSICAL);
|
||||
|
||||
if (item.hasType()) {
|
||||
Weapon weapon = new Weapon(playerData, item, item.getType());
|
||||
|
||||
@ -57,6 +65,19 @@ public class RealDualWieldHook implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (offhandItem.hasType()) {
|
||||
Weapon weapon = new Weapon(playerData, offhandItem, offhandItem.getType());
|
||||
|
||||
if (weapon.getMMOItem().getType().getItemSet() == TypeSet.RANGE) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!weapon.canBeUsed()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* cast on-hit abilities and add the extra damage to the damage event
|
||||
|
@ -31,65 +31,59 @@ import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
|
||||
public class CustomBlockListener implements Listener {
|
||||
Random rnd = new Random();
|
||||
|
||||
|
||||
public CustomBlockListener() {
|
||||
if(MMOItems.plugin.getLanguage().replaceMushroomDrops)
|
||||
if (MMOItems.plugin.getLanguage().replaceMushroomDrops)
|
||||
Bukkit.getPluginManager().registerEvents(new MushroomReplacer(), MMOItems.plugin);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void a(BlockPhysicsEvent event) {
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getChangedType())) {
|
||||
public void a(BlockPhysicsEvent event) {
|
||||
if (MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getChangedType())) {
|
||||
event.setCancelled(true);
|
||||
event.getBlock().getState().update(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void b(BlockBreakEvent event) {
|
||||
Material type = event.getBlock().getType();
|
||||
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(type)) {
|
||||
|
||||
if (MMOItems.plugin.getCustomBlocks().isMushroomBlock(type)) {
|
||||
CustomBlock block = CustomBlock.getFromData(event.getBlock().getBlockData());
|
||||
if(block != null) {
|
||||
if (block != null) {
|
||||
event.setDropItems(false);
|
||||
event.setExpToDrop(
|
||||
event.getPlayer().getGameMode() == GameMode.CREATIVE ? 0 :
|
||||
CustomBlockListener.getPickaxePower(event.getPlayer()) >= block.getRequiredPower() ?
|
||||
block.getMaxXPDrop() == 0 && block.getMinXPDrop() == 0 ? 0 :
|
||||
rnd.nextInt((block.getMaxXPDrop() - block.getMinXPDrop()) + 1) + block.getMinXPDrop() : 0);
|
||||
event.setExpToDrop(event.getPlayer().getGameMode() == GameMode.CREATIVE ? 0 : CustomBlockListener.getPickaxePower(event.getPlayer()) >= block.getRequiredPower() ? block.getMaxXPDrop() == 0 && block.getMinXPDrop() == 0 ? 0 : rnd.nextInt((block.getMaxXPDrop() - block.getMinXPDrop()) + 1) + block.getMinXPDrop() : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void c(PlayerInteractEvent event) {
|
||||
if(!event.hasItem()) return;
|
||||
if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if(event.getHand() != EquipmentSlot.HAND) return;
|
||||
if(event.getClickedBlock().getType().isInteractable()) return;
|
||||
if(event.getItem().getType() == Material.CLAY_BALL) {
|
||||
if(NBTItem.get(event.getItem()).getInteger("MMOITEMS_BLOCK_ID") > 160 ||
|
||||
NBTItem.get(event.getItem()).getInteger("MMOITEMS_BLOCK_ID") < 1) return;
|
||||
if (!event.hasItem() || event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getHand() != EquipmentSlot.HAND || event.getClickedBlock().getType().isInteractable())
|
||||
return;
|
||||
if (event.getItem().getType() == Material.CLAY_BALL) {
|
||||
NBTItem nbtItem = MMOItems.plugin.getNMS().getNBTItem(event.getItem());
|
||||
if (nbtItem.getInteger("MMOITEMS_BLOCK_ID") > 160 || nbtItem.getInteger("MMOITEMS_BLOCK_ID") < 1)
|
||||
return;
|
||||
|
||||
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(NBTItem.get(event.getItem()).getInteger("MMOITEMS_BLOCK_ID"));
|
||||
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(nbtItem.getInteger("MMOITEMS_BLOCK_ID"));
|
||||
|
||||
List<Material> mat = Arrays.asList(Material.GRASS, Material.TALL_GRASS, Material.SEAGRASS, Material.TALL_SEAGRASS,
|
||||
Material.FERN, Material.LARGE_FERN, Material.DEAD_BUSH, Material.SNOW);
|
||||
|
||||
Block modify = mat.contains(event.getClickedBlock().getType())
|
||||
? event.getClickedBlock() : event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
|
||||
if(isStandingInside(event.getPlayer().getLocation(), modify.getLocation())) return;
|
||||
|
||||
if(!mat.contains(modify.getType()))
|
||||
switch(modify.getType()) {
|
||||
case AIR:
|
||||
case CAVE_AIR:
|
||||
case STRUCTURE_VOID:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
List<Material> mat = Arrays.asList(Material.GRASS, Material.TALL_GRASS, Material.SEAGRASS, Material.TALL_SEAGRASS, Material.FERN, Material.LARGE_FERN, Material.DEAD_BUSH, Material.SNOW);
|
||||
|
||||
Block modify = mat.contains(event.getClickedBlock().getType()) ? event.getClickedBlock() : event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
|
||||
if (isStandingInside(event.getPlayer().getLocation(), modify.getLocation()))
|
||||
return;
|
||||
|
||||
if (!mat.contains(modify.getType()))
|
||||
switch (modify.getType()) {
|
||||
case AIR:
|
||||
case CAVE_AIR:
|
||||
case STRUCTURE_VOID:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
Block oldState = modify;
|
||||
@ -97,73 +91,77 @@ public class CustomBlockListener implements Listener {
|
||||
BlockData cachedData = modify.getBlockData();
|
||||
modify.setType(block.getType(), false);
|
||||
modify.setBlockData(block.getBlockData(), false);
|
||||
|
||||
|
||||
MMOItems.plugin.getNMS().playArmAnimation(event.getPlayer());
|
||||
modify.getWorld().playSound(event.getPlayer().getLocation(), MMOItems.plugin.getNMS().getBlockPlaceSound(modify), 0.8f, 1.0f);
|
||||
|
||||
|
||||
BlockPlaceEvent bpe = new BlockPlaceEvent(modify, oldState.getState(), event.getClickedBlock(), event.getItem(), event.getPlayer(), true, EquipmentSlot.HAND);
|
||||
Bukkit.getServer().getPluginManager().callEvent(bpe);
|
||||
if(bpe.isCancelled()) {
|
||||
if (bpe.isCancelled()) {
|
||||
modify.setType(cachedType);
|
||||
modify.setBlockData(cachedData);
|
||||
}
|
||||
else if(event.getPlayer().getGameMode() != GameMode.CREATIVE) {
|
||||
ItemStack stack = event.getItem(); stack.setAmount(stack.getAmount() - 1);
|
||||
} else if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
|
||||
ItemStack stack = event.getItem();
|
||||
stack.setAmount(stack.getAmount() - 1);
|
||||
event.getPlayer().getInventory().setItemInMainHand(stack.getAmount() > 0 ? stack : null);
|
||||
}
|
||||
}
|
||||
/**else if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getItem().getType())) {
|
||||
event.setCancelled(true);
|
||||
Block modify = event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
|
||||
if(isStandingInside(event.getPlayer().getLocation(), modify.getLocation())) return;
|
||||
if(modify.getType() != Material.AIR) return;
|
||||
|
||||
Block oldState = modify;
|
||||
modify.setType(event.getItem().getType(), false);
|
||||
modify.setBlockData(event.getItem().getType().createBlockData(), false);
|
||||
|
||||
BlockPlaceEvent bpe = new BlockPlaceEvent(modify, oldState.getState(), event.getClickedBlock(), event.getItem(), event.getPlayer(), true, EquipmentSlot.HAND);
|
||||
Bukkit.getServer().getPluginManager().callEvent(bpe);
|
||||
if(bpe.isCancelled()) modify.setType(Material.AIR);
|
||||
}*/
|
||||
/**
|
||||
* else
|
||||
* if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getItem().getType()))
|
||||
* { event.setCancelled(true); Block modify =
|
||||
* event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
*
|
||||
* if(isStandingInside(event.getPlayer().getLocation(),
|
||||
* modify.getLocation())) return; if(modify.getType() != Material.AIR)
|
||||
* return;
|
||||
*
|
||||
* Block oldState = modify; modify.setType(event.getItem().getType(),
|
||||
* false);
|
||||
* modify.setBlockData(event.getItem().getType().createBlockData(),
|
||||
* false);
|
||||
*
|
||||
* BlockPlaceEvent bpe = new BlockPlaceEvent(modify,
|
||||
* oldState.getState(), event.getClickedBlock(), event.getItem(),
|
||||
* event.getPlayer(), true, EquipmentSlot.HAND);
|
||||
* Bukkit.getServer().getPluginManager().callEvent(bpe);
|
||||
* if(bpe.isCancelled()) modify.setType(Material.AIR); }
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void d(BlockIgniteEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
if(event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.SPREAD) {
|
||||
BlockFace[] faces = { BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST };
|
||||
for(BlockFace face : faces)
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getBlock().getRelative(face).getType()) &&
|
||||
CustomBlock.getFromData(event.getBlock().getRelative(face).getBlockData()) != null) event.setCancelled(true);
|
||||
for (BlockFace face : faces)
|
||||
if (MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getBlock().getRelative(face).getType()) && CustomBlock.getFromData(event.getBlock().getRelative(face).getBlockData()) != null)
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean isStandingInside(Location p, Location b) {
|
||||
return (p.getBlockX() == b.getBlockX() &&
|
||||
(p.getBlockY() == b.getBlockY() || p.getBlockY() + 1 == b.getBlockY()) &&
|
||||
p.getBlockZ() == b.getBlockZ());
|
||||
return (p.getBlockX() == b.getBlockX() && (p.getBlockY() == b.getBlockY() || p.getBlockY() + 1 == b.getBlockY()) && p.getBlockZ() == b.getBlockZ());
|
||||
}
|
||||
|
||||
public static int getPickaxePower(Player player) {
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if(item != null && item.getType() != Material.AIR) {
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
NBTItem nbt = NBTItem.get(item);
|
||||
if(nbt.hasType()) {
|
||||
if (nbt.hasType())
|
||||
return nbt.getInteger("MMOITEMS_PICKAXE_POWER");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public class MushroomReplacer implements Listener {
|
||||
@EventHandler
|
||||
public void d(BlockBreakEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
if(MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getBlock().getType()) &&
|
||||
MMOItems.plugin.getDropTables().hasSilkTouchTool(event.getPlayer()))
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (MMOItems.plugin.getCustomBlocks().isMushroomBlock(event.getBlock().getType()) && MMOItems.plugin.getDropTables().hasSilkTouchTool(event.getPlayer()))
|
||||
event.setDropItems(false);
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,7 @@ import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem;
|
||||
import net.Indyuce.mmoitems.api.interaction.util.InteractItem;
|
||||
|
||||
public class CustomDurability implements Listener {
|
||||
private final List<DamageCause> applyDamageCauses = Arrays.asList(
|
||||
DamageCause.ENTITY_ATTACK, DamageCause.ENTITY_EXPLOSION, DamageCause.BLOCK_EXPLOSION, DamageCause.THORNS,
|
||||
DamageCause.CONTACT, DamageCause.FIRE, DamageCause.HOT_FLOOR, DamageCause.LAVA, DamageCause.PROJECTILE );
|
||||
private final List<DamageCause> applyDamageCauses = Arrays.asList(DamageCause.ENTITY_ATTACK, DamageCause.ENTITY_EXPLOSION, DamageCause.BLOCK_EXPLOSION, DamageCause.THORNS, DamageCause.CONTACT, DamageCause.FIRE, DamageCause.HOT_FLOOR, DamageCause.LAVA, DamageCause.PROJECTILE);
|
||||
private final List<String> hoeableBlocks = Arrays.asList("GRASS_PATH", "GRASS", "DIRT");
|
||||
private final List<PlayerFishEvent.State> applyFishStates = Arrays.asList(State.IN_GROUND, State.CAUGHT_ENTITY, State.CAUGHT_FISH);
|
||||
|
||||
@ -75,10 +73,9 @@ public class CustomDurability implements Listener {
|
||||
|
||||
if (!applyDamageCauses.contains(event.getCause()))
|
||||
return;
|
||||
|
||||
|
||||
int dura = 1;
|
||||
if(event.getCause() == DamageCause.BLOCK_EXPLOSION ||
|
||||
event.getCause() == DamageCause.ENTITY_EXPLOSION)
|
||||
if (event.getCause() == DamageCause.BLOCK_EXPLOSION || event.getCause() == DamageCause.ENTITY_EXPLOSION)
|
||||
dura = 2;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
@ -139,10 +136,9 @@ public class CustomDurability implements Listener {
|
||||
intItem.setItem(durItem.decreaseDurability(1).toItem());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void f(PlayerInteractEvent event) {
|
||||
if (event.isCancelled() || !event.hasItem() || event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock())
|
||||
if (!event.hasItem() || event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock())
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
@ -252,7 +248,7 @@ public class CustomDurability implements Listener {
|
||||
elytraDurabilityLoss.put(player.getUniqueId(), runnable);
|
||||
runnable.runTaskTimer(MMOItems.plugin, 10, 20);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void j(PlayerItemMendEvent event) {
|
||||
if (event.isCancelled())
|
||||
|
@ -69,8 +69,13 @@ public class ItemUse implements Listener {
|
||||
if (useItem instanceof Consumable && ((Consumable) useItem).hasVanillaEating())
|
||||
return;
|
||||
|
||||
if (!useItem.canBeUsed())
|
||||
/*
|
||||
* (BUG FIX) cancel the event to prevent things like shield blocking
|
||||
*/
|
||||
if (!useItem.canBeUsed()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// commands & consummables
|
||||
if (event.getAction().name().contains("RIGHT_CLICK")) {
|
||||
|
@ -15,20 +15,14 @@ import net.Indyuce.mmoitems.api.item.MMOItem;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
|
||||
public class ItemManager extends BukkitRunnable {
|
||||
private Map<Type, Map<String, LoadedItem>> map = new HashMap<>();
|
||||
private boolean cache = false;
|
||||
private final Map<Type, Map<String, LoadedItem>> map = new HashMap<>();
|
||||
private final boolean cache;
|
||||
|
||||
public ItemManager() {
|
||||
runTaskTimerAsynchronously(MMOItems.plugin, 60 * 20, 2 * 60 * 20);
|
||||
}
|
||||
|
||||
public void useCache(boolean cache) {
|
||||
public ItemManager(boolean cache) {
|
||||
this.cache = cache;
|
||||
if (!cache) {
|
||||
map.clear();
|
||||
if (!isCancelled())
|
||||
cancel();
|
||||
}
|
||||
|
||||
if (cache)
|
||||
runTaskTimerAsynchronously(MMOItems.plugin, 60 * 20, 2 * 60 * 20);
|
||||
}
|
||||
|
||||
public void uncache(Type type, String id) {
|
||||
@ -98,7 +92,8 @@ public class ItemManager extends BukkitRunnable {
|
||||
}
|
||||
|
||||
public class LoadedItem {
|
||||
private MMOItem item;
|
||||
private final MMOItem item;
|
||||
|
||||
private long loaded = System.currentTimeMillis();
|
||||
|
||||
public LoadedItem(MMOItem item) {
|
||||
|
@ -31,6 +31,7 @@ public class CustomModelDataHandler implements DurabilityHandler {
|
||||
public void repair(ItemStack item, int amount) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
((Damageable) meta).setDamage(Math.max(0, ((Damageable) meta).getDamage() - amount));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,6 +31,7 @@ public class Durability_v1_13_Handler implements DurabilityHandler {
|
||||
public void repair(ItemStack item, int amount) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
((Damageable) meta).setDamage(Math.max(0, ((Damageable) meta).getDamage() - amount));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user