Merge branch 'development'

This commit is contained in:
Brianna 2020-03-22 15:53:13 -04:00
commit 62a127998a
5 changed files with 120 additions and 11 deletions

5
.gitignore vendored
View File

@ -1,3 +1,6 @@
\.idea
\target
UltimateStacker.iml
UltimateStacker.iml
.settings/
.classpath
.project

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>1.11.6</version>
<version>1.11.7</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>UltimateStacker-${project.version}</finalName>
@ -93,6 +93,10 @@
<id>private</id>
<url>http://repo.songoda.com/artifactory/private/</url>
</repository>
<repository>
<id>public</id>
<url>http://repo.songoda.com/artifactory/public/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>

View File

@ -14,12 +14,7 @@ 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;
import com.songoda.ultimatestacker.commands.CommandReload;
import com.songoda.ultimatestacker.commands.CommandRemoveAll;
import com.songoda.ultimatestacker.commands.CommandSettings;
import com.songoda.ultimatestacker.commands.CommandUltimateStacker;
import com.songoda.ultimatestacker.commands.*;
import com.songoda.ultimatestacker.database.DataManager;
import com.songoda.ultimatestacker.database.migrations._1_InitialMigration;
import com.songoda.ultimatestacker.entity.EntityStack;
@ -120,6 +115,7 @@ public class UltimateStacker extends SongodaPlugin {
.addSubCommand(new CommandRemoveAll())
.addSubCommand(new CommandReload())
.addSubCommand(new CommandGiveSpawner())
.addSubCommand(new CommandSpawn())
.addSubCommand(new CommandConvert(guiManager));
this.entityUtils = new EntityUtils();
@ -398,6 +394,9 @@ public class UltimateStacker extends SongodaPlugin {
item.removeMetadata("US_AMT", INSTANCE);
itemStack.setAmount(newAmount);
}
// If amount is 0, Minecraft change the type to AIR
if (itemStack.getType() == Material.AIR)
return;
item.setItemStack(itemStack);
if ((blacklisted && !Settings.ITEM_HOLOGRAM_BLACKLIST.getBoolean())
@ -419,7 +418,7 @@ public class UltimateStacker extends SongodaPlugin {
public static int getActualItemAmount(Item item) {
ItemStack itemStack = item.getItemStack();
int amount = itemStack.getAmount();
if (amount >= (itemStack.getMaxStackSize() / 2) && item.hasMetadata("US_AMT")) {
if (/*amount >= (itemStack.getMaxStackSize() / 2) && */item.hasMetadata("US_AMT")) {
return item.getMetadata("US_AMT").get(0).asInt();
} else {
return amount;

View File

@ -0,0 +1,89 @@
package com.songoda.ultimatestacker.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.utils.Methods;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: 3/21/2020
* Time Created: 1:02 PM
*/
public class CommandSpawn extends AbstractCommand {
UltimateStacker instance;
public CommandSpawn() {
super(true, "spawn");
instance = UltimateStacker.getInstance();
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player p = (Player) sender;
if (args.length < 2) return ReturnType.SYNTAX_ERROR;
EntityType type = null;
for (EntityType types : EntityType.values()) {
String input = args[0].toUpperCase().replace("_", "").replace(" ", "");
String compare = types.name().toUpperCase().replace("_", "").replace(" ", "");
if (input.equals(compare))
type = types;
}
if (type == null) {
instance.getLocale().newMessage("&7The entity &6" + args[0] + " &7does not exist. Try one of these:").sendPrefixedMessage(sender);
StringBuilder list = new StringBuilder();
for (EntityType types : EntityType.values()) {
if (types.isSpawnable() && types.isAlive() && !types.toString().contains("ARMOR"))
list.append(types.name().toUpperCase().replace(" ", "_")).append("&7, &6");
}
sender.sendMessage(Methods.formatText("&6" + list));
} else {
Entity entity = p.getWorld().spawnEntity(p.getLocation(), type);
EntityStack stack = instance.getEntityStackManager().addStack(entity.getUniqueId(), (Methods.isInt(args[1])) ? Integer.parseInt(args[1]) : 1);
instance.getStackingTask().attemptSplit(stack, (LivingEntity) entity);
}
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) {
return Arrays.stream(EntityType.values())
.filter(types -> types.isSpawnable() && types.isAlive() && !types.toString().contains("ARMOR"))
.map(Enum::name).collect(Collectors.toList());
} else if (args.length == 2) {
return Arrays.asList("1", "2", "3", "4", "5");
}
return null;
}
@Override
public String getPermissionNode() {
return "ultimatestacker.admin";
}
@Override
public String getSyntax() {
return "/us spawn <entity> <amount>";
}
@Override
public String getDescription() {
return "Spawns a stack of the specified entity at your location.";
}
}

View File

@ -17,6 +17,8 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class ItemListeners implements Listener {
private final UltimateStacker instance;
@ -30,6 +32,9 @@ public class ItemListeners implements Listener {
int maxItemStackSize = Settings.MAX_STACK_ITEMS.getInt();
if (!Settings.STACK_ITEMS.getBoolean()) return;
List<String> disabledWorlds = Settings.DISABLED_WORLDS.getStringList();
if (disabledWorlds.stream().anyMatch(worldStr -> event.getEntity().getWorld().getName().equalsIgnoreCase(worldStr))) return;
Item item = event.getTarget();
ItemStack itemStack = item.getItemStack();
@ -68,6 +73,9 @@ public class ItemListeners implements Listener {
public void onExist(ItemSpawnEvent event) {
if (!Settings.STACK_ITEMS.getBoolean()) return;
List<String> disabledWorlds = Settings.DISABLED_WORLDS.getStringList();
if (disabledWorlds.stream().anyMatch(worldStr -> event.getEntity().getWorld().getName().equalsIgnoreCase(worldStr))) return;
ItemStack itemStack = event.getEntity().getItemStack();
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() &&
@ -81,12 +89,18 @@ public class ItemListeners implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPickup(PlayerPickupItemEvent event) {
if (!Settings.STACK_ITEMS.getBoolean()) return;
if (event.getItem().getItemStack().getAmount() < (event.getItem().getItemStack().getMaxStackSize() / 2)) return;
// Amount here is not the total amount of item (32 if more than 32) but the amount of item the player can retrieve
// ie there is x64 diamonds blocks (so 32), the player pick 8 items so the amount is 8 and not 32
int amount = UltimateStacker.getActualItemAmount(event.getItem());
if (/*event.getItem().getItemStack().getAmount()*/amount < (event.getItem().getItemStack().getMaxStackSize() / 2)) {
// Update
UltimateStacker.updateItemAmount(event.getItem(), event.getRemaining());
return;
}
event.setCancelled(true);
event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random()));
Methods.updateInventory(event.getItem(), event.getPlayer().getInventory());
}
}