mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
feat: added tag priority sorting and delay tag
This commit is contained in:
parent
7635a13421
commit
0044008105
@ -129,6 +129,7 @@ public class AdvancedPortalsCore {
|
||||
this.tagRegistry.registerTag(new TriggerBlockTag());
|
||||
this.tagRegistry.registerTag(new PermissionTag());
|
||||
this.tagRegistry.registerTag(new CommandTag());
|
||||
this.tagRegistry.registerTag(new PortalEventTag());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,7 +217,7 @@ public class CoreListeners {
|
||||
return false;
|
||||
}
|
||||
|
||||
var portalResult = this.portalServices.checkPortalActivation(player, toLoc, TriggerType.MOVEMENT);
|
||||
var portalResult = this.portalServices.checkPortalActivation(player, toLoc, TriggerType.PORTAL);
|
||||
|
||||
if(portalResult != PortalServices.PortalActivationResult.NOT_IN_PORTAL) {
|
||||
return false;
|
||||
|
@ -30,6 +30,10 @@ public class AdvancedPortal implements TagTarget {
|
||||
|
||||
private final HashMap<String, String[]> args = new HashMap<>();
|
||||
|
||||
private transient List<DataTag> portalTags = new ArrayList<>();
|
||||
|
||||
private transient boolean isSorted = false;
|
||||
|
||||
@Inject
|
||||
private transient PlayerDataServices playerDataServices;
|
||||
|
||||
@ -64,6 +68,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
|
||||
@Override
|
||||
public void setArgValues(String argName, String[] argValues) {
|
||||
this.isSorted = false;
|
||||
this.args.put(argName, argValues);
|
||||
}
|
||||
|
||||
@ -72,8 +77,26 @@ public class AdvancedPortal implements TagTarget {
|
||||
// TODO need to add the ability to add args after creation
|
||||
}
|
||||
|
||||
private void updatePortalTagList() {
|
||||
portalTags.clear();
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String[]> entry : args.entrySet()) {
|
||||
this.portalTags.add(new DataTag(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
// sort the tags by priority
|
||||
this.portalTags.sort(Comparator.comparingInt(o -> {
|
||||
var tag = tagRegistry.getTag(o.NAME);
|
||||
if (tag instanceof Tag.OrderPriority tagPriority) {
|
||||
return tagPriority.getPriority().ordinal();
|
||||
} else {
|
||||
return Tag.Priority.NORMAL.ordinal();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeArg(String arg) {
|
||||
this.isSorted = false;
|
||||
this.args.remove(arg);
|
||||
}
|
||||
|
||||
@ -113,6 +136,11 @@ public class AdvancedPortal implements TagTarget {
|
||||
* @return Whether the portal was successfully activated
|
||||
*/
|
||||
public ActivationResult activate(PlayerContainer player, TriggerType triggerType) {
|
||||
if(!isSorted) {
|
||||
updatePortalTagList();
|
||||
isSorted = true;
|
||||
}
|
||||
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
|
||||
if (playerData.hasJoinCooldown()) {
|
||||
@ -131,22 +159,23 @@ public class AdvancedPortal implements TagTarget {
|
||||
}
|
||||
|
||||
ActivationData data = new ActivationData(triggerType);
|
||||
DataTag[] portalTags = new DataTag[args.size()];
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String[]> entry : args.entrySet()) {
|
||||
portalTags[i++] = new DataTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
for (DataTag portalTag : portalTags) {
|
||||
for (DataTag portalTag : this.portalTags) {
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if (activationHandler != null
|
||||
&& !activationHandler.preActivated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME))) {
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
if (activationHandler != null) {
|
||||
var preActivated = activationHandler.preActivated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME));
|
||||
|
||||
if(!preActivated) {
|
||||
if(activationHandler instanceof Tag.DenyBehavior denyBehavior && denyBehavior.getDenyBehavior() == Tag.DenyBehavior.Behaviour.SILENT) {
|
||||
return ActivationResult.FAILED_DO_NOTHING;
|
||||
}
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (DataTag portalTag : portalTags) {
|
||||
for (DataTag portalTag : this.portalTags) {
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if (activationHandler != null
|
||||
@ -155,7 +184,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
}
|
||||
}
|
||||
for (DataTag portalTag : portalTags) {
|
||||
for (DataTag portalTag : this.portalTags) {
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if (activationHandler != null) {
|
||||
|
@ -103,9 +103,16 @@ public class TagRegistry {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
// TODO Make a copy of the list to prevent issues with modification
|
||||
public Tag getTag(String tagName) {
|
||||
for (Tag tag : this.tags) {
|
||||
if (tag.getName().equals(tagName)) {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.tags;
|
||||
public List<Tag> getTags() {
|
||||
return new ArrayList<>(this.tags);
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,14 @@ import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import com.sekwah.advancedportals.core.warphandler.TriggerType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PortalEventTag implements Tag.Activation {
|
||||
public class PortalEventTag implements Tag.Activation, Tag.AutoComplete, Tag.DenyBehavior, Tag.OrderPriority {
|
||||
@Inject
|
||||
PlayerDataServices playerDataServices;
|
||||
|
||||
@ -40,7 +44,7 @@ public class PortalEventTag implements Tag.Activation {
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[0];
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,16 +55,13 @@ public class PortalEventTag implements Tag.Activation {
|
||||
@Override
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activeData, String[] argData) {
|
||||
if (!player.hasPermission(argData[1])) {
|
||||
player.sendMessage(Lang.translate("portal.error.nopermission"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !Objects.equals(argData[0], "true") || activeData.getTriggerType() == TriggerType.PORTAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,4 +69,26 @@ public class PortalEventTag implements Tag.Activation {
|
||||
ActivationData activationData, String[] argData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> autoComplete(String argData) {
|
||||
return List.of("true", "false");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String splitString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Behaviour getDenyBehavior() {
|
||||
return Behaviour.SILENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Priority getPriority() {
|
||||
return Priority.HIGHEST;
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ public interface Tag {
|
||||
*/
|
||||
enum TagType { PORTAL, DESTINATION }
|
||||
|
||||
enum Priority { LOWEST, LOW, NORMAL, HIGH, HIGHEST }
|
||||
|
||||
/**
|
||||
* Used to flag where the auto complete should show more or less info.
|
||||
*
|
||||
@ -43,6 +45,16 @@ public interface Tag {
|
||||
|
||||
String description();
|
||||
|
||||
interface OrderPriority {
|
||||
Priority getPriority();
|
||||
}
|
||||
|
||||
interface DenyBehavior {
|
||||
enum Behaviour { SILENT, KNOCKBACK }
|
||||
|
||||
Behaviour getDenyBehavior();
|
||||
}
|
||||
|
||||
interface AutoComplete extends Tag {
|
||||
/**
|
||||
* This is used to get the auto complete for the tag. This is called
|
||||
|
Loading…
Reference in New Issue
Block a user