mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
feat: enhance the in portal mitigation
This commit is contained in:
parent
6a098e70cf
commit
ffddd87922
@ -16,7 +16,7 @@ import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.tags.activation.*;
|
||||
import com.sekwah.advancedportals.core.tags.*;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -14,6 +14,8 @@ import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.TriggerType;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CoreListeners {
|
||||
@ -31,7 +33,18 @@ public class CoreListeners {
|
||||
|
||||
public void playerJoin(PlayerContainer player) {
|
||||
this.playerDataServices.setJoinCooldown(player);
|
||||
this.playerDataServices.getPlayerData(player).setInPortal(true);
|
||||
|
||||
this.setIfInPortal(player);
|
||||
}
|
||||
|
||||
private void setIfInPortal(PlayerContainer player) {
|
||||
String inPortal = this.portalServices.inPortalRegionGetName(player.getBlockLoc());
|
||||
|
||||
if (inPortal == null) {
|
||||
inPortal = this.portalServices.inPortalRegionGetName(player.getBlockLoc().addY((int) player.getHeight()));
|
||||
}
|
||||
|
||||
this.playerDataServices.getPlayerData(player).setInPortal(inPortal);
|
||||
}
|
||||
|
||||
public void teleportEvent(PlayerContainer player) {
|
||||
@ -51,7 +64,7 @@ public class CoreListeners {
|
||||
* @param toLoc
|
||||
*/
|
||||
public void playerMove(PlayerContainer player, PlayerLocation toLoc) {
|
||||
this.portalServices.playerMove(player, toLoc);
|
||||
this.portalServices.checkPortalActivation(player, toLoc, TriggerType.MOVEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,7 +190,7 @@ public class CoreListeners {
|
||||
|
||||
public void worldChange(PlayerContainer player) {
|
||||
this.playerDataServices.setJoinCooldown(player);
|
||||
this.playerDataServices.getPlayerData(player).setInPortal(true);
|
||||
this.setIfInPortal(player);
|
||||
}
|
||||
|
||||
public boolean preventEntityCombust(EntityContainer entity) {
|
||||
@ -188,13 +201,35 @@ public class CoreListeners {
|
||||
var pos = entity.getBlockLoc();
|
||||
if (entity instanceof PlayerContainer player) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if (playerData.isNetherPortalCooldown()) {
|
||||
if (playerData.getPortalBlockCooldown()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !(portalServices.inPortalRegion(pos, 1) || portalServices.inPortalRegion(pos.addY((int) entity.getHeight()), 1));
|
||||
}
|
||||
|
||||
public boolean playerPortalEvent(PlayerContainer player, PlayerLocation toLoc) {
|
||||
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
|
||||
if (playerData.getPortalBlockCooldown()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var portalResult = this.portalServices.checkPortalActivation(player, toLoc, TriggerType.MOVEMENT);
|
||||
|
||||
if(portalResult != PortalServices.PortalActivationResult.NOT_IN_PORTAL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Extra checks to prevent the player from being teleported by touching a portal but not having their body fully in the portal
|
||||
var pos = player.getBlockLoc();
|
||||
|
||||
var feetInPortal = portalServices.inPortalRegion(pos, 1);
|
||||
var headInPortal = portalServices.inPortalRegion(
|
||||
pos.addY((int) entity.getHeight()), 1);
|
||||
pos.addY((int) player.getHeight()), 1);
|
||||
|
||||
return !(feetInPortal || headInPortal);
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,8 @@ 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.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag;
|
||||
import com.sekwah.advancedportals.core.tags.NameTag;
|
||||
import com.sekwah.advancedportals.core.tags.TriggerBlockTag;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.TagReader;
|
||||
|
@ -11,7 +11,7 @@ import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.tags.NameTag;
|
||||
import com.sekwah.advancedportals.core.util.Debug;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.sekwah.advancedportals.core.connector.containers;
|
||||
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.tags.activation.CommandTag;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.connector.containers;
|
||||
|
||||
import com.sekwah.advancedportals.core.tags.activation.CommandTag;
|
||||
import com.sekwah.advancedportals.core.tags.CommandTag;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -8,6 +8,8 @@ import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import com.sekwah.advancedportals.core.warphandler.TriggerType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -65,7 +67,7 @@ public class Destination implements TagTarget {
|
||||
}
|
||||
|
||||
public boolean activate(PlayerContainer player) {
|
||||
ActivationData data = new ActivationData(false);
|
||||
ActivationData data = new ActivationData(TriggerType.MANUAL);
|
||||
this.portalActivate(player, data);
|
||||
this.postActivate(player, data);
|
||||
return true;
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.sekwah.advancedportals.core.portal;
|
||||
|
||||
public enum ActivationResult {
|
||||
SUCCESS,
|
||||
FAILED_DO_KNOCKBACK,
|
||||
FAILED_DO_NOTHING
|
||||
|
||||
}
|
@ -9,10 +9,12 @@ import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag;
|
||||
import com.sekwah.advancedportals.core.tags.TriggerBlockTag;
|
||||
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 java.util.*;
|
||||
|
||||
/**
|
||||
@ -107,14 +109,12 @@ public class AdvancedPortal implements TagTarget {
|
||||
* @param player The player on the server attempting to use an
|
||||
* advanced
|
||||
* portal
|
||||
* @param moveActivated if the portal was activated by a move event (won't
|
||||
* trigger knockback)
|
||||
* @return
|
||||
* @param triggerType The type of trigger that activated the portal
|
||||
* @return Whether the portal was successfully activated
|
||||
*/
|
||||
public boolean activate(PlayerContainer player, boolean moveActivated) {
|
||||
public ActivationResult activate(PlayerContainer player, TriggerType triggerType) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if (playerData.isInPortal())
|
||||
return false;
|
||||
|
||||
if (playerData.hasJoinCooldown()) {
|
||||
var cooldown =
|
||||
(int) Math.ceil(playerData.getJoinCooldownLeft() / 1000D);
|
||||
@ -127,10 +127,10 @@ public class AdvancedPortal implements TagTarget {
|
||||
player.playSound("block.portal.travel", 0.05f,
|
||||
rand.nextFloat() * 0.4F + 0.8F);
|
||||
}
|
||||
return false;
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
}
|
||||
|
||||
ActivationData data = new ActivationData(moveActivated);
|
||||
ActivationData data = new ActivationData(triggerType);
|
||||
DataTag[] portalTags = new DataTag[args.size()];
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String[]> entry : args.entrySet()) {
|
||||
@ -143,7 +143,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
if (activationHandler != null
|
||||
&& !activationHandler.preActivated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME))) {
|
||||
return false;
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
}
|
||||
}
|
||||
for (DataTag portalTag : portalTags) {
|
||||
@ -152,7 +152,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
if (activationHandler != null
|
||||
&& !activationHandler.activated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME))) {
|
||||
return false;
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
}
|
||||
}
|
||||
for (DataTag portalTag : portalTags) {
|
||||
@ -164,11 +164,11 @@ public class AdvancedPortal implements TagTarget {
|
||||
}
|
||||
}
|
||||
if (data.hasActivated()) {
|
||||
playerData.setNetherPortalCooldown(1000);
|
||||
playerData.setInPortal(true);
|
||||
return true;
|
||||
playerData.setPortalBlockCooldown(1000);
|
||||
playerData.setInPortal(this.getName());
|
||||
return ActivationResult.SUCCESS;
|
||||
}
|
||||
return false;
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
}
|
||||
|
||||
public boolean isLocationInPortal(BlockLocation loc) {
|
||||
|
@ -4,7 +4,7 @@ import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.tags.NameTag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -6,7 +6,7 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.repository.IPortalRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.tags.NameTag;
|
||||
import java.util.*;
|
||||
|
||||
@Singleton
|
||||
|
@ -36,14 +36,14 @@ public class PlayerData {
|
||||
/**
|
||||
* If the player is in a portal. Stops re-triggering.
|
||||
*/
|
||||
private transient boolean isInPortal = false;
|
||||
private transient String inPortal = null;
|
||||
|
||||
/**
|
||||
* The next time System.currentTimeMillis() a player can use a portal.
|
||||
*/
|
||||
private transient long joinCooldown;
|
||||
|
||||
private transient long netherPortalCooldown;
|
||||
private transient long portalBlockCooldown;
|
||||
|
||||
private HashMap<String, Long> perPortalCooldowns = new HashMap<>();
|
||||
|
||||
@ -97,25 +97,25 @@ public class PlayerData {
|
||||
this.destiVisible = destiVisible;
|
||||
}
|
||||
|
||||
public boolean isInPortal() {
|
||||
return isInPortal;
|
||||
public String inPortal() {
|
||||
return this.inPortal;
|
||||
}
|
||||
|
||||
public void setInPortal(boolean inPortal) {
|
||||
isInPortal = inPortal;
|
||||
public void setInPortal(String inPortal) {
|
||||
this.inPortal = inPortal;
|
||||
}
|
||||
|
||||
public void setNetherPortalCooldown(long netherPortalCooldown) {
|
||||
this.netherPortalCooldown =
|
||||
System.currentTimeMillis() + netherPortalCooldown;
|
||||
public void setPortalBlockCooldown(long portalBlockCooldown) {
|
||||
this.portalBlockCooldown =
|
||||
System.currentTimeMillis() + portalBlockCooldown;
|
||||
}
|
||||
|
||||
public boolean hasJoinCooldown() {
|
||||
return System.currentTimeMillis() < joinCooldown;
|
||||
}
|
||||
|
||||
public boolean isNetherPortalCooldown() {
|
||||
return System.currentTimeMillis() < netherPortalCooldown;
|
||||
public boolean getPortalBlockCooldown() {
|
||||
return System.currentTimeMillis() < portalBlockCooldown;
|
||||
}
|
||||
|
||||
public void setPortalCooldown(String portalName, long cooldown) {
|
||||
@ -131,4 +131,8 @@ public class PlayerData {
|
||||
public double getPortalCooldownLeft(String portalName) {
|
||||
return perPortalCooldowns.get(portalName) - System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setNotInPortal() {
|
||||
this.inPortal = null;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core.services;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.portal.ActivationResult;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
@ -10,10 +11,12 @@ import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.tags.NameTag;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.PlayerUtils;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import com.sekwah.advancedportals.core.warphandler.TriggerType;
|
||||
|
||||
import java.util.*;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@ -67,42 +70,67 @@ public class PortalServices {
|
||||
}
|
||||
|
||||
public boolean inPortalRegion(BlockLocation loc, int extraBlocks) {
|
||||
for (AdvancedPortal portal : portalCache.values()) {
|
||||
if (portal.isLocationInPortal(loc, extraBlocks)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return inPortalRegionGetName(loc, extraBlocks) != null;
|
||||
}
|
||||
|
||||
public void playerMove(PlayerContainer player, PlayerLocation toLoc) {
|
||||
public String inPortalRegionGetName(PlayerLocation loc, int extraBlocks) {
|
||||
return inPortalRegionGetName(loc.toBlockPos(), extraBlocks);
|
||||
}
|
||||
|
||||
public String inPortalRegionGetName(BlockLocation loc) {
|
||||
return inPortalRegionGetName(loc, 0);
|
||||
}
|
||||
|
||||
public String inPortalRegionGetName(BlockLocation loc, int extraBlocks) {
|
||||
for (AdvancedPortal portal : portalCache.values()) {
|
||||
if (portal.isLocationInPortal(loc, extraBlocks)) {
|
||||
return portal.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum PortalActivationResult {
|
||||
NOT_IN_PORTAL,
|
||||
PORTAL_TELEPORTED,
|
||||
PORTAL_ACTIVATED,
|
||||
PORTAL_DENIED
|
||||
}
|
||||
|
||||
public PortalActivationResult checkPortalActivation(PlayerContainer player, PlayerLocation toLoc, TriggerType triggerType) {
|
||||
var blockLoc = toLoc.toBlockPos();
|
||||
var blockEntityTopLoc = blockLoc.addY(player.getHeight());
|
||||
var world = player.getWorld();
|
||||
var blockMaterial = world.getBlock(blockLoc);
|
||||
var blockEntityTopMaterial = world.getBlock(blockEntityTopLoc);
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
|
||||
var notInPortal = true;
|
||||
for (AdvancedPortal portal : portalCache.values()) {
|
||||
if ((portal.isLocationInPortal(toLoc)
|
||||
&& portal.isTriggerBlock(blockMaterial))
|
||||
|| (portal.isLocationInPortal(blockEntityTopLoc)
|
||||
&& portal.isTriggerBlock(blockEntityTopMaterial))) {
|
||||
notInPortal = false;
|
||||
if (portal.activate(player, true)) {
|
||||
return;
|
||||
var portalName = portal.getName();
|
||||
if(Objects.equals(playerData.inPortal(), portalName)) {
|
||||
return PortalActivationResult.PORTAL_DENIED;
|
||||
}
|
||||
switch (portal.activate(player, triggerType)) {
|
||||
case SUCCESS:
|
||||
playerData.setInPortal(portal.getName());
|
||||
return PortalActivationResult.PORTAL_ACTIVATED;
|
||||
case FAILED_DO_KNOCKBACK:
|
||||
playerData.setInPortal(portal.getName());
|
||||
var strength = configRepository.getThrowbackStrength();
|
||||
PlayerUtils.throwPlayerBack(player, strength);
|
||||
|
||||
return PortalActivationResult.PORTAL_DENIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if (!playerData.isInPortal() && !notInPortal) {
|
||||
playerData.setInPortal(true);
|
||||
var strength = configRepository.getThrowbackStrength();
|
||||
PlayerUtils.throwPlayerBack(player, strength);
|
||||
}
|
||||
if (playerData.isInPortal() && notInPortal) {
|
||||
playerData.setInPortal(false);
|
||||
if (playerData.inPortal() != null) {
|
||||
playerData.setNotInPortal();
|
||||
}
|
||||
return PortalActivationResult.NOT_IN_PORTAL;
|
||||
}
|
||||
|
||||
public List<String> getPortalNames() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.core.tags.activation;
|
||||
package com.sekwah.advancedportals.core.tags;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
@ -1,19 +1,16 @@
|
||||
package com.sekwah.advancedportals.core.tags.activation;
|
||||
package com.sekwah.advancedportals.core.tags;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.effect.WarpEffect;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.PlayerUtils;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Random;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.core.tags.activation;
|
||||
package com.sekwah.advancedportals.core.tags;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.core.tags.activation;
|
||||
package com.sekwah.advancedportals.core.tags;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.core.tags.activation;
|
||||
package com.sekwah.advancedportals.core.tags;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
@ -0,0 +1,118 @@
|
||||
package com.sekwah.advancedportals.core.tags;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
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 javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
public class PortalEventTag implements Tag.Activation, Tag.Creation {
|
||||
@Inject
|
||||
PlayerDataServices playerDataServices;
|
||||
|
||||
@Inject
|
||||
ConfigRepository configRepository;
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
|
||||
public static String TAG_NAME = "cooldown";
|
||||
|
||||
private final TagType[] tagTypes = new TagType[] {TagType.PORTAL};
|
||||
|
||||
@Override
|
||||
public TagType[] getTagTypes() {
|
||||
return tagTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return TAG_NAME;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return Lang.translate("tag.cooldown.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if (target instanceof AdvancedPortal portal) {
|
||||
var portalName = portal.getName();
|
||||
if (playerData.hasPortalCooldown(portalName)) {
|
||||
var cooldown = (int) Math.ceil(
|
||||
playerData.getPortalCooldownLeft(portalName) / 1000D);
|
||||
player.sendMessage(Lang.translateInsertVariables(
|
||||
"portal.cooldown.individual", cooldown,
|
||||
Lang.translate(cooldown == 1 ? "time.second"
|
||||
: "time.seconds")));
|
||||
if (configRepository.playFailSound()) {
|
||||
player.playSound("block.portal.travel", 0.05f,
|
||||
new Random().nextFloat() * 0.4F + 0.8F);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
if (activationData.hasActivated()) {
|
||||
if (target instanceof AdvancedPortal portal) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
try {
|
||||
playerData.setPortalCooldown(
|
||||
portal.getName(), Integer.parseInt(argData[0]) * 1000);
|
||||
} catch (NumberFormatException e) {
|
||||
infoLogger.warning(
|
||||
"Cooldown tag failed to set cooldown for portal: "
|
||||
+ portal.getName() + " with value: " + argData[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean created(TagTarget target, PlayerContainer player,
|
||||
String[] argData) {
|
||||
try {
|
||||
Integer.parseInt(argData[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("tag.cooldown.fail"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyed(TagTarget target, PlayerContainer player,
|
||||
String[] argData) {
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.sekwah.advancedportals.core.tags.activation;
|
||||
package com.sekwah.advancedportals.core.tags;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
@ -10,18 +10,18 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
public class ActivationData {
|
||||
private boolean warpAllowed = true;
|
||||
|
||||
public final boolean moveActivated;
|
||||
|
||||
private WarpedStatus warpStatus = WarpedStatus.NOTACTIVATED;
|
||||
|
||||
private PlayerLocation wantedLocation;
|
||||
|
||||
private TriggerType triggerType;
|
||||
|
||||
public WarpedStatus getWarped() {
|
||||
return this.warpStatus;
|
||||
}
|
||||
|
||||
public ActivationData(boolean moveActivated) {
|
||||
this.moveActivated = moveActivated;
|
||||
public ActivationData(TriggerType triggerType) {
|
||||
this.triggerType = triggerType;
|
||||
}
|
||||
|
||||
public void setWarpStatus(WarpedStatus warped) {
|
||||
@ -33,6 +33,10 @@ public class ActivationData {
|
||||
this.warpStatus = warped;
|
||||
}
|
||||
|
||||
public TriggerType getTriggerType() {
|
||||
return this.triggerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* In case you need to set the status back down a step for whatever reason.
|
||||
* However it is not recommended.
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.sekwah.advancedportals.core.warphandler;
|
||||
|
||||
public enum TriggerType {
|
||||
MOVEMENT,
|
||||
PORTAL,
|
||||
MANUAL
|
||||
}
|
@ -6,7 +6,6 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.tags.activation.CommandTag;
|
||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.spigot.reflection.MinecraftCustomPayload;
|
||||
import java.util.Arrays;
|
||||
@ -14,11 +13,9 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
/**
|
||||
* Just a temporary container for whenever advanced portals needs to get data
|
||||
|
@ -3,13 +3,12 @@ package com.sekwah.advancedportals.spigot.connector.container;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||
import com.sekwah.advancedportals.core.tags.activation.CommandTag;
|
||||
import com.sekwah.advancedportals.core.tags.CommandTag;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user