Skip to content

Commit

Permalink
feat: configure portal effects
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 13, 2024
1 parent d757d41 commit 56eda7d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void incomingMessage(PlayerContainer player, String channel, byte[] messa
switch (messageType) {
case ProxyMessages.SERVER_DESTI -> {
var serverDestiPacket = ServerDestiPacket.decode(buffer);
this.destinationServices.teleportToDestination(serverDestiPacket.getDestination(), player);
this.destinationServices.teleportToDestination(serverDestiPacket.getDestination(), player, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void registerEffect(String name, WarpEffect effect) {
}

public WarpEffect.Visual getVisualEffect(String name) {
if (this.warpEffects.containsKey(name)) {
if (this.warpEffects.containsKey(name.toLowerCase())) {
var effect = this.warpEffects.get(name);
if (effect instanceof WarpEffect.Visual visual) {
return visual;
Expand All @@ -51,7 +51,7 @@ public WarpEffect.Visual getVisualEffect(String name) {
}
} else {
this.infoLogger.warning("No effect called " + name
+ " was registered");
+ " is registered");
return null;
}
}
Expand All @@ -68,7 +68,7 @@ public WarpEffect.Sound getSoundEffect(String name) {
}
} else {
this.infoLogger.warning("No effect called " + name
+ " was registered");
+ " is registered");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public interface ConfigRepository {

boolean warpMessageInChat();

String getWarpParticles();
String getWarpVisual();

boolean getWarpEffectEnabled();

boolean getEnableProxySupport();
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,17 @@ public double getThrowbackStrength() {

@Override
public String getWarpSound() {
return this.config.warpSound;
return this.config.warpEffect.soundEffect;
}

@Override
public String getWarpParticles() {
return this.config.warpParticles;
public String getWarpVisual() {
return this.config.warpEffect.visualEffect;
}

@Override
public boolean getWarpEffectEnabled() {
return this.config.warpEffect.enabled;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public class Config {

public int joinCooldown = 5;

public String warpParticles = "ENDER";

public String warpSound = "ENDER";

public String translationFile = "en_GB";

public int showVisibleRange = 50;
Expand All @@ -41,4 +37,6 @@ public class Config {
public CommandPortalConfig commandPortals = new CommandPortalConfig();

public boolean enableProxySupport = false;

public WarpEffectConfig warpEffect = new WarpEffectConfig();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sekwah.advancedportals.core.serializeddata.config;

public class WarpEffectConfig {
public String visualEffect = "ender";
public String soundEffect = "ender";
public boolean enabled = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.effect.WarpEffect;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.registry.WarpEffectRegistry;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
Expand All @@ -20,6 +23,12 @@ public class DestinationServices {
@Inject
private IDestinationRepository destinationRepository;

@Inject
private WarpEffectRegistry warpEffectRegistry;

@Inject
private ConfigRepository configRepository;

@Inject
TagRegistry tagRegistry;

Expand Down Expand Up @@ -122,8 +131,23 @@ public Destination getDestination(String name) {

public boolean teleportToDestination(String name,
PlayerContainer playerContainer) {
return teleportToDestination(name, playerContainer, false);
}

public boolean teleportToDestination(String name,
PlayerContainer player, boolean doEffect) {
if(doEffect && configRepository.getWarpEffectEnabled()) {
var warpEffectVisual = warpEffectRegistry.getVisualEffect(configRepository.getWarpVisual());
if (warpEffectVisual != null) {
warpEffectVisual.onWarpVisual(player, WarpEffect.Action.ENTER);
}
var warpEffectSound = warpEffectRegistry.getSoundEffect(configRepository.getWarpSound());
if (warpEffectSound != null) {
warpEffectSound.onWarpSound(player, WarpEffect.Action.ENTER);
}
}
if (this.destinationRepository.containsKey(name)) {
playerContainer.teleport(
player.teleport(
this.destinationRepository.get(name).getLoc());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,26 @@ public boolean activated(TagTarget target, PlayerContainer player,
Destination destination =
destinationServices.getDestination(selectedArg);
if (destination != null) {
var warpEffectVisual = warpEffectRegistry.getVisualEffect("ender");
if (warpEffectVisual != null) {
warpEffectVisual.onWarpVisual(player, WarpEffect.Action.ENTER);
}
var warpEffectSound = warpEffectRegistry.getSoundEffect("ender");
if (warpEffectSound != null) {
warpEffectSound.onWarpSound(player, WarpEffect.Action.ENTER);
var warpEffectVisual = warpEffectRegistry.getVisualEffect(configRepository.getWarpVisual());
var warpEffectSound = warpEffectRegistry.getSoundEffect(configRepository.getWarpSound());
if(configRepository.getWarpEffectEnabled()) {
if (warpEffectVisual != null) {
warpEffectVisual.onWarpVisual(player, WarpEffect.Action.ENTER);
}
if (warpEffectSound != null) {
warpEffectSound.onWarpSound(player, WarpEffect.Action.ENTER);
}
}

player.teleport(destination.getLoc());
if (warpEffectVisual != null) {
warpEffectVisual.onWarpVisual(player, WarpEffect.Action.EXIT);
}
if (warpEffectSound != null) {
warpEffectSound.onWarpSound(player, WarpEffect.Action.EXIT);

if(configRepository.getWarpEffectEnabled()) {
if (warpEffectVisual != null) {
warpEffectVisual.onWarpVisual(player, WarpEffect.Action.EXIT);
}
if (warpEffectSound != null) {
warpEffectSound.onWarpSound(player, WarpEffect.Action.EXIT);
}
}
activationData.setWarpStatus(ActivationData.WarpedStatus.WARPED);
}
Expand Down

0 comments on commit 56eda7d

Please sign in to comment.