Skip to content

Commit

Permalink
feat: add a warning for no name being included
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 29, 2023
1 parent 0753839 commit 19d6d8f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;

Expand All @@ -20,6 +21,9 @@ public class CreatePortalSubCommand implements SubCommand {
@Inject
PortalServices portalServices;

@Inject
InfoLogger infoLogger;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
Expand All @@ -30,7 +34,10 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
}
ArrayList<DataTag> portalTags = TagReader.getTagsFromArgs(args);

AdvancedPortal portal = portalServices.createPortal(args[1], player, portalTags);
// Find the tag with the "name" NAME
DataTag nameTag = portalTags.stream().findFirst().filter(tag -> tag.NAME.equals("name")).orElse(null);

AdvancedPortal portal = portalServices.createPortal(nameTag == null ? null : nameTag.VALUES[0], player, portalTags);
if(portal != null) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.create.complete"));
sender.sendMessage(Lang.translate("command.create.tags"));
Expand All @@ -49,7 +56,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.error"));
}
else {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.error.noname"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.notags"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.effect.WarpEffect;
import com.sekwah.advancedportals.core.util.InfoLogger;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -20,6 +21,9 @@ public class WarpEffectRegistry {
@Inject
private AdvancedPortalsCore portalsCore;

@Inject
private InfoLogger infoLogger;

/**
* Register a new warp effect.
*
Expand Down Expand Up @@ -61,15 +65,15 @@ public WarpEffect getEffect(String name, WarpEffect.Type type){
list = this.visualEffects;
break;
default:
this.portalsCore.getInfoLogger().logWarning(type.toString()
this.infoLogger.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:"
this.infoLogger.logWarning("No effect of type:"
+ type.toString() + " was registered with the name: " + name);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;

import javax.inject.Singleton;
import java.util.ArrayList;
Expand All @@ -13,6 +16,10 @@

@Singleton
public class PortalServices {

@Inject
InfoLogger infoLogger;

public void loadPortals() {

}
Expand All @@ -34,6 +41,11 @@ public boolean removePortal(String name, PlayerContainer player) {
}

public AdvancedPortal createPortal(String name, PlayerContainer player, ArrayList<DataTag> portalTags) {
if(name == null){
infoLogger.logWarning("Attempted to make a portal with no name");
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
return null;
}
return null;
}

Expand Down
1 change: 1 addition & 0 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ portal.error.selection.differentworlds=Both the selected points need to be in th
desti.info.noargs=&cNo tags were given

command.error.noname= No name has been given.
command.error.notags= No tags have been given. You need to include at least &ename:(name)&c.

desti.error.takenname=The name given for the portal is already taken.

Expand Down

0 comments on commit 19d6d8f

Please sign in to comment.