mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Cleanup
This commit is contained in:
parent
c8154b564f
commit
5e85c0117a
@ -119,6 +119,8 @@ public final class MinecraftServer {
|
|||||||
|
|
||||||
private static ExtensionManager extensionManager;
|
private static ExtensionManager extensionManager;
|
||||||
|
|
||||||
|
private static final GlobalEventHandler GLOBAL_EVENT_HANDLER = new GlobalEventHandler();
|
||||||
|
|
||||||
private static UpdateManager updateManager;
|
private static UpdateManager updateManager;
|
||||||
private static MinecraftServer minecraftServer;
|
private static MinecraftServer minecraftServer;
|
||||||
|
|
||||||
@ -134,7 +136,6 @@ public final class MinecraftServer {
|
|||||||
private static ResponseDataConsumer responseDataConsumer;
|
private static ResponseDataConsumer responseDataConsumer;
|
||||||
private static String brandName = "Minestom";
|
private static String brandName = "Minestom";
|
||||||
private static Difficulty difficulty = Difficulty.NORMAL;
|
private static Difficulty difficulty = Difficulty.NORMAL;
|
||||||
private static GlobalEventHandler globalEventHandler = new GlobalEventHandler();
|
|
||||||
private static LootTableManager lootTableManager;
|
private static LootTableManager lootTableManager;
|
||||||
private static TagManager tagManager;
|
private static TagManager tagManager;
|
||||||
|
|
||||||
@ -293,7 +294,7 @@ public final class MinecraftServer {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public static GlobalEventHandler getGlobalEventHandler() {
|
public static GlobalEventHandler getGlobalEventHandler() {
|
||||||
return globalEventHandler;
|
return GLOBAL_EVENT_HANDLER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,11 +38,16 @@ public class CommandDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void unregister(@NotNull Command command) {
|
public void unregister(@NotNull Command command) {
|
||||||
commandMap.remove(command.getName().toLowerCase());
|
this.commandMap.remove(command.getName().toLowerCase());
|
||||||
for (String alias : command.getAliases()) {
|
|
||||||
this.commandMap.remove(alias.toLowerCase());
|
final String[] aliases = command.getAliases();
|
||||||
|
if (aliases != null) {
|
||||||
|
for (String alias : aliases) {
|
||||||
|
this.commandMap.remove(alias.toLowerCase());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
commands.remove(command);
|
|
||||||
|
this.commands.remove(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,7 @@ public class ArgumentDynamicWord extends Argument<String> {
|
|||||||
public static final int SPACE_ERROR = 1;
|
public static final int SPACE_ERROR = 1;
|
||||||
public static final int RESTRICTION_ERROR = 2;
|
public static final int RESTRICTION_ERROR = 2;
|
||||||
|
|
||||||
private SuggestionType suggestionType;
|
private final SuggestionType suggestionType;
|
||||||
|
|
||||||
private StringValidator dynamicRestriction;
|
private StringValidator dynamicRestriction;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ public class ArgumentBlockState extends ArgumentRegistry<Block> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Block getRegistry(String value) {
|
public Block getRegistry(@NotNull String value) {
|
||||||
return Registries.getBlock(value);
|
return Registries.getBlock(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package net.minestom.server.command.builder.arguments.minecraft.registry;
|
|||||||
|
|
||||||
import net.minestom.server.item.Enchantment;
|
import net.minestom.server.item.Enchantment;
|
||||||
import net.minestom.server.registry.Registries;
|
import net.minestom.server.registry.Registries;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an argument giving an {@link Enchantment}.
|
* Represents an argument giving an {@link Enchantment}.
|
||||||
@ -13,7 +14,7 @@ public class ArgumentEnchantment extends ArgumentRegistry<Enchantment> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Enchantment getRegistry(String value) {
|
public Enchantment getRegistry(@NotNull String value) {
|
||||||
return Registries.getEnchantment(value);
|
return Registries.getEnchantment(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package net.minestom.server.command.builder.arguments.minecraft.registry;
|
|||||||
|
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.registry.Registries;
|
import net.minestom.server.registry.Registries;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an argument giving an {@link EntityType}.
|
* Represents an argument giving an {@link EntityType}.
|
||||||
@ -13,7 +14,7 @@ public class ArgumentEntityType extends ArgumentRegistry<EntityType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityType getRegistry(String value) {
|
public EntityType getRegistry(@NotNull String value) {
|
||||||
return Registries.getEntityType(value);
|
return Registries.getEntityType(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package net.minestom.server.command.builder.arguments.minecraft.registry;
|
|||||||
|
|
||||||
import net.minestom.server.particle.Particle;
|
import net.minestom.server.particle.Particle;
|
||||||
import net.minestom.server.registry.Registries;
|
import net.minestom.server.registry.Registries;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an argument giving a {@link Particle}.
|
* Represents an argument giving a {@link Particle}.
|
||||||
@ -13,7 +14,7 @@ public class ArgumentParticle extends ArgumentRegistry<Particle> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Particle getRegistry(String value) {
|
public Particle getRegistry(@NotNull String value) {
|
||||||
return Registries.getParticle(value);
|
return Registries.getParticle(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package net.minestom.server.command.builder.arguments.minecraft.registry;
|
|||||||
|
|
||||||
import net.minestom.server.potion.PotionEffect;
|
import net.minestom.server.potion.PotionEffect;
|
||||||
import net.minestom.server.registry.Registries;
|
import net.minestom.server.registry.Registries;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an argument giving a {@link PotionEffect}.
|
* Represents an argument giving a {@link PotionEffect}.
|
||||||
@ -13,7 +14,7 @@ public class ArgumentPotionEffect extends ArgumentRegistry<PotionEffect> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PotionEffect getRegistry(String value) {
|
public PotionEffect getRegistry(@NotNull String value) {
|
||||||
return Registries.getPotionEffect(value);
|
return Registries.getPotionEffect(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ public abstract class Data implements PublicCloneable<Data> {
|
|||||||
return (Data) super.clone();
|
return (Data) super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
throw new IllegalStateException("Weird thing happened");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
|||||||
protected static final byte METADATA_POSE = 18;
|
protected static final byte METADATA_POSE = 18;
|
||||||
|
|
||||||
protected Instance instance;
|
protected Instance instance;
|
||||||
protected Position position;
|
protected final Position position;
|
||||||
protected float lastX, lastY, lastZ;
|
protected float lastX, lastY, lastZ;
|
||||||
protected float cacheX, cacheY, cacheZ; // Used to synchronize with #getPosition
|
protected float cacheX, cacheY, cacheZ; // Used to synchronize with #getPosition
|
||||||
protected float lastYaw, lastPitch;
|
protected float lastYaw, lastPitch;
|
||||||
|
@ -18,10 +18,10 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class ExtensionDependencyResolver implements DependencyResolver {
|
public class ExtensionDependencyResolver implements DependencyResolver {
|
||||||
|
|
||||||
private Map<String, DiscoveredExtension> extensionMap = new HashMap<>();
|
private final Map<String, DiscoveredExtension> extensionMap = new HashMap<>();
|
||||||
|
|
||||||
public ExtensionDependencyResolver(List<DiscoveredExtension> extensions) {
|
public ExtensionDependencyResolver(@NotNull List<DiscoveredExtension> extensions) {
|
||||||
for(DiscoveredExtension ext : extensions) {
|
for (DiscoveredExtension ext : extensions) {
|
||||||
extensionMap.put(ext.getName(), ext);
|
extensionMap.put(ext.getName(), ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ public class ExtensionDependencyResolver implements DependencyResolver {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ResolvedDependency resolve(@NotNull String extensionName, @NotNull File file) throws UnresolvedDependencyException {
|
public ResolvedDependency resolve(@NotNull String extensionName, @NotNull File file) throws UnresolvedDependencyException {
|
||||||
if(extensionMap.containsKey(extensionName)) {
|
if (extensionMap.containsKey(extensionName)) {
|
||||||
DiscoveredExtension ext = extensionMap.get(extensionName);
|
DiscoveredExtension ext = extensionMap.get(extensionName);
|
||||||
// convert extension URLs to subdependencies
|
// convert extension URLs to subdependencies
|
||||||
// FIXME: this is not a deep conversion, this might create an issue in this scenario with different classloaders:
|
// FIXME: this is not a deep conversion, this might create an issue in this scenario with different classloaders:
|
||||||
@ -38,17 +38,20 @@ public class ExtensionDependencyResolver implements DependencyResolver {
|
|||||||
// When loading B, with no deep conversion, Ext will not be added to the list of dependencies (because it is not a direct dependency)
|
// When loading B, with no deep conversion, Ext will not be added to the list of dependencies (because it is not a direct dependency)
|
||||||
// But when trying to call/access code from extension A, the parts dependent on Ext won't be inside B's dependencies, triggering a ClassNotFoundException
|
// But when trying to call/access code from extension A, the parts dependent on Ext won't be inside B's dependencies, triggering a ClassNotFoundException
|
||||||
List<ResolvedDependency> deps = new LinkedList<>();
|
List<ResolvedDependency> deps = new LinkedList<>();
|
||||||
for(URL u : ext.files) {
|
for (URL u : ext.files) {
|
||||||
deps.add(new ResolvedDependency(u.toExternalForm(), u.toExternalForm(), "", u, new LinkedList<>()));
|
deps.add(new ResolvedDependency(u.toExternalForm(), u.toExternalForm(), "", u, new LinkedList<>()));
|
||||||
}
|
}
|
||||||
return new ResolvedDependency(ext.getName(), ext.getName(), ext.getVersion(), ext.files.get(0), deps);
|
return new ResolvedDependency(ext.getName(), ext.getName(), ext.getVersion(), ext.files.get(0), deps);
|
||||||
}
|
}
|
||||||
throw new UnresolvedDependencyException("No extension named "+extensionName);
|
throw new UnresolvedDependencyException("No extension named " + extensionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String list = extensionMap.values().stream().map(entry -> entry.getName()).collect(Collectors.joining(", "));
|
String list = extensionMap.values()
|
||||||
|
.stream()
|
||||||
|
.map(DiscoveredExtension::getName)
|
||||||
|
.collect(Collectors.joining(", "));
|
||||||
return "ExtensionDependencyResolver[" + list + "]";
|
return "ExtensionDependencyResolver[" + list + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,11 @@ public class ExtensionManager {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LOGGER.error("Failed to load code modifier for extension in files: " + extension.files.stream().map(u -> u.toExternalForm()).collect(Collectors.joining(", ")), e);
|
LOGGER.error("Failed to load code modifier for extension in files: " +
|
||||||
|
extension.files
|
||||||
|
.stream()
|
||||||
|
.map(URL::toExternalForm)
|
||||||
|
.collect(Collectors.joining(", ")), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.info("Done loading code modifiers.");
|
LOGGER.info("Done loading code modifiers.");
|
||||||
@ -628,6 +632,6 @@ public class ExtensionManager {
|
|||||||
* Shutdowns all the extensions by unloading them.
|
* Shutdowns all the extensions by unloading them.
|
||||||
*/
|
*/
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
this.extensionList.forEach(extension -> unload(extension));
|
this.extensionList.forEach(this::unload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class MinestomBytecodeProvider implements IClassBytecodeProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassNode getClassNode(String name) throws ClassNotFoundException, IOException {
|
public ClassNode getClassNode(String name) throws ClassNotFoundException {
|
||||||
return getClassNode(name, false);
|
return getClassNode(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,8 @@ public final class NettyServer {
|
|||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
private PacketProcessor packetProcessor;
|
private final PacketProcessor packetProcessor;
|
||||||
|
private final GlobalChannelTrafficShapingHandler globalTrafficHandler;
|
||||||
|
|
||||||
private EventLoopGroup boss, worker;
|
private EventLoopGroup boss, worker;
|
||||||
private ServerBootstrap bootstrap;
|
private ServerBootstrap bootstrap;
|
||||||
@ -68,8 +69,6 @@ public final class NettyServer {
|
|||||||
private String address;
|
private String address;
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
private GlobalChannelTrafficShapingHandler globalTrafficHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scheduler used by {@code globalTrafficHandler}.
|
* Scheduler used by {@code globalTrafficHandler}.
|
||||||
*/
|
*/
|
||||||
|
@ -137,6 +137,7 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
|||||||
return ServerPacketIdentifier.CHUNK_DATA;
|
return ServerPacketIdentifier.CHUNK_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public TemporaryPacketCache getCache() {
|
public TemporaryPacketCache getCache() {
|
||||||
return CACHE;
|
return CACHE;
|
||||||
|
@ -69,6 +69,7 @@ public class UpdateLightPacket implements ServerPacket, CacheablePacket {
|
|||||||
return ServerPacketIdentifier.UPDATE_LIGHT;
|
return ServerPacketIdentifier.UPDATE_LIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public TemporaryPacketCache getCache() {
|
public TemporaryPacketCache getCache() {
|
||||||
return CACHE;
|
return CACHE;
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
package net.minestom.server.utils;
|
package net.minestom.server.utils;
|
||||||
|
|
||||||
import java.util.*;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class NamespaceIDHashMap<V> extends AbstractMap<NamespaceID, V> {
|
public class NamespaceIDHashMap<V> extends AbstractMap<NamespaceID, V> {
|
||||||
|
|
||||||
private final Map<NamespaceID, V> backing = new HashMap<>();
|
private final Map<NamespaceID, V> backing = new HashMap<>();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<Entry<NamespaceID, V>> entrySet() {
|
public Set<Entry<NamespaceID, V>> entrySet() {
|
||||||
return backing.entrySet();
|
return backing.entrySet();
|
||||||
|
@ -111,9 +111,8 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final long[] data = blocksId;
|
writeVarIntBuf(buffer, blocksId.length);
|
||||||
writeVarIntBuf(buffer, data.length);
|
for (long datum : blocksId) {
|
||||||
for (long datum : data) {
|
|
||||||
buffer.writeLong(datum);
|
buffer.writeLong(datum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user