Skip to content

Commit

Permalink
fix sponge bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmakila committed Dec 2, 2024
1 parent a8fe92e commit 54cd47a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public void startup() {
PacketEvents.getAPI().getEventManager().registerListener(this.packetListener, PacketListenerPriority.NORMAL);
}

public void shutdown() {
PacketEvents.getAPI().getEventManager().unregisterListener(this.packetListener);
}

public void createLevelProviderFactory(BiFunction<P, String, Boolean> permissionChecker, Class<P> playerClass) {
this.levelProviderFactory = new LevelProviderFactory<>(this, permissionChecker, playerClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public LevelProvider<P> levelProvider() {
}

public void createLuckPermsProvider(LuckPerms luckPerms) {
this.luckPermsLevelProvider = new LuckPermsLevelProvider<P>(luckPerms, this.logger, this.playerClass);
this.luckPermsLevelProvider = new LuckPermsLevelProvider<>(luckPerms, this.logger, this.playerClass);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package fi.fabianadrian.operatorlevel.common.packet;

import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketListenerCommon;
import com.github.retrooper.packetevents.event.PacketListenerPriority;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityStatus;

public final class PacketListener extends PacketListenerCommon implements com.github.retrooper.packetevents.event.PacketListener {
@Override
public PacketListenerAbstract asAbstract(PacketListenerPriority priority) {
return com.github.retrooper.packetevents.event.PacketListener.super.asAbstract(priority);
}

public final class PacketListener implements com.github.retrooper.packetevents.event.PacketListener {
@Override
public void onPacketSend(PacketSendEvent event) {
if (event.getPacketType() != PacketType.Play.Server.ENTITY_STATUS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ public void onEnable() {
new Metrics(this, 23464);
}

@Override
public void onDisable() {
this.operatorLevel.shutdown();
}

public void registerListeners() {
getServer().getPluginManager().registerEvents(new PlayerListener(this.operatorLevel), this);
}

public void reload() {
this.operatorLevel.reload();
getServer().getOnlinePlayers().forEach(this.operatorLevel::updateLevel);
}

@Override
public Logger logger() {
return getSLF4JLogger();
Expand All @@ -57,4 +43,13 @@ public Path configDirectory() {
public Player player(UUID uuid) {
return getServer().getPlayer(uuid);
}

public void registerListeners() {
getServer().getPluginManager().registerEvents(new PlayerListener(this.operatorLevel), this);
}

public void reload() {
this.operatorLevel.reload();
getServer().getOnlinePlayers().forEach(this.operatorLevel::updateLevel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.Command;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
import org.spongepowered.api.event.lifecycle.StartedEngineEvent;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.builtin.jvm.Plugin;

import java.nio.file.Path;
import java.util.UUID;

@Plugin("operatorlevel")
public final class OperatorLevelSponge implements Platform<Player> {
public final class OperatorLevelSponge implements Platform<ServerPlayer> {
private final PluginContainer container;
private final OperatorLevel<Player> operatorLevel;
private final OperatorLevel<ServerPlayer> operatorLevel;
private final Logger logger;
private final Path configDirectory;

Expand All @@ -42,8 +42,8 @@ public OperatorLevelSponge(

this.operatorLevel = new OperatorLevel<>(this);
this.operatorLevel.createLevelProviderFactory(
(player, permission) -> ((ServerPlayer) player).hasPermission(permission),
Player.class
Subject::hasPermission,
ServerPlayer.class
);

metricsFactory.make(24064);
Expand All @@ -60,15 +60,6 @@ public void onRegisterCommands(final RegisterCommandEvent<Command.Parameterized>
event.register(this.container, new SpongeOperatorLevelCommand(this).command(), "operatorlevel");
}

public void registerListeners() {
Sponge.eventManager().registerListeners(this.container, new PlayerListener(this.operatorLevel));
}

public void reload() {
this.operatorLevel.reload();
Sponge.server().onlinePlayers().forEach(this.operatorLevel::updateLevel);
}

@Override
public Logger logger() {
return this.logger;
Expand All @@ -83,4 +74,13 @@ public Path configDirectory() {
public ServerPlayer player(UUID uuid) {
return Sponge.server().player(uuid).orElse(null);
}

public void registerListeners() {
Sponge.eventManager().registerListeners(this.container, new PlayerListener(this.operatorLevel));
}

public void reload() {
this.operatorLevel.reload();
Sponge.server().onlinePlayers().forEach(this.operatorLevel::updateLevel);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package fi.fabianadrian.operatorlevel.sponge.listener;

import fi.fabianadrian.operatorlevel.common.OperatorLevel;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.network.ServerSideConnectionEvent;

public final class PlayerListener {
private final OperatorLevel<Player> operatorLevel;
private final OperatorLevel<ServerPlayer> operatorLevel;

public PlayerListener(OperatorLevel<Player> operatorLevel) {
public PlayerListener(OperatorLevel<ServerPlayer> operatorLevel) {
this.operatorLevel = operatorLevel;
}

Expand Down

0 comments on commit 54cd47a

Please sign in to comment.