Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
a3ed1058e6 | |||
f70ba24e95 | |||
f6438eb872 | |||
2bf5422b2a | |||
f95ee0b85d | |||
1e06e0e01d | |||
bddf8c55d5 | |||
05a5fb2160 | |||
d9f535cd07 | |||
62952611b8 |
11
README.md
11
README.md
@ -306,6 +306,7 @@ folders:
|
||||
gates:
|
||||
maxGatesEachNetwork - If non-zero, will define the maximum amount of gates allowed on any network.
|
||||
defaultGateNetwork - The default gate network
|
||||
exitVelocity - The velocity to give players exiting stargates, relative to the entry velocity (1 = same as entry velocity)
|
||||
cosmetic:
|
||||
rememberDestination - Whether to set the first destination as the last used destination for all gates
|
||||
sortNetworkDestinations - If true, network lists will be sorted alphabetically.
|
||||
@ -396,6 +397,16 @@ portalInfoServer=Server: %server%
|
||||
|
||||
# Changes
|
||||
|
||||
#### \[Version 0.9.3.2] EpicKnarvik97 fork
|
||||
|
||||
- Adds a config option to set the exit velocity of any players exiting a stargate
|
||||
- Adjusts vehicle teleportation a bit to prevent passengers' exit rotation from being wrong
|
||||
- Improves the checking for buggy double-clicks on non-button blocks
|
||||
|
||||
#### \[Version 0.9.3.1] EpicKnarvik97 fork
|
||||
|
||||
- Ignores the type of air when checking if a stargate is valid
|
||||
|
||||
#### \[Version 0.9.3.0] EpicKnarvik97 fork
|
||||
|
||||
- Adds support for RGB colors (use hex color codes)
|
||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>Stargate</artifactId>
|
||||
<version>0.9.3.0</version>
|
||||
<version>0.9.3.2</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
|
@ -90,6 +90,15 @@ public class CommandConfig implements CommandExecutor {
|
||||
configuration.set(selectedOption.getConfigNode(), intValue);
|
||||
}
|
||||
}
|
||||
case DOUBLE -> {
|
||||
Double doubleValue = getDouble(commandSender, selectedOption, value);
|
||||
if (doubleValue == null) {
|
||||
return;
|
||||
} else {
|
||||
Stargate.getStargateConfig().getConfigOptionsReference().put(selectedOption, doubleValue);
|
||||
configuration.set(selectedOption.getConfigNode(), doubleValue);
|
||||
}
|
||||
}
|
||||
case STRING -> {
|
||||
updateStringConfigValue(selectedOption, commandSender, value);
|
||||
configuration.set(selectedOption.getConfigNode(), value);
|
||||
@ -314,6 +323,30 @@ public class CommandConfig implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a double from a string
|
||||
*
|
||||
* @param commandSender <p>The command sender that sent the config command</p>
|
||||
* @param selectedOption <p>The option the command sender is trying to change</p>
|
||||
* @param value <p>The value given</p>
|
||||
* @return <p>A double, or null if it was invalid</p>
|
||||
*/
|
||||
private Double getDouble(CommandSender commandSender, ConfigOption selectedOption, String value) {
|
||||
try {
|
||||
double doubleValue = Double.parseDouble(value);
|
||||
|
||||
if (selectedOption == ConfigOption.EXIT_VELOCITY && doubleValue < 0) {
|
||||
commandSender.sendMessage(ChatColor.RED + "This config option cannot be negative.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return doubleValue;
|
||||
} catch (NumberFormatException exception) {
|
||||
commandSender.sendMessage(ChatColor.RED + "Invalid number given");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the config if necessary
|
||||
*
|
||||
|
@ -21,16 +21,17 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
|
||||
private List<String> signTypes;
|
||||
private List<String> booleans;
|
||||
private List<String> numbers;
|
||||
private List<String> integers;
|
||||
private List<String> chatColors;
|
||||
private List<String> languages;
|
||||
private List<String> extendedColors;
|
||||
private List<String> doubles;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] args) {
|
||||
if (signTypes == null || booleans == null || numbers == null || chatColors == null || languages == null) {
|
||||
if (signTypes == null || booleans == null || integers == null || chatColors == null || languages == null) {
|
||||
initializeAutoCompleteLists();
|
||||
}
|
||||
if (args.length > 1) {
|
||||
@ -104,7 +105,16 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
//If the config value is an integer, display some valid numbers
|
||||
if (selectedOption.getDataType() == OptionDataType.INTEGER) {
|
||||
if (typedText.trim().isEmpty()) {
|
||||
return numbers;
|
||||
return integers;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
//If the config value is a double, display some valid numbers
|
||||
if (selectedOption.getDataType() == OptionDataType.DOUBLE) {
|
||||
if (typedText.trim().isEmpty()) {
|
||||
return doubles;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -164,9 +174,9 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
booleans.add("true");
|
||||
booleans.add("false");
|
||||
|
||||
numbers = new ArrayList<>();
|
||||
numbers.add("0");
|
||||
numbers.add("5");
|
||||
integers = new ArrayList<>();
|
||||
integers.add("0");
|
||||
integers.add("5");
|
||||
|
||||
signTypes = new ArrayList<>();
|
||||
for (Material material : Material.values()) {
|
||||
@ -181,6 +191,12 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
extendedColors = new ArrayList<>(chatColors);
|
||||
extendedColors.add("default");
|
||||
extendedColors.add("inverted");
|
||||
|
||||
doubles = new ArrayList<>();
|
||||
doubles.add("5");
|
||||
doubles.add("1");
|
||||
doubles.add("0.5");
|
||||
doubles.add("0.1");
|
||||
}
|
||||
|
||||
|
||||
|
@ -156,8 +156,12 @@ public enum ConfigOption {
|
||||
/**
|
||||
* Whether to alert admins about new updates
|
||||
*/
|
||||
ADMIN_UPDATE_ALERT("adminUpdateAlert", "Whether to alert admins about new plugin updates", true);
|
||||
ADMIN_UPDATE_ALERT("adminUpdateAlert", "Whether to alert admins about new plugin updates", true),
|
||||
|
||||
/**
|
||||
* The velocity of players exiting a stargate, relative to the entry velocity
|
||||
*/
|
||||
EXIT_VELOCITY("gates.exitVelocity", "The velocity of players exiting stargates, relative to the entry velocity", 0.1D);
|
||||
|
||||
private final String configNode;
|
||||
private final String description;
|
||||
@ -184,6 +188,8 @@ public enum ConfigOption {
|
||||
this.dataType = OptionDataType.BOOLEAN;
|
||||
} else if (defaultValue instanceof Integer) {
|
||||
this.dataType = OptionDataType.INTEGER;
|
||||
} else if (defaultValue instanceof Double) {
|
||||
this.dataType = OptionDataType.DOUBLE;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown config data type encountered: " + defaultValue);
|
||||
}
|
||||
|
@ -6,17 +6,28 @@ package net.knarcraft.stargate.config;
|
||||
public enum OptionDataType {
|
||||
|
||||
/**
|
||||
* The data type for the option is a String
|
||||
* The data type if the option is a String
|
||||
*/
|
||||
STRING,
|
||||
|
||||
/**
|
||||
* The data type for the option is a Boolean
|
||||
* The data type if the option is a Boolean
|
||||
*/
|
||||
BOOLEAN,
|
||||
STRING_LIST,
|
||||
|
||||
/**
|
||||
* The data type for the option is an Integer
|
||||
* The data type if the option is a string list
|
||||
*/
|
||||
INTEGER
|
||||
STRING_LIST,
|
||||
|
||||
/**
|
||||
* The data type if the option is an Integer
|
||||
*/
|
||||
INTEGER,
|
||||
|
||||
/**
|
||||
* The data type if the option is a double
|
||||
*/
|
||||
DOUBLE
|
||||
|
||||
}
|
||||
|
@ -358,6 +358,7 @@ public final class StargateConfig {
|
||||
}
|
||||
case BOOLEAN -> optionValue = newConfig.getBoolean(configNode);
|
||||
case INTEGER -> optionValue = newConfig.getInt(configNode);
|
||||
case DOUBLE -> optionValue = newConfig.getDouble(configNode);
|
||||
default -> throw new IllegalArgumentException("Invalid config data type encountered");
|
||||
}
|
||||
configOptions.put(option, optionValue);
|
||||
|
@ -179,6 +179,15 @@ public final class StargateGateConfig {
|
||||
return (String) configOptions.get(ConfigOption.DEFAULT_GATE_NETWORK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the exit velocity of players using stargates, relative to the entry velocity
|
||||
*
|
||||
* @return <p>The relative exit velocity</p>
|
||||
*/
|
||||
public double getExitVelocity() {
|
||||
return (double) configOptions.get(ConfigOption.EXIT_VELOCITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all config values related to gates
|
||||
*/
|
||||
|
@ -34,14 +34,16 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This listener listens to any player-related events related to stargates
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerEventListener implements Listener {
|
||||
|
||||
private static long eventTime;
|
||||
private static PlayerInteractEvent previousEvent;
|
||||
private static final Map<Player, Long> previousEventTimes = new HashMap<>();
|
||||
|
||||
/**
|
||||
* This event handler handles detection of any player teleporting through a bungee gate
|
||||
@ -295,7 +297,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
|
||||
//Prevent a double click caused by a Spigot bug
|
||||
if (clickIsBug(event, block)) {
|
||||
if (clickIsBug(event.getPlayer(), block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -366,19 +368,17 @@ public class PlayerEventListener implements Listener {
|
||||
* immediately, or causing portal information printing twice. This fix should detect the bug without breaking
|
||||
* clicking once the bug is fixed.</p>
|
||||
*
|
||||
* @param event <p>The event causing the right click</p>
|
||||
* @param block <p>The block to check</p>
|
||||
* @param player <p>The player performing the right-click</p>
|
||||
* @param block <p>The block to check</p>
|
||||
* @return <p>True if the click is a bug and should be cancelled</p>
|
||||
*/
|
||||
private boolean clickIsBug(PlayerInteractEvent event, Block block) {
|
||||
if (previousEvent != null &&
|
||||
event.getPlayer() == previousEvent.getPlayer() && eventTime + 15 > System.currentTimeMillis()) {
|
||||
previousEvent = null;
|
||||
eventTime = 0;
|
||||
private boolean clickIsBug(Player player, Block block) {
|
||||
Long previousEventTime = previousEventTimes.get(player);
|
||||
if (previousEventTime != null && previousEventTime + 50 > System.currentTimeMillis()) {
|
||||
previousEventTimes.put(player, null);
|
||||
return true;
|
||||
}
|
||||
previousEvent = event;
|
||||
eventTime = System.currentTimeMillis();
|
||||
previousEventTimes.put(player, System.currentTimeMillis());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ public class Gate {
|
||||
Material type = topLeft.getRelativeLocation(entranceVector, yaw).getType();
|
||||
|
||||
//Ignore entrance if it's air or water, and we're creating a new gate
|
||||
if (onCreate && (type == Material.AIR || type == Material.WATER)) {
|
||||
if (onCreate && (type.isAir() || type == Material.WATER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,12 @@ package net.knarcraft.stargate.portal.teleporter;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.event.StargatePlayerPortalEvent;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* The portal teleporter takes care of the actual portal teleportation for any players
|
||||
@ -32,6 +35,7 @@ public class PlayerTeleporter extends Teleporter {
|
||||
* @param event <p>The player move event triggering the event</p>
|
||||
*/
|
||||
public void teleport(Portal origin, PlayerMoveEvent event) {
|
||||
double velocity = player.getVelocity().length();
|
||||
Location traveller = player.getLocation();
|
||||
Location exit = getExit(player, traveller);
|
||||
|
||||
@ -56,9 +60,16 @@ public class PlayerTeleporter extends Teleporter {
|
||||
if (event == null) {
|
||||
player.teleport(exit);
|
||||
} else {
|
||||
//The new method to teleport in a move event is set the "to" field.
|
||||
//Set the exit location of the event
|
||||
event.setTo(exit);
|
||||
}
|
||||
|
||||
//Set the velocity of the teleported player after the teleportation is finished
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () -> {
|
||||
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getYaw());
|
||||
Vector newVelocity = newVelocityDirection.multiply(velocity * Stargate.getGateConfig().getExitVelocity());
|
||||
player.setVelocity(newVelocity);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ public abstract class Teleporter {
|
||||
}
|
||||
float newYaw = (portal.getYaw() + adjust) % 360;
|
||||
Stargate.debug("Portal::adjustRotation", "Setting exit yaw to " + newYaw);
|
||||
exit.setYaw(newYaw);
|
||||
exit.setDirection(DirectionHelper.getDirectionVectorFromYaw(newYaw));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,7 +141,7 @@ public abstract class Teleporter {
|
||||
if (entitySize > 1) {
|
||||
double entityOffset;
|
||||
if (portal.getOptions().isAlwaysOn()) {
|
||||
entityOffset = entityBoxSize / 2D;
|
||||
entityOffset = (entityBoxSize / 2D);
|
||||
} else {
|
||||
entityOffset = (entitySize / 2D) - 1;
|
||||
}
|
||||
@ -217,8 +217,8 @@ public abstract class Teleporter {
|
||||
protected void loadChunks() {
|
||||
for (Chunk chunk : getChunksToLoad()) {
|
||||
chunk.addPluginChunkTicket(Stargate.getInstance());
|
||||
//Allow the chunk to unload after 3 seconds
|
||||
Stargate.addChunkUnloadRequest(new ChunkUnloadRequest(chunk, 3000L));
|
||||
//Allow the chunk to unload after 10 seconds
|
||||
Stargate.addChunkUnloadRequest(new ChunkUnloadRequest(chunk, 10000L));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
private void teleportLivingVehicle(Location exit, List<Entity> passengers, Portal origin) {
|
||||
teleportingVehicle.eject();
|
||||
teleportingVehicle.teleport(exit);
|
||||
handleVehiclePassengers(passengers, teleportingVehicle, 2, origin);
|
||||
handleVehiclePassengers(passengers, teleportingVehicle, 2, origin, exit.getDirection());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,19 +194,20 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
teleportingVehicle.remove();
|
||||
//Set rotation, add passengers and restore velocity
|
||||
newVehicle.setRotation(exit.getYaw(), exit.getPitch());
|
||||
handleVehiclePassengers(passengers, newVehicle, 1, origin);
|
||||
handleVehiclePassengers(passengers, newVehicle, 1, origin, exit.getDirection());
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> newVehicle.setVelocity(newVelocity), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ejects, teleports and adds all passengers to the target vehicle
|
||||
*
|
||||
* @param passengers <p>The passengers to handle</p>
|
||||
* @param vehicle <p>The vehicle the passengers should be put into</p>
|
||||
* @param delay <p>The amount of milliseconds to wait before adding the vehicle passengers</p>
|
||||
* @param origin <p>The portal the vehicle teleported from</p>
|
||||
* @param passengers <p>The passengers to handle</p>
|
||||
* @param vehicle <p>The vehicle the passengers should be put into</p>
|
||||
* @param delay <p>The amount of milliseconds to wait before adding the vehicle passengers</p>
|
||||
* @param origin <p>The portal the vehicle teleported from</p>
|
||||
* @param exitRotation <p>The rotation of any passengers exiting the stargate</p>
|
||||
*/
|
||||
private void handleVehiclePassengers(List<Entity> passengers, Vehicle vehicle, long delay, Portal origin) {
|
||||
private void handleVehiclePassengers(List<Entity> passengers, Vehicle vehicle, long delay, Portal origin, Vector exitRotation) {
|
||||
for (Entity passenger : passengers) {
|
||||
passenger.eject();
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> {
|
||||
@ -214,7 +215,7 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
//Teleport any creatures leashed by the player in a 15-block range
|
||||
teleportLeashedCreatures(player, origin);
|
||||
}
|
||||
teleportAndAddPassenger(vehicle, passenger);
|
||||
teleportAndAddPassenger(vehicle, passenger, exitRotation);
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
@ -227,9 +228,10 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
*
|
||||
* @param targetVehicle <p>The vehicle to add the passenger to</p>
|
||||
* @param passenger <p>The passenger to teleport and add</p>
|
||||
* @param exitDirection <p>The direction of any passengers exiting the stargate</p>
|
||||
*/
|
||||
private void teleportAndAddPassenger(Vehicle targetVehicle, Entity passenger) {
|
||||
if (!passenger.teleport(targetVehicle.getLocation())) {
|
||||
private void teleportAndAddPassenger(Vehicle targetVehicle, Entity passenger, Vector exitDirection) {
|
||||
if (!passenger.teleport(targetVehicle.getLocation().clone().setDirection(exitDirection))) {
|
||||
Stargate.debug("handleVehiclePassengers", "Failed to teleport passenger");
|
||||
}
|
||||
if (!targetVehicle.addPassenger(passenger)) {
|
||||
|
@ -15,6 +15,8 @@ gates:
|
||||
maxGatesEachNetwork: 0
|
||||
# defaultGateNetwork - The default gate network
|
||||
defaultGateNetwork: central
|
||||
# exitVelocity - The velocity to give players exiting stargates, relative to the entry velocity
|
||||
exitVelocity: 0.1
|
||||
cosmetic:
|
||||
# rememberDestination - Whether to remember the cursor location between uses
|
||||
rememberDestination: false
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: Stargate
|
||||
main: net.knarcraft.stargate.Stargate
|
||||
version: 0.9.3.0
|
||||
version: 0.9.3.2
|
||||
description: Stargate mod for Bukkit Revived
|
||||
author: EpicKnarvik97
|
||||
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
||||
|
Reference in New Issue
Block a user