feat: add the ability for tags to reject values
This commit is contained in:
parent
d51b6dbcdb
commit
b84f3a9921
|
@ -138,7 +138,6 @@ public class AdvancedPortalsCore {
|
||||||
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
|
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
|
||||||
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
|
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
|
||||||
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());
|
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());
|
||||||
this.destiCommand.registerSubCommand("reload", new ReloadDestiSubCommand());
|
|
||||||
|
|
||||||
commandRegister.registerCommand("destination", this.destiCommand);
|
commandRegister.registerCommand("destination", this.destiCommand);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
package com.sekwah.advancedportals.core.commands.subcommands.desti;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
|
||||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
|
||||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
|
||||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
|
||||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
|
||||||
import com.sekwah.advancedportals.core.services.PortalTempDataServices;
|
|
||||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
|
||||||
import com.sekwah.advancedportals.core.util.Lang;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will be different from the old show command and I believe it is 1.16+ till the latest version as of writing this.
|
|
||||||
*/
|
|
||||||
public class ReloadDestiSubCommand implements SubCommand {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
DestinationServices destinationServices;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
|
||||||
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.reload"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(CommandSenderContainer sender) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBasicHelpText() {
|
|
||||||
return Lang.translate("command.destination.reload.help");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDetailedHelpText() {
|
|
||||||
return Lang.translate("command.destination.reload.detailedhelp");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -74,7 +74,7 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*sender.sendMessage("Debug");
|
/*sender.sendMessage("Debug");
|
||||||
if(sender.getPlayerContainer() != null) {
|
if(sender.getPlayerContainer() != null) {
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package com.sekwah.advancedportals.core.registry;
|
package com.sekwah.advancedportals.core.registry;
|
||||||
|
|
||||||
public enum ErrorCode {
|
public enum CommandErrorCode {
|
||||||
INSUFFICIENT_ARGUMENTS(""),
|
INSUFFICIENT_ARGUMENTS(""),
|
||||||
NO_PERMISSION("");
|
NO_PERMISSION("");
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
ErrorCode(String message) {
|
CommandErrorCode(String message) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,15 @@
|
||||||
package com.sekwah.advancedportals.core.registry;
|
package com.sekwah.advancedportals.core.registry;
|
||||||
|
|
||||||
public class CommandException {
|
public class CommandException {
|
||||||
private ErrorCode errorCode;
|
private CommandErrorCode errorCode;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public CommandException(ErrorCode errorCode, String message) {
|
public CommandException(CommandErrorCode errorCode, String message) {
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorCode getErrorCode() {
|
public CommandErrorCode getErrorCode() {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.sekwah.advancedportals.core.registry;
|
package com.sekwah.advancedportals.core.registry;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
|
||||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ public class TagRegistry {
|
||||||
* @param arg
|
* @param arg
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Tag.TagStatus getTagStatusHandler(String arg) {
|
public Tag.TagStatus getStatusHandler(String arg) {
|
||||||
return this.statusTags.get(arg);
|
return this.statusTags.get(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.google.inject.Inject;
|
||||||
import com.sekwah.advancedportals.core.destination.Destination;
|
import com.sekwah.advancedportals.core.destination.Destination;
|
||||||
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||||
|
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -58,6 +59,11 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
|
||||||
List<String> allFiles = dataStorage.listAllFiles(fileLocation, false);
|
List<String> allFiles = dataStorage.listAllFiles(fileLocation, false);
|
||||||
for (String fileName : allFiles) {
|
for (String fileName : allFiles) {
|
||||||
Destination destination = dataStorage.loadJson(Destination.class, fileLocation + fileName);
|
Destination destination = dataStorage.loadJson(Destination.class, fileLocation + fileName);
|
||||||
|
// Forces the name tag to be up-to-date on load
|
||||||
|
String[] name = destination.getArgValues(NameTag.TAG_NAME);
|
||||||
|
if(name != null && name.length > 0) {
|
||||||
|
destination.setArgValues(NameTag.TAG_NAME, new String[]{fileName.replace(".json", "")});
|
||||||
|
}
|
||||||
destinations.add(destination);
|
destinations.add(destination);
|
||||||
}
|
}
|
||||||
return destinations;
|
return destinations;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.sekwah.advancedportals.core.services;
|
||||||
|
|
||||||
|
public enum Creation {
|
||||||
|
SUCCESS,
|
||||||
|
NAME_IN_USE,
|
||||||
|
TAG_REJECTED
|
||||||
|
}
|
|
@ -3,12 +3,13 @@ package com.sekwah.advancedportals.core.services;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
|
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||||
import com.sekwah.advancedportals.core.destination.Destination;
|
import com.sekwah.advancedportals.core.destination.Destination;
|
||||||
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
||||||
import com.sekwah.advancedportals.core.util.Lang;
|
import com.sekwah.advancedportals.core.util.Lang;
|
||||||
import com.sekwah.advancedportals.core.util.Response;
|
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -22,23 +23,12 @@ public class DestinationServices {
|
||||||
@Inject
|
@Inject
|
||||||
private IDestinationRepository destinationRepository;
|
private IDestinationRepository destinationRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
TagRegistry tagRegistry;
|
||||||
|
|
||||||
private final Map<String, Destination> destinationCache = new HashMap<>();
|
private final Map<String, Destination> destinationCache = new HashMap<>();
|
||||||
|
|
||||||
public Response.Creation create(String name, Destination destination) {
|
|
||||||
if (!destinationRepository.containsKey(name)) {
|
|
||||||
destinationRepository.save(name, destination);
|
|
||||||
return Response.Creation.SUCCESS;
|
|
||||||
}
|
|
||||||
return Response.Creation.NAME_IN_USE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean delete(String name) {
|
|
||||||
if (!destinationRepository.containsKey(name)) {
|
|
||||||
destinationRepository.delete(name);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getDestinationNames() {
|
public List<String> getDestinationNames() {
|
||||||
return destinationRepository.getAllNames();
|
return destinationRepository.getAllNames();
|
||||||
}
|
}
|
||||||
|
@ -49,6 +39,7 @@ public class DestinationServices {
|
||||||
|
|
||||||
public void loadDestinations() {
|
public void loadDestinations() {
|
||||||
List<String> destinationNames = destinationRepository.getAllNames();
|
List<String> destinationNames = destinationRepository.getAllNames();
|
||||||
|
destinationCache.clear();
|
||||||
for (String name : destinationNames) {
|
for (String name : destinationNames) {
|
||||||
Destination destination = destinationRepository.get(name);
|
Destination destination = destinationRepository.get(name);
|
||||||
destinationCache.put(name, destination);
|
destinationCache.put(name, destination);
|
||||||
|
@ -80,17 +71,17 @@ public class DestinationServices {
|
||||||
desti.setArgValues(portalTag);
|
desti.setArgValues(portalTag);
|
||||||
}
|
}
|
||||||
for (DataTag destiTag : tags) {
|
for (DataTag destiTag : tags) {
|
||||||
// TODO sort tag handle registry
|
Tag.Creation creation = tagRegistry.getCreationHandler(destiTag.NAME);
|
||||||
/*TagHandler.Creation<Destination> creation = AdvancedPortalsCore.getDestinationTagRegistry().getCreationHandler(destiTag.NAME);
|
|
||||||
if(creation != null) {
|
if(creation != null) {
|
||||||
creation.created(desti, player, destiTag.VALUE);
|
if(!creation.created(desti, player, destiTag.VALUES)) {
|
||||||
}*/
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(this.destinationRepository.save(name, desti)) {
|
if(this.destinationRepository.save(name, desti)) {
|
||||||
this.destinationCache.put(name, desti);
|
this.destinationCache.put(name, desti);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save"));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.sekwah.advancedportals.core.services;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
|
import com.sekwah.advancedportals.core.destination.Destination;
|
||||||
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
||||||
import com.sekwah.advancedportals.core.repository.IPortalRepository;
|
import com.sekwah.advancedportals.core.repository.IPortalRepository;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||||
|
@ -15,6 +16,7 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -29,6 +31,8 @@ public class PortalServices {
|
||||||
@Inject
|
@Inject
|
||||||
private PortalTempDataServices portalTempDataServices;
|
private PortalTempDataServices portalTempDataServices;
|
||||||
|
|
||||||
|
private final Map<String, AdvancedPortal> portalCache = new HashMap<>();
|
||||||
|
|
||||||
public void loadPortals() {
|
public void loadPortals() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class DestiTag implements Tag.Activation, Tag.AutoComplete {
|
public class DestiTag implements Tag.Activation, Tag.AutoComplete {
|
||||||
|
|
||||||
|
public static String TAG_NAME = "name";
|
||||||
@Inject
|
@Inject
|
||||||
DestinationServices destinationServices;
|
DestinationServices destinationServices;
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "destination";
|
return TAG_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,7 +15,9 @@ import java.util.List;
|
||||||
* <p>
|
* <p>
|
||||||
* Most tags shouldn't be like this unless they are to be paired with another tag.
|
* Most tags shouldn't be like this unless they are to be paired with another tag.
|
||||||
*/
|
*/
|
||||||
public class NameTag implements Tag.AutoComplete {
|
public class NameTag implements Tag.AutoComplete, Tag.Creation {
|
||||||
|
|
||||||
|
public static String TAG_NAME = "name";
|
||||||
|
|
||||||
private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL, TagType.DESTINATION };
|
private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL, TagType.DESTINATION };
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ public class NameTag implements Tag.AutoComplete {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "name";
|
return TAG_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,4 +45,21 @@ public class NameTag implements Tag.AutoComplete {
|
||||||
public List<String> autoComplete(String argData) {
|
public List<String> autoComplete(String argData) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean created(TagTarget target, PlayerContainer player, String[] argData) {
|
||||||
|
if (argData.length > 0) {
|
||||||
|
String name = argData[0];
|
||||||
|
if (name.contains(" ")) {
|
||||||
|
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("tag.name.error.nospaces"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyed(TagTarget target, PlayerContainer player, String[] argData) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package com.sekwah.advancedportals.core.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Need to make more of the plugin use this rather than just returning true or false.
|
|
||||||
*/
|
|
||||||
public class Response {
|
|
||||||
|
|
||||||
public enum Creation {
|
|
||||||
SUCCESS,
|
|
||||||
NAME_IN_USE,
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -67,8 +67,9 @@ public interface Tag {
|
||||||
*
|
*
|
||||||
* @param player if null then created by the server or a plugin
|
* @param player if null then created by the server or a plugin
|
||||||
* @param argData
|
* @param argData
|
||||||
|
* @return If the tag is valid or allowed creation
|
||||||
*/
|
*/
|
||||||
void created(TagTarget target, PlayerContainer player, String[] argData);
|
boolean created(TagTarget target, PlayerContainer player, String[] argData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example if the player does not have access to remove the portal or destination.
|
* Example if the player does not have access to remove the portal or destination.
|
||||||
|
|
|
@ -142,3 +142,4 @@ items.interact.left=Left Click
|
||||||
items.interact.right=Right Click
|
items.interact.right=Right Click
|
||||||
|
|
||||||
tag.desti.description=Sets the destination of the portal
|
tag.desti.description=Sets the destination of the portal
|
||||||
|
tag.name.error.nospaces= The name cannot contain spaces.
|
||||||
|
|
Loading…
Reference in New Issue