Skip to content

Commit

Permalink
feat: add base repos and portal data
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 6d2ed12 commit d7e6df2
Show file tree
Hide file tree
Showing 18 changed files with 968 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger) {
this.infoLogger = infoLogger;
this.module = new AdvancedPortalsModule(this);
this.configRepository = module.getInjector().getInstance(ConfigRepository.class);

// Force values to get injected, either because the initial ones were created too early or to ensure they are not null.
module.getInjector().injectMembers(Lang.instance);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.sekwah.advancedportals.core.destination;

import com.google.gson.annotations.SerializedName;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.TagHandler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* Possibly look at adding the ability to add some tags to destinations such as permissions. Would make it easier
* to add permissions to block access to certain areas and such. Could be a different permission system or just
* it takes the tags on the destination and automatically applies them when a portal wants to warp to there.
* (Of course it would not work cross server unless the data was communicated and checked first however that
* could effect performance and would definitely effect speed)
*
* @author sekwah41
*/
public class Destination {

@Inject
TagRegistry<Destination> tagRegistry;

@SerializedName("l")
private PlayerLocation loc;

@SerializedName("a")
private HashMap<String, String> args = new HashMap<>();

private transient Set<String> argsCol;

public Destination(PlayerLocation loc) {
this.loc = loc;
}

public String getArg(String argName) {
return this.args.get(argName);
}

public void setArg(String argName, String argValue) {
this.args.put(argName, argValue);
}

public void setArg(DataTag portalTag) {
this.setArg(portalTag.NAME, portalTag.VALUE);
}

public void removeArg(String arg) {
this.args.remove(arg);
}

public boolean activate(PlayerContainer player) {
ActivationData data = new ActivationData();
this.portalActivate(player, data);
this.postActivate(player, data);
return true;
}

public boolean portalActivate(PlayerContainer player, ActivationData data) {
DataTag[] destiTags = new DataTag[args.size()];
int i = 0;
for(Map.Entry<String, String> entry : args.entrySet()) {
destiTags[i++] = new DataTag(entry.getKey(), entry.getValue());
}
for(DataTag destiTag : destiTags) {
TagHandler.Activation<Destination> activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
if(activationHandler != null) {
activationHandler.preActivated(this, player, data, this.getArg(destiTag.NAME));
}
}
for(DataTag destiTag : destiTags) {
TagHandler.Activation<Destination> activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
if(activationHandler != null) {
activationHandler.activated(this, player, data, this.getArg(destiTag.NAME));
}
}
return true;
}

public void postActivate(PlayerContainer player, ActivationData data) {
DataTag[] destiTags = new DataTag[args.size()];
int i = 0;
for(Map.Entry<String, String> entry : args.entrySet()) {
destiTags[i++] = new DataTag(entry.getKey(), entry.getValue());
}
for(DataTag destiTag : destiTags) {
TagHandler.Activation<Destination> activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
if(activationHandler != null) {
activationHandler.postActivated(this, player, data, this.getArg(destiTag.NAME));
}
}
}

public ArrayList<DataTag> getArgs() {
ArrayList<DataTag> tagList = new ArrayList<>();
for(Map.Entry<String, String> entry : this.args.entrySet()){
tagList.add(new DataTag(entry.getKey(), entry.getValue()));
}
return tagList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.sekwah.advancedportals.core.effect;


import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.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 {

protected abstract void onWarp(PlayerContainer player, WorldLocation loc, Action action, Type type, AdvancedPortal portal);

public enum Action {
ENTER,
EXIT;
}

public enum Type {
SOUND,
VISUAL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.sekwah.advancedportals.core.portal;

import com.google.gson.annotations.SerializedName;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.WorldLocation;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.TagHandler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
* @author sekwah41
*/
public class AdvancedPortal {

@Inject
TagRegistry<AdvancedPortal> tagRegistry;

@SerializedName("max")
private WorldLocation maxLoc;

@SerializedName("min")
private WorldLocation minLoc;

@SerializedName("t")
private String[] triggerBlocks = {"PORTAL"};

@SerializedName("a")
private HashMap<String, String> args = new HashMap<>();

public AdvancedPortal(WorldLocation maxLoc, WorldLocation minLoc) {
this.maxLoc = maxLoc;
this.minLoc = minLoc;
}

public WorldLocation getMaxLoc() {
return this.maxLoc;
}

public WorldLocation getMinLoc() {
return this.minLoc;
}

public String getArg(String argName) {
return this.args.get(argName);
}

public void setArg(String argName, String argValue) {
this.args.put(argName, argValue);
}

public void removeArg(String arg) {
this.args.remove(arg);
}

public boolean hasTriggerBlock(String blockMaterial) {
for(String triggerBlock : triggerBlocks) {
if(blockMaterial.equals(triggerBlock)) {
return true;
}
}
return false;
}

public boolean activate(PlayerContainer player) {
ActivationData data = new ActivationData();
DataTag[] portalTags = new DataTag[args.size()];
int i = 0;
for(Map.Entry<String, String> entry : args.entrySet()) {
portalTags[i++] = new DataTag(entry.getKey(), entry.getValue());
}

for(DataTag portalTag : portalTags) {
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
if(activationHandler != null) {
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
}
}
for(DataTag portalTag : portalTags) {
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
if(activationHandler != null) {
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
}
}
for(DataTag portalTag : portalTags) {
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
if(activationHandler != null) {
activationHandler.postActivated(this, player, data, this.getArg(portalTag.NAME));
}
}
return true;
}

public void setArg(DataTag portalTag) {
this.setArg(portalTag.NAME, portalTag.VALUE);
}

public ArrayList<DataTag> getArgs() {
ArrayList<DataTag> tagList = new ArrayList<>();
for(Map.Entry<String, String> entry : this.args.entrySet()){
tagList.add(new DataTag(entry.getKey(), entry.getValue()));
}
return tagList;
}

public void setTriggerBlocks(String[] triggerBlocks) {
this.triggerBlocks = triggerBlocks;
}

public String[] getTriggerBlocks() {
return triggerBlocks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sekwah.advancedportals.core.registry;

public class CommandException {
private ErrorCode errorCode;
private String message;

public CommandException(ErrorCode errorCode, String message) {
this.errorCode = errorCode;
this.message = message;
}

public ErrorCode getErrorCode() {
return errorCode;
}

public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sekwah.advancedportals.core.registry;

import com.google.common.collect.ImmutableList;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;

public interface CommandHandler {
void onExecute(String commandName, String parentCommand, CommandSenderContainer sender, ImmutableList<String> args);

default void onCommandFailure(String[] command, CommandSenderContainer sender, CommandException exception, ImmutableList<String> args) {
sender.sendMessage(exception.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sekwah.advancedportals.core.registry;

public enum ErrorCode {
INSUFFICIENT_ARGUMENTS(""),
NO_PERMISSION("");
;


ErrorCode(String message) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sekwah.advancedportals.core.registry;

import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class RegisterBuilder<T extends CommandHandler> {
public static RegisterBuilder newBuilder() {
return new RegisterBuilder();
}

private RegisterBuilder() {
}

private boolean allowPermissionInheritance;
private String scanDirectory;
private final Class<T> genericType = (Class<T>) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];


public RegisterBuilder<T> inheritPermissions(boolean allowInheritance) {
allowPermissionInheritance = allowInheritance;
return this;
}

public RegisterBuilder<T> scanDirectory(String directoryName) {
this.scanDirectory = directoryName;
return this;
}

}
Loading

0 comments on commit d7e6df2

Please sign in to comment.