-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add base repos and portal data
- Loading branch information
Showing
18 changed files
with
968 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
core/src/main/java/com/sekwah/advancedportals/core/destination/Destination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/java/com/sekwah/advancedportals/core/effect/WarpEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
120 changes: 120 additions & 0 deletions
120
core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/java/com/sekwah/advancedportals/core/registry/CommandException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core/src/main/java/com/sekwah/advancedportals/core/registry/CommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core/src/main/java/com/sekwah/advancedportals/core/registry/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
core/src/main/java/com/sekwah/advancedportals/core/registry/RegisterBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.