mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-02-27 01:31:21 +01:00
feat: add the ability for tags to reject values
This commit is contained in:
parent
6629151fc6
commit
3558629f8e
@ -138,7 +138,6 @@ public class AdvancedPortalsCore {
|
||||
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand("reload", new ReloadDestiSubCommand());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*sender.sendMessage("Debug");
|
||||
if(sender.getPlayerContainer() != null) {
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
public enum ErrorCode {
|
||||
public enum CommandErrorCode {
|
||||
INSUFFICIENT_ARGUMENTS(""),
|
||||
NO_PERMISSION("");
|
||||
;
|
||||
|
||||
|
||||
ErrorCode(String message) {
|
||||
CommandErrorCode(String message) {
|
||||
|
||||
}
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
public class CommandException {
|
||||
private ErrorCode errorCode;
|
||||
private CommandErrorCode errorCode;
|
||||
private String message;
|
||||
|
||||
public CommandException(ErrorCode errorCode, String message) {
|
||||
public CommandException(CommandErrorCode errorCode, String message) {
|
||||
this.errorCode = errorCode;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ErrorCode getErrorCode() {
|
||||
public CommandErrorCode getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
@ -53,7 +52,7 @@ public class TagRegistry {
|
||||
* @param arg
|
||||
* @return
|
||||
*/
|
||||
public Tag.TagStatus getTagStatusHandler(String arg) {
|
||||
public Tag.TagStatus getStatusHandler(String 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.repository.IDestinationRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@ -58,6 +59,11 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
|
||||
List<String> allFiles = dataStorage.listAllFiles(fileLocation, false);
|
||||
for (String fileName : allFiles) {
|
||||
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);
|
||||
}
|
||||
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.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.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
||||
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 java.util.ArrayList;
|
||||
@ -22,23 +23,12 @@ public class DestinationServices {
|
||||
@Inject
|
||||
private IDestinationRepository destinationRepository;
|
||||
|
||||
|
||||
@Inject
|
||||
TagRegistry tagRegistry;
|
||||
|
||||
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() {
|
||||
return destinationRepository.getAllNames();
|
||||
}
|
||||
@ -49,6 +39,7 @@ public class DestinationServices {
|
||||
|
||||
public void loadDestinations() {
|
||||
List<String> destinationNames = destinationRepository.getAllNames();
|
||||
destinationCache.clear();
|
||||
for (String name : destinationNames) {
|
||||
Destination destination = destinationRepository.get(name);
|
||||
destinationCache.put(name, destination);
|
||||
@ -80,17 +71,17 @@ public class DestinationServices {
|
||||
desti.setArgValues(portalTag);
|
||||
}
|
||||
for (DataTag destiTag : tags) {
|
||||
// TODO sort tag handle registry
|
||||
/*TagHandler.Creation<Destination> creation = AdvancedPortalsCore.getDestinationTagRegistry().getCreationHandler(destiTag.NAME);
|
||||
Tag.Creation creation = tagRegistry.getCreationHandler(destiTag.NAME);
|
||||
if(creation != null) {
|
||||
creation.created(desti, player, destiTag.VALUE);
|
||||
}*/
|
||||
if(!creation.created(desti, player, destiTag.VALUES)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if(this.destinationRepository.save(name, desti)) {
|
||||
this.destinationCache.put(name, desti);
|
||||
} else {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save"));
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -3,6 +3,7 @@ package com.sekwah.advancedportals.core.services;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.Inject;
|
||||
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.IPortalRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
@ -15,6 +16,7 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
@ -29,6 +31,8 @@ public class PortalServices {
|
||||
@Inject
|
||||
private PortalTempDataServices portalTempDataServices;
|
||||
|
||||
private final Map<String, AdvancedPortal> portalCache = new HashMap<>();
|
||||
|
||||
public void loadPortals() {
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||
|
||||
public class DestiTag implements Tag.Activation, Tag.AutoComplete {
|
||||
|
||||
public static String TAG_NAME = "name";
|
||||
@Inject
|
||||
DestinationServices destinationServices;
|
||||
|
||||
@ -23,7 +24,7 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "destination";
|
||||
return TAG_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,9 @@ import java.util.List;
|
||||
* <p>
|
||||
* 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 };
|
||||
|
||||
@ -26,7 +28,7 @@ public class NameTag implements Tag.AutoComplete {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "name";
|
||||
return TAG_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,4 +45,21 @@ public class NameTag implements Tag.AutoComplete {
|
||||
public List<String> autoComplete(String argData) {
|
||||
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 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.
|
||||
|
@ -145,3 +145,4 @@ items.interact.left=Left Click
|
||||
items.interact.right=Right Click
|
||||
|
||||
tag.desti.description=Sets the destination of the portal
|
||||
tag.name.error.nospaces= The name cannot contain spaces.
|
||||
|
Loading…
Reference in New Issue
Block a user