mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-25 12:06:17 +01:00
Updated readme and some info
This commit is contained in:
parent
130ae81857
commit
a08b60c64f
@ -1,8 +1,10 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.api.managers.DestinationManager;
|
||||
import com.sekwah.advancedportals.core.api.managers.PortalManager;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.api.registry.WarpEffectRegistry;
|
||||
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
|
||||
@ -22,7 +24,8 @@ public class AdvancedPortalsCore {
|
||||
private final int mcMinorVer;
|
||||
|
||||
private WarpEffectRegistry warpEffectRegistry;
|
||||
private TagRegistry tagRegistry;
|
||||
private TagRegistry<AdvancedPortal> portalTagRegistry;
|
||||
private TagRegistry<Destination> destiTagRegistry;
|
||||
|
||||
private CoreListeners coreListeners;
|
||||
|
||||
@ -38,10 +41,9 @@ public class AdvancedPortalsCore {
|
||||
public static final String lastTranslationUpdate = "1.0.0";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataStorage
|
||||
* @param infoLogger
|
||||
* @param commandRegister
|
||||
* @param dataStorage - The implementation of data storage for the specific platform
|
||||
* @param infoLogger - The implementation of the logger for the specific platform
|
||||
* @param commandRegister - Handles the command registry, different on each platform
|
||||
* @param mcVer Minecraft version e.g. 1.12.2
|
||||
*/
|
||||
public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger, CommandRegister commandRegister, int[] mcVer) {
|
||||
@ -52,7 +54,6 @@ public class AdvancedPortalsCore {
|
||||
this.mcMinorVer = this.checkMcVer(mcVer);
|
||||
|
||||
this.onEnable();
|
||||
|
||||
}
|
||||
|
||||
private int checkMcVer(int[] mcVer) {
|
||||
@ -100,7 +101,8 @@ public class AdvancedPortalsCore {
|
||||
this.portalManager = new PortalManager(this);
|
||||
this.destiManager = new DestinationManager(this);
|
||||
this.warpEffectRegistry = new WarpEffectRegistry();
|
||||
this.tagRegistry = new TagRegistry();
|
||||
this.portalTagRegistry = new TagRegistry<>();
|
||||
this.destiTagRegistry = new TagRegistry<>();
|
||||
|
||||
this.dataStorage.copyDefaultFile("lang/en_GB.lang", false);
|
||||
|
||||
@ -187,7 +189,11 @@ public class AdvancedPortalsCore {
|
||||
return instance.destiManager;
|
||||
}
|
||||
|
||||
public static TagRegistry getTagRegistry() {
|
||||
return instance.tagRegistry;
|
||||
public static TagRegistry getPortalTagRegistry() {
|
||||
return instance.portalTagRegistry;
|
||||
}
|
||||
|
||||
public static TagRegistry getDestinationTagRegistry() {
|
||||
return instance.destiTagRegistry;
|
||||
}
|
||||
}
|
||||
|
@ -148,8 +148,8 @@ public class PortalManager {
|
||||
portal.setArg(portalTag);
|
||||
}
|
||||
for(DataTag portalTag : tags) {
|
||||
TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME);
|
||||
creation.portalCreated(portal, player, portalTag.VALUE);
|
||||
TagHandler.Creation<AdvancedPortal> creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME);
|
||||
creation.created(portal, player, portalTag.VALUE);
|
||||
}
|
||||
if(name == null || name.equals("")) {
|
||||
throw new PortalException("portal.error.noname");
|
||||
@ -167,14 +167,14 @@ public class PortalManager {
|
||||
}
|
||||
|
||||
public void removePlayerSelection(PlayerContainer player) throws PortalException {
|
||||
String portal = this.selectedPortal.get(player.getUUID());
|
||||
String portal = this.selectedPortal.get(player.getUUID().toString());
|
||||
if(portal != null) {
|
||||
try {
|
||||
this.removePortal(player, portal);
|
||||
}
|
||||
catch(PortalException e) {
|
||||
if(e.getMessage().equals("command.remove.noname")) {
|
||||
this.selectedPortal.remove(player.getUUID());
|
||||
this.selectedPortal.remove(player.getUUID().toString());
|
||||
throw new PortalException("command.remove.invalidselection");
|
||||
}
|
||||
else {
|
||||
@ -187,7 +187,7 @@ public class PortalManager {
|
||||
|
||||
/**
|
||||
* @param player null if a player didnt send it
|
||||
* @param portalName
|
||||
* @param portalName name of portal
|
||||
* @throws PortalException
|
||||
*/
|
||||
public void removePortal(PlayerContainer player, String portalName) throws PortalException {
|
||||
@ -197,8 +197,8 @@ public class PortalManager {
|
||||
}
|
||||
|
||||
for(DataTag portalTag : portal.getArgs()) {
|
||||
TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME);
|
||||
creation.portalCreated(portal, player, portalTag.VALUE);
|
||||
TagHandler.Creation<AdvancedPortal> creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME);
|
||||
creation.created(portal, player, portalTag.VALUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -64,20 +64,25 @@ public class AdvancedPortal {
|
||||
}
|
||||
|
||||
public boolean activatePortal(PlayerContainer player) {
|
||||
TagRegistry tagRegistry = AdvancedPortalsCore.getTagRegistry();
|
||||
TagRegistry tagRegistry = AdvancedPortalsCore.getPortalTagRegistry();
|
||||
ActivationData data = new ActivationData();
|
||||
DataTag[] portalTags = new DataTag[argsCol.size()];
|
||||
String[] argNames = argsCol.toArray(new String[argsCol.size()]);
|
||||
for (int i = 0; i < argNames.length; i++) {
|
||||
portalTags[i] = new DataTag(argNames[i], this.getArg(argNames[i]));
|
||||
}
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
|
||||
try {
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
|
||||
}
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
|
||||
}
|
||||
}
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
|
||||
catch(PortalException e) {
|
||||
// TODO add portal error message
|
||||
}
|
||||
for(DataTag portalTag : portalTags) {
|
||||
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.sekwah.advancedportals.core.api.portal;
|
||||
|
||||
/**
|
||||
* Returns a message saying what went wrong with the portal tag.
|
||||
* Returns a message saying what went wrong with the portal or the action was blocked for a reason.
|
||||
*/
|
||||
public class PortalException extends Exception {
|
||||
public PortalException(String reason) {
|
||||
|
@ -14,7 +14,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class TagRegistry {
|
||||
public class TagRegistry<T> {
|
||||
|
||||
/**
|
||||
* List of tag names which should be in order alphabetically
|
||||
@ -24,16 +24,16 @@ public class TagRegistry {
|
||||
* Description of tags for help commands
|
||||
*/
|
||||
private Map<String, String> tagDesc = new HashMap();
|
||||
private Map<String, TagHandler.Activation> activationHandlers = new HashMap();
|
||||
private Map<String, TagHandler.Creation> creationHandlers = new HashMap();
|
||||
private Map<String, TagHandler.TagStatus> statusHandlers = 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 getActivationHandler(String arg) {
|
||||
public TagHandler.Activation<T> getActivationHandler(String arg) {
|
||||
return this.activationHandlers.get(arg);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class TagRegistry {
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
public TagHandler.Creation getCreationHandler(String arg) {
|
||||
public TagHandler.Creation<T> getCreationHandler(String arg) {
|
||||
return this.creationHandlers.get(arg);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ public class TagRegistry {
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
public TagHandler.TagStatus getTagStatusHandler(String arg) {
|
||||
public TagHandler.TagStatus<T> getTagStatusHandler(String arg) {
|
||||
return this.statusHandlers.get(arg);
|
||||
}
|
||||
|
||||
@ -123,9 +123,10 @@ public class TagRegistry {
|
||||
}
|
||||
|
||||
/**
|
||||
* File must extend
|
||||
* @return if the tag has been registered or if it already exists.
|
||||
*/
|
||||
public boolean registerTag(String tag, TagHandler tagHandler) {
|
||||
public boolean registerTag(String tag, Object tagHandler) {
|
||||
|
||||
if (tag == null) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("A tag cannot be null.");
|
||||
@ -136,18 +137,14 @@ public class TagRegistry {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tagHandler != null && !(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) &&
|
||||
!(tagHandler instanceof TagHandler.Creation)) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("Error with tag: " + tag + ". A tag handler must implement one of the handlers. Not just extend.");
|
||||
if (tagHandler instanceof TagHandler.Activation) {
|
||||
this.activationHandlers.put(tag, (TagHandler.Activation) tagHandler);
|
||||
}
|
||||
if (tagHandler instanceof TagHandler.TagStatus) {
|
||||
this.statusHandlers.put(tag, (TagHandler.TagStatus) tagHandler);
|
||||
}
|
||||
if (tagHandler instanceof TagHandler.Creation) {
|
||||
this.creationHandlers.put(tag, (TagHandler.Creation) tagHandler);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -7,41 +7,61 @@ public class TagHandler {
|
||||
/**
|
||||
* The events for portal creation and destroying
|
||||
*/
|
||||
public interface Creation<T> {
|
||||
interface Creation<T> extends TagHandler {
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to use a tag on the portal.
|
||||
* Example if the player does not have access to use the tag.
|
||||
*
|
||||
* @param player if null the portal has been created by the server or a plugin
|
||||
* @param player if null then created by the server or a plugin
|
||||
* @param argData
|
||||
* @throws PortalException message given is the reason the portal cant be made
|
||||
* @throws PortalException message given is the reason the portal (or destination) cannot be made
|
||||
*/
|
||||
void portalCreated(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
void created(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to remove the portal.
|
||||
* Example if the player does not have access to remove the portal or destination.
|
||||
*
|
||||
* @param player if null the portal has been destroyed by the server or a plugin
|
||||
* @param player if null then removed by the server or a plugin
|
||||
* @param argData
|
||||
* @throws PortalException message given is the reason the portal cant be removed
|
||||
*/
|
||||
void portalDestroyed(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
void destroyed(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
|
||||
}
|
||||
|
||||
public interface Activation<T> {
|
||||
/**
|
||||
* 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 portal activation.
|
||||
* 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
|
||||
*/
|
||||
void preActivated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
void preActivated(T target, PlayerContainer player, ActivationData activeData, String argData) throws PortalException;
|
||||
|
||||
/**
|
||||
* Activates after portal activation
|
||||
* Activates after activation
|
||||
*
|
||||
* Any actions to do with player location should be done in activate
|
||||
*
|
||||
* @param player
|
||||
* @param activeData
|
||||
@ -50,17 +70,20 @@ public class TagHandler {
|
||||
void postActivated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
|
||||
/**
|
||||
* Activates if the portal is allowed from pre
|
||||
* 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.
|
||||
*
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
*/
|
||||
void activated(T target, PlayerContainer player, ActivationData activeData, String argData);
|
||||
void activated(T target, PlayerContainer player, ActivationData activeData, String argData) throws PortalException;
|
||||
|
||||
}
|
||||
|
||||
public interface TagStatus<T> {
|
||||
interface TagStatus<T> extends TagHandler {
|
||||
|
||||
/**
|
||||
* If the user has access to add the tag (this does not include being added on creation)
|
||||
@ -69,7 +92,7 @@ public class TagHandler {
|
||||
* @param argData
|
||||
* @return if the tag will be added.
|
||||
*/
|
||||
boolean tagAdded(T target, PlayerContainer player, String argData);
|
||||
boolean tagAdded(T target, PlayerContainer player, String argData) throws PortalException;
|
||||
|
||||
/**
|
||||
* If the user has access to remove the tag (this does not include being added on destruction)
|
||||
|
@ -63,7 +63,7 @@ public class CreateSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
private String getTag(String arg) {
|
||||
ArrayList<String> tags = AdvancedPortalsCore.getTagRegistry().getTags();
|
||||
ArrayList<String> tags = AdvancedPortalsCore.getPortalTagRegistry().getTags();
|
||||
for(String tag : tags) {
|
||||
if(arg.startsWith(tag + ":")) {
|
||||
return tag;
|
||||
|
Loading…
Reference in New Issue
Block a user