mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 10:36:17 +01:00
feat: add base repos and portal data
This commit is contained in:
parent
6d2ed12f36
commit
d7e6df2556
@ -23,6 +23,8 @@ public class AdvancedPortalsCore {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
public enum ErrorCode {
|
||||
INSUFFICIENT_ARGUMENTS(""),
|
||||
NO_PERMISSION("");
|
||||
;
|
||||
|
||||
|
||||
ErrorCode(String message) {
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Do not register to here. Register to the sprcific subcommand registry classes.
|
||||
* <p>
|
||||
* Designed to let addons add new command sections to access, edit or add new functonality.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class SubCommandRegistry {
|
||||
|
||||
protected Map<String, SubCommand> subCommandMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* List of subcommand names which should be in order alphabetically
|
||||
*/
|
||||
protected ArrayList<String> subCommands = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
|
||||
/**
|
||||
* @param arg argument needed to activate
|
||||
* @param subCommand
|
||||
* @return if the subcommand is registered or not
|
||||
*/
|
||||
public boolean registerSubCommand(String arg, SubCommand subCommand) {
|
||||
|
||||
if (subCommand == null) {
|
||||
this.infoLogger.logWarning("The subcommand '" + arg + "' cannot be null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(this.subCommandMap.containsKey(arg)){
|
||||
this.infoLogger.logWarning("The subcommand '" + arg + "' already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.subCommandMap.put(arg.toLowerCase(), subCommand);
|
||||
|
||||
this.subCommands.add(arg.toLowerCase());
|
||||
|
||||
Collections.sort(this.subCommands);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of arguments of registered subcommands
|
||||
*/
|
||||
public ArrayList<String> getSubCommands(){
|
||||
return this.subCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
* I may be wrong but for larger lists containsKey is faster with a hashmap than arraylist.
|
||||
*
|
||||
* Though im not sure at what size it becomes more efficient.
|
||||
* @param arg
|
||||
* @return if the argument is registered
|
||||
*/
|
||||
public boolean isArgRegistered(String arg){
|
||||
return this.subCommandMap.containsKey(arg.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subcommand corresponding to the string argument
|
||||
* @param arg
|
||||
* @return the subcommand linked to the arg
|
||||
*/
|
||||
public SubCommand getSubCommand(String arg){
|
||||
if(this.subCommandMap.containsKey(arg.toLowerCase())){
|
||||
return this.subCommandMap.get(arg.toLowerCase());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.warphandler.TagHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Allows a portal to register a tag and add a handler. If a plugin wants to add functionality
|
||||
* to someone elses tag then they should use the events.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class TagRegistry<T> {
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* List of tag names which should be in order alphabetically
|
||||
*/
|
||||
private ArrayList<String> tags = new ArrayList();
|
||||
/**
|
||||
* Description of tags for help commands
|
||||
*/
|
||||
private Map<String, String> tagDesc = new HashMap();
|
||||
private Map<String, TagHandler.Activation<T>> activationHandlers = new HashMap();
|
||||
private Map<String, TagHandler.Creation<T>> creationHandlers = new HashMap();
|
||||
private Map<String, TagHandler.TagStatus<T>> statusHandlers = new HashMap();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
public TagHandler.Activation<T> getActivationHandler(String arg) {
|
||||
return this.activationHandlers.get(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
public TagHandler.Creation<T> getCreationHandler(String arg) {
|
||||
return this.creationHandlers.get(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
public TagHandler.TagStatus<T> getTagStatusHandler(String arg) {
|
||||
return this.statusHandlers.get(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tag
|
||||
* @param desc
|
||||
* @param tagHandler
|
||||
* @return if the tag was registered
|
||||
*/
|
||||
public boolean registerTag(String tag, String desc, TagHandler tagHandler) {
|
||||
if (registerTag(tag, tagHandler)) {
|
||||
this.tagDesc.put(tag, desc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* It is reccomended that you use the taghandlers to add tag functionality. However
|
||||
* if needed such as extra data for a tag then this is here.
|
||||
*
|
||||
* @param tag
|
||||
* @return if the tag was registered
|
||||
*/
|
||||
public boolean registerTag(String tag) {
|
||||
if (tag.contains(" ")) {
|
||||
this.portalsCore.getInfoLogger().logWarning("The tag '"
|
||||
+ tag + "' is invalid as it contains spaces.");
|
||||
return false;
|
||||
}
|
||||
if (this.tags.contains(tag)) {
|
||||
this.portalsCore.getInfoLogger().logWarning("The tag "
|
||||
+ tag + " has already been registered.");
|
||||
return false;
|
||||
}
|
||||
this.tags.add(tag);
|
||||
Collections.sort(this.tags);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as registerTag(String tag) but allows a description to be added.
|
||||
*
|
||||
* @param tag Tag to be used on command line
|
||||
* @param desc
|
||||
* @return if the tag was registered
|
||||
*/
|
||||
public boolean registerTag(String tag, String desc) {
|
||||
if (registerTag(tag)) {
|
||||
this.tagDesc.put(tag, desc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a non referenced copy of the array list.
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<String> getTags() {
|
||||
ArrayList<String> newArrayList = new ArrayList<>();
|
||||
newArrayList.addAll(this.tags);
|
||||
return newArrayList;
|
||||
}
|
||||
|
||||
public boolean isTagRegistered(String tag){
|
||||
return this.tagDesc.containsKey(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* File must extend
|
||||
* @return if the tag has been registered or if it already exists.
|
||||
*/
|
||||
public boolean registerTag(String tag, Object tagHandler) {
|
||||
|
||||
if (tag == null) {
|
||||
this.portalsCore.getInfoLogger().logWarning("A tag cannot be null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.registerTag(tag)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tagHandler instanceof TagHandler.Activation) {
|
||||
this.activationHandlers.put(tag, (TagHandler.Activation<T>) tagHandler);
|
||||
}
|
||||
if (tagHandler instanceof TagHandler.TagStatus) {
|
||||
this.statusHandlers.put(tag, (TagHandler.TagStatus<T>) tagHandler);
|
||||
}
|
||||
if (tagHandler instanceof TagHandler.Creation) {
|
||||
this.creationHandlers.put(tag, (TagHandler.Creation<T>) tagHandler);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.effect.WarpEffect;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class WarpEffectRegistry {
|
||||
|
||||
|
||||
private Map<String, WarpEffect> visualEffects = new HashMap();
|
||||
|
||||
private Map<String, WarpEffect> soundEffects = new HashMap();
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* Register a new warp effect.
|
||||
*
|
||||
* @param name
|
||||
* @param effect
|
||||
* @return if the effect was registered
|
||||
*/
|
||||
public boolean registerEffect(String name, WarpEffect effect, WarpEffect.Type type) {
|
||||
if(name == null){
|
||||
return false;
|
||||
}
|
||||
Map<String, WarpEffect> list = null;
|
||||
switch (type){
|
||||
case SOUND:
|
||||
list = this.soundEffects;
|
||||
break;
|
||||
case VISUAL:
|
||||
list = this.visualEffects;
|
||||
break;
|
||||
default:
|
||||
this.portalsCore.getInfoLogger().logWarning(type.toString()
|
||||
+ " effect type not recognised");
|
||||
return false;
|
||||
}
|
||||
if(list.containsKey(name)){
|
||||
return false;
|
||||
}
|
||||
list.put(name, effect);
|
||||
return true;
|
||||
}
|
||||
|
||||
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.portalsCore.getInfoLogger().logWarning(type.toString()
|
||||
+ " effect type not recognised");
|
||||
return null;
|
||||
}
|
||||
if(list.containsKey(name)) {
|
||||
return list.get(name);
|
||||
}
|
||||
else{
|
||||
this.portalsCore.getInfoLogger().logWarning("No effect of type:"
|
||||
+ type.toString() + " was registered with the name: " + name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
public class DestinationRepository implements IDestinationRepository<Destination> {
|
||||
private final String fileLocation = "";
|
||||
|
||||
|
||||
private Map<String, Destination> destinationCache = new HashMap<String, Destination>();
|
||||
|
||||
/*Is there any reason to load it into the array if it's not been used or connected? Q for Sekwah*/
|
||||
public void AddDestination(String name, Destination destination) throws IOException {
|
||||
gson.toJson(destination, new FileWriter(fileLocation + name + ".json"));
|
||||
}
|
||||
|
||||
private void test() {
|
||||
destinationCache.get("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(String name, Destination destination) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsKey(String name) {
|
||||
return Files.exists(Paths.get(fileLocation + "\\" + name + ".json"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String name) {
|
||||
try {
|
||||
Files.deleteIfExists(Paths.get(fileLocation + "\\" + name + ".json"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(String name, Destination destination) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImmutableMap<String, Destination> get(String s) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
public interface IDestinationRepository<T> extends IJsonRepository<T> {
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public interface IJsonRepository<T> {
|
||||
Gson gson = new Gson();
|
||||
boolean save(String name, T t);
|
||||
|
||||
boolean containsKey(String name);
|
||||
|
||||
boolean delete(String name);
|
||||
|
||||
boolean update(String name, T t);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.sekwah.advancedportals.core.data.WorldLocation;
|
||||
|
||||
public interface IPortalRepository extends IJsonRepository<WorldLocation> {
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.data.WorldLocation;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Singleton
|
||||
public class PortalRepository implements IPortalRepository {
|
||||
|
||||
public String getSelectedPortal(UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(String name, WorldLocation portalLocation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(String name, WorldLocation portalLocation) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.sekwah.advancedportals.core.warphandler;
|
||||
|
||||
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
|
||||
/**
|
||||
* Created by on 30/07/2016.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class ActivationData {
|
||||
|
||||
private boolean warpAllowed = true;
|
||||
|
||||
private WarpedStatus warpStatus = WarpedStatus.NOTACTIVATED;
|
||||
|
||||
private PlayerLocation wantedLocation;
|
||||
|
||||
public WarpedStatus getWarped() {
|
||||
return this.warpStatus;
|
||||
}
|
||||
|
||||
public void setWarpStatus(WarpedStatus warped) {
|
||||
if (this.warpStatus == WarpedStatus.WARPED) {
|
||||
return;
|
||||
} else if (this.warpStatus == WarpedStatus.NOTACTIVATED) {
|
||||
return;
|
||||
}
|
||||
this.warpStatus = warped;
|
||||
}
|
||||
|
||||
/**
|
||||
* In case you need to set the status back down a step for whatever reason. However it is not recommended.
|
||||
*
|
||||
* @param warped
|
||||
*/
|
||||
public void setWarpStatusAbsolute(WarpedStatus warped) {
|
||||
this.warpStatus = warped;
|
||||
}
|
||||
|
||||
public boolean getAllowed() {
|
||||
return this.warpAllowed;
|
||||
}
|
||||
|
||||
public void setAllowed(boolean allowed) {
|
||||
this.warpAllowed = allowed;
|
||||
}
|
||||
|
||||
public enum WarpedStatus {
|
||||
/**
|
||||
* Player has moved or something major has happened. (only one of these should activate)
|
||||
*/
|
||||
WARPED,
|
||||
/**
|
||||
* Shows that the portal has been activated even if a major function is not performed.
|
||||
*/
|
||||
ACTIVATED,
|
||||
/**
|
||||
* Nothing has activated on the portal (may need to come up with a new name)
|
||||
*/
|
||||
NOTACTIVATED;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package com.sekwah.advancedportals.core.warphandler;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
|
||||
/**
|
||||
* If a tag can be used for any of them then either make it cast the target or if it doesnt need a target
|
||||
* then the exact same tag can be registered into both and ignore the portal info.
|
||||
*
|
||||
* Will probably make better documentation on how to do so or some tutorial videos though take a look at the source code
|
||||
* on github for how the current tags are added.
|
||||
*
|
||||
* Also not sure if its good practice or not in java however these all extend TagHandler so they can be accepted in 1
|
||||
* method nicer than if they didn't
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public interface TagHandler {
|
||||
|
||||
/**
|
||||
* The events for portal creation and destroying
|
||||
*/
|
||||
interface Creation<T> extends TagHandler {
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to use the tag.
|
||||
*
|
||||
* @param player if null then created by the server or a plugin
|
||||
* @param argData
|
||||
*/
|
||||
void created(T target, PlayerContainer player, String argData);
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to remove the portal or destination.
|
||||
*
|
||||
* @param player if null then removed by the server or a plugin
|
||||
* @param argData
|
||||
*/
|
||||
void destroyed(T target, PlayerContainer player, String argData);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Order of activation
|
||||
* Portal and Desti:
|
||||
* preActivated
|
||||
* activated
|
||||
* postActivated
|
||||
*
|
||||
* Order of them combined:
|
||||
* Portal.preActivated
|
||||
* Portal.activated - when desti tag is hit (if listed) then next two actions are activated
|
||||
* - Desti.preActivate
|
||||
* - Desti.activate
|
||||
* Portal.postActivate - when desti tag is hit (if listed) then the next action is activated
|
||||
* - Desti.postActivate
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
interface Activation<T> extends TagHandler {
|
||||
|
||||
/**
|
||||
* Activates before the main part of activation. This should be for prechecks e.g. if the player has enough
|
||||
* money before then taking the money in postActivated.
|
||||
*
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*
|
||||
* @return If the tag has allowed the warp
|
||||
*/
|
||||
boolean preActivated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* Activates after activation, should be used for actions such as removing money for a teleport.
|
||||
*
|
||||
* Any actions to do with player location should be done in activate
|
||||
*
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*/
|
||||
void postActivated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* Activates if the portal is allowed from preActivating. Should be used to set the intended warp location
|
||||
*
|
||||
* You should do some second checks if it can be dependent on the preActivate, the destination tags will also be
|
||||
* triggered here if a desti is listed.
|
||||
*
|
||||
* (You can still cancel here but it is advised to check properly in preActive)
|
||||
*
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*
|
||||
* @return If the tag has allowed the warp
|
||||
*/
|
||||
boolean activated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
|
||||
}
|
||||
|
||||
interface TagStatus<T> extends TagHandler {
|
||||
|
||||
/**
|
||||
* If the user has access to add the tag (this does not include being added on creation)
|
||||
*
|
||||
* @param player
|
||||
* @param argData
|
||||
* @return if the tag will be added.
|
||||
*/
|
||||
boolean tagAdded(T target, PlayerContainer player, String argData);
|
||||
|
||||
/**
|
||||
* If the user has access to remove the tag (this does not include being added on destruction)
|
||||
*
|
||||
* @param player
|
||||
* @param argData
|
||||
* @return if the tag will be removed.
|
||||
*/
|
||||
boolean tagRemoved(T target, PlayerContainer player, String argData);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user