Added code to check if the material exists

This commit is contained in:
sekwah 2018-02-22 04:03:44 +00:00 committed by Sekwah
parent 538a0a15ae
commit bd0fc09faf
5 changed files with 28 additions and 13 deletions

View File

@ -14,6 +14,7 @@ import com.sekwah.advancedportals.core.util.Config;
import com.sekwah.advancedportals.core.util.DataStorage;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.ConnectorDataCollector;
import com.sekwah.advancedportals.coreconnector.command.CommandRegister;
public class AdvancedPortalsCore {
@ -23,6 +24,7 @@ public class AdvancedPortalsCore {
private final DataStorage dataStorage;
private final InfoLogger infoLogger;
private final int mcMinorVer;
private final ConnectorDataCollector dataCollector;
private WarpEffectRegistry warpEffectRegistry;
private TagRegistry<AdvancedPortal> portalTagRegistry;
@ -47,11 +49,13 @@ public class AdvancedPortalsCore {
* @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) {
public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger, CommandRegister commandRegister,
ConnectorDataCollector dataCollector, int[] mcVer) {
this.dataStorage = dataStorage;
this.infoLogger = infoLogger;
this.instance = this;
this.commandRegister = commandRegister;
this.dataCollector = dataCollector;
this.mcMinorVer = this.checkMcVer(mcVer);
this.onEnable();
@ -181,6 +185,10 @@ public class AdvancedPortalsCore {
return instance.infoLogger;
}
public static ConnectorDataCollector getDataCollector() {
return instance.dataCollector;
}
public static CoreListeners getCoreListeners() {
return instance.coreListeners;
}

View File

@ -157,7 +157,15 @@ public class PortalManager {
AdvancedPortal portal = new AdvancedPortal(maxLoc, minLoc);
for(DataTag portalTag : tags) {
if(portalTag.NAME.equalsIgnoreCase("triggerblock")) {
portal.setTriggerBlocks(portalTag.VALUE.split(","));
ArrayList<String> triggers = new ArrayList<>();
for(String trigger : portalTag.VALUE.split(",")) {
if(AdvancedPortalsCore.getDataCollector().materialExists(trigger)) {
triggers.add(trigger.toLowerCase());
}
}
if(triggers.size() != 0) {
portal.setTriggerBlocks(triggers.toArray(new String[0]));
}
}
else {
portal.setArg(portalTag);

View File

@ -50,11 +50,9 @@ public class CreateDestiSubCommand extends CreateSubCommand implements SubComman
}
protected String getTag(String arg) {
ArrayList<String> tags = AdvancedPortalsCore.getDestinationTagRegistry().getTags();
for(String tag : tags) {
if(arg.startsWith(tag + ":")) {
return tag;
}
int splitLoc = arg.indexOf(":");
if(splitLoc != -1) {
return arg.substring(0,splitLoc + 1);
}
return null;
}

View File

@ -26,6 +26,7 @@ public class CreatePortalSubCommand extends CreateSubCommand implements SubComma
}
ArrayList<DataTag> portalTags = this.getTagsFromArgs(args);
try {
System.out.println(Arrays.toString(portalTags.toArray()));
AdvancedPortal portal = AdvancedPortalsCore.getPortalManager().createPortal(args[1], player, portalTags);
if(portal != null) {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.create.complete"));
@ -46,11 +47,9 @@ public class CreatePortalSubCommand extends CreateSubCommand implements SubComma
}
protected String getTag(String arg) {
ArrayList<String> tags = AdvancedPortalsCore.getPortalTagRegistry().getTags();
for(String tag : tags) {
if(arg.startsWith(tag + ":")) {
return tag;
}
int splitLoc = arg.indexOf(":");
if(splitLoc != -1) {
return arg.substring(0,splitLoc + 1);
}
return null;
}

View File

@ -1,7 +1,9 @@
package com.sekwah.advancedportals.coreconnector;
/**
* Gets info from the specific implementation
*/
public class ConnectorDataCollector {
public boolean materialExists(String materialName) {
return false;
}