Skip to content

Commit

Permalink
feat: add default trigger block if unspecified
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Dec 20, 2023
1 parent a6de44b commit f40a52a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
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;
Expand All @@ -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) {
Expand Down Expand Up @@ -68,11 +73,16 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
}
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
*/
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;
Expand Down Expand Up @@ -96,6 +98,7 @@ public String getDetailedHelpText() {
@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()) {
Expand Down Expand Up @@ -131,7 +134,7 @@ public void registered() {
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);
}
}
Expand Down Expand Up @@ -171,14 +174,15 @@ private void debugVisuals(PlayerContainer player, BlockLocation pos1, BlockLocat
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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,4 @@ public boolean isTriggerBlock(String blockMaterial) {
}
return false;
}

/*public void setTriggerBlocks(String[] triggerBlocks) {
this.triggerBlocks = triggerBlocks;
}*/

/*public String[] getTriggerBlocks() {
return triggerBlocks;
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public interface ConfigRepository {

boolean getUseOnlySpecialAxe();

void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe);

String getTranslation();

String getSelectorMaterial();
Expand All @@ -18,5 +16,7 @@ public interface ConfigRepository {

int getMaxTriggerVisualisationSize();

String getDefaultTriggerBlock();


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ public <T> T getValue(String output) {
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;
}
Expand All @@ -52,6 +52,11 @@ public int getMaxTriggerVisualisationSize() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Config {

public int portalProtectionRaduis = 5;

public String defaultTriggerBlock = "PORTAL";
public String defaultTriggerBlock = "NETHER_PORTAL";

public boolean stopWaterFlow = true;

Expand Down

0 comments on commit f40a52a

Please sign in to comment.