wip: switching stuff over for warp effects
This commit is contained in:
parent
bc6c492899
commit
7b3004ea35
|
@ -11,7 +11,7 @@ public interface EntityContainer {
|
|||
|
||||
BlockLocation getBlockLoc();
|
||||
|
||||
void teleport(PlayerLocation location);
|
||||
boolean teleport(PlayerLocation location);
|
||||
|
||||
WorldContainer getWorld();
|
||||
|
||||
|
|
|
@ -2,30 +2,24 @@ package com.sekwah.advancedportals.core.effect;
|
|||
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
|
||||
/**
|
||||
* Effects to be registered to the list.
|
||||
* <p>
|
||||
* Fires once at each end.
|
||||
* <p>
|
||||
* Can be a Visual effect or a Sound. Just register to the correct one
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public abstract class WarpEffect {
|
||||
public interface WarpEffect {
|
||||
|
||||
protected abstract void onWarp(PlayerContainer player, WorldLocation loc, Action action, Type type, AdvancedPortal portal);
|
||||
|
||||
public enum Action {
|
||||
enum Action {
|
||||
ENTER,
|
||||
EXIT;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
SOUND,
|
||||
VISUAL;
|
||||
interface Sound extends WarpEffect {
|
||||
|
||||
void onWarpSound(PlayerContainer player, Action action, AdvancedPortal portal);
|
||||
|
||||
}
|
||||
|
||||
interface Visual extends WarpEffect {
|
||||
|
||||
void onWarpVisual(PlayerContainer player, Action action, AdvancedPortal portal);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.google.inject.*;
|
|||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.registry.WarpEffectRegistry;
|
||||
import com.sekwah.advancedportals.core.repository.IPlayerDataRepository;
|
||||
import com.sekwah.advancedportals.core.repository.impl.PlayerDataRepositoryImpl;
|
||||
import com.sekwah.advancedportals.core.serializeddata.config.Config;
|
||||
|
@ -53,6 +54,7 @@ public class AdvancedPortalsModule extends AbstractModule {
|
|||
// Providers
|
||||
bind(Config.class).toProvider(ConfigProvider.class);
|
||||
bind(TagRegistry.class).asEagerSingleton();
|
||||
bind(WarpEffectRegistry.class).asEagerSingleton();
|
||||
|
||||
// Delayed Bindings
|
||||
for(DelayedBinding delayedBinding : delayedBindings) {
|
||||
|
|
|
@ -14,9 +14,7 @@ import java.util.Map;
|
|||
public class WarpEffectRegistry {
|
||||
|
||||
|
||||
private Map<String, WarpEffect> visualEffects = new HashMap();
|
||||
|
||||
private Map<String, WarpEffect> soundEffects = new HashMap();
|
||||
private Map<String, WarpEffect> warpEffects = new HashMap();
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
@ -31,50 +29,49 @@ public class WarpEffectRegistry {
|
|||
* @param effect
|
||||
* @return if the effect was registered
|
||||
*/
|
||||
public boolean registerEffect(String name, WarpEffect effect, WarpEffect.Type type) {
|
||||
public void registerEffect(String name, WarpEffect effect) {
|
||||
|
||||
if(name == null){
|
||||
return false;
|
||||
this.infoLogger.warning("Effect name cannot be null");
|
||||
return;
|
||||
}
|
||||
Map<String, WarpEffect> list = null;
|
||||
switch (type){
|
||||
case SOUND:
|
||||
list = this.soundEffects;
|
||||
break;
|
||||
case VISUAL:
|
||||
list = this.visualEffects;
|
||||
break;
|
||||
default:
|
||||
this.portalsCore.getInfoLogger().warning(type.toString()
|
||||
+ " effect type not recognised");
|
||||
return false;
|
||||
if(this.warpEffects.containsKey(name)){
|
||||
this.infoLogger.warning("Effect with the name: " + name + " already exists");
|
||||
return;
|
||||
}
|
||||
if(list.containsKey(name)){
|
||||
return false;
|
||||
}
|
||||
list.put(name, effect);
|
||||
return true;
|
||||
this.warpEffects.put(name, effect);
|
||||
}
|
||||
|
||||
public WarpEffect getEffect(String name, WarpEffect.Type type){
|
||||
Map<String, WarpEffect> list = null;
|
||||
switch (type){
|
||||
case SOUND:
|
||||
list = this.soundEffects;
|
||||
break;
|
||||
case VISUAL:
|
||||
list = this.visualEffects;
|
||||
break;
|
||||
default:
|
||||
this.infoLogger.warning(type.toString()
|
||||
+ " effect type not recognised");
|
||||
public WarpEffect.Visual getVisualEffect(String name){
|
||||
if(this.warpEffects.containsKey(name)) {
|
||||
var effect = this.warpEffects.get(name);
|
||||
if(effect instanceof WarpEffect.Visual visual){
|
||||
return visual;
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("Effect called " + name + " is not a visual effect");
|
||||
return null;
|
||||
}
|
||||
if(list.containsKey(name)) {
|
||||
return list.get(name);
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("No effect of type:"
|
||||
+ type.toString() + " was registered with the name: " + name);
|
||||
this.infoLogger.warning("No effect called " + name + " was registered");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public WarpEffect.Sound getSoundEffect(String name){
|
||||
if(this.warpEffects.containsKey(name)) {
|
||||
var effect = this.warpEffects.get(name);
|
||||
if(effect instanceof WarpEffect.Sound sound){
|
||||
return sound;
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("Effect called " + name + " is not a sound effect");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("No effect called " + name + " was registered");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,4 +103,8 @@ public class DestinationServices {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Destination getDestination(String name) {
|
||||
return destinationCache.get(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ package com.sekwah.advancedportals.core.tags.activation;
|
|||
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.TagTarget;
|
||||
import com.sekwah.advancedportals.core.registry.WarpEffectRegistry;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
|
@ -18,6 +20,9 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
|||
@Inject
|
||||
DestinationServices destinationServices;
|
||||
|
||||
@Inject
|
||||
WarpEffectRegistry warpEffectRegistry;
|
||||
|
||||
private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL };
|
||||
|
||||
@Override
|
||||
|
@ -58,7 +63,16 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
|||
|
||||
@Override
|
||||
public boolean activated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
|
||||
return false;
|
||||
System.out.println("Teleporting to destination");
|
||||
Destination destination = destinationServices.getDestination(argData[0]);
|
||||
if (destination != null) {
|
||||
var warpEffect = warpEffectRegistry.getVisualEffect("ender");
|
||||
if (warpEffect != null) {
|
||||
warpEffect.onWarpVisual(player, ac);
|
||||
}
|
||||
player.teleport(destination.getLoc());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.sekwah.advancedportals.spigot.commands.subcommands.portal.UpdatePorta
|
|||
import com.sekwah.advancedportals.spigot.connector.command.SpigotCommandRegister;
|
||||
import com.sekwah.advancedportals.spigot.connector.container.SpigotServerContainer;
|
||||
import com.sekwah.advancedportals.spigot.metrics.Metrics;
|
||||
import com.sekwah.advancedportals.spigot.warpeffects.SpigotWarpEffects;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -56,6 +57,10 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
|||
GameScheduler scheduler = injector.getInstance(GameScheduler.class);
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, scheduler::tick, 1, 1);
|
||||
|
||||
var warpEffects = new SpigotWarpEffects();
|
||||
injector.injectMembers(warpEffects);
|
||||
warpEffects.registerEffects();
|
||||
|
||||
// Try to do this after setting up everything that would need to be injected to.
|
||||
this.portalsCore.onEnable();
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public class SpigotEntityContainer implements EntityContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void teleport(PlayerLocation location) {
|
||||
this.entity.teleport(new Location(Bukkit.getWorld(location.getWorldName()), location.getPosX(), location.getPosY(), location.getPosZ()));
|
||||
public boolean teleport(PlayerLocation location) {
|
||||
return this.entity.teleport(new Location(Bukkit.getWorld(location.getWorldName()), location.getPosX(), location.getPosY(), location.getPosZ()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play
|
|||
}
|
||||
|
||||
@Override
|
||||
public void teleport(PlayerLocation location) {
|
||||
this.player.teleport(new Location(Bukkit.getWorld(location.getWorldName()), location.getPosX(), location.getPosY(), location.getPosZ()));
|
||||
public boolean teleport(PlayerLocation location) {
|
||||
return this.player.teleport(new Location(Bukkit.getWorld(location.getWorldName()), location.getPosX(), location.getPosY(), location.getPosZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,4 +97,8 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.sekwah.advancedportals.spigot.warpeffects;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.effect.WarpEffect;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
|
||||
import com.sekwah.advancedportals.spigot.connector.container.SpigotPlayerContainer;
|
||||
|
||||
public class EnderWarpEffect implements WarpEffect.Visual, WarpEffect.Sound {
|
||||
|
||||
@Override
|
||||
public void onWarpSound(PlayerContainer playerContainer, WarpEffect.Action action, AdvancedPortal portal) {
|
||||
if(playerContainer instanceof SpigotPlayerContainer spigotPlayerContainer) {
|
||||
var player = spigotPlayerContainer.getPlayer();
|
||||
|
||||
player.playSound(player.getLocation(), "entity.enderman.teleport", 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWarpVisual(PlayerContainer player, WarpEffect.Action action, AdvancedPortal portal) {
|
||||
if (action == WarpEffect.Action.ENTER) {
|
||||
player.spawnParticle(new WorldLocation(portal.getPortalLocation()), "ENDER_SIGNAL", 1, 1, 1, 1, 1);
|
||||
} else {
|
||||
player.spawnParticle(new WorldLocation(portal.getPortalLocation()), "ENDER_SIGNAL", 1, 1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.sekwah.advancedportals.spigot.warpeffects;
|
||||
|
||||
import com.sekwah.advancedportals.core.effect.WarpEffect;
|
||||
import com.sekwah.advancedportals.core.registry.WarpEffectRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class SpigotWarpEffects {
|
||||
|
||||
@Inject
|
||||
private WarpEffectRegistry warpEffectRegistry;
|
||||
|
||||
public void registerEffects() {
|
||||
warpEffectRegistry.registerEffect("ender", new EnderWarpEffect());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue