mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-31 21:07:47 +01:00
merge
This commit is contained in:
commit
fa58db39c2
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "UltimateStacker"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "1.10.5"
|
||||
version: "1.10.8"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -12,6 +12,7 @@ import com.songoda.core.database.MySQLConnector;
|
||||
import com.songoda.core.database.SQLiteConnector;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.hooks.HologramManager;
|
||||
import com.songoda.core.hooks.WorldGuardHook;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatestacker.commands.CommandConvert;
|
||||
import com.songoda.ultimatestacker.commands.CommandGiveSpawner;
|
||||
@ -86,6 +87,9 @@ public class UltimateStacker extends SongodaPlugin {
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
|
||||
// Register WorldGuard
|
||||
WorldGuardHook.addHook("mob-stacking", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -385,9 +389,9 @@ public class UltimateStacker extends SongodaPlugin {
|
||||
|
||||
boolean blacklisted = isMaterialBlacklisted(itemStack);
|
||||
|
||||
if (newAmount > 32 && !blacklisted) {
|
||||
if (newAmount > (itemStack.getMaxStackSize() / 2) && !blacklisted) {
|
||||
item.setMetadata("US_AMT", new FixedMetadataValue(INSTANCE, newAmount));
|
||||
itemStack.setAmount(32);
|
||||
itemStack.setAmount(Math.max(1, itemStack.getMaxStackSize() / 2));
|
||||
} else {
|
||||
item.removeMetadata("US_AMT", INSTANCE);
|
||||
itemStack.setAmount(newAmount);
|
||||
@ -411,8 +415,9 @@ public class UltimateStacker extends SongodaPlugin {
|
||||
* @return stacker-corrected value for the stack size
|
||||
*/
|
||||
public static int getActualItemAmount(Item item) {
|
||||
int amount = item.getItemStack().getAmount();
|
||||
if (amount >= 32 && item.hasMetadata("US_AMT")) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
int amount = itemStack.getAmount();
|
||||
if (amount >= (itemStack.getMaxStackSize() / 2) && item.hasMetadata("US_AMT")) {
|
||||
return item.getMetadata("US_AMT").get(0).asInt();
|
||||
} else {
|
||||
return amount;
|
||||
|
@ -114,35 +114,30 @@ public class DeathListeners implements Listener {
|
||||
|
||||
if (Settings.KILL_WHOLE_STACK_ON_DEATH.getBoolean() && Settings.REALISTIC_DAMAGE.getBoolean()) {
|
||||
Player player = (Player) event.getDamager();
|
||||
ItemStack tool = player.getInventory().getItemInMainHand();
|
||||
if (tool.getType().getMaxDurability() < 1 || (tool.getItemMeta() != null && (tool.getItemMeta().isUnbreakable()
|
||||
ItemStack tool = player.getInventory().getItemInHand();
|
||||
if (tool.getType().getMaxDurability() < 1 || (tool.getItemMeta() != null && (tool.getItemMeta().spigot().isUnbreakable()
|
||||
|| (ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER) && tool.getItemMeta().spigot().isUnbreakable()))))
|
||||
return;
|
||||
|
||||
int unbreakingLevel = tool.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
Damageable damageable = (Damageable) tool.getItemMeta();
|
||||
|
||||
int actualDamage = 0;
|
||||
for (int i = 0; i < stack.getAmount(); i++)
|
||||
if (checkUnbreakingChance(unbreakingLevel))
|
||||
actualDamage++;
|
||||
|
||||
damageable.setDamage(damageable.getDamage() + actualDamage-1);
|
||||
tool.setItemMeta((ItemMeta) damageable);
|
||||
tool.setDurability((short)(tool.getDurability() + actualDamage));
|
||||
|
||||
if (!this.hasEnoughDurability(tool, 1))
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
player.getInventory().setItemInHand(null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasEnoughDurability(ItemStack tool, int requiredAmount) {
|
||||
if (!tool.hasItemMeta() || !(tool.getItemMeta() instanceof Damageable) || tool.getType().getMaxDurability() < 1)
|
||||
if (tool.getType().getMaxDurability() <= 1)
|
||||
return true;
|
||||
|
||||
Damageable damageable = (Damageable) tool.getItemMeta();
|
||||
int durabilityRemaining = tool.getType().getMaxDurability() - damageable.getDamage();
|
||||
return durabilityRemaining > requiredAmount;
|
||||
return tool.getDurability() + requiredAmount <= tool.getType().getMaxDurability();
|
||||
}
|
||||
|
||||
public boolean checkUnbreakingChance(int level) {
|
||||
|
@ -75,13 +75,13 @@ public class ItemListeners implements Listener {
|
||||
return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
|
||||
}
|
||||
|
||||
UltimateStacker.updateItemAmount(event.getEntity(), itemStack, event.getEntity().getItemStack().getAmount());
|
||||
UltimateStacker.updateItemAmount(event.getEntity(), itemStack, itemStack.getAmount());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPickup(PlayerPickupItemEvent event) {
|
||||
if (!Settings.STACK_ITEMS.getBoolean()) return;
|
||||
if (event.getItem().getItemStack().getAmount() < 32) return;
|
||||
if (event.getItem().getItemStack().getAmount() < (event.getItem().getItemStack().getMaxStackSize() / 2)) return;
|
||||
event.setCancelled(true);
|
||||
|
||||
event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random()));
|
||||
|
@ -179,7 +179,7 @@ public class Settings {
|
||||
"This is added only because it looks smoother in game. This is only visual and",
|
||||
"doesn't actually effect the item.");
|
||||
|
||||
public static final ConfigSetting ITEM_BLACKLIST = new ConfigSetting(config, "Items.Blacklist", Collections.singletonList("EGG"),
|
||||
public static final ConfigSetting ITEM_BLACKLIST = new ConfigSetting(config, "Items.Blacklist", Collections.singletonList("BARRIER"),
|
||||
"Items included in this list will stack to default Minecraft amounts.",
|
||||
"Material list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html",
|
||||
"Leave this empty by using \"blacklist: []\" if you do not wish to disable",
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatestacker.tasks;
|
||||
|
||||
import com.songoda.core.hooks.WorldGuardHook;
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||
@ -147,6 +148,10 @@ public class StackingTask extends BukkitRunnable {
|
||||
// Make sure the entity has not already been processed.
|
||||
if (this.processed.contains(entity.getUniqueId())) continue;
|
||||
|
||||
// Check our WorldGuard flag.
|
||||
if (WorldGuardHook.isEnabled() && !WorldGuardHook.getBooleanFlag(entity.getLocation(), "mob-stacking"))
|
||||
continue;
|
||||
|
||||
// Get this entities friendStack.
|
||||
EntityStack friendStack = stackManager.getStack(entity);
|
||||
|
||||
@ -210,6 +215,10 @@ public class StackingTask extends BukkitRunnable {
|
||||
// If our entity is stacked then skip this entity.
|
||||
if (isStack) return;
|
||||
|
||||
// Check our WorldGuard flag.
|
||||
if (WorldGuardHook.isEnabled() && !WorldGuardHook.getBooleanFlag(livingEntity.getLocation(), "mob-stacking"))
|
||||
return;
|
||||
|
||||
// Remove all stacked entities from our stackable friends.
|
||||
stackableFriends.removeIf(stackManager::isStacked);
|
||||
|
||||
|
@ -2,6 +2,7 @@ name: UltimateStacker
|
||||
description: UltimateStacker
|
||||
version: maven-version-number
|
||||
softdepend: [HolographicDisplays, Holograms, CMI, WorldGuard, EpicSpawners, mcMMO, WildStacker, StackMob]
|
||||
loadbefore: [WorldGuard]
|
||||
main: com.songoda.ultimatestacker.UltimateStacker
|
||||
author: songoda
|
||||
api-version: 1.13
|
||||
|
Loading…
Reference in New Issue
Block a user