Skip to content

Commit

Permalink
Implement new plugins system
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSlimeDiamond authored Jun 23, 2023
1 parent e8e736c commit f322398
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'net.zenoc'
version = '1.17.1-1.1.0-beta.1'
version = '1.17.1-1.1.0-beta.2'
var mainClass = "net.zenoc.gallium.Main"

repositories {
Expand Down Expand Up @@ -34,7 +34,7 @@ dependencies {
// implementation 'com.mojang:authlib:1.5.25'
implementation 'io.netty:netty-all:4.1.10.Final'
implementation 'org.joml:joml:1.10.5'
implementation 'net.zenoc.gallium:gallium:1.1.0-beta.1'
implementation 'net.zenoc.gallium:gallium:1.1.0-beta.2'
implementation 'net.minecraft:server:1.17.1'
implementation 'com.github.oshi:oshi-core:6.2.2'
implementation 'commons-io:commons-io:2.11.0'
Expand All @@ -43,6 +43,7 @@ dependencies {
implementation 'net.kyori:event-method-asm:3.0.0'
implementation 'net.kyori:adventure-text-serializer-gson:4.2.0'
implementation 'org.xerial:sqlite-jdbc:3.42.0.0'
implementation 'org.json:json:20230618'
}

test {
Expand Down
Binary file added libs/GalliumLib-1.1.0-beta.2.jar
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/java/net/minecraft/server/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import net.minecraft.world.level.storage.PrimaryLevelData;
import net.minecraft.world.level.storage.WorldData;
import net.zenoc.gallium.Gallium;
import net.zenoc.gallium.plugin.Plugin;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/minecraft/server/MinecraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@
import net.minecraft.world.level.storage.loot.PredicateManager;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.zenoc.gallium.Gallium;
import net.zenoc.gallium.Mod;
import net.zenoc.gallium.api.event.system.ServerShutdownEvent;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -619,6 +621,11 @@ public void close() {
}

public void stopServer() {
// Gallium start
new ServerShutdownEvent("I haven't added the reason part of this yet").call();
Gallium.getPluginManager().unloadPlugins();
// Gallium end

LOGGER.info("Stopping server");
if (this.getConnection() != null) {
this.getConnection().stop();
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
import net.minecraft.world.level.storage.WorldData;
import net.zenoc.gallium.Gallium;
import net.zenoc.gallium.api.event.system.ServerStartEvent;
import net.zenoc.gallium.plugin.Plugin;
import net.zenoc.gallium.plugin.PluginBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -90,16 +88,6 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Nullable
private final Component resourcePackPrompt;

// Gallium start: internal Minecraft plugin
// TODO: Use this for Minecraft's default commands
public Plugin plugin = new PluginBuilder()
.setName("Minecraft")
.setId("minecraft")
.setVersion(getServerVersion())
.addAuthor("Mojang")
.build();
// Gallium end

public DedicatedServer(Thread thread, RegistryAccess.RegistryHolder registryHolder, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, ServerResources serverResources, WorldData worldData, DedicatedServerSettings dedicatedServerSettings, DataFixer dataFixer, MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository, GameProfileCache gameProfileCache, ChunkProgressListenerFactory chunkProgressListenerFactory) {
super(thread, registryHolder, levelStorageAccess, worldData, packRepository, Proxy.NO_PROXY, dataFixer, serverResources, minecraftSessionService, gameProfileRepository, gameProfileCache, chunkProgressListenerFactory);
this.settings = dedicatedServerSettings;
Expand Down Expand Up @@ -192,7 +180,6 @@ public void run() {
SkullBlockEntity.setMainThreadExecutor(this);
GameProfileCache.setUsesAuthentication(this.usesAuthentication());
Gallium.loadPlugins(); // Gallium
Gallium.getPluginManager().loadPlugin(plugin);
LOGGER.info("Preparing level \"{}\"", this.getLevelIdName());
this.loadLevel();
long m = Util.getNanos() - l;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.zenoc.gallium.api.event.player.PlayerChatEvent;
import net.zenoc.gallium.api.event.player.PlayerDisconnectEvent;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -1141,9 +1142,17 @@ private void handleChat(TextFilter.FilteredText filteredText) {
String string2 = filteredText.getFiltered();
Component component = string2.isEmpty() ? null : new TranslatableComponent("chat.type.text", new Object[]{this.player.getDisplayName(), string2});
Component component2 = new TranslatableComponent("chat.type.text", new Object[]{this.player.getDisplayName(), string});

// Gallium start: chat event
PlayerChatEvent chatEvent = (PlayerChatEvent) new PlayerChatEvent(new net.zenoc.gallium.api.world.entity.Player(this.player), string2).call();
LOGGER.debug("Chat");
if (chatEvent.isCancelled()) return;

// TODO: Custom chat format in config
this.server.getPlayerList().broadcastMessage(component2, (serverPlayer) -> {
return this.player.shouldFilterMessageTo(serverPlayer) ? component : component2;
}, ChatType.CHAT, this.player.getUUID());
// Gallium end
}

this.chatSpamTickCount += 20;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/zenoc/gallium/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public Mod() {
this.bannedPlayersFile = new File("data/banned-players.json");
this.opListFile = new File("data/ops.json");
this.whitelistFile = new File("data/whitelist.json");
this.pluginConfigDirectory = new File("config/");

try {
database.addGroupsToGroupManager(groupManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//package net.zenoc.gallium.internal.minecraftplugin;
//
//@Plugin(
// name = "Minecraft",
// id = "minecraft",
// description = "Minecraft",
// authors = {"Mojang"},
// version = "1.17.1"
//)
//public class MinecraftPlugin extends JavaPlugin {
// // TODO: Assign Minecraft default commands to this
//}
2 changes: 1 addition & 1 deletion src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="debug">
<Root level="info">
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
</filters>
Expand Down

0 comments on commit f322398

Please sign in to comment.