feat: add default trigger block if unspecified

This commit is contained in:
Sekwah 2023-12-20 05:58:20 +00:00
parent 29b2e2734b
commit c90597228a
6 changed files with 33 additions and 22 deletions

View File

@ -5,11 +5,13 @@ import com.sekwah.advancedportals.core.commands.subcommands.common.CreateTaggedS
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
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.tags.activation.NameTag;
import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
@ -30,6 +32,9 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
@Inject
InfoLogger infoLogger;
@Inject
ConfigRepository config;
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
@ -68,11 +73,16 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
}
sender.sendMessage("");
var triggerBlockTag = portalTags.stream().filter(tag -> tag.NAME.equals(TriggerBlockTag.TAG_NAME)).findFirst().orElse(null);
if(triggerBlockTag == null) {
portalTags.add(new DataTag(TriggerBlockTag.TAG_NAME, config.getDefaultTriggerBlock()));
}
AdvancedPortal portal = portalServices.createPortal(player, portalTags);
if(portal != null) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.create.complete"));
sender.sendMessage(Lang.translate("command.create.tags"));
//sender.sendMessage("\u00A7a" + " triggerBlock\u00A77:\u00A7e" + Arrays.toString(portal.getTriggerBlocks()));
this.printTags(sender, portal.getArgs());
} else {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.error"));

View File

@ -26,7 +26,9 @@ import java.util.function.Consumer;
*/
public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOnInit {
static final int SHOW_TICKS = 1300;
static final int SHOW_TICKS = 1010;
boolean alternate_show_trigger = true;
@Inject
PortalTempDataServices tempDataServices;
@ -96,6 +98,7 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
@Override
public void registered() {
gameScheduler.intervalTickEvent("show_portal", () -> {
alternate_show_trigger = !alternate_show_trigger;
for(PlayerContainer player : serverContainer.getPlayers()) {
var tempData = tempDataServices.getPlayerTempData(player);
if(!tempData.isPortalVisible()) {
@ -131,7 +134,7 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
else
color = new Color(0, 0, 0, 0);
}
debugVisuals(player, portal, OUTLINE_COLOR, 1000, TRIGGER_COLOR);
debugVisuals(player, portal, OUTLINE_COLOR, SHOW_TICKS, TRIGGER_COLOR);
Debug.addMarker(player, midPoint, portal.getArgValues(NameTag.TAG_NAME)[0], color, SHOW_TICKS);
}
}
@ -171,14 +174,15 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
for (int z = minZ; z <= maxZ; z++) {
var pos = new BlockLocation(pos1.worldName, x, y, z);
boolean isTrigger = portal != null && portal.isTriggerBlock(world.getBlock(pos));
System.out.println(world.getBlock(pos));
boolean isOutline = (y == minY || y == maxY) && (x == minX || x == maxX || z == minZ || z == maxZ) || (z == minZ || z == maxZ) && (x == minX || x == maxX);
if (isTrigger && isOutline) {
if (isTrigger && isOutline && alternate_show_trigger) {
Debug.addMarker(player, pos, "", TRIGGER_OUTLINE_COLOR, time);
}
else if(isTrigger) {
Debug.addMarker(player, pos, "", triggerColor, time);
} else if (isOutline) {
Debug.addMarker(player, pos, "", color, time);
} else if(isTrigger) {
if(alternate_show_trigger)
Debug.addMarker(player, pos, "", triggerColor, time);
}
}
}

View File

@ -163,12 +163,4 @@ public class AdvancedPortal implements TagTarget {
}
return false;
}
/*public void setTriggerBlocks(String[] triggerBlocks) {
this.triggerBlocks = triggerBlocks;
}*/
/*public String[] getTriggerBlocks() {
return triggerBlocks;
}*/
}

View File

@ -6,8 +6,6 @@ public interface ConfigRepository {
boolean getUseOnlySpecialAxe();
void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe);
String getTranslation();
String getSelectorMaterial();
@ -18,5 +16,7 @@ public interface ConfigRepository {
int getMaxTriggerVisualisationSize();
String getDefaultTriggerBlock();
}

View File

@ -27,22 +27,22 @@ public class ConfigRepositoryImpl implements ConfigRepository {
return null;
}
@Override
public boolean getUseOnlySpecialAxe() {
return this.config.useOnlySpecialAxe;
}
public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) {
this.config.useOnlySpecialAxe = useOnlyServerMadeAxe;
}
@Override
public String getTranslation() {
return this.config.translationFile;
}
@Override
public String getSelectorMaterial() {
return this.config.selectorMaterial;
}
@Override
public int getVisibleRange() {
return this.config.visibleRange;
}
@ -52,6 +52,11 @@ public class ConfigRepositoryImpl implements ConfigRepository {
return this.config.maxTriggerVisualisationSize;
}
@Override
public String getDefaultTriggerBlock() {
return this.config.defaultTriggerBlock;
}
@Override
public void loadConfig(DataStorage dataStorage) {
this.config = dataStorage.loadJson(Config.class, "config.json");

View File

@ -13,7 +13,7 @@ public class Config {
public int portalProtectionRaduis = 5;
public String defaultTriggerBlock = "PORTAL";
public String defaultTriggerBlock = "NETHER_PORTAL";
public boolean stopWaterFlow = true;