mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-22 08:02:31 +01:00
Merge branches 'experimental' and 'master' of https://github.com/Minestom/Minestom
Conflicts: src/main/java/net/minestom/server/inventory/Inventory.java
This commit is contained in:
commit
7cbd13a560
@ -1 +1 @@
|
|||||||
Subproject commit fc2078a404b7b6041a1d60f15b6b2b482890bbfb
|
Subproject commit bf55e7257113471e1d6a8116e83edb6cf5011cca
|
@ -1276,6 +1276,10 @@ public enum Block {
|
|||||||
return defaultID;
|
return defaultID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return namespaceID;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAir() {
|
public boolean isAir() {
|
||||||
return isAir;
|
return isAir;
|
||||||
}
|
}
|
||||||
|
@ -250,6 +250,7 @@ public class BlockEnumGenerator extends MinestomEnumGenerator<BlockContainer> {
|
|||||||
generator.addHardcodedField("List<BlockAlternative>", "alternatives", "new ArrayList<BlockAlternative>()");
|
generator.addHardcodedField("List<BlockAlternative>", "alternatives", "new ArrayList<BlockAlternative>()");
|
||||||
generator.setParams("String namespaceID", "short defaultID", "double hardness", "double resistance", "boolean isAir", "boolean isSolid", "NamespaceID blockEntity", "boolean singleState");
|
generator.setParams("String namespaceID", "short defaultID", "double hardness", "double resistance", "boolean isAir", "boolean isSolid", "NamespaceID blockEntity", "boolean singleState");
|
||||||
generator.addMethod("getBlockId", "()", "short", "return defaultID;");
|
generator.addMethod("getBlockId", "()", "short", "return defaultID;");
|
||||||
|
generator.addMethod("getName", "()", "String", "return namespaceID;");
|
||||||
generator.addMethod("isAir", "()", "boolean", "return isAir;");
|
generator.addMethod("isAir", "()", "boolean", "return isAir;");
|
||||||
generator.addMethod("hasBlockEntity", "()", "boolean", "return blockEntity != null;");
|
generator.addMethod("hasBlockEntity", "()", "boolean", "return blockEntity != null;");
|
||||||
generator.addMethod("getBlockEntityName", "()", "NamespaceID", "return blockEntity;");
|
generator.addMethod("getBlockEntityName", "()", "NamespaceID", "return blockEntity;");
|
||||||
|
@ -27,6 +27,7 @@ import net.minestom.server.scoreboard.TeamManager;
|
|||||||
import net.minestom.server.storage.StorageFolder;
|
import net.minestom.server.storage.StorageFolder;
|
||||||
import net.minestom.server.storage.StorageManager;
|
import net.minestom.server.storage.StorageManager;
|
||||||
import net.minestom.server.timer.SchedulerManager;
|
import net.minestom.server.timer.SchedulerManager;
|
||||||
|
import net.minestom.server.utils.thread.MinestomThread;
|
||||||
import net.minestom.server.world.Difficulty;
|
import net.minestom.server.world.Difficulty;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -251,6 +252,10 @@ public class MinecraftServer {
|
|||||||
nettyServer.stop();
|
nettyServer.stop();
|
||||||
schedulerManager.shutdown();
|
schedulerManager.shutdown();
|
||||||
storageManager.getLoadedFolders().forEach(StorageFolder::close);
|
storageManager.getLoadedFolders().forEach(StorageFolder::close);
|
||||||
|
LOGGER.info("Shutting down all thread pools.");
|
||||||
|
MinestomThread.shutdownAll();
|
||||||
|
benchmarkManager.disable();
|
||||||
|
commandManager.stopConsoleThread();
|
||||||
LOGGER.info("Minestom server stopped successfully.");
|
LOGGER.info("Minestom server stopped successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
|
private boolean running;
|
||||||
private String commandPrefix = "/";
|
private String commandPrefix = "/";
|
||||||
|
|
||||||
private ConsoleSender consoleSender = new ConsoleSender();
|
private ConsoleSender consoleSender = new ConsoleSender();
|
||||||
@ -21,18 +22,26 @@ public class CommandManager {
|
|||||||
private Map<String, CommandProcessor> commandProcessorMap = new HashMap<>();
|
private Map<String, CommandProcessor> commandProcessorMap = new HashMap<>();
|
||||||
|
|
||||||
public CommandManager() {
|
public CommandManager() {
|
||||||
|
running = true;
|
||||||
// Setup console thread
|
// Setup console thread
|
||||||
new Thread(() -> {
|
Thread consoleThread = new Thread(() -> {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
while (true) {
|
while (running) {
|
||||||
|
if(scanner.hasNext()) {
|
||||||
String command = scanner.nextLine();
|
String command = scanner.nextLine();
|
||||||
if (!command.startsWith(commandPrefix))
|
if (!command.startsWith(commandPrefix))
|
||||||
continue;
|
continue;
|
||||||
command = command.replaceFirst(commandPrefix, "");
|
command = command.replaceFirst(commandPrefix, "");
|
||||||
execute(consoleSender, command);
|
execute(consoleSender, command);
|
||||||
|
|
||||||
}
|
}
|
||||||
}, "ConsoleCommand-Thread").start();
|
}
|
||||||
|
}, "ConsoleCommand-Thread");
|
||||||
|
consoleThread.setDaemon(true);
|
||||||
|
consoleThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopConsoleThread() {
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Command<CommandSender> command) {
|
public void register(Command<CommandSender> command) {
|
||||||
|
@ -90,8 +90,8 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
@Override
|
@Override
|
||||||
public synchronized boolean addItemStack(ItemStack itemStack) {
|
public synchronized boolean addItemStack(ItemStack itemStack) {
|
||||||
StackingRule stackingRule = itemStack.getStackingRule();
|
StackingRule stackingRule = itemStack.getStackingRule();
|
||||||
for (int i = 0; i < getItemStacks().length; i++) {
|
for (int i = 0; i < getSize(); i++) {
|
||||||
ItemStack item = getItemStacks()[i];
|
ItemStack item = getItemStack(i);
|
||||||
StackingRule itemStackingRule = item.getStackingRule();
|
StackingRule itemStackingRule = item.getStackingRule();
|
||||||
if (itemStackingRule.canBeStacked(itemStack, item)) {
|
if (itemStackingRule.canBeStacked(itemStack, item)) {
|
||||||
int itemAmount = itemStackingRule.getAmount(item);
|
int itemAmount = itemStackingRule.getAmount(item);
|
||||||
@ -216,7 +216,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
|
|
||||||
private synchronized void safeItemInsert(int slot, ItemStack itemStack) {
|
private synchronized void safeItemInsert(int slot, ItemStack itemStack) {
|
||||||
itemStack = ItemStackUtils.notNull(itemStack);
|
itemStack = ItemStackUtils.notNull(itemStack);
|
||||||
this.itemStacks[slot] = itemStack;
|
setItemStackInternal(slot, itemStack);
|
||||||
SetSlotPacket setSlotPacket = new SetSlotPacket();
|
SetSlotPacket setSlotPacket = new SetSlotPacket();
|
||||||
setSlotPacket.windowId = getWindowId();
|
setSlotPacket.windowId = getWindowId();
|
||||||
setSlotPacket.slot = (short) slot;
|
setSlotPacket.slot = (short) slot;
|
||||||
@ -224,10 +224,15 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
sendPacketToViewers(setSlotPacket);
|
sendPacketToViewers(setSlotPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setItemStackInternal(int slot, ItemStack itemStack) {
|
||||||
|
itemStacks[slot] = itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
private WindowItemsPacket createWindowItemsPacket() {
|
private WindowItemsPacket createWindowItemsPacket() {
|
||||||
WindowItemsPacket windowItemsPacket = new WindowItemsPacket();
|
WindowItemsPacket windowItemsPacket = new WindowItemsPacket();
|
||||||
windowItemsPacket.windowId = getWindowId();
|
windowItemsPacket.windowId = getWindowId();
|
||||||
windowItemsPacket.items = itemStacks;
|
windowItemsPacket.count = (short) getSize();
|
||||||
|
windowItemsPacket.items = getItemStacks();
|
||||||
return windowItemsPacket;
|
return windowItemsPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +333,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
} else {
|
} else {
|
||||||
clickResult = clickProcessor.shiftClick(this, player, slot, clicked, cursor,
|
clickResult = clickProcessor.shiftClick(this, player, slot, clicked, cursor,
|
||||||
// Window loop
|
// Window loop
|
||||||
new InventoryClickLoopHandler(0, itemStacks.length, 1,
|
new InventoryClickLoopHandler(0, getSize(), 1,
|
||||||
i -> i,
|
i -> i,
|
||||||
index -> isClickInWindow(index) ? getItemStack(index) : playerInventory.getItemStack(index, offset),
|
index -> isClickInWindow(index) ? getItemStack(index) : playerInventory.getItemStack(index, offset),
|
||||||
(index, itemStack) -> {
|
(index, itemStack) -> {
|
||||||
@ -462,9 +467,9 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
|||||||
|
|
||||||
InventoryClickResult clickResult = clickProcessor.doubleClick(this, player, slot, cursor,
|
InventoryClickResult clickResult = clickProcessor.doubleClick(this, player, slot, cursor,
|
||||||
// Start by looping through the opened inventory
|
// Start by looping through the opened inventory
|
||||||
new InventoryClickLoopHandler(0, itemStacks.length, 1,
|
new InventoryClickLoopHandler(0, getSize(), 1,
|
||||||
i -> i,
|
i -> i,
|
||||||
index -> itemStacks[index],
|
index -> getItemStack(index),
|
||||||
(index, itemStack) -> setItemStack(index, itemStack)),
|
(index, itemStack) -> setItemStack(index, itemStack)),
|
||||||
// Looping through player inventory
|
// Looping through player inventory
|
||||||
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE - 9, 1,
|
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE - 9, 1,
|
||||||
|
@ -1,15 +1,37 @@
|
|||||||
package net.minestom.server.utils;
|
package net.minestom.server.utils;
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
NORTH,
|
NORTH(0, 0, -1),
|
||||||
EAST,
|
EAST(1, 0, 0),
|
||||||
SOUTH,
|
SOUTH(0, 0, 1),
|
||||||
WEST,
|
WEST(-1, 0, 0),
|
||||||
UP,
|
UP(0, 1, 0),
|
||||||
DOWN;
|
DOWN(0, -1, 0);
|
||||||
|
|
||||||
public static final Direction[] HORIZONTAL = { SOUTH, WEST, NORTH, EAST };
|
public static final Direction[] HORIZONTAL = { SOUTH, WEST, NORTH, EAST };
|
||||||
|
|
||||||
|
private final int normalX;
|
||||||
|
private final int normalY;
|
||||||
|
private final int normalZ;
|
||||||
|
|
||||||
|
Direction(int normalX, int normalY, int normalZ) {
|
||||||
|
this.normalX = normalX;
|
||||||
|
this.normalY = normalY;
|
||||||
|
this.normalZ = normalZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int normalX() {
|
||||||
|
return normalX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int normalY() {
|
||||||
|
return normalY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int normalZ() {
|
||||||
|
return normalZ;
|
||||||
|
}
|
||||||
|
|
||||||
public Direction opposite() {
|
public Direction opposite() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case UP:
|
case UP:
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
package net.minestom.server.utils.thread;
|
package net.minestom.server.utils.thread;
|
||||||
|
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.timer.SchedulerManager;
|
||||||
|
import net.minestom.server.timer.TaskRunnable;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class MinestomThread extends ThreadPoolExecutor {
|
public class MinestomThread extends ThreadPoolExecutor {
|
||||||
|
|
||||||
|
private static final List<MinestomThread> executors = new LinkedList<>();
|
||||||
|
|
||||||
public MinestomThread(int nThreads, String name) {
|
public MinestomThread(int nThreads, String name) {
|
||||||
super(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), r -> {
|
super(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), r -> {
|
||||||
Thread thread = new Thread(r);
|
Thread thread = new Thread(r);
|
||||||
|
thread.setDaemon(true);
|
||||||
thread.setName(thread.getName().replace("Thread", name));
|
thread.setName(thread.getName().replace("Thread", name));
|
||||||
return thread;
|
return thread;
|
||||||
});
|
});
|
||||||
|
executors.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shutdownAll() {
|
||||||
|
executors.forEach(MinestomThread::shutdownNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user