mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Added a SkinApplyEvent that can cancel/edit the to be applied skin
This commit is contained in:
@@ -69,6 +69,7 @@ public final class VelocityPlatformModule extends AbstractModule {
|
||||
bind(CommandUtil.class).to(VelocityCommandUtil.class);
|
||||
bind(PlatformUtils.class).to(VelocityPlatformUtils.class);
|
||||
bind(FloodgateLogger.class).to(Slf4jFloodgateLogger.class);
|
||||
bind(SkinApplier.class).to(VelocitySkinApplier.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -112,12 +113,6 @@ public final class VelocityPlatformModule extends AbstractModule {
|
||||
return new VelocityPluginMessageRegistration(proxy);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SkinApplier skinApplier(ProxyServer server) {
|
||||
return new VelocitySkinApplier(server);
|
||||
}
|
||||
|
||||
/*
|
||||
DebugAddon / PlatformInjector
|
||||
*/
|
||||
|
||||
@@ -25,43 +25,60 @@
|
||||
|
||||
package org.geysermc.floodgate.util;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.util.GameProfile.Property;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.floodgate.api.event.skin.SkinApplyEvent;
|
||||
import org.geysermc.floodgate.api.event.skin.SkinApplyEvent.SkinData;
|
||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||
import org.geysermc.floodgate.event.EventBus;
|
||||
import org.geysermc.floodgate.event.skin.SkinApplyEventImpl;
|
||||
import org.geysermc.floodgate.skin.SkinApplier;
|
||||
import org.geysermc.floodgate.skin.SkinData;
|
||||
import org.geysermc.floodgate.skin.SkinDataImpl;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Singleton
|
||||
public class VelocitySkinApplier implements SkinApplier {
|
||||
private final ProxyServer server;
|
||||
@Inject private ProxyServer server;
|
||||
@Inject private EventBus eventBus;
|
||||
|
||||
@Override
|
||||
public void applySkin(FloodgatePlayer floodgatePlayer, SkinData skinData) {
|
||||
public void applySkin(@NonNull FloodgatePlayer floodgatePlayer, @NonNull SkinData skinData) {
|
||||
server.getPlayer(floodgatePlayer.getCorrectUniqueId()).ifPresent(player -> {
|
||||
List<Property> properties = new ArrayList<>(player.getGameProfileProperties());
|
||||
properties.add(new Property("textures", skinData.getValue(), skinData.getSignature()));
|
||||
|
||||
SkinData currentSkin = currentSkin(properties);
|
||||
|
||||
SkinApplyEvent event = new SkinApplyEventImpl(floodgatePlayer, currentSkin, skinData);
|
||||
event.setCancelled(floodgatePlayer.isLinked());
|
||||
|
||||
eventBus.fire(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
replaceSkin(properties, event.newSkin());
|
||||
player.setGameProfileProperties(properties);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkin(FloodgatePlayer floodgatePlayer) {
|
||||
Optional<Player> player = server.getPlayer(floodgatePlayer.getCorrectUniqueId());
|
||||
|
||||
if (player.isPresent()) {
|
||||
for (Property property : player.get().getGameProfileProperties()) {
|
||||
if (property.getName().equals("textures")) {
|
||||
if (!property.getValue().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
private SkinData currentSkin(List<Property> properties) {
|
||||
for (Property property : properties) {
|
||||
if (property.getName().equals("textures")) {
|
||||
if (!property.getValue().isEmpty()) {
|
||||
return new SkinDataImpl(property.getValue(), property.getSignature());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void replaceSkin(List<Property> properties, SkinData skinData) {
|
||||
properties.removeIf(property -> property.getName().equals("textures"));
|
||||
properties.add(new Property("textures", skinData.value(), skinData.signature()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user