Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
ae5795da17
Commit
a3aa343683
@ -1242,6 +1242,7 @@ SELECT_ITEM_BAUPLATTFORM=§eBuild platform
|
|||||||
SELECT_ITEM_TESTBLOCK=§eDummy
|
SELECT_ITEM_TESTBLOCK=§eDummy
|
||||||
|
|
||||||
CHESTFILLER_FILLED = §eChest filled
|
CHESTFILLER_FILLED = §eChest filled
|
||||||
|
CHESTFILLER_COUNT = §7{0}§8: §e§l{1}
|
||||||
|
|
||||||
# Warp
|
# Warp
|
||||||
WARP_DISALLOWED = §cYou are not allowed to use the warp here
|
WARP_DISALLOWED = §cYou are not allowed to use the warp here
|
||||||
|
@ -23,11 +23,13 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Container;
|
import org.bukkit.block.Container;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -50,4 +52,64 @@ public class InventoryFiller implements Listener {
|
|||||||
}
|
}
|
||||||
BauSystem.MESSAGE.sendPrefixless("CHESTFILLER_FILLED", event.getPlayer(), ChatMessageType.ACTION_BAR);
|
BauSystem.MESSAGE.sendPrefixless("CHESTFILLER_FILLED", event.getPlayer(), ChatMessageType.ACTION_BAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For MacOS user: https://www.curseforge.com/minecraft/mc-mods/shift-scroll-fix/download
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||||
|
if (!event.getPlayer().isSneaking()) return;
|
||||||
|
ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand();
|
||||||
|
if (itemStack.getType() == Material.AIR) return;
|
||||||
|
Block block = event.getPlayer().getTargetBlockExact(5);
|
||||||
|
if (block == null) return;
|
||||||
|
if (!(block.getState() instanceof Container)) return;
|
||||||
|
Container container = (Container) block.getState();
|
||||||
|
Inventory inventory = container.getInventory();
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
int upperBound = event.getPreviousSlot() + 5;
|
||||||
|
if (upperBound > 8) upperBound -= 8;
|
||||||
|
int lowerBound = event.getPreviousSlot() - 5;
|
||||||
|
if (lowerBound < 0) lowerBound += 8;
|
||||||
|
|
||||||
|
int direction = 0;
|
||||||
|
if (event.getNewSlot() > event.getPreviousSlot() || event.getNewSlot() < upperBound) {
|
||||||
|
direction = -1;
|
||||||
|
} else if (event.getNewSlot() < event.getPreviousSlot() || event.getNewSlot() > lowerBound) {
|
||||||
|
direction = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
int emptySlot = -1;
|
||||||
|
int filledSlot = -1;
|
||||||
|
for (int i = 0; i < inventory.getSize(); i++) {
|
||||||
|
ItemStack current = inventory.getItem(i);
|
||||||
|
if (current == null) {
|
||||||
|
if (emptySlot == -1) emptySlot = i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (current.getType() == itemStack.getType()) {
|
||||||
|
count += current.getAmount();
|
||||||
|
int emptyAmount = itemStack.getType().getMaxStackSize() - current.getAmount();
|
||||||
|
if (direction == -1) filledSlot = Math.max(filledSlot, i);
|
||||||
|
if (emptyAmount > 0) filledSlot = Math.min(i, filledSlot);
|
||||||
|
if (emptyAmount > 0 && filledSlot == -1) filledSlot = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int slotToUse = direction == -1 ? filledSlot : (filledSlot == -1 ? emptySlot : filledSlot);
|
||||||
|
if (slotToUse == -1) return;
|
||||||
|
|
||||||
|
ItemStack current = inventory.getItem(slotToUse);
|
||||||
|
if (current == null) {
|
||||||
|
ItemStack now = itemStack.clone();
|
||||||
|
now.setAmount(1);
|
||||||
|
inventory.setItem(slotToUse, now);
|
||||||
|
} else {
|
||||||
|
current.setAmount(current.getAmount() + direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
BauSystem.MESSAGE.sendPrefixless("CHESTFILLER_COUNT", event.getPlayer(), ChatMessageType.ACTION_BAR, itemStack.getType(), count + direction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren