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