mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-09-27 14:52:59 +02:00
feat: add global cooldown and throwback sounds
This commit is contained in:
parent
1b5ade0e82
commit
687ec8c9c9
@ -168,7 +168,7 @@ public class CoreListeners {
|
|||||||
var pos = entity.getBlockLoc();
|
var pos = entity.getBlockLoc();
|
||||||
if(entity instanceof PlayerContainer player) {
|
if(entity instanceof PlayerContainer player) {
|
||||||
var playerData = playerDataServices.getPlayerData(player);
|
var playerData = playerDataServices.getPlayerData(player);
|
||||||
if(playerData.isPortalCooldown()) {
|
if(playerData.isNetherPortalCooldown()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core.connector.containers;
|
|||||||
|
|
||||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||||
|
import com.sekwah.advancedportals.core.serializeddata.Vector;
|
||||||
|
|
||||||
public interface EntityContainer {
|
public interface EntityContainer {
|
||||||
|
|
||||||
@ -18,4 +19,6 @@ public interface EntityContainer {
|
|||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
String getWorldName();
|
String getWorldName();
|
||||||
|
|
||||||
|
void setVelocity(Vector vector);
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,6 @@ public interface PlayerContainer extends EntityContainer {
|
|||||||
void giveItem(String material, String itemName, String... itemDescription);
|
void giveItem(String material, String itemName, String... itemDescription);
|
||||||
|
|
||||||
boolean sendPacket(String channel, byte[] bytes);
|
boolean sendPacket(String channel, byte[] bytes);
|
||||||
|
|
||||||
|
void playSound(String sound, float volume, float pitch);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||||
|
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||||
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||||
@ -13,10 +14,7 @@ import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag;
|
|||||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author sekwah41
|
* @author sekwah41
|
||||||
@ -38,6 +36,9 @@ public class AdvancedPortal implements TagTarget {
|
|||||||
@Inject
|
@Inject
|
||||||
transient PlayerDataServices playerDataServices;
|
transient PlayerDataServices playerDataServices;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
transient ConfigRepository configRepository;
|
||||||
|
|
||||||
public AdvancedPortal(BlockLocation minLoc, BlockLocation maxLoc) {
|
public AdvancedPortal(BlockLocation minLoc, BlockLocation maxLoc) {
|
||||||
this.updateBounds(minLoc, maxLoc);
|
this.updateBounds(minLoc, maxLoc);
|
||||||
}
|
}
|
||||||
@ -98,7 +99,22 @@ public class AdvancedPortal implements TagTarget {
|
|||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public boolean activate(PlayerContainer player) {
|
/**
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param moveActivated if the portal was activated by a move event (won't trigger knockback)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean activate(PlayerContainer player, boolean moveActivated) {
|
||||||
|
var playerData = playerDataServices.getPlayerData(player);
|
||||||
|
if(playerData.isGlobalCooldown()) {
|
||||||
|
if(configRepository.playFailSound()) {
|
||||||
|
player.playSound("block.portal.travel", 0.05f, new Random().nextFloat() * 0.4F + 0.8F);
|
||||||
|
}
|
||||||
|
if(moveActivated) throwPlayerBack(player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ActivationData data = new ActivationData();
|
ActivationData data = new ActivationData();
|
||||||
DataTag[] portalTags = new DataTag[args.size()];
|
DataTag[] portalTags = new DataTag[args.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -129,12 +145,19 @@ public class AdvancedPortal implements TagTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(data.hasActivated()) {
|
if(data.hasActivated()) {
|
||||||
playerDataServices.getPlayerData(player).setNetherPortalCooldown(1000);
|
playerData.setNetherPortalCooldown(1000);
|
||||||
|
playerData.setGlobalCooldown(configRepository.getPortalCooldown() * 1000);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void throwPlayerBack(PlayerContainer player) {
|
||||||
|
var strength = configRepository.getThrowbackStrength();
|
||||||
|
var playerLoc = player.getLoc().getDirection();
|
||||||
|
player.setVelocity(playerLoc.setY(0).normalize().multiply(-1).setY(0.5).multiply(strength));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isLocationInPortal(BlockLocation loc) {
|
public boolean isLocationInPortal(BlockLocation loc) {
|
||||||
return this.isLocationInPortal(loc, 0);
|
return this.isLocationInPortal(loc, 0);
|
||||||
|
@ -27,4 +27,8 @@ public interface ConfigRepository {
|
|||||||
boolean getPortalProtection();
|
boolean getPortalProtection();
|
||||||
|
|
||||||
long getPortalCooldown();
|
long getPortalCooldown();
|
||||||
|
|
||||||
|
double getThrowbackStrength();
|
||||||
|
|
||||||
|
boolean playFailSound();
|
||||||
}
|
}
|
||||||
|
@ -82,9 +82,19 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
|||||||
return this.config.portalCooldown;
|
return this.config.portalCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getThrowbackStrength() {
|
||||||
|
return this.config.throwbackStrength;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadConfig(DataStorage dataStorage) {
|
public void loadConfig(DataStorage dataStorage) {
|
||||||
this.config = dataStorage.loadJson(Config.class, "config.json");
|
this.config = dataStorage.loadJson(Config.class, "config.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean playFailSound() {
|
||||||
|
return this.config.playFailSound;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,11 @@ public class PlayerData {
|
|||||||
this.netherPortalCooldown = System.currentTimeMillis() + netherPortalCooldown;
|
this.netherPortalCooldown = System.currentTimeMillis() + netherPortalCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPortalCooldown() {
|
public boolean isGlobalCooldown() {
|
||||||
|
return System.currentTimeMillis() < globalCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNetherPortalCooldown() {
|
||||||
return System.currentTimeMillis() < netherPortalCooldown;
|
return System.currentTimeMillis() < netherPortalCooldown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,15 @@ public class PlayerLocation extends WorldLocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getPosX() {
|
public double getPosX() {
|
||||||
return posX;
|
return X;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPosY() {
|
public double getPosY() {
|
||||||
return posY;
|
return Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPosZ() {
|
public double getPosZ() {
|
||||||
return posZ;
|
return Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorldName() {
|
public String getWorldName() {
|
||||||
@ -45,4 +45,16 @@ public class PlayerLocation extends WorldLocation {
|
|||||||
public float getPitch() {
|
public float getPitch() {
|
||||||
return pitch;
|
return pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector getDirection() {
|
||||||
|
double rotX = this.getYaw();
|
||||||
|
double rotY = this.getPitch();
|
||||||
|
|
||||||
|
var y = -Math.sin(Math.toRadians(rotY));
|
||||||
|
double xz = Math.cos(Math.toRadians(rotY));
|
||||||
|
var x = (-xz * Math.sin(Math.toRadians(rotX)));
|
||||||
|
var z = Math.cos(Math.toRadians(rotX));
|
||||||
|
|
||||||
|
return new Vector(x, y, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.sekwah.advancedportals.core.serializeddata;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class Vector {
|
||||||
|
@SerializedName("x")
|
||||||
|
public final double X;
|
||||||
|
|
||||||
|
@SerializedName("y")
|
||||||
|
public final double Y;
|
||||||
|
|
||||||
|
@SerializedName("z")
|
||||||
|
public final double Z;
|
||||||
|
|
||||||
|
public Vector(double X, double Y, double Z) {
|
||||||
|
this.X = X;
|
||||||
|
this.Y = Y;
|
||||||
|
this.Z = Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector add(Vector vec) {
|
||||||
|
return new Vector(this.X + vec.X, this.Y + vec.Y, this.Z + vec.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector multiply(double value) {
|
||||||
|
return new Vector(this.X * value, this.Y * value, this.Z * value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector setY(double y) {
|
||||||
|
return new Vector(this.X, y, this.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double distanceTo(Vector pos) {
|
||||||
|
return Math.sqrt(this.distanceToSq(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
private double distanceToSq(Vector pos) {
|
||||||
|
double dx = this.X - pos.X;
|
||||||
|
double dy = this.Y - pos.Y;
|
||||||
|
double dz = this.Z - pos.Z;
|
||||||
|
return dx * dx + dy * dy + dz * dz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
|
return this.X;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getY() {
|
||||||
|
return this.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getZ() {
|
||||||
|
return this.Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector normalize() {
|
||||||
|
return this.multiply(1.0D / this.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
private double length() {
|
||||||
|
return Math.sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
|
||||||
|
}
|
||||||
|
}
|
@ -2,39 +2,17 @@ package com.sekwah.advancedportals.core.serializeddata;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public class WorldLocation {
|
public class WorldLocation extends Vector {
|
||||||
|
|
||||||
@SerializedName("x")
|
|
||||||
public final double posX;
|
|
||||||
|
|
||||||
@SerializedName("y")
|
|
||||||
public final double posY;
|
|
||||||
|
|
||||||
@SerializedName("z")
|
|
||||||
public final double posZ;
|
|
||||||
|
|
||||||
@SerializedName("w")
|
@SerializedName("w")
|
||||||
public final String worldName;
|
public final String worldName;
|
||||||
|
|
||||||
public WorldLocation(String worldName, double posX, double posY, double posZ) {
|
public WorldLocation(String worldName, double posX, double posY, double posZ) {
|
||||||
|
super(posX, posY, posZ);
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
this.posX = posX;
|
|
||||||
this.posY = posY;
|
|
||||||
this.posZ = posZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double distanceTo(WorldLocation pos) {
|
|
||||||
return Math.sqrt(this.distanceToSq(pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
public double distanceToSq(WorldLocation pos) {
|
|
||||||
double dx = this.posX - pos.posX;
|
|
||||||
double dy = this.posY - pos.posY;
|
|
||||||
double dz = this.posZ - pos.posZ;
|
|
||||||
return dx * dx + dy * dy + dz * dz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockLocation toBlockPos() {
|
public BlockLocation toBlockPos() {
|
||||||
return new BlockLocation(this.worldName, (int) Math.floor(this.posX), (int) Math.floor(this.posY), (int) Math.floor(this.posZ));
|
return new BlockLocation(this.worldName, (int) Math.floor(this.X), (int) Math.floor(this.Y), (int) Math.floor(this.Z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,4 +31,7 @@ public class Config {
|
|||||||
|
|
||||||
public int maxTriggerVisualisationSize = 1000;
|
public int maxTriggerVisualisationSize = 1000;
|
||||||
|
|
||||||
|
public double throwbackStrength = 1;
|
||||||
|
|
||||||
|
public boolean playFailSound = true;
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,6 @@ public class PortalServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void playerMove(PlayerContainer player, PlayerLocation toLoc) {
|
public void playerMove(PlayerContainer player, PlayerLocation toLoc) {
|
||||||
PlayerData tempData = playerDataServices.getPlayerData(player);
|
|
||||||
|
|
||||||
if(tempData.getGlobalCooldown() > System.currentTimeMillis()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var blockLoc = toLoc.toBlockPos();
|
var blockLoc = toLoc.toBlockPos();
|
||||||
var blockEntityTopLoc = blockLoc.addY(player.getHeight());
|
var blockEntityTopLoc = blockLoc.addY(player.getHeight());
|
||||||
@ -90,7 +85,9 @@ public class PortalServices {
|
|||||||
&& portal.isTriggerBlock(blockMaterial))
|
&& portal.isTriggerBlock(blockMaterial))
|
||||||
|| (portal.isLocationInPortal(blockEntityTopLoc)
|
|| (portal.isLocationInPortal(blockEntityTopLoc)
|
||||||
&& portal.isTriggerBlock(blockEntityTopMaterial))) {
|
&& portal.isTriggerBlock(blockEntityTopMaterial))) {
|
||||||
portal.activate(player);
|
if(portal.activate(player, true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,10 @@ import com.sekwah.advancedportals.core.connector.containers.EntityContainer;
|
|||||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
import com.sekwah.advancedportals.core.serializeddata.Vector;
|
||||||
import com.sekwah.advancedportals.spigot.reflection.MinecraftCustomPayload;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just a temporary container for whenever advanced portals needs to get data from a player
|
* Just a temporary container for whenever advanced portals needs to get data from a player
|
||||||
@ -67,4 +61,9 @@ public class SpigotEntityContainer implements EntityContainer {
|
|||||||
public String getWorldName() {
|
public String getWorldName() {
|
||||||
return this.entity.getWorld().getName();
|
return this.entity.getWorld().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVelocity(Vector vector) {
|
||||||
|
this.entity.setVelocity(new org.bukkit.util.Vector(vector.getX(), vector.getY(), vector.getZ()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,4 +101,9 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play
|
|||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playSound(String sound, float volume, float pitch) {
|
||||||
|
this.player.playSound(this.player.getLocation(), sound, volume, pitch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user