Compare commits
19 Commits
master
...
yml-storag
| Author | SHA1 | Date | |
|---|---|---|---|
| 0edb800cd3 | |||
| c5a964337a | |||
| 48b4151038 | |||
| e30f41071c | |||
| d080644364 | |||
| 061430dfe4 | |||
| 3ad13137bd | |||
| e9559a2601 | |||
| 766b63d2f3 | |||
| 01dca5aac8 | |||
| 3751ef070c | |||
| 2dcf7b7af0 | |||
| 0f0b8b7087 | |||
| e1ca1fe8b0 | |||
| 6954d46af4 | |||
| a1f25a794e | |||
| fbabe7b117 | |||
| 5e456a1326 | |||
| 99ee5c6978 |
16
README.md
16
README.md
@@ -1,11 +1,3 @@
|
|||||||
> **Documentation may be found** [here](https://sgrewritten.org/legacywiki)<br>
|
|
||||||
> **Support is available via** [discord](https://sgrewritten.org/discord)**.**
|
|
||||||
|
|
||||||
> **THIS IS A LEGACY-BASED BRANCH: IT IS SUPPORTED, BUT NOT ACTIVELY UPDATED**<br>
|
|
||||||
> This branch expands upon Drakia's original 2013 codebase, with fixes as needed.<br>
|
|
||||||
> In the near future, this branch will be superseded by [SGR](https://github.com/stargate-rewritten/Stargate-Bukkit) (a
|
|
||||||
> complete rewrite).
|
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
The Original, and still the best, MineCraft transportation solution!<br>Intuitively and organically facilitates instant
|
The Original, and still the best, MineCraft transportation solution!<br>Intuitively and organically facilitates instant
|
||||||
@@ -37,8 +29,9 @@ Highly capable, simple to use, with robust network capabilities and extensive cu
|
|||||||
support for UUIDs & Material Strings).
|
support for UUIDs & Material Strings).
|
||||||
- EpicKnarvik97 forked that version to clean up the code, added leash support, and improved vehicle support.
|
- EpicKnarvik97 forked that version to clean up the code, added leash support, and improved vehicle support.
|
||||||
- LockedCraft and LittleBigBug also forked that version to add underwater and tag support, as well as a few bug fixes.
|
- LockedCraft and LittleBigBug also forked that version to add underwater and tag support, as well as a few bug fixes.
|
||||||
- This version is a combination of all the forks above, maintained by the Stargate Rewritten project.
|
- This version is a combination of all the forks above, maintained by EpicKnarvik97.
|
||||||
- This branch is currently in a maintenance-only mode; a total rewrite is forthcoming.
|
- A rewrite was underway, but because of a mix of real life obligations, and a general lack of motivation, progress
|
||||||
|
stopped.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
@@ -540,9 +533,6 @@ Please note that %variableName% should be kept, as it will be replaced with a re
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
> **PLEASE NOTE**: This method of localisation is slated to change in the upcoming rewrite!<br> If stargate does not
|
|
||||||
> currently support your language, please submit a translation [here](https://sgrewritten.org/translate)!
|
|
||||||
|
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
#### \[Version 0.11.5.11] Unified Legacy Fork
|
#### \[Version 0.11.5.11] Unified Legacy Fork
|
||||||
|
|||||||
@@ -7,30 +7,26 @@ import net.knarcraft.knarlib.util.ConfigHelper;
|
|||||||
import net.knarcraft.knarlib.util.UpdateChecker;
|
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||||
import net.knarcraft.stargate.command.CommandStarGate;
|
import net.knarcraft.stargate.command.CommandStarGate;
|
||||||
import net.knarcraft.stargate.command.StarGateTabCompleter;
|
import net.knarcraft.stargate.command.StarGateTabCompleter;
|
||||||
import net.knarcraft.stargate.config.EconomyConfig;
|
|
||||||
import net.knarcraft.stargate.config.Message;
|
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
|
||||||
import net.knarcraft.stargate.config.StargateConfig;
|
import net.knarcraft.stargate.config.StargateConfig;
|
||||||
import net.knarcraft.stargate.config.StargateGateConfig;
|
import net.knarcraft.stargate.config.StargateGateConfig;
|
||||||
|
import net.knarcraft.stargate.config.addons.EconomyConfig;
|
||||||
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.container.ChunkUnloadRequest;
|
import net.knarcraft.stargate.container.ChunkUnloadRequest;
|
||||||
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
||||||
import net.knarcraft.stargate.listener.BlockEventListener;
|
import net.knarcraft.stargate.listener.EnvironmentChangeListener;
|
||||||
import net.knarcraft.stargate.listener.EntityEventListener;
|
|
||||||
import net.knarcraft.stargate.listener.EntitySpawnListener;
|
|
||||||
import net.knarcraft.stargate.listener.PlayerEventListener;
|
import net.knarcraft.stargate.listener.PlayerEventListener;
|
||||||
import net.knarcraft.stargate.listener.PluginEventListener;
|
import net.knarcraft.stargate.listener.StargateBreakListener;
|
||||||
import net.knarcraft.stargate.listener.PortalEventListener;
|
import net.knarcraft.stargate.listener.StargateCreateDestroyListener;
|
||||||
import net.knarcraft.stargate.listener.TeleportEventListener;
|
import net.knarcraft.stargate.listener.StargateTeleportListener;
|
||||||
import net.knarcraft.stargate.listener.VehicleEventListener;
|
|
||||||
import net.knarcraft.stargate.listener.WorldEventListener;
|
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||||
import net.knarcraft.stargate.thread.ChunkUnloadThread;
|
import net.knarcraft.stargate.thread.ChunkUnloadThread;
|
||||||
import net.knarcraft.stargate.thread.ControlBlocksUpdateThread;
|
import net.knarcraft.stargate.thread.ControlBlocksUpdateThread;
|
||||||
import net.knarcraft.stargate.thread.StarGateThread;
|
import net.knarcraft.stargate.thread.StarGateThread;
|
||||||
import net.knarcraft.stargate.utility.BStatsHelper;
|
import net.knarcraft.stargate.utility.BStatsHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@@ -340,7 +336,7 @@ public class Stargate extends ConfigCommentPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
PortalHandler.closeAllPortals();
|
PortalUtil.closeAllPortals();
|
||||||
PortalRegistry.clearPortals();
|
PortalRegistry.clearPortals();
|
||||||
if (stargateConfig != null) {
|
if (stargateConfig != null) {
|
||||||
stargateConfig.clearManagedWorlds();
|
stargateConfig.clearManagedWorlds();
|
||||||
@@ -384,7 +380,7 @@ public class Stargate extends ConfigCommentPlugin {
|
|||||||
registerCommand("stargate", new CommandStarGate(this), new StarGateTabCompleter());
|
registerCommand("stargate", new CommandStarGate(this), new StarGateTabCompleter());
|
||||||
|
|
||||||
//Check for any available updates
|
//Check for any available updates
|
||||||
UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=109355",
|
UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=97784",
|
||||||
Stargate::getPluginVersion, Stargate::setUpdateAvailable);
|
Stargate::getPluginVersion, Stargate::setUpdateAvailable);
|
||||||
|
|
||||||
BStatsHelper.initialize(this);
|
BStatsHelper.initialize(this);
|
||||||
@@ -407,15 +403,10 @@ public class Stargate extends ConfigCommentPlugin {
|
|||||||
*/
|
*/
|
||||||
private void registerEventListeners() {
|
private void registerEventListeners() {
|
||||||
pluginManager.registerEvents(new PlayerEventListener(), this);
|
pluginManager.registerEvents(new PlayerEventListener(), this);
|
||||||
pluginManager.registerEvents(new BlockEventListener(), this);
|
pluginManager.registerEvents(new StargateCreateDestroyListener(), this);
|
||||||
|
pluginManager.registerEvents(new StargateTeleportListener(), this);
|
||||||
pluginManager.registerEvents(new VehicleEventListener(), this);
|
pluginManager.registerEvents(new EnvironmentChangeListener(this), this);
|
||||||
pluginManager.registerEvents(new EntityEventListener(), this);
|
pluginManager.registerEvents(new StargateBreakListener(), this);
|
||||||
pluginManager.registerEvents(new PortalEventListener(), this);
|
|
||||||
pluginManager.registerEvents(new WorldEventListener(), this);
|
|
||||||
pluginManager.registerEvents(new PluginEventListener(this), this);
|
|
||||||
pluginManager.registerEvents(new TeleportEventListener(), this);
|
|
||||||
pluginManager.registerEvents(new EntitySpawnListener(), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package net.knarcraft.stargate.command;
|
|||||||
import de.themoep.minedown.MineDown;
|
import de.themoep.minedown.MineDown;
|
||||||
import net.knarcraft.knarlib.util.FileHelper;
|
import net.knarcraft.knarlib.util.FileHelper;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ package net.knarcraft.stargate.command;
|
|||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.ConfigOption;
|
import net.knarcraft.stargate.config.ConfigOption;
|
||||||
import net.knarcraft.stargate.config.ConfigTag;
|
import net.knarcraft.stargate.config.ConfigTag;
|
||||||
import net.knarcraft.stargate.config.DynmapManager;
|
|
||||||
import net.knarcraft.stargate.config.Message;
|
|
||||||
import net.knarcraft.stargate.config.OptionDataType;
|
import net.knarcraft.stargate.config.OptionDataType;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.Permission;
|
||||||
|
import net.knarcraft.stargate.config.addons.DynmapManager;
|
||||||
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||||
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@@ -32,7 +34,7 @@ public class CommandConfig implements CommandExecutor {
|
|||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||||
@NotNull String[] args) {
|
@NotNull String[] args) {
|
||||||
if (commandSender instanceof Player player) {
|
if (commandSender instanceof Player player) {
|
||||||
if (!player.hasPermission("stargate.admin.config")) {
|
if (!PermissionHelper.hasPermission(player, Permission.CONFIG)) {
|
||||||
new SGFormatBuilder("Permission Denied").error(commandSender);
|
new SGFormatBuilder("Permission Denied").error(commandSender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package net.knarcraft.stargate.command;
|
package net.knarcraft.stargate.command;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.Permission;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -17,7 +19,7 @@ public class CommandReload implements CommandExecutor {
|
|||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||||
@NotNull String[] args) {
|
@NotNull String[] args) {
|
||||||
if (commandSender instanceof Player player) {
|
if (commandSender instanceof Player player) {
|
||||||
if (!player.hasPermission("stargate.admin.reload")) {
|
if (!PermissionHelper.hasPermission(player, Permission.RELOAD)) {
|
||||||
new SGFormatBuilder("Permission Denied").error(commandSender);
|
new SGFormatBuilder("Permission Denied").error(commandSender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.knarcraft.stargate.command;
|
package net.knarcraft.stargate.command;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.config.Permission;
|
||||||
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
@@ -47,10 +49,10 @@ public class StarGateTabCompleter implements TabCompleter {
|
|||||||
private List<String> getAvailableCommands(@NotNull CommandSender commandSender) {
|
private List<String> getAvailableCommands(@NotNull CommandSender commandSender) {
|
||||||
List<String> commands = new ArrayList<>();
|
List<String> commands = new ArrayList<>();
|
||||||
commands.add("about");
|
commands.add("about");
|
||||||
if (!(commandSender instanceof Player player) || player.hasPermission("stargate.admin.reload")) {
|
if (!(commandSender instanceof Player player) || PermissionHelper.hasPermission(player, Permission.RELOAD)) {
|
||||||
commands.add("reload");
|
commands.add("reload");
|
||||||
}
|
}
|
||||||
if (!(commandSender instanceof Player player) || player.hasPermission("stargate.admin.config")) {
|
if (!(commandSender instanceof Player player) || PermissionHelper.hasPermission(player, Permission.CONFIG)) {
|
||||||
commands.add("config");
|
commands.add("config");
|
||||||
}
|
}
|
||||||
return commands;
|
return commands;
|
||||||
|
|||||||
68
src/main/java/net/knarcraft/stargate/config/Permission.java
Normal file
68
src/main/java/net/knarcraft/stargate/config/Permission.java
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
package net.knarcraft.stargate.config;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A representation of all Stargate permissions
|
||||||
|
*/
|
||||||
|
public enum Permission {
|
||||||
|
|
||||||
|
ADMIN("admin"),
|
||||||
|
CONFIG("admin.config"),
|
||||||
|
RELOAD("admin.reload"),
|
||||||
|
CREATE_BUNGEE("admin.bungee"),
|
||||||
|
DYE_SIGN("admin.dye"),
|
||||||
|
|
||||||
|
SEE_HIDDEN("admin.hidden"),
|
||||||
|
USE_PRIVATE("admin.private"),
|
||||||
|
|
||||||
|
FREE_USAGE("free.use"),
|
||||||
|
FREE_DESTRUCTION("free.destroy"),
|
||||||
|
FREE_CREATION("free.create"),
|
||||||
|
|
||||||
|
ACCESS_SERVER("server"),
|
||||||
|
ACCESS_NETWORK("network"),
|
||||||
|
ACCESS_WORLD("world"),
|
||||||
|
|
||||||
|
CREATE_GATE("create.gate"),
|
||||||
|
CREATE_NETWORK("create.network"),
|
||||||
|
CREATE_PERSONAL("create.personal"),
|
||||||
|
|
||||||
|
DESTROY_NETWORK("destroy.network"),
|
||||||
|
DESTROY_PERSONAL("destroy.personal"),
|
||||||
|
|
||||||
|
OPTION_HIDDEN("option.hidden"),
|
||||||
|
OPTION_ALWAYS_ON("option.alwayson"),
|
||||||
|
OPTIONS_PRIVATE("options.private"),
|
||||||
|
OPTIONS_FREE("options.free"),
|
||||||
|
OPTIONS_BACKWARDS("options.backwards"),
|
||||||
|
OPTIONS_SHOW("options.show"),
|
||||||
|
OPTIONS_NO_NETWORK("options.nonetwork"),
|
||||||
|
OPTIONS_RANDOM("options.random"),
|
||||||
|
OPTIONS_BUNGEE("options.bungee"),
|
||||||
|
OPTIONS_QUIET("options.quiet"),
|
||||||
|
OPTIONS_INVISIBLE("options.invisible"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new permission
|
||||||
|
*
|
||||||
|
* @param node <p>The permission node</p>
|
||||||
|
*/
|
||||||
|
Permission(@NotNull String node) {
|
||||||
|
this.node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the permission node of this permission
|
||||||
|
*
|
||||||
|
* @return <p>The node of this permission</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public String getNode() {
|
||||||
|
return "stargate." + this.node;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,14 +5,19 @@ import net.knarcraft.knarlib.formatting.Translator;
|
|||||||
import net.knarcraft.knarlib.property.ColorConversion;
|
import net.knarcraft.knarlib.property.ColorConversion;
|
||||||
import net.knarcraft.knarlib.util.ConfigHelper;
|
import net.knarcraft.knarlib.util.ConfigHelper;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.config.addons.DynmapManager;
|
||||||
|
import net.knarcraft.stargate.config.addons.EconomyConfig;
|
||||||
|
import net.knarcraft.stargate.config.formatting.LanguageLoader;
|
||||||
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.listener.BungeeCordListener;
|
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||||
|
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -279,7 +284,7 @@ public final class StargateConfig {
|
|||||||
}
|
}
|
||||||
//Force all portals to close
|
//Force all portals to close
|
||||||
closeAllOpenPortals();
|
closeAllOpenPortals();
|
||||||
PortalHandler.closeAllPortals();
|
PortalUtil.closeAllPortals();
|
||||||
|
|
||||||
//Clear queues and lists
|
//Clear queues and lists
|
||||||
activePortalsQueue.clear();
|
activePortalsQueue.clear();
|
||||||
@@ -358,7 +363,21 @@ public final class StargateConfig {
|
|||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
messenger.registerOutgoingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
messenger.registerOutgoingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
||||||
messenger.registerIncomingPluginChannel(Stargate.getInstance(), bungeeChannel, new BungeeCordListener());
|
messenger.registerIncomingPluginChannel(Stargate.getInstance(), bungeeChannel, (channel, unused, message) -> {
|
||||||
|
//Ignore plugin messages if some other plugin message is received
|
||||||
|
if (!channel.equals(BungeeHelper.getBungeeChannel())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Try to read the plugin message
|
||||||
|
String receivedMessage = BungeeHelper.readPluginMessage(message);
|
||||||
|
if (receivedMessage == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Use the message to initiate teleportation
|
||||||
|
BungeeHelper.handleTeleportMessage(receivedMessage);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
messenger.unregisterIncomingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
messenger.unregisterIncomingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
||||||
messenger.unregisterOutgoingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
messenger.unregisterOutgoingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.knarcraft.stargate.config;
|
package net.knarcraft.stargate.config.addons;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||||
@@ -74,7 +74,7 @@ public final class DynmapManager {
|
|||||||
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
World world = portal.getWorld();
|
World world = portal.getLocation().getWorld();
|
||||||
if (portal.getOptions().isHidden() || world == null) {
|
if (portal.getOptions().isHidden() || world == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ public final class DynmapManager {
|
|||||||
Location location;
|
Location location;
|
||||||
@Nullable RelativeBlockVector exit = portal.getGate().getLayout().getExit();
|
@Nullable RelativeBlockVector exit = portal.getGate().getLayout().getExit();
|
||||||
if (exit == null) {
|
if (exit == null) {
|
||||||
location = portal.getTopLeft();
|
location = portal.getLocation().getTopLeft();
|
||||||
} else {
|
} else {
|
||||||
location = portal.getBlockAt(exit);
|
location = portal.getBlockAt(exit);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package net.knarcraft.stargate.config;
|
package net.knarcraft.stargate.config.addons;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.config.ConfigOption;
|
||||||
|
import net.knarcraft.stargate.config.Permission;
|
||||||
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
@@ -218,7 +222,7 @@ public final class EconomyConfig {
|
|||||||
* @return <p>The cost of creating the gate</p>
|
* @return <p>The cost of creating the gate</p>
|
||||||
*/
|
*/
|
||||||
public int getCreateCost(@NotNull Player player, @NotNull Gate gate) {
|
public int getCreateCost(@NotNull Player player, @NotNull Gate gate) {
|
||||||
if (isFree(player, "create")) {
|
if (isFree(player, Permission.FREE_CREATION)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return gate.getCreateCost();
|
return gate.getCreateCost();
|
||||||
@@ -233,7 +237,7 @@ public final class EconomyConfig {
|
|||||||
* @return <p>The cost of destroying the gate</p>
|
* @return <p>The cost of destroying the gate</p>
|
||||||
*/
|
*/
|
||||||
public int getDestroyCost(@NotNull Player player, @NotNull Gate gate) {
|
public int getDestroyCost(@NotNull Player player, @NotNull Gate gate) {
|
||||||
if (isFree(player, "destroy")) {
|
if (isFree(player, Permission.FREE_DESTRUCTION)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return gate.getDestroyCost();
|
return gate.getDestroyCost();
|
||||||
@@ -243,12 +247,12 @@ public final class EconomyConfig {
|
|||||||
/**
|
/**
|
||||||
* Determines if a player can do a gate action for free
|
* Determines if a player can do a gate action for free
|
||||||
*
|
*
|
||||||
* @param player <p>The player to check</p>
|
* @param player <p>The player to check</p>
|
||||||
* @param permissionNode <p>The free.permissionNode necessary to allow free gate {action}</p>
|
* @param permission <p>The permission necessary to allow free gate {action}</p>
|
||||||
* @return <p></p>
|
* @return <p></p>
|
||||||
*/
|
*/
|
||||||
private boolean isFree(@NotNull Player player, @NotNull String permissionNode) {
|
private boolean isFree(@NotNull Player player, @NotNull Permission permission) {
|
||||||
return !useEconomy() || PermissionHelper.hasPermission(player, "stargate.free." + permissionNode);
|
return !useEconomy() || PermissionHelper.hasPermission(player, permission.getNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.knarcraft.stargate.config;
|
package net.knarcraft.stargate.config.formatting;
|
||||||
|
|
||||||
import net.knarcraft.knarlib.property.ColorConversion;
|
import net.knarcraft.knarlib.property.ColorConversion;
|
||||||
import net.knarcraft.knarlib.util.FileHelper;
|
import net.knarcraft.knarlib.util.FileHelper;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.knarcraft.stargate.config;
|
package net.knarcraft.stargate.config.formatting;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.knarcraft.stargate.config;
|
package net.knarcraft.stargate.config.formatting;
|
||||||
|
|
||||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
@@ -2,6 +2,7 @@ package net.knarcraft.stargate.container;
|
|||||||
|
|
||||||
import org.bukkit.Axis;
|
import org.bukkit.Axis;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
public class BlockChangeRequest {
|
public class BlockChangeRequest {
|
||||||
|
|
||||||
private final BlockLocation blockLocation;
|
private final Block blockLocation;
|
||||||
private final Material newMaterial;
|
private final Material newMaterial;
|
||||||
private final Axis newAxis;
|
private final Axis newAxis;
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ public class BlockChangeRequest {
|
|||||||
* @param material <p>The new material to change the block to</p>
|
* @param material <p>The new material to change the block to</p>
|
||||||
* @param axis <p>The new axis to orient the block along</p>
|
* @param axis <p>The new axis to orient the block along</p>
|
||||||
*/
|
*/
|
||||||
public BlockChangeRequest(@NotNull BlockLocation blockLocation, @NotNull Material material, @Nullable Axis axis) {
|
public BlockChangeRequest(@NotNull Block blockLocation, @NotNull Material material, @Nullable Axis axis) {
|
||||||
this.blockLocation = blockLocation;
|
this.blockLocation = blockLocation;
|
||||||
newMaterial = material;
|
newMaterial = material;
|
||||||
newAxis = axis;
|
newAxis = axis;
|
||||||
@@ -33,7 +34,7 @@ public class BlockChangeRequest {
|
|||||||
* @return <p>The location of the block</p>
|
* @return <p>The location of the block</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockLocation getBlockLocation() {
|
public Block getBlockLocation() {
|
||||||
return blockLocation;
|
return blockLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.bukkit.block.data.Directional;
|
|
||||||
import org.bukkit.block.data.type.Sign;
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -22,8 +18,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
public class BlockLocation extends Location {
|
public class BlockLocation extends Location {
|
||||||
|
|
||||||
private BlockLocation parent = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new block location
|
* Creates a new block location
|
||||||
*
|
*
|
||||||
@@ -148,50 +142,6 @@ public class BlockLocation extends Location {
|
|||||||
return this.clone();
|
return this.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets this block location's parent block
|
|
||||||
*
|
|
||||||
* <p>The parent block is the block the item at this block location is attached to. Usually this is the block a
|
|
||||||
* sign or wall sign is attached to.</p>
|
|
||||||
*
|
|
||||||
* @return <p>This block location's parent block</p>
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public Block getParent() {
|
|
||||||
if (parent == null) {
|
|
||||||
findParent();
|
|
||||||
}
|
|
||||||
if (parent == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return parent.getBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to find the parent block location
|
|
||||||
*
|
|
||||||
* <p>If this block location is a sign, the parent is the block location of the block the sign is connected to.</p>
|
|
||||||
*/
|
|
||||||
private void findParent() {
|
|
||||||
int offsetX = 0;
|
|
||||||
int offsetY = 0;
|
|
||||||
int offsetZ = 0;
|
|
||||||
|
|
||||||
BlockData blockData = getBlock().getBlockData();
|
|
||||||
if (blockData instanceof Directional) {
|
|
||||||
//Get the offset of the block "behind" this block
|
|
||||||
BlockFace facing = ((Directional) blockData).getFacing().getOppositeFace();
|
|
||||||
offsetX = facing.getModX();
|
|
||||||
offsetZ = facing.getModZ();
|
|
||||||
} else if (blockData instanceof Sign) {
|
|
||||||
//Get offset the block beneath the sign
|
|
||||||
offsetY = -1;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
parent = this.makeRelativeBlockLocation(offsetX, offsetY, offsetZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.knarcraft.stargate.container;
|
package net.knarcraft.stargate.container;
|
||||||
|
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -54,6 +55,15 @@ public record RelativeBlockVector(int right, int down, int out) {
|
|||||||
return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd);
|
return new RelativeBlockVector(this.right, this.down, this.out + valueToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a relative vector in the real space representing this relative block vector
|
||||||
|
*
|
||||||
|
* @return <p>A vector representing this relative block vector</p>
|
||||||
|
*/
|
||||||
|
public Vector toVector() {
|
||||||
|
return new Vector(this.right, -this.down, this.out);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a relative block vector which is this inverted (pointing in the opposite direction)
|
* Gets a relative block vector which is this inverted (pointing in the opposite direction)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener teleports a user if a valid message is received from BungeeCord
|
|
||||||
*
|
|
||||||
* <p>Specifically, if a string starts with SGBungee encoded to be readable by readUTF followed by
|
|
||||||
* [PlayerUUID]delimiter[DestinationPortal] is received on the BungeeCord channel, this listener will teleport the
|
|
||||||
* player to the destination portal.</p>
|
|
||||||
*/
|
|
||||||
public class BungeeCordListener implements PluginMessageListener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Receives plugin messages
|
|
||||||
*
|
|
||||||
* @param channel <p>The channel the message was received on</p>
|
|
||||||
* @param unused <p>Unused.</p>
|
|
||||||
* @param message <p>The message received from the plugin</p>
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player unused, byte[] message) {
|
|
||||||
//Ignore plugin messages if some other plugin message is received
|
|
||||||
if (!channel.equals(BungeeHelper.getBungeeChannel())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Try to read the plugin message
|
|
||||||
String receivedMessage = BungeeHelper.readPluginMessage(message);
|
|
||||||
if (receivedMessage == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Use the message to initiate teleportation
|
|
||||||
BungeeHelper.handleTeleportMessage(receivedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
|
||||||
import net.knarcraft.stargate.utility.EntityHelper;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
import org.bukkit.event.entity.EntityPortalEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener listens for any relevant events on portal entities
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class EntityEventListener implements Listener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event handler prevents sending entities to the normal nether instead of the stargate target
|
|
||||||
*
|
|
||||||
* @param event <p>The event to check and possibly cancel</p>
|
|
||||||
*/
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPortalEvent(@NotNull EntityPortalEvent event) {
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = event.getEntity();
|
|
||||||
//Cancel normal portal event is near a stargate
|
|
||||||
if (PortalHandler.getByAdjacentEntrance(event.getFrom(), EntityHelper.getEntityMaxSizeInt(entity)) != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method catches any explosion events
|
|
||||||
*
|
|
||||||
* <p>If destroyed by explosions is enabled, any portals destroyed by the explosion will be unregistered. If not,
|
|
||||||
* the explosion will be cancelled.</p>
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered explosion event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onEntityExplode(@NotNull EntityExplodeEvent event) {
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (Block block : event.blockList()) {
|
|
||||||
Portal portal = PortalHandler.getByBlock(block);
|
|
||||||
if (portal == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (Stargate.getGateConfig().destroyedByExplosion()) {
|
|
||||||
PortalRegistry.unregisterPortal(portal, true);
|
|
||||||
} else {
|
|
||||||
event.setCancelled(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A listener that listens for any relevant events causing entities to spawn
|
|
||||||
*/
|
|
||||||
public class EntitySpawnListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onCreatureSpawn(@NotNull CreatureSpawnEvent event) {
|
|
||||||
//Prevent Zombified Piglins and other creatures form spawning at stargates
|
|
||||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL &&
|
|
||||||
PortalHandler.getByEntrance(event.getLocation()) != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
Stargate.debug("EntitySpawnListener", "Prevented creature from spawning at Stargate");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package net.knarcraft.stargate.listener;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.config.StargateConfig;
|
||||||
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
|
import org.bukkit.event.world.WorldUnloadEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This listener listens for any plugins/worlds being enabled or disabled
|
||||||
|
*/
|
||||||
|
public class EnvironmentChangeListener implements Listener {
|
||||||
|
|
||||||
|
private final Stargate stargate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new plugin event listener
|
||||||
|
*
|
||||||
|
* @param stargate <p>A reference to the stargate plugin to </p>
|
||||||
|
*/
|
||||||
|
public EnvironmentChangeListener(@NotNull Stargate stargate) {
|
||||||
|
this.stargate = stargate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event listens for and announces that the vault plugin was detected and enabled
|
||||||
|
*
|
||||||
|
* <p>Each time this event is called, the economy handler will try to enable vault</p>
|
||||||
|
*
|
||||||
|
* @param ignored <p>The actual event called. This is currently not used</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginEnable(@NotNull PluginEnableEvent ignored) {
|
||||||
|
if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) {
|
||||||
|
Plugin vault = Stargate.getEconomyConfig().getVault();
|
||||||
|
if (vault != null) {
|
||||||
|
String vaultVersion = vault.getDescription().getVersion();
|
||||||
|
Stargate.logInfo(new SGFormatBuilder(Message.VAULT_LOADED).replace("%version%", vaultVersion).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event listens for the vault plugin being disabled and notifies the console
|
||||||
|
*
|
||||||
|
* @param event <p>The event caused by disabling a plugin</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginDisable(@NotNull PluginDisableEvent event) {
|
||||||
|
if (event.getPlugin().equals(Stargate.getEconomyConfig().getVault())) {
|
||||||
|
Stargate.logInfo("Vault plugin lost.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This listener listens for the loading of a world and loads all gates from the world if not already loaded
|
||||||
|
*
|
||||||
|
* @param event <p>The triggered world load event</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onWorldLoad(@NotNull WorldLoadEvent event) {
|
||||||
|
StargateConfig config = Stargate.getStargateConfig();
|
||||||
|
if (!config.getManagedWorlds().contains(event.getWorld().getName()) &&
|
||||||
|
PortalFileHelper.loadAllPortals(event.getWorld())) {
|
||||||
|
config.addManagedWorld(event.getWorld().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This listener listens for the unloading of a world
|
||||||
|
*
|
||||||
|
* @param event <p>The triggered world unload event</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onWorldUnload(@NotNull WorldUnloadEvent event) {
|
||||||
|
Stargate.debug("onWorldUnload", "Reloading all Stargates");
|
||||||
|
World world = event.getWorld();
|
||||||
|
String worldName = world.getName();
|
||||||
|
StargateConfig config = Stargate.getStargateConfig();
|
||||||
|
if (config.getManagedWorlds().contains(worldName)) {
|
||||||
|
config.removeManagedWorld(worldName);
|
||||||
|
PortalRegistry.clearPortals(world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,59 +3,42 @@ package net.knarcraft.stargate.listener;
|
|||||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||||
import net.knarcraft.knarlib.util.UpdateChecker;
|
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.Permission;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalActivator;
|
import net.knarcraft.stargate.portal.PortalActivator;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
|
||||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.type.WallSign;
|
import org.bukkit.block.data.type.WallSign;
|
||||||
import org.bukkit.entity.AbstractHorse;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Vehicle;
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import org.geysermc.floodgate.api.FloodgateApi;
|
|
||||||
import org.geysermc.geyser.api.GeyserApi;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This listener listens to any player-related events related to stargates
|
* This listener listens to any player-related events related to stargates
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class PlayerEventListener implements Listener {
|
public class PlayerEventListener implements Listener {
|
||||||
|
|
||||||
private static final Map<Player, Long> previousEventTimes = new HashMap<>();
|
private static final Map<Player, Long> previousEventTimes = new HashMap<>();
|
||||||
private boolean hasGeyser = true;
|
|
||||||
private boolean hasFloodgate = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event handler handles detection of any player teleporting through a bungee gate
|
* This event handler handles detection of any player teleporting through a bungee gate
|
||||||
@@ -71,7 +54,7 @@ public class PlayerEventListener implements Listener {
|
|||||||
//Notify joining admins about the available update
|
//Notify joining admins about the available update
|
||||||
String availableUpdate = Stargate.getUpdateAvailable();
|
String availableUpdate = Stargate.getUpdateAvailable();
|
||||||
if (availableUpdate != null && Stargate.getStargateConfig().alertAdminsAboutUpdates() &&
|
if (availableUpdate != null && Stargate.getStargateConfig().alertAdminsAboutUpdates() &&
|
||||||
player.hasPermission("stargate.admin")) {
|
PermissionHelper.hasPermission(player, Permission.ADMIN)) {
|
||||||
String updateMessage = UpdateChecker.getUpdateAvailableString(availableUpdate, Stargate.getPluginVersion());
|
String updateMessage = UpdateChecker.getUpdateAvailableString(availableUpdate, Stargate.getPluginVersion());
|
||||||
new SGFormatBuilder(updateMessage).error(player);
|
new SGFormatBuilder(updateMessage).error(player);
|
||||||
}
|
}
|
||||||
@@ -87,7 +70,7 @@ public class PlayerEventListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Portal portal = PortalHandler.getBungeePortal(destination);
|
Portal portal = PortalUtil.getBungeePortal(destination);
|
||||||
if (portal == null) {
|
if (portal == null) {
|
||||||
Stargate.debug("PlayerJoin", "Error fetching destination portal: " + destination);
|
Stargate.debug("PlayerJoin", "Error fetching destination portal: " + destination);
|
||||||
return;
|
return;
|
||||||
@@ -96,198 +79,6 @@ public class PlayerEventListener implements Listener {
|
|||||||
new PlayerTeleporter(portal, player).teleport(portal, null);
|
new PlayerTeleporter(portal, player).teleport(portal, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This event handler detects if a player moves into a portal
|
|
||||||
*
|
|
||||||
* @param event <p>The player move event which was triggered</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
|
||||||
if (event.isCancelled() || event.getTo() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockLocation fromLocation = new BlockLocation(event.getFrom().getBlock());
|
|
||||||
BlockLocation toLocation = new BlockLocation(event.getTo().getBlock());
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
|
|
||||||
//Check whether the event needs to be considered
|
|
||||||
if (!isRelevantMoveEvent(event, player, fromLocation, toLocation)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
|
||||||
//Check an additional block away in case the portal is a bungee portal using END_PORTAL
|
|
||||||
if (entrancePortal == null) {
|
|
||||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
|
||||||
// This should never realistically be null
|
|
||||||
if (entrancePortal == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
|
||||||
if (destination == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity playerVehicle = player.getVehicle();
|
|
||||||
//If the player is in a vehicle, but vehicle handling is disabled, just ignore the player
|
|
||||||
if (playerVehicle == null || (playerVehicle instanceof LivingEntity &&
|
|
||||||
Stargate.getGateConfig().handleVehicles())) {
|
|
||||||
teleportPlayer(playerVehicle, player, entrancePortal, destination, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Teleports a player, also teleports the player's vehicle if it's a living entity
|
|
||||||
*
|
|
||||||
* @param playerVehicle <p>The vehicle the player is currently sitting in</p>
|
|
||||||
* @param player <p>The player which moved</p>
|
|
||||||
* @param entrancePortal <p>The entrance the player entered</p>
|
|
||||||
* @param destination <p>The destination of the entrance portal</p>
|
|
||||||
* @param event <p>The move event causing the teleportation to trigger</p>
|
|
||||||
*/
|
|
||||||
private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal,
|
|
||||||
@NotNull Portal destination, @NotNull PlayerMoveEvent event) {
|
|
||||||
if (playerVehicle instanceof LivingEntity) {
|
|
||||||
//Make sure any horses are properly tamed
|
|
||||||
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
|
|
||||||
horse.setTamed(true);
|
|
||||||
horse.setOwner(player);
|
|
||||||
}
|
|
||||||
//Teleport the player's vehicle
|
|
||||||
player.setVelocity(new Vector());
|
|
||||||
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal);
|
|
||||||
} else {
|
|
||||||
//Just teleport the player like normal
|
|
||||||
new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event);
|
|
||||||
}
|
|
||||||
if (!entrancePortal.getOptions().isQuiet()) {
|
|
||||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
|
||||||
}
|
|
||||||
entrancePortal.getPortalOpener().closePortal(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether a player move event is relevant for this plugin
|
|
||||||
*
|
|
||||||
* @param event <p>The player move event to check</p>
|
|
||||||
* @param player <p>The player which moved</p>
|
|
||||||
* @param fromLocation <p>The location the player is moving from</p>
|
|
||||||
* @param toLocation <p>The location the player is moving to</p>
|
|
||||||
* @return <p>True if the event is relevant</p>
|
|
||||||
*/
|
|
||||||
private boolean isRelevantMoveEvent(@NotNull PlayerMoveEvent event, Player player,
|
|
||||||
@NotNull BlockLocation fromLocation, @NotNull BlockLocation toLocation) {
|
|
||||||
//Check to see if the player moved to another block
|
|
||||||
if (fromLocation.equals(toLocation)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the portal the player entered, if any
|
|
||||||
Portal entrancePortal = getEnteredPortal(toLocation, player);
|
|
||||||
if (entrancePortal == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
|
||||||
|
|
||||||
//Catch always open portals without a valid destination to prevent the user for being teleported and denied
|
|
||||||
if (!entrancePortal.getOptions().isBungee() && destination == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Decide if the anything stops the player from teleport
|
|
||||||
if (PermissionHelper.playerCannotTeleport(entrancePortal, destination, player, event)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Decide if the user should be teleported to another bungee server
|
|
||||||
if (entrancePortal.getOptions().isBungee()) {
|
|
||||||
if (BungeeHelper.bungeeTeleport(player, entrancePortal, event) && !entrancePortal.getOptions().isQuiet()) {
|
|
||||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Make sure to check if the player has any leashed creatures, even though leashed teleportation is disabled
|
|
||||||
return TeleportHelper.noLeashedCreaturesPreventTeleportation(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the portal a player entered
|
|
||||||
*
|
|
||||||
* @param toLocation <p>The location the player moved to</p>
|
|
||||||
* @param player <p>The player that moved</p>
|
|
||||||
* @return <p>The portal the player entered, or null if no portal was entered</p>
|
|
||||||
*/
|
|
||||||
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
|
|
||||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
|
||||||
// Return if in an entrance
|
|
||||||
if (entrancePortal != null) {
|
|
||||||
return entrancePortal;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check an additional block away for special cases like BungeeCord portals using END_PORTAL as its material
|
|
||||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
|
||||||
if (entrancePortal == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
|
|
||||||
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
|
|
||||||
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the real materials in the entrance, as END_GATEWAY or END_PORTAL may be available, but not chosen
|
|
||||||
Set<Material> materialsInEntrance = new HashSet<>();
|
|
||||||
for (BlockLocation location : entrancePortal.getStructure().getEntrances()) {
|
|
||||||
materialsInEntrance.add(location.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Abort if not a special case
|
|
||||||
if ((!materialsInEntrance.contains(Material.END_GATEWAY) || !isGeyserPlayer(player)) &&
|
|
||||||
(!entrancePortal.getOptions().isBungee() || !materialsInEntrance.contains(Material.END_PORTAL))) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entrancePortal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the given player is connected through Geyser
|
|
||||||
*
|
|
||||||
* @param player <p>The player to check</p>
|
|
||||||
* @return <p>True if the player is connected through Geyser</p>
|
|
||||||
*/
|
|
||||||
private boolean isGeyserPlayer(@NotNull Player player) {
|
|
||||||
// Prevent unnecessary checking for non-geyser and floodgate servers
|
|
||||||
if (!hasGeyser && !hasFloodgate) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use Geyser API to get connection status
|
|
||||||
if (hasGeyser) {
|
|
||||||
try {
|
|
||||||
return GeyserApi.api().connectionByUuid(player.getUniqueId()) != null;
|
|
||||||
} catch (NoClassDefFoundError error1) {
|
|
||||||
hasGeyser = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use Floodgate API to get connection status
|
|
||||||
if (hasFloodgate) {
|
|
||||||
try {
|
|
||||||
return FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
|
|
||||||
} catch (NoClassDefFoundError error2) {
|
|
||||||
hasFloodgate = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event handler detects if a player clicks a button or a sign
|
* This event handler detects if a player clicks a button or a sign
|
||||||
*
|
*
|
||||||
@@ -324,7 +115,7 @@ public class PlayerEventListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
private void handleSignClick(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull Block block,
|
private void handleSignClick(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull Block block,
|
||||||
boolean leftClick) {
|
boolean leftClick) {
|
||||||
Portal portal = PortalHandler.getByBlock(block);
|
Portal portal = PortalUtil.getByBlock(block);
|
||||||
if (portal == null) {
|
if (portal == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -372,7 +163,7 @@ public class PlayerEventListener implements Listener {
|
|||||||
private boolean dyeSign(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull Portal portal) {
|
private boolean dyeSign(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull Portal portal) {
|
||||||
EquipmentSlot hand = event.getHand();
|
EquipmentSlot hand = event.getHand();
|
||||||
// Check if the player is allowed to dye the sign
|
// Check if the player is allowed to dye the sign
|
||||||
if (hand == null || (!PermissionHelper.hasPermission(player, "stargate.admin.dye") &&
|
if (hand == null || (!PermissionHelper.hasPermission(player, Permission.DYE_SIGN) &&
|
||||||
!portal.isOwner(player))) {
|
!portal.isOwner(player))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -434,7 +225,7 @@ public class PlayerEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MaterialHelper.isButtonCompatible(block.getType())) {
|
if (MaterialHelper.isButtonCompatible(block.getType())) {
|
||||||
Portal portal = PortalHandler.getByBlock(block);
|
Portal portal = PortalUtil.getByBlock(block);
|
||||||
if (portal == null) {
|
if (portal == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -470,7 +261,7 @@ public class PlayerEventListener implements Listener {
|
|||||||
* @param player <p>The player that clicked the block</p>
|
* @param player <p>The player that clicked the block</p>
|
||||||
*/
|
*/
|
||||||
private void displayPortalInfo(@NotNull Block block, @NotNull Player player) {
|
private void displayPortalInfo(@NotNull Block block, @NotNull Player player) {
|
||||||
Portal portal = PortalHandler.getByBlock(block);
|
Portal portal = PortalUtil.getByBlock(block);
|
||||||
if (portal == null) {
|
if (portal == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
|
||||||
import net.knarcraft.stargate.config.Message;
|
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener listens for any plugins being enabled or disabled to catch the loading of vault
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class PluginEventListener implements Listener {
|
|
||||||
|
|
||||||
private final Stargate stargate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new plugin event listener
|
|
||||||
*
|
|
||||||
* @param stargate <p>A reference to the stargate plugin to </p>
|
|
||||||
*/
|
|
||||||
public PluginEventListener(@NotNull Stargate stargate) {
|
|
||||||
this.stargate = stargate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event listens for and announces that the vault plugin was detected and enabled
|
|
||||||
*
|
|
||||||
* <p>Each time this event is called, the economy handler will try to enable vault</p>
|
|
||||||
*
|
|
||||||
* @param ignored <p>The actual event called. This is currently not used</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginEnable(@NotNull PluginEnableEvent ignored) {
|
|
||||||
if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) {
|
|
||||||
Plugin vault = Stargate.getEconomyConfig().getVault();
|
|
||||||
if (vault != null) {
|
|
||||||
String vaultVersion = vault.getDescription().getVersion();
|
|
||||||
Stargate.logInfo(new SGFormatBuilder(Message.VAULT_LOADED).replace("%version%", vaultVersion).toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event listens for the vault plugin being disabled and notifies the console
|
|
||||||
*
|
|
||||||
* @param event <p>The event caused by disabling a plugin</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginDisable(@NotNull PluginDisableEvent event) {
|
|
||||||
if (event.getPlugin().equals(Stargate.getEconomyConfig().getVault())) {
|
|
||||||
Stargate.logInfo("Vault plugin lost.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
|
||||||
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityPortalEnterEvent;
|
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
|
||||||
import org.bukkit.event.world.PortalCreateEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listens for and cancels relevant portal events
|
|
||||||
*/
|
|
||||||
public class PortalEventListener implements Listener {
|
|
||||||
|
|
||||||
private static final Map<Player, FromTheEndTeleportation> playersFromTheEnd = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listens for and aborts vanilla portal creation caused by stargate creation
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onPortalCreation(@NotNull PortalCreateEvent event) {
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Unnecessary nether portal creation is only triggered by nether pairing
|
|
||||||
if (event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR) {
|
|
||||||
//If an entity is standing in a Stargate entrance, it can be assumed that the creation is a mistake
|
|
||||||
Entity entity = event.getEntity();
|
|
||||||
if (entity != null && PortalHandler.getByAdjacentEntrance(entity.getLocation()) != null) {
|
|
||||||
Stargate.debug("PortalEventListener::onPortalCreation",
|
|
||||||
"Cancelled nether portal create event");
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listen for entities entering an artificial end portal
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onEntityPortalEnter(@NotNull EntityPortalEnterEvent event) {
|
|
||||||
Location location = event.getLocation();
|
|
||||||
World world = location.getWorld();
|
|
||||||
Entity entity = event.getEntity();
|
|
||||||
|
|
||||||
//Hijack normal portal teleportation if teleporting from a stargate, and teleporting from an end portal in the
|
|
||||||
// end
|
|
||||||
if (!(entity instanceof Player player) || location.getBlock().getType() != Material.END_PORTAL ||
|
|
||||||
world == null || world.getEnvironment() != World.Environment.THE_END) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Portal portal = PortalHandler.getByAdjacentEntrance(location);
|
|
||||||
if (portal == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
|
||||||
"Found player " + player + " entering END_PORTAL " + portal);
|
|
||||||
|
|
||||||
//Decide if the anything stops the player from teleporting
|
|
||||||
if (PermissionHelper.playerCannotTeleport(portal, portal.getPortalActivator().getDestination(),
|
|
||||||
player, null) || portal.getOptions().isBungee()) {
|
|
||||||
//Teleport the player back to the portal they came in, just in case
|
|
||||||
playersFromTheEnd.put(player, new FromTheEndTeleportation(portal));
|
|
||||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
|
||||||
"Sending player back to the entrance");
|
|
||||||
} else {
|
|
||||||
Portal destination = portal.getPortalActivator().getDestination();
|
|
||||||
if (destination != null) {
|
|
||||||
playersFromTheEnd.put(player, new FromTheEndTeleportation(destination));
|
|
||||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
|
||||||
"Sending player to destination");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listen for the respawn event to catch players teleporting from the end in an artificial end portal
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onRespawn(@NotNull PlayerRespawnEvent event) {
|
|
||||||
Player respawningPlayer = event.getPlayer();
|
|
||||||
FromTheEndTeleportation teleportation = playersFromTheEnd.remove(respawningPlayer);
|
|
||||||
if (teleportation == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Portal exitPortal = teleportation.exitPortal();
|
|
||||||
|
|
||||||
//Overwrite respawn location to respawn in front of the portal
|
|
||||||
PlayerTeleporter teleporter = new PlayerTeleporter(exitPortal, respawningPlayer);
|
|
||||||
Location respawnLocation = teleporter.getExit();
|
|
||||||
event.setRespawnLocation(respawnLocation);
|
|
||||||
//Try and force the player if for some reason the changing of respawn location isn't properly handled
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () ->
|
|
||||||
respawningPlayer.teleport(respawnLocation), 1);
|
|
||||||
|
|
||||||
//Properly close the portal to prevent it from staying in a locked state until it times out
|
|
||||||
exitPortal.getPortalOpener().closePortal(false);
|
|
||||||
|
|
||||||
Stargate.debug("PortalEventListener::onRespawn", "Overwriting respawn for " + respawningPlayer +
|
|
||||||
" to " + respawnLocation.getWorld() + ":" + respawnLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,267 @@
|
|||||||
|
package net.knarcraft.stargate.listener;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.data.Directional;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBurnEvent;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
import org.bukkit.event.block.BlockExplodeEvent;
|
||||||
|
import org.bukkit.event.block.BlockFadeEvent;
|
||||||
|
import org.bukkit.event.block.BlockFertilizeEvent;
|
||||||
|
import org.bukkit.event.block.BlockFormEvent;
|
||||||
|
import org.bukkit.event.block.BlockFromToEvent;
|
||||||
|
import org.bukkit.event.block.BlockIgniteEvent;
|
||||||
|
import org.bukkit.event.block.BlockMultiPlaceEvent;
|
||||||
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
|
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||||
|
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||||
|
import org.bukkit.event.block.LeavesDecayEvent;
|
||||||
|
import org.bukkit.event.block.SpongeAbsorbEvent;
|
||||||
|
import org.bukkit.event.block.TNTPrimeEvent;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
import org.bukkit.event.entity.EntityBreakDoorEvent;
|
||||||
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.EntityPlaceEvent;
|
||||||
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
|
import org.bukkit.event.world.PortalCreateEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A listener for any events that might cause a Stargate to be altered or break
|
||||||
|
*/
|
||||||
|
public class StargateBreakListener implements Listener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels blocks from being placed in the Stargate's entrance
|
||||||
|
*
|
||||||
|
* @param event <p>The event to check and possibly cancel</p>
|
||||||
|
*/
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onBlockPlace(@NotNull BlockPlaceEvent event) {
|
||||||
|
if (!Stargate.getGateConfig().protectEntrance()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Block block = event.getBlock();
|
||||||
|
Portal portal = PortalUtil.getByEntrance(block);
|
||||||
|
if (portal != null) {
|
||||||
|
//Prevent blocks from being placed in the entrance, if protectEntrance is enabled, as breaking the block
|
||||||
|
// would destroy the portal
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method catches any explosion events
|
||||||
|
*
|
||||||
|
* <p>If destroyed by explosions is enabled, any portals destroyed by the explosion will be unregistered. If not,
|
||||||
|
* the explosion will be cancelled.</p>
|
||||||
|
*
|
||||||
|
* @param event <p>The triggered explosion event</p>
|
||||||
|
*/
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityExplode(@NotNull EntityExplodeEvent event) {
|
||||||
|
for (Block block : event.blockList()) {
|
||||||
|
Portal portal = PortalUtil.getByBlock(block);
|
||||||
|
if (portal == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Stargate.getGateConfig().destroyedByExplosion()) {
|
||||||
|
PortalRegistry.unregisterPortal(portal, true);
|
||||||
|
} else {
|
||||||
|
event.setCancelled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onCreatureSpawn(@NotNull CreatureSpawnEvent event) {
|
||||||
|
//Prevent Zombified Piglins and other creatures form spawning at stargates
|
||||||
|
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL &&
|
||||||
|
PortalUtil.getByEntrance(event.getLocation()) != null) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Stargate.debug("EntitySpawnListener", "Prevented creature from spawning at Stargate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||||
|
cancelPistonIfNeeded(event.getBlocks(), event.getDirection(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPistonRetract(@NotNull BlockPistonRetractEvent event) {
|
||||||
|
cancelPistonIfNeeded(event.getBlocks(), event.getDirection(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockExplode(@NotNull BlockExplodeEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.blockList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockFromTo(@NotNull BlockFromToEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getToBlock());
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockFormEvent(@NotNull BlockFormEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockPhysics(@NotNull BlockPhysicsEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockBurn(@NotNull BlockBurnEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockIgnite(@NotNull BlockIgniteEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockFade(@NotNull BlockFadeEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockFertilize(@NotNull BlockFertilizeEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockMultiPlace(@NotNull BlockMultiPlaceEvent event) {
|
||||||
|
cancelIfAtEntrance(event, getBlocksFromBlockStates(event.getReplacedBlockStates()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onEntityBlockForm(@NotNull EntityBlockFormEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onLeavesDecay(@NotNull LeavesDecayEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onSpongeAbsorb(@NotNull SpongeAbsorbEvent event) {
|
||||||
|
cancelIfAtEntrance(event, getBlocksFromBlockStates(event.getBlocks()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onEntityChangeBlock(@NotNull EntityChangeBlockEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onEntityBreakDoor(@NotNull EntityBreakDoorEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPortalCreate(@NotNull PortalCreateEvent event) {
|
||||||
|
cancelIfAtEntrance(event, getBlocksFromBlockStates(event.getBlocks()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onEntityPlace(@NotNull EntityPlaceEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerBucketEmpty(@NotNull PlayerBucketEmptyEvent event) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBlockDispense(@NotNull BlockDispenseEvent event) {
|
||||||
|
if (event.getBlock().getBlockData() instanceof Directional dispenser) {
|
||||||
|
cancelIfAtEntrance(event, event.getBlock().getRelative(dispenser.getFacing()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onTNTPrime(@NotNull TNTPrimeEvent tntPrimeEvent) {
|
||||||
|
cancelIfAtEntrance(tntPrimeEvent, tntPrimeEvent.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the given event if it involves a Stargate's entrance
|
||||||
|
*
|
||||||
|
* @param event <p>The event to cancel</p>
|
||||||
|
* @param block <p>The block in question</p>
|
||||||
|
*/
|
||||||
|
private boolean cancelIfAtEntrance(@NotNull Cancellable event, @NotNull Block block) {
|
||||||
|
if (PortalUtil.getByEntrance(block) != null || PortalUtil.getByControl(block) != null ||
|
||||||
|
PortalUtil.getByBlock(block) != null) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the given event if it involves a Stargate's entrance
|
||||||
|
*
|
||||||
|
* @param event <p>The event to cancel</p>
|
||||||
|
* @param blocks <p>The blocks in question</p>
|
||||||
|
*/
|
||||||
|
private void cancelIfAtEntrance(@NotNull Cancellable event, @NotNull List<Block> blocks) {
|
||||||
|
for (Block block : blocks) {
|
||||||
|
if (cancelIfAtEntrance(event, block)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of blocks from a list of block states
|
||||||
|
*
|
||||||
|
* @param blockStates <p>The block states to convert into blocks</p>
|
||||||
|
* @return <p>The corresponding blocks</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private List<Block> getBlocksFromBlockStates(@NotNull List<BlockState> blockStates) {
|
||||||
|
return blockStates.stream().map(BlockState::getBlock).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the movement of a piston if it would interfere with a Stargate
|
||||||
|
*
|
||||||
|
* @param blocks <p>The blocks involved in the move</p>
|
||||||
|
* @param blockFace <p>The block face of the piston</p>
|
||||||
|
* @param event <p>The event to possibly cancel</p>
|
||||||
|
*/
|
||||||
|
private void cancelPistonIfNeeded(@NotNull List<Block> blocks, @NotNull BlockFace blockFace,
|
||||||
|
@NotNull Cancellable event) {
|
||||||
|
cancelIfAtEntrance(event, blocks);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Block> movedBlocks = blocks.stream().map(block -> block.getRelative(blockFace)).toList();
|
||||||
|
cancelIfAtEntrance(event, movedBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,68 +1,33 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
package net.knarcraft.stargate.listener;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.container.BlockLocation;
|
||||||
import net.knarcraft.stargate.event.StargateDestroyEvent;
|
import net.knarcraft.stargate.event.StargateDestroyEvent;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalCreator;
|
import net.knarcraft.stargate.portal.PortalCreator;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.type.WallSign;
|
import org.bukkit.block.data.type.WallSign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Snowman;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
|
||||||
import org.bukkit.event.block.BlockPistonEvent;
|
|
||||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
|
||||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for listening to relevant block events related to creating and breaking portals
|
* This class is responsible for listening to relevant block events related to creating and breaking portals
|
||||||
*/
|
*/
|
||||||
public class BlockEventListener implements Listener {
|
public class StargateCreateDestroyListener implements Listener {
|
||||||
|
|
||||||
/**
|
|
||||||
* Detects snowmen ruining portals
|
|
||||||
*
|
|
||||||
* <p>If entrance protection or portal verification is enabled, the snowman will be prevented from placing snow in
|
|
||||||
* the portal entrance.</p>
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onBlockFormedByEntity(@NotNull EntityBlockFormEvent event) {
|
|
||||||
if ((!Stargate.getGateConfig().protectEntrance() &&
|
|
||||||
!Stargate.getGateConfig().verifyPortals())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//We are only interested in snowman events
|
|
||||||
if (!(event.getEntity() instanceof Snowman)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Cancel the event if a snowman is trying to place snow in the portal's entrance
|
|
||||||
if (PortalHandler.getByEntrance(event.getBlock()) != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects sign changes to detect if the user is creating a new gate
|
* Detects sign changes to detect if the user is creating a new gate
|
||||||
@@ -86,8 +51,8 @@ public class BlockEventListener implements Listener {
|
|||||||
|
|
||||||
//Remove the sign if the no sign option is enabled
|
//Remove the sign if the no sign option is enabled
|
||||||
if (portal.getOptions().hasNoSign()) {
|
if (portal.getOptions().hasNoSign()) {
|
||||||
Material replaceMaterial = PortalFileHelper.decideRemovalMaterial(portal.getSignLocation(), portal);
|
Material replaceMaterial = PortalFileHelper.decideRemovalMaterial(portal.getLocation().getSignBlock(), portal);
|
||||||
BlockChangeRequest request = new BlockChangeRequest(portal.getSignLocation(), replaceMaterial, null);
|
BlockChangeRequest request = new BlockChangeRequest(portal.getLocation().getSignBlock(), replaceMaterial, null);
|
||||||
Stargate.addControlBlockUpdateRequest(request);
|
Stargate.addControlBlockUpdateRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,20 +62,6 @@ public class BlockEventListener implements Listener {
|
|||||||
portal::drawSign, 1);
|
portal::drawSign, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
|
||||||
public void onBlockPlace(@NotNull BlockPlaceEvent event) {
|
|
||||||
if (!Stargate.getGateConfig().protectEntrance()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Block block = event.getBlock();
|
|
||||||
Portal portal = PortalHandler.getByEntrance(block);
|
|
||||||
if (portal != null) {
|
|
||||||
//Prevent blocks from being placed in the entrance, if protectEntrance is enabled, as breaking the block
|
|
||||||
// would destroy the portal
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects block breaking to detect if the user is destroying a gate
|
* Detects block breaking to detect if the user is destroying a gate
|
||||||
*
|
*
|
||||||
@@ -122,9 +73,9 @@ public class BlockEventListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
//Decide if a portal is broken
|
//Decide if a portal is broken
|
||||||
Portal portal = PortalHandler.getByBlock(block);
|
Portal portal = PortalUtil.getByBlock(block);
|
||||||
if (portal == null && Stargate.getGateConfig().protectEntrance()) {
|
if (portal == null && Stargate.getGateConfig().protectEntrance()) {
|
||||||
portal = PortalHandler.getByEntrance(block);
|
portal = PortalUtil.getByEntrance(block);
|
||||||
}
|
}
|
||||||
if (portal == null) {
|
if (portal == null) {
|
||||||
return;
|
return;
|
||||||
@@ -206,77 +157,4 @@ public class BlockEventListener implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevents any block physics events which may damage parts of the portal
|
|
||||||
*
|
|
||||||
* @param event <p>The event to check and possibly cancel</p>
|
|
||||||
*/
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onBlockPhysics(@NotNull BlockPhysicsEvent event) {
|
|
||||||
Block block = event.getBlock();
|
|
||||||
Portal portal = null;
|
|
||||||
|
|
||||||
if (block.getType() == Material.NETHER_PORTAL) {
|
|
||||||
portal = PortalHandler.getByEntrance(block);
|
|
||||||
} else if (MaterialHelper.isButtonCompatible(block.getType())) {
|
|
||||||
portal = PortalHandler.getByControl(block);
|
|
||||||
}
|
|
||||||
if (portal != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels any block move events which may cause a block to enter the opening of a portal
|
|
||||||
*
|
|
||||||
* @param event <p>The event to check and possibly cancel</p>
|
|
||||||
*/
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onBlockFromTo(@NotNull BlockFromToEvent event) {
|
|
||||||
Portal portal = PortalHandler.getByEntrance(event.getBlock());
|
|
||||||
|
|
||||||
if (portal != null && event.getBlock().getY() == event.getToBlock().getY()) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels any piston extend events if the target block is part of a portal
|
|
||||||
*
|
|
||||||
* @param event <p>The event to check and possibly cancel</p>
|
|
||||||
*/
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onPistonExtend(@NotNull BlockPistonExtendEvent event) {
|
|
||||||
cancelPistonEvent(event, event.getBlocks());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels any piston retract events if the target block is part of a portal
|
|
||||||
*
|
|
||||||
* @param event <p>The event to check and possibly cancel</p>
|
|
||||||
*/
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onPistonRetract(@NotNull BlockPistonRetractEvent event) {
|
|
||||||
if (!event.isSticky()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cancelPistonEvent(event, event.getBlocks());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels a piston event if it would destroy a portal
|
|
||||||
*
|
|
||||||
* @param event <p>The event to cancel</p>
|
|
||||||
* @param blocks <p>The blocks included in the event</p>
|
|
||||||
*/
|
|
||||||
private void cancelPistonEvent(@NotNull BlockPistonEvent event, @NotNull List<Block> blocks) {
|
|
||||||
for (Block block : blocks) {
|
|
||||||
Portal portal = PortalHandler.getByBlock(block);
|
|
||||||
if (portal != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,530 @@
|
|||||||
|
package net.knarcraft.stargate.listener;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
|
import net.knarcraft.stargate.container.BlockLocation;
|
||||||
|
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
||||||
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
|
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||||
|
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||||
|
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||||
|
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||||
|
import net.knarcraft.stargate.utility.EntityHelper;
|
||||||
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
|
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.AbstractHorse;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Vehicle;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityPortalEnterEvent;
|
||||||
|
import org.bukkit.event.entity.EntityPortalEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import org.geysermc.floodgate.api.FloodgateApi;
|
||||||
|
import org.geysermc.geyser.api.GeyserApi;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This listener listens for the vehicle move event to teleport vehicles through portals
|
||||||
|
*/
|
||||||
|
public class StargateTeleportListener implements Listener {
|
||||||
|
|
||||||
|
private static final Map<Player, FromTheEndTeleportation> playersFromTheEnd = new HashMap<>();
|
||||||
|
private boolean hasGeyser = true;
|
||||||
|
private boolean hasFloodgate = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event handler handles some special teleportation events
|
||||||
|
*
|
||||||
|
* <p>This event cancels nether portal, end gateway and end portal teleportation if the user teleported from a
|
||||||
|
* stargate entrance. This prevents the user from just teleporting to the nether or the end with portals using
|
||||||
|
* the special teleportation blocks.</p>
|
||||||
|
*
|
||||||
|
* @param event <p>The event to check and possibly cancel</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
|
||||||
|
PlayerTeleportEvent.TeleportCause cause = event.getCause();
|
||||||
|
|
||||||
|
//Block normal portal teleportation if teleporting from a stargate
|
||||||
|
if (!event.isCancelled() && (cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
|
||||||
|
cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY ||
|
||||||
|
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
|
||||||
|
&& PortalUtil.getByAdjacentEntrance(event.getFrom()) != null) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event handler prevents sending entities to the normal nether instead of the stargate target
|
||||||
|
*
|
||||||
|
* @param event <p>The event to check and possibly cancel</p>
|
||||||
|
*/
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPortalEvent(@NotNull EntityPortalEvent event) {
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity entity = event.getEntity();
|
||||||
|
//Cancel normal portal event is near a stargate
|
||||||
|
if (PortalUtil.getByAdjacentEntrance(event.getFrom(), EntityHelper.getEntityMaxSizeInt(entity)) != null) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for a vehicle moving through a portal
|
||||||
|
*
|
||||||
|
* @param event <p>The triggered move event</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onVehicleMove(@NotNull VehicleMoveEvent event) {
|
||||||
|
if (!Stargate.getGateConfig().handleVehicles()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Entity> passengers = event.getVehicle().getPassengers();
|
||||||
|
Vehicle vehicle = event.getVehicle();
|
||||||
|
|
||||||
|
Portal entrancePortal;
|
||||||
|
int entitySize = EntityHelper.getEntityMaxSizeInt(vehicle);
|
||||||
|
if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
|
||||||
|
entrancePortal = PortalUtil.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
||||||
|
} else {
|
||||||
|
entrancePortal = PortalUtil.getByEntrance(event.getTo());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return if the portal cannot be teleported through
|
||||||
|
if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.getOptions().isBungee()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
teleportVehicle(passengers, entrancePortal, vehicle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event handler detects if a player moves into a portal
|
||||||
|
*
|
||||||
|
* @param event <p>The player move event which was triggered</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||||
|
if (event.isCancelled() || event.getTo() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockLocation fromLocation = new BlockLocation(event.getFrom().getBlock());
|
||||||
|
BlockLocation toLocation = new BlockLocation(event.getTo().getBlock());
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
//Check whether the event needs to be considered
|
||||||
|
if (!isRelevantMoveEvent(event, player, fromLocation, toLocation)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Portal entrancePortal = PortalUtil.getByEntrance(toLocation);
|
||||||
|
//Check an additional block away in case the portal is a bungee portal using END_PORTAL
|
||||||
|
if (entrancePortal == null) {
|
||||||
|
entrancePortal = PortalUtil.getByAdjacentEntrance(toLocation);
|
||||||
|
// This should never realistically be null
|
||||||
|
if (entrancePortal == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||||
|
if (destination == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity playerVehicle = player.getVehicle();
|
||||||
|
//If the player is in a vehicle, but vehicle handling is disabled, just ignore the player
|
||||||
|
if (playerVehicle == null || (playerVehicle instanceof LivingEntity &&
|
||||||
|
Stargate.getGateConfig().handleVehicles())) {
|
||||||
|
teleportPlayer(playerVehicle, player, entrancePortal, destination, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen for entities entering an artificial end portal
|
||||||
|
*
|
||||||
|
* @param event <p>The triggered event</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityPortalEnter(@NotNull EntityPortalEnterEvent event) {
|
||||||
|
Location location = event.getLocation();
|
||||||
|
World world = location.getWorld();
|
||||||
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
|
//Hijack normal portal teleportation if teleporting from a stargate, and teleporting from an end portal in the
|
||||||
|
// end
|
||||||
|
if (!(entity instanceof Player player) || location.getBlock().getType() != Material.END_PORTAL ||
|
||||||
|
world == null || world.getEnvironment() != World.Environment.THE_END) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Portal portal = PortalUtil.getByAdjacentEntrance(location);
|
||||||
|
if (portal == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||||
|
"Found player " + player + " entering END_PORTAL " + portal);
|
||||||
|
|
||||||
|
//Decide if the anything stops the player from teleporting
|
||||||
|
if (PermissionHelper.playerCannotTeleport(portal, portal.getPortalActivator().getDestination(),
|
||||||
|
player, null) || portal.getOptions().isBungee()) {
|
||||||
|
//Teleport the player back to the portal they came in, just in case
|
||||||
|
playersFromTheEnd.put(player, new FromTheEndTeleportation(portal));
|
||||||
|
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||||
|
"Sending player back to the entrance");
|
||||||
|
} else {
|
||||||
|
Portal destination = portal.getPortalActivator().getDestination();
|
||||||
|
if (destination != null) {
|
||||||
|
playersFromTheEnd.put(player, new FromTheEndTeleportation(destination));
|
||||||
|
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||||
|
"Sending player to destination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen for the respawn event to catch players teleporting from the end in an artificial end portal
|
||||||
|
*
|
||||||
|
* @param event <p>The triggered event</p>
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onRespawn(@NotNull PlayerRespawnEvent event) {
|
||||||
|
Player respawningPlayer = event.getPlayer();
|
||||||
|
FromTheEndTeleportation teleportation = playersFromTheEnd.remove(respawningPlayer);
|
||||||
|
if (teleportation == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Portal exitPortal = teleportation.exitPortal();
|
||||||
|
|
||||||
|
//Overwrite respawn location to respawn in front of the portal
|
||||||
|
PlayerTeleporter teleporter = new PlayerTeleporter(exitPortal, respawningPlayer);
|
||||||
|
Location respawnLocation = teleporter.getExit();
|
||||||
|
event.setRespawnLocation(respawnLocation);
|
||||||
|
//Try and force the player if for some reason the changing of respawn location isn't properly handled
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () ->
|
||||||
|
respawningPlayer.teleport(respawnLocation), 1);
|
||||||
|
|
||||||
|
//Properly close the portal to prevent it from staying in a locked state until it times out
|
||||||
|
exitPortal.getPortalOpener().closePortal(false);
|
||||||
|
|
||||||
|
Stargate.debug("PortalEventListener::onRespawn", "Overwriting respawn for " + respawningPlayer +
|
||||||
|
" to " + respawnLocation.getWorld() + ":" + respawnLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teleports a vehicle through a stargate
|
||||||
|
*
|
||||||
|
* @param passengers <p>The passengers inside the vehicle</p>
|
||||||
|
* @param entrancePortal <p>The portal the vehicle is entering</p>
|
||||||
|
* @param vehicle <p>The vehicle passing through</p>
|
||||||
|
*/
|
||||||
|
private static void teleportVehicle(@NotNull List<Entity> passengers, @NotNull Portal entrancePortal,
|
||||||
|
@NotNull Vehicle vehicle) {
|
||||||
|
String route = "VehicleEventListener::teleportVehicle";
|
||||||
|
|
||||||
|
if (!passengers.isEmpty() && TeleportHelper.containsPlayer(passengers)) {
|
||||||
|
Stargate.debug(route, "Found passenger vehicle");
|
||||||
|
teleportPlayerAndVehicle(entrancePortal, vehicle);
|
||||||
|
} else {
|
||||||
|
Stargate.debug(route, "Found vehicle without players");
|
||||||
|
Portal destinationPortal = entrancePortal.getPortalActivator().getDestination();
|
||||||
|
if (destinationPortal == null) {
|
||||||
|
Stargate.debug(route, "Unable to find portal destination");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Stargate.debug("vehicleTeleport", destinationPortal.getLocation().getWorld() + " " +
|
||||||
|
destinationPortal.getLocation().getSignBlock());
|
||||||
|
new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teleports a player and the vehicle the player sits in
|
||||||
|
*
|
||||||
|
* @param entrancePortal <p>The portal the minecart entered</p>
|
||||||
|
* @param vehicle <p>The vehicle to teleport</p>
|
||||||
|
*/
|
||||||
|
private static void teleportPlayerAndVehicle(@NotNull Portal entrancePortal, @NotNull Vehicle vehicle) {
|
||||||
|
Entity rootEntity = vehicle;
|
||||||
|
while (rootEntity.getVehicle() != null) {
|
||||||
|
rootEntity = rootEntity.getVehicle();
|
||||||
|
}
|
||||||
|
List<Player> players = TeleportHelper.getPlayers(rootEntity.getPassengers());
|
||||||
|
Portal destinationPortal = getDestinationPortal(players, entrancePortal);
|
||||||
|
|
||||||
|
//Cancel the teleport if no players activated the portal, or if any players are denied access
|
||||||
|
boolean cancelTeleportation = false;
|
||||||
|
for (Player player : players) {
|
||||||
|
if (destinationPortal == null) {
|
||||||
|
cancelTeleportation = true;
|
||||||
|
if (!entrancePortal.getOptions().isQuiet()) {
|
||||||
|
new SGFormatBuilder(Message.INVALID_DESTINATION).error(player);
|
||||||
|
}
|
||||||
|
} else if (!TeleportHelper.playerCanTeleport(player, entrancePortal, destinationPortal)) {
|
||||||
|
cancelTeleportation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cancelTeleportation || destinationPortal == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Take payment from all players
|
||||||
|
if (!takePayment(players, entrancePortal, destinationPortal)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the teleportation
|
||||||
|
teleportPlayerAndVehicle(players, vehicle, entrancePortal, destinationPortal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the teleportation of one or more players in a vehicle
|
||||||
|
*
|
||||||
|
* @param players <p>The players to be teleported</p>
|
||||||
|
* @param vehicle <p>The vehicle that triggered the teleportation</p>
|
||||||
|
* @param entrancePortal <p>The portal the player(s) and vehicle entered from</p>
|
||||||
|
* @param destinationPortal <p>The portal the player(s) and vehicle are teleporting to</p>
|
||||||
|
*/
|
||||||
|
private static void teleportPlayerAndVehicle(@NotNull List<Player> players, @NotNull Vehicle vehicle,
|
||||||
|
@NotNull Portal entrancePortal, @NotNull Portal destinationPortal) {
|
||||||
|
//Teleport the vehicle and inform the user if the vehicle was teleported
|
||||||
|
boolean teleported = new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
||||||
|
if (!teleported) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entrancePortal.getOptions().isQuiet()) {
|
||||||
|
for (Player player : players) {
|
||||||
|
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entrancePortal.getPortalOpener().closePortal(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to get the destination portal selected by one of the players included in the teleportation
|
||||||
|
*
|
||||||
|
* @param players <p>The players to be teleported</p>
|
||||||
|
* @param entrancePortal <p>The portal the players are entering</p>
|
||||||
|
* @return <p>The destination portal, or null if not found</p>
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private static Portal getDestinationPortal(@NotNull List<Player> players, @NotNull Portal entrancePortal) {
|
||||||
|
for (Player player : players) {
|
||||||
|
//The entrance portal must be open for one player for the teleportation to happen
|
||||||
|
if (!entrancePortal.getPortalOpener().isOpenFor(player)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if any of the players has selected the destination
|
||||||
|
Portal possibleDestinationPortal = entrancePortal.getPortalActivator().getDestination(player);
|
||||||
|
if (possibleDestinationPortal != null) {
|
||||||
|
return possibleDestinationPortal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes payment for the given players
|
||||||
|
*
|
||||||
|
* @param players <p>The players to take payment from</p>
|
||||||
|
* @param entrancePortal <p>The portal the players are travelling from</p>
|
||||||
|
* @param destinationPortal <p>The portal the players are travelling to</p>
|
||||||
|
* @return <p>True if payment was successfully taken, false otherwise</p>
|
||||||
|
*/
|
||||||
|
private static boolean takePayment(@NotNull List<Player> players, @NotNull Portal entrancePortal,
|
||||||
|
@NotNull Portal destinationPortal) {
|
||||||
|
for (Player player : players) {
|
||||||
|
//To prevent the case where the first passenger pays and then the second passenger is denied, this has to be
|
||||||
|
// run after it has been confirmed that all passengers are able to pay. Also note that some players might
|
||||||
|
// not have to pay, and thus the cost check has to be in the loop,
|
||||||
|
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
||||||
|
if (cost > 0) {
|
||||||
|
if (EconomyHelper.cannotPayTeleportFee(entrancePortal, player, cost)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teleports a player, also teleports the player's vehicle if it's a living entity
|
||||||
|
*
|
||||||
|
* @param playerVehicle <p>The vehicle the player is currently sitting in</p>
|
||||||
|
* @param player <p>The player which moved</p>
|
||||||
|
* @param entrancePortal <p>The entrance the player entered</p>
|
||||||
|
* @param destination <p>The destination of the entrance portal</p>
|
||||||
|
* @param event <p>The move event causing the teleportation to trigger</p>
|
||||||
|
*/
|
||||||
|
private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal,
|
||||||
|
@NotNull Portal destination, @NotNull PlayerMoveEvent event) {
|
||||||
|
if (playerVehicle instanceof LivingEntity) {
|
||||||
|
//Make sure any horses are properly tamed
|
||||||
|
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
|
||||||
|
horse.setTamed(true);
|
||||||
|
horse.setOwner(player);
|
||||||
|
}
|
||||||
|
//Teleport the player's vehicle
|
||||||
|
player.setVelocity(new Vector());
|
||||||
|
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal);
|
||||||
|
} else {
|
||||||
|
//Just teleport the player like normal
|
||||||
|
new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event);
|
||||||
|
}
|
||||||
|
if (!entrancePortal.getOptions().isQuiet()) {
|
||||||
|
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||||
|
}
|
||||||
|
entrancePortal.getPortalOpener().closePortal(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a player move event is relevant for this plugin
|
||||||
|
*
|
||||||
|
* @param event <p>The player move event to check</p>
|
||||||
|
* @param player <p>The player which moved</p>
|
||||||
|
* @param fromLocation <p>The location the player is moving from</p>
|
||||||
|
* @param toLocation <p>The location the player is moving to</p>
|
||||||
|
* @return <p>True if the event is relevant</p>
|
||||||
|
*/
|
||||||
|
private boolean isRelevantMoveEvent(@NotNull PlayerMoveEvent event, Player player,
|
||||||
|
@NotNull BlockLocation fromLocation, @NotNull BlockLocation toLocation) {
|
||||||
|
//Check to see if the player moved to another block
|
||||||
|
if (fromLocation.equals(toLocation)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the portal the player entered, if any
|
||||||
|
Portal entrancePortal = getEnteredPortal(toLocation, player);
|
||||||
|
if (entrancePortal == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||||
|
|
||||||
|
//Catch always open portals without a valid destination to prevent the user for being teleported and denied
|
||||||
|
if (!entrancePortal.getOptions().isBungee() && destination == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Decide if the anything stops the player from teleport
|
||||||
|
if (PermissionHelper.playerCannotTeleport(entrancePortal, destination, player, event)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Decide if the user should be teleported to another bungee server
|
||||||
|
if (entrancePortal.getOptions().isBungee()) {
|
||||||
|
if (BungeeHelper.bungeeTeleport(player, entrancePortal, event) && !entrancePortal.getOptions().isQuiet()) {
|
||||||
|
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Make sure to check if the player has any leashed creatures, even though leashed teleportation is disabled
|
||||||
|
return TeleportHelper.noLeashedCreaturesPreventTeleportation(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the portal a player entered
|
||||||
|
*
|
||||||
|
* @param toLocation <p>The location the player moved to</p>
|
||||||
|
* @param player <p>The player that moved</p>
|
||||||
|
* @return <p>The portal the player entered, or null if no portal was entered</p>
|
||||||
|
*/
|
||||||
|
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
|
||||||
|
Portal entrancePortal = PortalUtil.getByEntrance(toLocation);
|
||||||
|
// Return if in an entrance
|
||||||
|
if (entrancePortal != null) {
|
||||||
|
return entrancePortal;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check an additional block away for special cases like BungeeCord portals using END_PORTAL as its material
|
||||||
|
entrancePortal = PortalUtil.getByAdjacentEntrance(toLocation);
|
||||||
|
if (entrancePortal == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
|
||||||
|
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
|
||||||
|
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the real materials in the entrance, as END_GATEWAY or END_PORTAL may be available, but not chosen
|
||||||
|
Set<Material> materialsInEntrance = new HashSet<>();
|
||||||
|
for (BlockLocation location : entrancePortal.getStructure().getEntrances()) {
|
||||||
|
materialsInEntrance.add(location.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abort if not a special case
|
||||||
|
if ((!materialsInEntrance.contains(Material.END_GATEWAY) || !isGeyserPlayer(player)) &&
|
||||||
|
(!entrancePortal.getOptions().isBungee() || !materialsInEntrance.contains(Material.END_PORTAL))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return entrancePortal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given player is connected through Geyser
|
||||||
|
*
|
||||||
|
* @param player <p>The player to check</p>
|
||||||
|
* @return <p>True if the player is connected through Geyser</p>
|
||||||
|
*/
|
||||||
|
private boolean isGeyserPlayer(@NotNull Player player) {
|
||||||
|
// Prevent unnecessary checking for non-geyser and floodgate servers
|
||||||
|
if (!hasGeyser && !hasFloodgate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use Geyser API to get connection status
|
||||||
|
if (hasGeyser) {
|
||||||
|
try {
|
||||||
|
return GeyserApi.api().connectionByUuid(player.getUniqueId()) != null;
|
||||||
|
} catch (NoClassDefFoundError error1) {
|
||||||
|
hasGeyser = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use Floodgate API to get connection status
|
||||||
|
if (hasFloodgate) {
|
||||||
|
try {
|
||||||
|
return FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
|
||||||
|
} catch (NoClassDefFoundError error2) {
|
||||||
|
hasFloodgate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener listens to teleportation-related events
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class TeleportEventListener implements Listener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event handler handles some special teleportation events
|
|
||||||
*
|
|
||||||
* <p>This event cancels nether portal, end gateway and end portal teleportation if the user teleported from a
|
|
||||||
* stargate entrance. This prevents the user from just teleporting to the nether or the end with portals using
|
|
||||||
* the special teleportation blocks.</p>
|
|
||||||
*
|
|
||||||
* @param event <p>The event to check and possibly cancel</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
|
|
||||||
PlayerTeleportEvent.TeleportCause cause = event.getCause();
|
|
||||||
|
|
||||||
//Block normal portal teleportation if teleporting from a stargate
|
|
||||||
if (!event.isCancelled() && (cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
|
|
||||||
cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY ||
|
|
||||||
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
|
|
||||||
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
|
||||||
import net.knarcraft.stargate.config.Message;
|
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
|
||||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
|
||||||
import net.knarcraft.stargate.utility.EntityHelper;
|
|
||||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.Vehicle;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener listens for the vehicle move event to teleport vehicles through portals
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class VehicleEventListener implements Listener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check for a vehicle moving through a portal
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered move event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicleMove(@NotNull VehicleMoveEvent event) {
|
|
||||||
if (!Stargate.getGateConfig().handleVehicles()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<Entity> passengers = event.getVehicle().getPassengers();
|
|
||||||
Vehicle vehicle = event.getVehicle();
|
|
||||||
|
|
||||||
Portal entrancePortal;
|
|
||||||
int entitySize = EntityHelper.getEntityMaxSizeInt(vehicle);
|
|
||||||
if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
|
|
||||||
entrancePortal = PortalHandler.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
|
||||||
} else {
|
|
||||||
entrancePortal = PortalHandler.getByEntrance(event.getTo());
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return if the portal cannot be teleported through
|
|
||||||
if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.getOptions().isBungee()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
teleportVehicle(passengers, entrancePortal, vehicle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Teleports a vehicle through a stargate
|
|
||||||
*
|
|
||||||
* @param passengers <p>The passengers inside the vehicle</p>
|
|
||||||
* @param entrancePortal <p>The portal the vehicle is entering</p>
|
|
||||||
* @param vehicle <p>The vehicle passing through</p>
|
|
||||||
*/
|
|
||||||
private static void teleportVehicle(@NotNull List<Entity> passengers, @NotNull Portal entrancePortal,
|
|
||||||
@NotNull Vehicle vehicle) {
|
|
||||||
String route = "VehicleEventListener::teleportVehicle";
|
|
||||||
|
|
||||||
if (!passengers.isEmpty() && TeleportHelper.containsPlayer(passengers)) {
|
|
||||||
Stargate.debug(route, "Found passenger vehicle");
|
|
||||||
teleportPlayerAndVehicle(entrancePortal, vehicle);
|
|
||||||
} else {
|
|
||||||
Stargate.debug(route, "Found vehicle without players");
|
|
||||||
Portal destinationPortal = entrancePortal.getPortalActivator().getDestination();
|
|
||||||
if (destinationPortal == null) {
|
|
||||||
Stargate.debug(route, "Unable to find portal destination");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " +
|
|
||||||
destinationPortal.getSignLocation());
|
|
||||||
new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Teleports a player and the vehicle the player sits in
|
|
||||||
*
|
|
||||||
* @param entrancePortal <p>The portal the minecart entered</p>
|
|
||||||
* @param vehicle <p>The vehicle to teleport</p>
|
|
||||||
*/
|
|
||||||
private static void teleportPlayerAndVehicle(@NotNull Portal entrancePortal, @NotNull Vehicle vehicle) {
|
|
||||||
Entity rootEntity = vehicle;
|
|
||||||
while (rootEntity.getVehicle() != null) {
|
|
||||||
rootEntity = rootEntity.getVehicle();
|
|
||||||
}
|
|
||||||
List<Player> players = TeleportHelper.getPlayers(rootEntity.getPassengers());
|
|
||||||
Portal destinationPortal = getDestinationPortal(players, entrancePortal);
|
|
||||||
|
|
||||||
//Cancel the teleport if no players activated the portal, or if any players are denied access
|
|
||||||
boolean cancelTeleportation = false;
|
|
||||||
for (Player player : players) {
|
|
||||||
if (destinationPortal == null) {
|
|
||||||
cancelTeleportation = true;
|
|
||||||
if (!entrancePortal.getOptions().isQuiet()) {
|
|
||||||
new SGFormatBuilder(Message.INVALID_DESTINATION).error(player);
|
|
||||||
}
|
|
||||||
} else if (!TeleportHelper.playerCanTeleport(player, entrancePortal, destinationPortal)) {
|
|
||||||
cancelTeleportation = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cancelTeleportation || destinationPortal == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Take payment from all players
|
|
||||||
if (!takePayment(players, entrancePortal, destinationPortal)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform the teleportation
|
|
||||||
teleportPlayerAndVehicle(players, vehicle, entrancePortal, destinationPortal);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the teleportation of one or more players in a vehicle
|
|
||||||
*
|
|
||||||
* @param players <p>The players to be teleported</p>
|
|
||||||
* @param vehicle <p>The vehicle that triggered the teleportation</p>
|
|
||||||
* @param entrancePortal <p>The portal the player(s) and vehicle entered from</p>
|
|
||||||
* @param destinationPortal <p>The portal the player(s) and vehicle are teleporting to</p>
|
|
||||||
*/
|
|
||||||
private static void teleportPlayerAndVehicle(@NotNull List<Player> players, @NotNull Vehicle vehicle,
|
|
||||||
@NotNull Portal entrancePortal, @NotNull Portal destinationPortal) {
|
|
||||||
//Teleport the vehicle and inform the user if the vehicle was teleported
|
|
||||||
boolean teleported = new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
|
||||||
if (!teleported) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!entrancePortal.getOptions().isQuiet()) {
|
|
||||||
for (Player player : players) {
|
|
||||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entrancePortal.getPortalOpener().closePortal(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to get the destination portal selected by one of the players included in the teleportation
|
|
||||||
*
|
|
||||||
* @param players <p>The players to be teleported</p>
|
|
||||||
* @param entrancePortal <p>The portal the players are entering</p>
|
|
||||||
* @return <p>The destination portal, or null if not found</p>
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
private static Portal getDestinationPortal(@NotNull List<Player> players, @NotNull Portal entrancePortal) {
|
|
||||||
for (Player player : players) {
|
|
||||||
//The entrance portal must be open for one player for the teleportation to happen
|
|
||||||
if (!entrancePortal.getPortalOpener().isOpenFor(player)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if any of the players has selected the destination
|
|
||||||
Portal possibleDestinationPortal = entrancePortal.getPortalActivator().getDestination(player);
|
|
||||||
if (possibleDestinationPortal != null) {
|
|
||||||
return possibleDestinationPortal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes payment for the given players
|
|
||||||
*
|
|
||||||
* @param players <p>The players to take payment from</p>
|
|
||||||
* @param entrancePortal <p>The portal the players are travelling from</p>
|
|
||||||
* @param destinationPortal <p>The portal the players are travelling to</p>
|
|
||||||
* @return <p>True if payment was successfully taken, false otherwise</p>
|
|
||||||
*/
|
|
||||||
private static boolean takePayment(@NotNull List<Player> players, @NotNull Portal entrancePortal,
|
|
||||||
@NotNull Portal destinationPortal) {
|
|
||||||
for (Player player : players) {
|
|
||||||
//To prevent the case where the first passenger pays and then the second passenger is denied, this has to be
|
|
||||||
// run after it has been confirmed that all passengers are able to pay. Also note that some players might
|
|
||||||
// not have to pay, and thus the cost check has to be in the loop,
|
|
||||||
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
|
||||||
if (cost > 0) {
|
|
||||||
if (EconomyHelper.cannotPayTeleportFee(entrancePortal, player, cost)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package net.knarcraft.stargate.listener;
|
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
|
||||||
import net.knarcraft.stargate.config.StargateConfig;
|
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.world.WorldLoadEvent;
|
|
||||||
import org.bukkit.event.world.WorldUnloadEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener listens for the loading and unloading of worlds to load and unload stargates
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class WorldEventListener implements Listener {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener listens for the loading of a world and loads all gates from the world if not already loaded
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered world load event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onWorldLoad(@NotNull WorldLoadEvent event) {
|
|
||||||
StargateConfig config = Stargate.getStargateConfig();
|
|
||||||
if (!config.getManagedWorlds().contains(event.getWorld().getName()) &&
|
|
||||||
PortalFileHelper.loadAllPortals(event.getWorld())) {
|
|
||||||
config.addManagedWorld(event.getWorld().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This listener listens for the unloading of a world
|
|
||||||
*
|
|
||||||
* @param event <p>The triggered world unload event</p>
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onWorldUnload(@NotNull WorldUnloadEvent event) {
|
|
||||||
Stargate.debug("onWorldUnload", "Reloading all Stargates");
|
|
||||||
World world = event.getWorld();
|
|
||||||
String worldName = world.getName();
|
|
||||||
StargateConfig config = Stargate.getStargateConfig();
|
|
||||||
if (config.getManagedWorlds().contains(worldName)) {
|
|
||||||
config.removeManagedWorld(worldName);
|
|
||||||
PortalRegistry.clearPortals(world);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package net.knarcraft.stargate.portal;
|
package net.knarcraft.stargate.portal;
|
||||||
|
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
|
||||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOptions;
|
import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||||
@@ -10,7 +8,7 @@ import net.knarcraft.stargate.portal.property.PortalStrings;
|
|||||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -47,7 +45,7 @@ public class Portal {
|
|||||||
* @param portalOwner <p>The portal's owner</p>
|
* @param portalOwner <p>The portal's owner</p>
|
||||||
* @param options <p>A map containing all possible portal options, with true for the ones enabled</p>
|
* @param options <p>A map containing all possible portal options, with true for the ones enabled</p>
|
||||||
*/
|
*/
|
||||||
public Portal(@NotNull PortalLocation portalLocation, @Nullable BlockLocation button,
|
public Portal(@NotNull PortalLocation portalLocation, @Nullable Block button,
|
||||||
@NotNull PortalStrings portalStrings, @NotNull Gate gate, @NotNull PortalOwner portalOwner,
|
@NotNull PortalStrings portalStrings, @NotNull Gate gate, @NotNull PortalOwner portalOwner,
|
||||||
@NotNull Map<PortalOption, Boolean> options) {
|
@NotNull Map<PortalOption, Boolean> options) {
|
||||||
this.location = portalLocation;
|
this.location = portalLocation;
|
||||||
@@ -263,59 +261,6 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the world this portal belongs to
|
|
||||||
*
|
|
||||||
* @return <p>The world this portal belongs to</p>
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public World getWorld() {
|
|
||||||
return location.getWorld();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the location of this portal's sign
|
|
||||||
*
|
|
||||||
* @return <p>The location of this portal's sign</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public BlockLocation getSignLocation() {
|
|
||||||
return this.location.getSignLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the rotation (yaw) of this portal
|
|
||||||
*
|
|
||||||
* <p>The yaw is used to calculate all kinds of directions. See DirectionHelper to see how the yaw is used to
|
|
||||||
* calculate to/from other direction types.</p>
|
|
||||||
*
|
|
||||||
* @return <p>The rotation (yaw) of this portal</p>
|
|
||||||
*/
|
|
||||||
public float getYaw() {
|
|
||||||
return this.location.getYaw();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the location of the top-left block of the portal
|
|
||||||
*
|
|
||||||
* @return <p>The location of the top-left portal block</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public BlockLocation getTopLeft() {
|
|
||||||
return this.location.getTopLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the block at the given location relative to this portal's top-left block
|
|
||||||
*
|
|
||||||
* @param vector <p>The relative block vector explaining the position of the block</p>
|
|
||||||
* @return <p>The block at the given relative position</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public BlockLocation getBlockAt(@NotNull RelativeBlockVector vector) {
|
|
||||||
return getTopLeft().getRelativeLocation(vector, getYaw());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans a string by removing color codes, lower-casing and replacing spaces with underscores
|
* Cleans a string by removing color codes, lower-casing and replacing spaces with underscores
|
||||||
*
|
*
|
||||||
@@ -324,13 +269,14 @@ public class Portal {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String cleanString(@NotNull String string) {
|
public static String cleanString(@NotNull String string) {
|
||||||
|
// TODO: Replace special characters such as : and .
|
||||||
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', string)).toLowerCase();
|
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', string)).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("Portal [id=%s, network=%s name=%s, type=%s]", getSignLocation(), network, name,
|
return String.format("Portal [id=%s, network=%s name=%s, type=%s]", this.location.getSignBlock(), network, name,
|
||||||
structure.getGate().getFilename());
|
structure.getGate().getFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package net.knarcraft.stargate.portal;
|
package net.knarcraft.stargate.portal;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.event.StargateActivateEvent;
|
import net.knarcraft.stargate.event.StargateActivateEvent;
|
||||||
import net.knarcraft.stargate.event.StargateDeactivateEvent;
|
import net.knarcraft.stargate.event.StargateDeactivateEvent;
|
||||||
import net.knarcraft.stargate.utility.ListHelper;
|
import net.knarcraft.stargate.utility.ListHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -74,16 +75,16 @@ public class PortalActivator {
|
|||||||
String portalNetwork = portal.getCleanNetwork();
|
String portalNetwork = portal.getCleanNetwork();
|
||||||
if (portal.getOptions().isRandom()) {
|
if (portal.getOptions().isRandom()) {
|
||||||
//Find possible destinations
|
//Find possible destinations
|
||||||
List<String> destinations = PortalHandler.getDestinations(portal, player, portalNetwork);
|
List<String> destinations = PortalUtil.getDestinations(portal, player, portalNetwork);
|
||||||
if (destinations.isEmpty()) {
|
if (destinations.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//Get one random destination
|
//Get one random destination
|
||||||
String randomDestination = ListHelper.getRandom(destinations);
|
String randomDestination = ListHelper.getRandom(destinations);
|
||||||
return PortalHandler.getByName(randomDestination, portalNetwork);
|
return PortalUtil.getByName(randomDestination, portalNetwork);
|
||||||
} else {
|
} else {
|
||||||
//Just return the normal fixed destination
|
//Just return the normal fixed destination
|
||||||
return PortalHandler.getByName(destination, portalNetwork);
|
return PortalUtil.getByName(destination, portalNetwork);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ public class PortalActivator {
|
|||||||
activePlayer = player;
|
activePlayer = player;
|
||||||
|
|
||||||
String network = portal.getCleanNetwork();
|
String network = portal.getCleanNetwork();
|
||||||
destinations = PortalHandler.getDestinations(portal, player, network);
|
destinations = PortalUtil.getDestinations(portal, player, network);
|
||||||
|
|
||||||
//Sort destinations if enabled
|
//Sort destinations if enabled
|
||||||
if (Stargate.getGateConfig().sortNetworkDestinations()) {
|
if (Stargate.getGateConfig().sortNetworkDestinations()) {
|
||||||
@@ -250,7 +251,7 @@ public class PortalActivator {
|
|||||||
}
|
}
|
||||||
activate = true;
|
activate = true;
|
||||||
|
|
||||||
List<String> portalsInNetwork = PortalHandler.getNetwork(portal.getCleanNetwork());
|
List<String> portalsInNetwork = PortalUtil.getNetwork(portal.getCleanNetwork());
|
||||||
if (portalsInNetwork != null) {
|
if (portalsInNetwork != null) {
|
||||||
Stargate.debug("cycleDestination", "Network Size: " + portalsInNetwork.size());
|
Stargate.debug("cycleDestination", "Network Size: " + portalsInNetwork.size());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package net.knarcraft.stargate.portal;
|
package net.knarcraft.stargate.portal;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
|
||||||
import net.knarcraft.stargate.event.StargateCreateEvent;
|
import net.knarcraft.stargate.event.StargateCreateEvent;
|
||||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||||
@@ -19,11 +17,13 @@ import net.knarcraft.stargate.utility.ListHelper;
|
|||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ public class PortalCreator {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Portal createPortal() {
|
public Portal createPortal() {
|
||||||
String route = "PortalCreator::createPortal";
|
String route = "PortalCreator::createPortal";
|
||||||
BlockLocation signLocation = new BlockLocation(event.getBlock());
|
Block signLocation = event.getBlock();
|
||||||
Block signControlBlock = signLocation.getParent();
|
Block signControlBlock = DirectionHelper.getParent(signLocation);
|
||||||
|
|
||||||
//Return early if the sign is not placed on a block, or the block is not a control block
|
//Return early if the sign is not placed on a block, or the block is not a control block
|
||||||
if (signControlBlock == null || GateHandler.getGatesByControlBlock(signControlBlock).isEmpty()) {
|
if (signControlBlock == null || GateHandler.getGatesByControlBlock(signControlBlock).isEmpty()) {
|
||||||
@@ -70,50 +70,51 @@ public class PortalCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//The control block is already part of another portal
|
//The control block is already part of another portal
|
||||||
if (PortalHandler.getByBlock(signControlBlock) != null) {
|
if (PortalUtil.getByBlock(signControlBlock) != null) {
|
||||||
Stargate.debug(route, "idParent belongs to existing stargate");
|
Stargate.debug(route, "idParent belongs to existing stargate");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get necessary information from the gate's sign
|
//Get necessary information from the gate's sign
|
||||||
@NotNull String portalName = PortalHandler.filterName(event.getLine(0));
|
@NotNull String portalName = PortalUtil.filterName(event.getLine(0));
|
||||||
@NotNull String destinationName = PortalHandler.filterName(event.getLine(1));
|
@NotNull String destinationName = PortalUtil.filterName(event.getLine(1));
|
||||||
@NotNull String network = PortalHandler.filterName(event.getLine(2));
|
@NotNull String network = PortalUtil.filterName(event.getLine(2));
|
||||||
@NotNull String options = PortalHandler.filterName(event.getLine(3)).toLowerCase();
|
@NotNull String options = PortalUtil.filterName(event.getLine(3)).toLowerCase();
|
||||||
|
|
||||||
PortalStrings portalStrings = new PortalStrings(portalName, network, destinationName);
|
PortalStrings portalStrings = new PortalStrings(portalName, network, destinationName);
|
||||||
|
|
||||||
//Get portal options available to the player creating the portal
|
//Get portal options available to the player creating the portal
|
||||||
Map<PortalOption, Boolean> portalOptions = PortalHandler.getPortalOptions(player, destinationName, options);
|
Map<PortalOption, Boolean> portalOptions = PortalUtil.getPortalOptions(player, destinationName, options);
|
||||||
|
|
||||||
//Get the yaw
|
//Get the yaw
|
||||||
float yaw = DirectionHelper.getYawFromLocationDifference(signControlBlock.getLocation(),
|
|
||||||
signLocation.getLocation());
|
|
||||||
|
|
||||||
//Get the direction the button should be facing
|
|
||||||
BlockFace buttonFacing = DirectionHelper.getBlockFaceFromYaw(yaw);
|
|
||||||
|
|
||||||
PortalLocation portalLocation = new PortalLocation();
|
BlockFace facing = DirectionHelper.getFacing(signLocation);
|
||||||
portalLocation.setButtonFacing(buttonFacing).setYaw(yaw).setSignLocation(signLocation);
|
if (facing == null) {
|
||||||
|
facing = DirectionHelper.getBlockFaceFromLocationDifference(signControlBlock.getLocation(),
|
||||||
|
signLocation.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
PortalLocation portalLocation = new PortalLocation(signLocation, facing);
|
||||||
|
|
||||||
Stargate.debug(route, "Finished getting all portal info");
|
Stargate.debug(route, "Finished getting all portal info");
|
||||||
|
|
||||||
return createPortal(portalStrings, portalOptions, yaw, portalLocation);
|
return createPortal(portalStrings, portalOptions, portalLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Portal createPortal(@NotNull PortalStrings portalStrings, @NotNull Map<PortalOption, Boolean> portalOptions,
|
private Portal createPortal(@NotNull PortalStrings portalStrings, @NotNull Map<PortalOption, Boolean> portalOptions,
|
||||||
float yaw, @NotNull PortalLocation portalLocation) {
|
@NotNull PortalLocation portalLocation) {
|
||||||
String route = "PortalCreator::createPortal";
|
String route = "PortalCreator::createPortal";
|
||||||
//Try and find a gate matching the new portal
|
//Try and find a gate matching the new portal
|
||||||
Gate gate = PortalHandler.findMatchingGate(portalLocation, player.getWorld());
|
Gate gate = PortalUtil.findMatchingGate(portalLocation);
|
||||||
if ((gate == null) || (portalLocation.getButtonVector() == null)) {
|
if ((gate == null) || (portalLocation.getButtonBlock() == null)) {
|
||||||
Stargate.debug(route, "Could not find matching gate layout");
|
Stargate.debug(route, "Could not find matching gate layout");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the portal is a bungee portal and invalid, abort here
|
//If the portal is a bungee portal and invalid, abort here
|
||||||
if (!PortalHandler.isValidBungeePortal(portalOptions, player, portalStrings.destination(),
|
if (!PortalUtil.isValidBungeePortal(portalOptions, player, portalStrings.destination(),
|
||||||
portalStrings.network())) {
|
portalStrings.network())) {
|
||||||
Stargate.debug(route, "Portal is an invalid bungee portal");
|
Stargate.debug(route, "Portal is an invalid bungee portal");
|
||||||
return null;
|
return null;
|
||||||
@@ -151,7 +152,7 @@ public class PortalCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check if a conflict exists
|
//Check if a conflict exists
|
||||||
if (conflictsWithExistingPortal(gate, portalLocation.getTopLeft(), yaw, player)) {
|
if (conflictsWithExistingPortal(gate, portalLocation, player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,9 +210,9 @@ public class PortalCreator {
|
|||||||
|
|
||||||
//Check if the user can create portals to this world.
|
//Check if the user can create portals to this world.
|
||||||
if (!bungee && !destinationName.isEmpty()) {
|
if (!bungee && !destinationName.isEmpty()) {
|
||||||
Portal destinationPortal = PortalHandler.getByName(destinationName, network);
|
Portal destinationPortal = PortalUtil.getByName(destinationName, network);
|
||||||
if (destinationPortal != null && destinationPortal.getWorld() != null) {
|
if (destinationPortal != null) {
|
||||||
String world = destinationPortal.getWorld().getName();
|
String world = destinationPortal.getLocation().getWorld().getName();
|
||||||
if (PermissionHelper.cannotAccessWorld(player, world)) {
|
if (PermissionHelper.cannotAccessWorld(player, world)) {
|
||||||
Stargate.debug("PortalCreator::canCreatePortal", "Player does not have access to destination world");
|
Stargate.debug("PortalCreator::canCreatePortal", "Player does not have access to destination world");
|
||||||
return new SGFormatBuilder(Message.CREATION_WORLD_DENIED).toString();
|
return new SGFormatBuilder(Message.CREATION_WORLD_DENIED).toString();
|
||||||
@@ -265,21 +266,19 @@ public class PortalCreator {
|
|||||||
|
|
||||||
//Add button if the portal is not always on
|
//Add button if the portal is not always on
|
||||||
if (!portalOptions.isAlwaysOn()) {
|
if (!portalOptions.isAlwaysOn()) {
|
||||||
PortalFileHelper.generatePortalButton(portal, portalLocation.getButtonFacing());
|
PortalFileHelper.generatePortalButton(portal, portalLocation.getFacing());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Register the new portal
|
//Register the new portal
|
||||||
PortalHandler.registerPortal(portal);
|
PortalUtil.registerPortal(portal);
|
||||||
updateNewPortalOpenState(destinationName);
|
updateNewPortalOpenState(destinationName);
|
||||||
|
|
||||||
//Update portals pointing at this one if it's not a bungee portal
|
//Update portals pointing at this one if it's not a bungee portal
|
||||||
if (!portal.getOptions().isBungee()) {
|
if (!portal.getOptions().isBungee()) {
|
||||||
PortalHandler.updatePortalsPointingAtNewPortal(portal);
|
PortalUtil.updatePortalsPointingAtNewPortal(portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (portal.getWorld() != null) {
|
PortalFileHelper.saveAllPortals(portal.getLocation().getWorld());
|
||||||
PortalFileHelper.saveAllPortals(portal.getWorld());
|
|
||||||
}
|
|
||||||
|
|
||||||
return portal;
|
return portal;
|
||||||
}
|
}
|
||||||
@@ -311,14 +310,14 @@ public class PortalCreator {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Check if the portal name has been duplicated on the network
|
//Check if the portal name has been duplicated on the network
|
||||||
if (PortalHandler.getByName(portal.getCleanName(), portal.getCleanNetwork()) != null) {
|
if (PortalUtil.getByName(portal.getCleanName(), portal.getCleanNetwork()) != null) {
|
||||||
Stargate.debug(route, "Gate name duplicate");
|
Stargate.debug(route, "Gate name duplicate");
|
||||||
new SGFormatBuilder(Message.CREATION_NAME_COLLISION).error(player);
|
new SGFormatBuilder(Message.CREATION_NAME_COLLISION).error(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if the number of portals in the network has been surpassed
|
//Check if the number of portals in the network has been surpassed
|
||||||
List<String> networkList = PortalHandler.getNetwork(portal.getCleanNetwork());
|
List<String> networkList = PortalUtil.getNetwork(portal.getCleanNetwork());
|
||||||
int maxGates = Stargate.getGateConfig().maxGatesEachNetwork();
|
int maxGates = Stargate.getGateConfig().maxGatesEachNetwork();
|
||||||
if (maxGates > 0 && networkList != null && networkList.size() >= maxGates) {
|
if (maxGates > 0 && networkList != null && networkList.size() >= maxGates) {
|
||||||
new SGFormatBuilder(Message.CREATION_NETWORK_FULL).error(player);
|
new SGFormatBuilder(Message.CREATION_NETWORK_FULL).error(player);
|
||||||
@@ -351,7 +350,7 @@ public class PortalCreator {
|
|||||||
portal.getPortalOpener().openPortal(true);
|
portal.getPortalOpener().openPortal(true);
|
||||||
} else if (portal.getOptions().isAlwaysOn()) {
|
} else if (portal.getOptions().isAlwaysOn()) {
|
||||||
//For a normal always-on portal, open both the portal and the destination
|
//For a normal always-on portal, open both the portal and the destination
|
||||||
Portal destinationPortal = PortalHandler.getByName(destinationName, portal.getCleanNetwork());
|
Portal destinationPortal = PortalUtil.getByName(destinationName, portal.getCleanNetwork());
|
||||||
if (destinationPortal != null) {
|
if (destinationPortal != null) {
|
||||||
portal.getPortalOpener().openPortal(true);
|
portal.getPortalOpener().openPortal(true);
|
||||||
destinationPortal.drawSign();
|
destinationPortal.drawSign();
|
||||||
@@ -363,7 +362,7 @@ public class PortalCreator {
|
|||||||
portal.getGate().getPortalClosedMaterials()).stream().toList();
|
portal.getGate().getPortalClosedMaterials()).stream().toList();
|
||||||
Material closedType = ListHelper.getRandom(possibleMaterials);
|
Material closedType = ListHelper.getRandom(possibleMaterials);
|
||||||
|
|
||||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||||
entrance.setType(closedType);
|
entrance.setType(closedType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,17 +371,16 @@ public class PortalCreator {
|
|||||||
/**
|
/**
|
||||||
* Checks whether the new portal conflicts with an existing portal
|
* Checks whether the new portal conflicts with an existing portal
|
||||||
*
|
*
|
||||||
* @param gate <p>The gate type of the new portal</p>
|
* @param gate <p>The gate type of the new portal</p>
|
||||||
* @param topLeft <p>The top-left block of the new portal</p>
|
* @param portalLocation <p>The location of the portal to check</p>
|
||||||
* @param yaw <p>The yaw when looking directly outwards from the portal</p>
|
* @param player <p>The player creating the new portal</p>
|
||||||
* @param player <p>The player creating the new portal</p>
|
|
||||||
* @return <p>True if a conflict was found. False otherwise</p>
|
* @return <p>True if a conflict was found. False otherwise</p>
|
||||||
*/
|
*/
|
||||||
private static boolean conflictsWithExistingPortal(@NotNull Gate gate, @NotNull BlockLocation topLeft, double yaw,
|
private static boolean conflictsWithExistingPortal(@NotNull Gate gate, @NotNull PortalLocation portalLocation,
|
||||||
@NotNull Player player) {
|
@NotNull Player player) {
|
||||||
for (RelativeBlockVector borderVector : gate.getLayout().getBorder()) {
|
for (BlockVector borderVector : gate.getLayout().getBorder()) {
|
||||||
BlockLocation borderBlockLocation = topLeft.getRelativeLocation(borderVector, yaw);
|
Block borderBlockLocation = portalLocation.getRelative(borderVector);
|
||||||
if (PortalHandler.getByBlock(borderBlockLocation.getBlock()) != null) {
|
if (PortalUtil.getByBlock(borderBlockLocation) != null) {
|
||||||
Stargate.debug("PortalCreator::conflictsWithExistingPortal",
|
Stargate.debug("PortalCreator::conflictsWithExistingPortal",
|
||||||
"Gate conflicts with existing gate");
|
"Gate conflicts with existing gate");
|
||||||
new SGFormatBuilder(Message.CREATION_CONFLICT).error(player);
|
new SGFormatBuilder(Message.CREATION_CONFLICT).error(player);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.knarcraft.stargate.portal;
|
|||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.event.StargateCloseEvent;
|
import net.knarcraft.stargate.event.StargateCloseEvent;
|
||||||
import net.knarcraft.stargate.event.StargateOpenEvent;
|
import net.knarcraft.stargate.event.StargateOpenEvent;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOptions;
|
import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||||
@@ -12,6 +11,7 @@ import net.knarcraft.stargate.utility.MaterialHelper;
|
|||||||
import org.bukkit.Axis;
|
import org.bukkit.Axis;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.Orientable;
|
import org.bukkit.block.data.Orientable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -98,10 +98,10 @@ public class PortalOpener {
|
|||||||
Material openType = ListHelper.getRandom(possibleMaterials);
|
Material openType = ListHelper.getRandom(possibleMaterials);
|
||||||
|
|
||||||
//Adjust orientation if applicable
|
//Adjust orientation if applicable
|
||||||
Axis axis = (openType.createBlockData() instanceof Orientable) ? portal.getLocation().getRotationAxis() : null;
|
Axis axis = (openType.createBlockData() instanceof Orientable) ? portal.getLocation().getVectorOperation().getNormalAxis() : null;
|
||||||
|
|
||||||
//Change the entrance blocks to the correct type
|
//Change the entrance blocks to the correct type
|
||||||
for (BlockLocation inside : portal.getStructure().getEntrances()) {
|
for (Block inside : portal.getStructure().getEntrances()) {
|
||||||
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(inside, openType, axis));
|
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(inside, openType, axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ public class PortalOpener {
|
|||||||
destination.getPortalActivator().setDestination(portal);
|
destination.getPortalActivator().setDestination(portal);
|
||||||
|
|
||||||
//Update the destination's sign if it exists
|
//Update the destination's sign if it exists
|
||||||
if (new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(destination.getLocation().getSignLocation().getType())) {
|
if (new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(destination.getLocation().getSignBlock().getType())) {
|
||||||
destination.drawSign();
|
destination.drawSign();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,9 +182,9 @@ public class PortalOpener {
|
|||||||
Material closedType = ListHelper.getRandom(possibleMaterials);
|
Material closedType = ListHelper.getRandom(possibleMaterials);
|
||||||
|
|
||||||
//Adjust orientation if applicable
|
//Adjust orientation if applicable
|
||||||
Axis axis = (closedType.createBlockData() instanceof Orientable) ? portal.getLocation().getRotationAxis() : null;
|
Axis axis = (closedType.createBlockData() instanceof Orientable) ? portal.getLocation().getVectorOperation().getNormalAxis() : null;
|
||||||
|
|
||||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||||
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(entrance, closedType, axis));
|
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(entrance, closedType, axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package net.knarcraft.stargate.portal;
|
package net.knarcraft.stargate.portal;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.DynmapManager;
|
import net.knarcraft.stargate.config.addons.DynmapManager;
|
||||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -20,9 +21,9 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class PortalRegistry {
|
public class PortalRegistry {
|
||||||
|
|
||||||
private static final Map<BlockLocation, Portal> lookupBlocks = new HashMap<>();
|
private static final Map<Block, Portal> lookupBlocks = new HashMap<>();
|
||||||
private static final Map<BlockLocation, Portal> lookupEntrances = new HashMap<>();
|
private static final Map<Block, Portal> lookupEntrances = new HashMap<>();
|
||||||
private static final Map<BlockLocation, Portal> lookupControls = new HashMap<>();
|
private static final Map<Block, Portal> lookupControls = new HashMap<>();
|
||||||
|
|
||||||
private static final Map<String, Map<String, Portal>> portalLookupByNetwork = new HashMap<>();
|
private static final Map<String, Map<String, Portal>> portalLookupByNetwork = new HashMap<>();
|
||||||
private static final Map<String, List<String>> allPortalNetworks = new HashMap<>();
|
private static final Map<String, List<String>> allPortalNetworks = new HashMap<>();
|
||||||
@@ -52,7 +53,7 @@ public class PortalRegistry {
|
|||||||
//Storing the portals to clear is necessary to avoid a concurrent modification exception
|
//Storing the portals to clear is necessary to avoid a concurrent modification exception
|
||||||
List<Portal> portalsToRemove = new ArrayList<>();
|
List<Portal> portalsToRemove = new ArrayList<>();
|
||||||
allPortals.forEach((portal) -> {
|
allPortals.forEach((portal) -> {
|
||||||
if (portal.getWorld() != null && portal.getWorld().equals(world)) {
|
if (portal.getLocation().getWorld().equals(world)) {
|
||||||
portalsToRemove.add(portal);
|
portalsToRemove.add(portal);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -103,7 +104,7 @@ public class PortalRegistry {
|
|||||||
* @return <p>The portal the frame block belongs to, or null</p>
|
* @return <p>The portal the frame block belongs to, or null</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Portal getPortalFromFrame(@NotNull BlockLocation blockLocation) {
|
public static Portal getPortalFromFrame(@NotNull Block blockLocation) {
|
||||||
return lookupBlocks.get(blockLocation);
|
return lookupBlocks.get(blockLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ public class PortalRegistry {
|
|||||||
* @return <p>The portal the control block belongs to, or null</p>
|
* @return <p>The portal the control block belongs to, or null</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Portal getPortalFromControl(@NotNull BlockLocation blockLocation) {
|
public static Portal getPortalFromControl(@NotNull Block blockLocation) {
|
||||||
return lookupControls.get(blockLocation);
|
return lookupControls.get(blockLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +142,7 @@ public class PortalRegistry {
|
|||||||
* @return <p>A portal, or null</p>
|
* @return <p>A portal, or null</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Portal getPortalFromEntrance(@NotNull BlockLocation blockLocation) {
|
public static Portal getPortalFromEntrance(@NotNull Block blockLocation) {
|
||||||
return lookupEntrances.get(blockLocation);
|
return lookupEntrances.get(blockLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +204,9 @@ public class PortalRegistry {
|
|||||||
|
|
||||||
//Update all portals in the same network with this portal as its destination
|
//Update all portals in the same network with this portal as its destination
|
||||||
for (String originName : allPortalNetworks.get(networkName)) {
|
for (String originName : allPortalNetworks.get(networkName)) {
|
||||||
Portal origin = PortalHandler.getByName(originName, portal.getCleanNetwork());
|
Portal origin = PortalUtil.getByName(originName, portal.getCleanNetwork());
|
||||||
if (origin == null || !origin.getDestinationName().equalsIgnoreCase(portalName) ||
|
if (origin == null || !origin.getDestinationName().equalsIgnoreCase(portalName) ||
|
||||||
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignLocation().getType())) {
|
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignBlock().getType())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Update the portal's sign
|
//Update the portal's sign
|
||||||
@@ -222,9 +223,7 @@ public class PortalRegistry {
|
|||||||
//Mark the portal's sign as unregistered
|
//Mark the portal's sign as unregistered
|
||||||
new PortalSignDrawer(portal).drawUnregisteredSign();
|
new PortalSignDrawer(portal).drawUnregisteredSign();
|
||||||
|
|
||||||
if (portal.getWorld() != null) {
|
PortalFileHelper.saveAllPortals(portal.getLocation().getWorld());
|
||||||
PortalFileHelper.saveAllPortals(portal.getWorld());
|
|
||||||
}
|
|
||||||
portal.setRegistered(false);
|
portal.setRegistered(false);
|
||||||
DynmapManager.removePortalMarker(portal);
|
DynmapManager.removePortalMarker(portal);
|
||||||
}
|
}
|
||||||
@@ -237,22 +236,22 @@ public class PortalRegistry {
|
|||||||
*/
|
*/
|
||||||
private static void clearLookupMaps(@NotNull Portal portal, boolean removeAll) {
|
private static void clearLookupMaps(@NotNull Portal portal, boolean removeAll) {
|
||||||
//Remove portal from lookup blocks
|
//Remove portal from lookup blocks
|
||||||
for (BlockLocation block : portal.getStructure().getFrame()) {
|
for (Block block : portal.getStructure().getFrame()) {
|
||||||
lookupBlocks.remove(block);
|
lookupBlocks.remove(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove registered info about the lookup controls and blocks
|
//Remove registered info about the lookup controls and blocks
|
||||||
lookupBlocks.remove(portal.getSignLocation());
|
lookupBlocks.remove(portal.getLocation().getSignBlock());
|
||||||
lookupControls.remove(portal.getSignLocation());
|
lookupControls.remove(portal.getLocation().getSignBlock());
|
||||||
|
|
||||||
BlockLocation button = portal.getStructure().getButton();
|
Block button = portal.getStructure().getButton();
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
lookupBlocks.remove(button);
|
lookupBlocks.remove(button);
|
||||||
lookupControls.remove(button);
|
lookupControls.remove(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove entrances
|
//Remove entrances
|
||||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||||
lookupEntrances.remove(entrance);
|
lookupEntrances.remove(entrance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,23 +302,23 @@ public class PortalRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Register all frame blocks to the lookup list
|
//Register all frame blocks to the lookup list
|
||||||
for (BlockLocation block : portal.getStructure().getFrame()) {
|
for (Block block : portal.getStructure().getFrame()) {
|
||||||
lookupBlocks.put(block, portal);
|
lookupBlocks.put(block, portal);
|
||||||
}
|
}
|
||||||
//Register the sign and button to the lookup lists
|
//Register the sign and button to the lookup lists
|
||||||
if (!portal.getOptions().hasNoSign()) {
|
if (!portal.getOptions().hasNoSign()) {
|
||||||
lookupBlocks.put(portal.getSignLocation(), portal);
|
lookupBlocks.put(portal.getLocation().getSignBlock(), portal);
|
||||||
lookupControls.put(portal.getSignLocation(), portal);
|
lookupControls.put(portal.getLocation().getSignBlock(), portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockLocation button = portal.getStructure().getButton();
|
Block button = portal.getStructure().getButton();
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
lookupBlocks.put(button, portal);
|
lookupBlocks.put(button, portal);
|
||||||
lookupControls.put(button, portal);
|
lookupControls.put(button, portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Register entrances to the lookup list
|
//Register entrances to the lookup list
|
||||||
for (BlockLocation entrance : portal.getStructure().getEntrances()) {
|
for (Block entrance : portal.getStructure().getEntrances()) {
|
||||||
lookupEntrances.put(entrance, portal);
|
lookupEntrances.put(entrance, portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package net.knarcraft.stargate.portal;
|
|||||||
import net.knarcraft.knarlib.property.ColorConversion;
|
import net.knarcraft.knarlib.property.ColorConversion;
|
||||||
import net.knarcraft.knarlib.util.ColorHelper;
|
import net.knarcraft.knarlib.util.ColorHelper;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.container.SignData;
|
import net.knarcraft.stargate.container.SignData;
|
||||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalUtil;
|
||||||
import net.knarcraft.stargate.utility.SignHelper;
|
import net.knarcraft.stargate.utility.SignHelper;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -130,7 +131,7 @@ public class PortalSignDrawer {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private Sign getSign() {
|
private Sign getSign() {
|
||||||
Block signBlock = portal.getSignLocation().getBlock();
|
Block signBlock = portal.getLocation().getSignBlock();
|
||||||
BlockState state = signBlock.getState();
|
BlockState state = signBlock.getState();
|
||||||
if (!(state instanceof Sign sign)) {
|
if (!(state instanceof Sign sign)) {
|
||||||
if (!portal.getOptions().hasNoSign()) {
|
if (!portal.getOptions().hasNoSign()) {
|
||||||
@@ -272,7 +273,7 @@ public class PortalSignDrawer {
|
|||||||
ChatColor highlightColor = signData.getHighlightSignColor();
|
ChatColor highlightColor = signData.getHighlightSignColor();
|
||||||
ChatColor mainColor = signData.getMainSignColor();
|
ChatColor mainColor = signData.getMainSignColor();
|
||||||
if (freeGatesColored) {
|
if (freeGatesColored) {
|
||||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
Portal destination = PortalUtil.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||||
boolean free = PermissionHelper.isFree(Objects.requireNonNull(portal.getActivePlayer()), portal, destination);
|
boolean free = PermissionHelper.isFree(Objects.requireNonNull(portal.getActivePlayer()), portal, destination);
|
||||||
ChatColor nameColor = (free ? freeColor : highlightColor);
|
ChatColor nameColor = (free ? freeColor : highlightColor);
|
||||||
setLine(signData, signLineIndex, nameColor + ">" + (free ? freeColor : mainColor) +
|
setLine(signData, signLineIndex, nameColor + ">" + (free ? freeColor : mainColor) +
|
||||||
@@ -311,7 +312,7 @@ public class PortalSignDrawer {
|
|||||||
PortalActivator destinations = portal.getPortalActivator();
|
PortalActivator destinations = portal.getPortalActivator();
|
||||||
String destinationName = destinations.getDestinations().get(destinationIndex);
|
String destinationName = destinations.getDestinations().get(destinationIndex);
|
||||||
if (freeGatesColored) {
|
if (freeGatesColored) {
|
||||||
Portal destination = PortalHandler.getByName(destinationName, portal.getNetwork());
|
Portal destination = PortalUtil.getByName(destinationName, portal.getNetwork());
|
||||||
boolean free = PermissionHelper.isFree(Objects.requireNonNull(portal.getActivePlayer()), portal, destination);
|
boolean free = PermissionHelper.isFree(Objects.requireNonNull(portal.getActivePlayer()), portal, destination);
|
||||||
setLine(signData, signLineIndex, (free ? freeColor : mainColor) + translateAllColorCodes(destinationName), output);
|
setLine(signData, signLineIndex, (free ? freeColor : mainColor) + translateAllColorCodes(destinationName), output);
|
||||||
} else {
|
} else {
|
||||||
@@ -365,7 +366,7 @@ public class PortalSignDrawer {
|
|||||||
private void drawFixedSign(@NotNull SignData signData, @NotNull String[] output) {
|
private void drawFixedSign(@NotNull SignData signData, @NotNull String[] output) {
|
||||||
ChatColor highlightColor = signData.getHighlightSignColor();
|
ChatColor highlightColor = signData.getHighlightSignColor();
|
||||||
ChatColor mainColor = signData.getMainSignColor();
|
ChatColor mainColor = signData.getMainSignColor();
|
||||||
Portal destinationPortal = PortalHandler.getByName(portal.getDestinationName(), portal.getCleanNetwork());
|
Portal destinationPortal = PortalUtil.getByName(portal.getDestinationName(), portal.getCleanNetwork());
|
||||||
String destinationName = portal.getOptions().isRandom() ? new SGFormatBuilder(Message.SIGN_RANDOM).toString() :
|
String destinationName = portal.getOptions().isRandom() ? new SGFormatBuilder(Message.SIGN_RANDOM).toString() :
|
||||||
(destinationPortal != null ? destinationPortal.getName() : portal.getDestinationName());
|
(destinationPortal != null ? destinationPortal.getName() : portal.getDestinationName());
|
||||||
setLine(signData, 1, highlightColor + ">" + mainColor + translateAllColorCodes(destinationName) +
|
setLine(signData, 1, highlightColor + ">" + mainColor + translateAllColorCodes(destinationName) +
|
||||||
@@ -377,7 +378,7 @@ public class PortalSignDrawer {
|
|||||||
setLine(signData, 2, highlightColor + "(" + mainColor +
|
setLine(signData, 2, highlightColor + "(" + mainColor +
|
||||||
translateAllColorCodes(portal.getNetwork()) + highlightColor + ")", output);
|
translateAllColorCodes(portal.getNetwork()) + highlightColor + ")", output);
|
||||||
}
|
}
|
||||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
Portal destination = PortalUtil.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||||
if (destination == null && !portal.getOptions().isRandom()) {
|
if (destination == null && !portal.getOptions().isRandom()) {
|
||||||
setLine(signData, 3, errorColor + new SGFormatBuilder(Message.SIGN_DISCONNECTED).toString(), output);
|
setLine(signData, 3, errorColor + new SGFormatBuilder(Message.SIGN_DISCONNECTED).toString(), output);
|
||||||
} else {
|
} else {
|
||||||
@@ -394,7 +395,7 @@ public class PortalSignDrawer {
|
|||||||
*/
|
*/
|
||||||
public static void markPortalWithInvalidGate(@NotNull PortalLocation portalLocation, @NotNull String gateName,
|
public static void markPortalWithInvalidGate(@NotNull PortalLocation portalLocation, @NotNull String gateName,
|
||||||
int lineIndex) {
|
int lineIndex) {
|
||||||
BlockState blockState = portalLocation.getSignLocation().getBlock().getState();
|
BlockState blockState = portalLocation.getSignBlock().getState();
|
||||||
if (!(blockState instanceof Sign sign)) {
|
if (!(blockState instanceof Sign sign)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package net.knarcraft.stargate.portal.property;
|
package net.knarcraft.stargate.portal.property;
|
||||||
|
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
|
||||||
import org.bukkit.Axis;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -14,29 +14,61 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
@SuppressWarnings("UnusedReturnValue")
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public class PortalLocation {
|
public class PortalLocation {
|
||||||
|
|
||||||
private BlockLocation topLeft;
|
private @Nullable Block topLeft;
|
||||||
private float yaw;
|
private @NotNull BlockFace facing;
|
||||||
private BlockLocation signLocation;
|
private @NotNull Block signBlock;
|
||||||
private RelativeBlockVector buttonVector;
|
private @Nullable Block buttonBlock;
|
||||||
private BlockFace buttonFacing;
|
private final @NotNull World world;
|
||||||
|
private final SimpleVectorOperation vectorOperation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new portal location
|
||||||
|
*
|
||||||
|
* @param topLeft <p>The top-left block of the portal</p>
|
||||||
|
* @param facing <p>The direction the portal is facing</p>
|
||||||
|
* @param signBlock <p>The block the sign is attached to</p>
|
||||||
|
* @param buttonBlock <p>The block of the portal, or null if the portal doesn't need a button</p>
|
||||||
|
*/
|
||||||
|
public PortalLocation(@NotNull Block topLeft, @NotNull BlockFace facing, @NotNull Block signBlock,
|
||||||
|
@Nullable Block buttonBlock) {
|
||||||
|
this.world = topLeft.getWorld();
|
||||||
|
this.topLeft = topLeft;
|
||||||
|
this.facing = facing;
|
||||||
|
this.signBlock = signBlock;
|
||||||
|
this.buttonBlock = buttonBlock;
|
||||||
|
this.vectorOperation = new SimpleVectorOperation(facing);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new portal location
|
||||||
|
*
|
||||||
|
* @param signBlock <p>The block the sign is attached to</p>
|
||||||
|
* @param facing <p>The direction the portal is facing</p>
|
||||||
|
*/
|
||||||
|
public PortalLocation(@NotNull Block signBlock, @NotNull BlockFace facing) {
|
||||||
|
this.world = signBlock.getWorld();
|
||||||
|
this.signBlock = signBlock;
|
||||||
|
this.facing = facing;
|
||||||
|
this.vectorOperation = new SimpleVectorOperation(facing);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the top-left block of the portal
|
* Gets the top-left block of the portal
|
||||||
*
|
*
|
||||||
* @return <p>The top-left block of the portal</p>
|
* @return <p>The top-left block of the portal</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@Nullable
|
||||||
public BlockLocation getTopLeft() {
|
public Block getTopLeft() {
|
||||||
return topLeft;
|
return topLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the yaw for looking outwards from the portal
|
* Gets the block face the portal is facing towards
|
||||||
*
|
*
|
||||||
* @return <p>The portal's yaw</p>
|
* @return <p>The portal's facing direction</p>
|
||||||
*/
|
*/
|
||||||
public float getYaw() {
|
public BlockFace getFacing() {
|
||||||
return yaw;
|
return facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +77,8 @@ public class PortalLocation {
|
|||||||
* @return <p>The location of the portal's sign</p>
|
* @return <p>The location of the portal's sign</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockLocation getSignLocation() {
|
public Block getSignBlock() {
|
||||||
return signLocation;
|
return signBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,30 +87,8 @@ public class PortalLocation {
|
|||||||
* @return <p>The relative location of the portal's button</p>
|
* @return <p>The relative location of the portal's button</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public RelativeBlockVector getButtonVector() {
|
public Block getButtonBlock() {
|
||||||
return buttonVector;
|
return buttonBlock;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the block face determining the button's direction
|
|
||||||
*
|
|
||||||
* @return <p>The button's block face</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public BlockFace getButtonFacing() {
|
|
||||||
return buttonFacing;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the rotation axis, which is the axis along which the gate is placed
|
|
||||||
*
|
|
||||||
* <p>The portal's rotation axis is the cross axis of the button's axis</p>
|
|
||||||
*
|
|
||||||
* @return <p>The portal's rotation axis</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public Axis getRotationAxis() {
|
|
||||||
return getYaw() == 0.0F || getYaw() == 180.0F ? Axis.X : Axis.Z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,9 +96,19 @@ public class PortalLocation {
|
|||||||
*
|
*
|
||||||
* @return <p>The world this portal resides in</p>
|
* @return <p>The world this portal resides in</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NotNull
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return topLeft.getWorld();
|
return this.world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the vector operation to use in order to convert this portal's relative vectors to the real space
|
||||||
|
*
|
||||||
|
* @return <p>The vector operation</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public SimpleVectorOperation getVectorOperation() {
|
||||||
|
return this.vectorOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,59 +121,62 @@ public class PortalLocation {
|
|||||||
* @return <p>The portal location Object</p>
|
* @return <p>The portal location Object</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public PortalLocation setTopLeft(@NotNull BlockLocation topLeft) {
|
public PortalLocation setTopLeft(@NotNull Block topLeft) {
|
||||||
this.topLeft = topLeft;
|
this.topLeft = topLeft;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the portal's yaw
|
* Sets the portal's facing direction
|
||||||
*
|
*
|
||||||
* <p>The portal's yaw is the yaw a player would get when looking directly out from the portal</p>
|
* <p>The portal's facing direction is the direction a player would get when looking directly out from the portal</p>
|
||||||
*
|
*
|
||||||
* @param yaw <p>The portal's new yaw</p>
|
* @param facing <p>The portal's new facing direction</p>
|
||||||
* @return <p>The portal location Object</p>
|
* @return <p>The portal location Object</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public PortalLocation setYaw(float yaw) {
|
public PortalLocation setFacing(@NotNull BlockFace facing) {
|
||||||
this.yaw = yaw;
|
this.facing = facing;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the location of the portal's sign
|
* Sets the location of the portal's sign
|
||||||
*
|
*
|
||||||
* @param signLocation <p>The new sign location</p>
|
* @param signBlock <p>The new sign location</p>
|
||||||
* @return <p>The portal location Object</p>
|
* @return <p>The portal location Object</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public PortalLocation setSignLocation(@NotNull BlockLocation signLocation) {
|
public PortalLocation setSignBlock(@NotNull Block signBlock) {
|
||||||
this.signLocation = signLocation;
|
this.signBlock = signBlock;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the relative location of the portal's button
|
* Sets the relative location of the portal's button
|
||||||
*
|
*
|
||||||
* @param buttonVector <p>The new relative button location</p>
|
* @param buttonBlock <p>The new relative button location</p>
|
||||||
* @return <p>The portal location Object</p>
|
* @return <p>The portal location Object</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public PortalLocation setButtonVector(@Nullable RelativeBlockVector buttonVector) {
|
public PortalLocation setButtonBlock(@Nullable Block buttonBlock) {
|
||||||
this.buttonVector = buttonVector;
|
this.buttonBlock = buttonBlock;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the block face for the direction the portal button is facing
|
* Gets a block relative to this portal's top-left block
|
||||||
*
|
*
|
||||||
* @param buttonFacing <p>The new block face of the portal's button</p>
|
* @param vector <p>The relative vector pointing at the block</p>
|
||||||
* @return <p>The portal location Object</p>
|
* @return <p>The block</p>
|
||||||
|
* @throws IllegalStateException <p>If the top-left location is not set</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public PortalLocation setButtonFacing(@NotNull BlockFace buttonFacing) {
|
public Block getRelative(@NotNull BlockVector vector) throws IllegalStateException {
|
||||||
this.buttonFacing = buttonFacing;
|
if (this.topLeft == null) {
|
||||||
return this;
|
throw new IllegalStateException("Top-left is not set");
|
||||||
|
}
|
||||||
|
return this.vectorOperation.getRealLocationBlock(this.topLeft, vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.knarcraft.stargate.portal.property;
|
package net.knarcraft.stargate.portal.property;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.config.Permission;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,71 +11,71 @@ public enum PortalOption {
|
|||||||
/**
|
/**
|
||||||
* This option allows a portal to be hidden from others
|
* This option allows a portal to be hidden from others
|
||||||
*/
|
*/
|
||||||
HIDDEN('h', "hidden", 11),
|
HIDDEN('h', Permission.OPTION_HIDDEN, 11),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option allows a portal that's always on and does not need to be activated or opened each time
|
* This option allows a portal that's always on and does not need to be activated or opened each time
|
||||||
*/
|
*/
|
||||||
ALWAYS_ON('a', "alwayson", 12),
|
ALWAYS_ON('a', Permission.OPTION_ALWAYS_ON, 12),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option allows a portal that's private to the stargate's owner
|
* This option allows a portal that's private to the stargate's owner
|
||||||
*/
|
*/
|
||||||
PRIVATE('p', "private", 13),
|
PRIVATE('p', Permission.OPTIONS_PRIVATE, 13),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option allows a portal that's free even if stargates usually are not
|
* This option allows a portal that's free even if stargates usually are not
|
||||||
*/
|
*/
|
||||||
FREE('f', "free", 15),
|
FREE('f', Permission.OPTIONS_FREE, 15),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option allows a portal where players exit through the back of the portal
|
* This option allows a portal where players exit through the back of the portal
|
||||||
*/
|
*/
|
||||||
BACKWARDS('b', "backwards", 16),
|
BACKWARDS('b', Permission.OPTIONS_BACKWARDS, 16),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option shows the gate in the network list even if it's always on
|
* This option shows the gate in the network list even if it's always on
|
||||||
*/
|
*/
|
||||||
SHOW('s', "show", 17),
|
SHOW('s', Permission.OPTIONS_SHOW, 17),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option hides the network name on the sign
|
* This option hides the network name on the sign
|
||||||
*/
|
*/
|
||||||
NO_NETWORK('n', "nonetwork", 18),
|
NO_NETWORK('n', Permission.OPTIONS_NO_NETWORK, 18),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option allows a portal where players teleport to a random exit portal in the network
|
* This option allows a portal where players teleport to a random exit portal in the network
|
||||||
*/
|
*/
|
||||||
RANDOM('r', "random", 19),
|
RANDOM('r', Permission.OPTIONS_RANDOM, 19),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option allows a portal to teleport to another server connected through BungeeCord
|
* This option allows a portal to teleport to another server connected through BungeeCord
|
||||||
*/
|
*/
|
||||||
BUNGEE('u', "bungee", 20),
|
BUNGEE('u', Permission.OPTIONS_BUNGEE, 20),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option allows a portal which does not display a teleportation message, for better immersion
|
* This option allows a portal which does not display a teleportation message, for better immersion
|
||||||
*/
|
*/
|
||||||
QUIET('q', "quiet", 21),
|
QUIET('q', Permission.OPTIONS_QUIET, 21),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This option causes a fixed portal's sign to be removed after creation
|
* This option causes a fixed portal's sign to be removed after creation
|
||||||
*/
|
*/
|
||||||
NO_SIGN('v', "nosign", 22);
|
INVISIBLE('v', Permission.OPTIONS_INVISIBLE, 22);
|
||||||
|
|
||||||
private final char characterRepresentation;
|
private final char characterRepresentation;
|
||||||
private final String permissionString;
|
private final Permission permission;
|
||||||
private final int saveIndex;
|
private final int saveIndex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new portal options
|
* Instantiates a new portal options
|
||||||
*
|
*
|
||||||
* @param characterRepresentation <p>The character representation used on the sign to allow this option</p>
|
* @param characterRepresentation <p>The character representation used on the sign to allow this option</p>
|
||||||
* @param permissionString <p>The permission necessary to use this option</p>
|
* @param permission <p>The permission necessary to use this option</p>
|
||||||
*/
|
*/
|
||||||
PortalOption(final char characterRepresentation, @NotNull String permissionString, int saveIndex) {
|
PortalOption(final char characterRepresentation, @NotNull Permission permission, int saveIndex) {
|
||||||
this.characterRepresentation = characterRepresentation;
|
this.characterRepresentation = characterRepresentation;
|
||||||
this.permissionString = "stargate.option." + permissionString;
|
this.permission = permission;
|
||||||
this.saveIndex = saveIndex;
|
this.saveIndex = saveIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +94,8 @@ public enum PortalOption {
|
|||||||
* @return <p>The permission necessary for this option</p>
|
* @return <p>The permission necessary for this option</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getPermissionString() {
|
public Permission getPermission() {
|
||||||
return this.permissionString;
|
return this.permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class PortalOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.hasNoSign() && !this.isFixed) {
|
if (this.hasNoSign() && !this.isFixed) {
|
||||||
this.options.put(PortalOption.NO_SIGN, false);
|
this.options.put(PortalOption.INVISIBLE, false);
|
||||||
Stargate.debug("PortalOptions", "Gate marked with no sign, but not fixed. Setting NoSign = false");
|
Stargate.debug("PortalOptions", "Gate marked with no sign, but not fixed. Setting NoSign = false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,17 @@ public class PortalOptions {
|
|||||||
* @return <p>Whether this portal has no sign</p>
|
* @return <p>Whether this portal has no sign</p>
|
||||||
*/
|
*/
|
||||||
public boolean hasNoSign() {
|
public boolean hasNoSign() {
|
||||||
return this.options.get(PortalOption.NO_SIGN);
|
return this.options.get(PortalOption.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given portal option is true
|
||||||
|
*
|
||||||
|
* @param option <p>The option to check</p>
|
||||||
|
* @return <p>True if enabled for the portal</p>
|
||||||
|
*/
|
||||||
|
public boolean checkOption(@NotNull PortalOption option) {
|
||||||
|
return this.options.get(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package net.knarcraft.stargate.portal.property;
|
package net.knarcraft.stargate.portal.property;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -18,9 +18,9 @@ public class PortalStructure {
|
|||||||
|
|
||||||
private final Portal portal;
|
private final Portal portal;
|
||||||
private final Gate gate;
|
private final Gate gate;
|
||||||
private BlockLocation button;
|
private Block button;
|
||||||
private BlockLocation[] frame;
|
private Block[] frame;
|
||||||
private BlockLocation[] entrances;
|
private Block[] entrances;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new portal structure
|
* Instantiates a new portal structure
|
||||||
@@ -29,7 +29,7 @@ public class PortalStructure {
|
|||||||
* @param gate <p>The gate type used by this portal structure</p>
|
* @param gate <p>The gate type used by this portal structure</p>
|
||||||
* @param button <p>The real location of the portal's button</p>
|
* @param button <p>The real location of the portal's button</p>
|
||||||
*/
|
*/
|
||||||
public PortalStructure(@NotNull Portal portal, @NotNull Gate gate, @Nullable BlockLocation button) {
|
public PortalStructure(@NotNull Portal portal, @NotNull Gate gate, @Nullable Block button) {
|
||||||
this.portal = portal;
|
this.portal = portal;
|
||||||
this.gate = gate;
|
this.gate = gate;
|
||||||
this.button = button;
|
this.button = button;
|
||||||
@@ -51,7 +51,7 @@ public class PortalStructure {
|
|||||||
* @return <p>The location of this portal's button</p>
|
* @return <p>The location of this portal's button</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public BlockLocation getButton() {
|
public Block getButton() {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class PortalStructure {
|
|||||||
*
|
*
|
||||||
* @param button <p>The location of this portal's button</p>
|
* @param button <p>The location of this portal's button</p>
|
||||||
*/
|
*/
|
||||||
public void setButton(@NotNull BlockLocation button) {
|
public void setButton(@NotNull Block button) {
|
||||||
this.button = button;
|
this.button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class PortalStructure {
|
|||||||
*/
|
*/
|
||||||
public boolean checkIntegrity() {
|
public boolean checkIntegrity() {
|
||||||
if (Stargate.getGateConfig().verifyPortals()) {
|
if (Stargate.getGateConfig().verifyPortals()) {
|
||||||
return gate.matches(portal.getTopLeft(), portal.getYaw());
|
return gate.matches(portal.getLocation().getTopLeft(), portal.getLocation().getFacing());
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -87,10 +87,10 @@ public class PortalStructure {
|
|||||||
* @return <p>A list of block locations</p>
|
* @return <p>A list of block locations</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
private BlockLocation[] relativeBlockVectorsToBlockLocations(@NotNull RelativeBlockVector[] vectors) {
|
private Block[] relativeBlockVectorsToBlockLocations(@NotNull BlockVector[] vectors) {
|
||||||
BlockLocation[] locations = new BlockLocation[vectors.length];
|
Block[] locations = new Block[vectors.length];
|
||||||
for (int i = 0; i < vectors.length; i++) {
|
for (int i = 0; i < vectors.length; i++) {
|
||||||
locations[i] = portal.getBlockAt(vectors[i]);
|
locations[i] = portal.getLocation().getRelative(vectors[i]);
|
||||||
}
|
}
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ public class PortalStructure {
|
|||||||
* @return <p>The locations of this portal's entrances</p>
|
* @return <p>The locations of this portal's entrances</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockLocation[] getEntrances() {
|
public Block[] getEntrances() {
|
||||||
if (entrances == null) {
|
if (entrances == null) {
|
||||||
//Get the locations of the entrances once, and only if necessary as it's an expensive operation
|
//Get the locations of the entrances once, and only if necessary as it's an expensive operation
|
||||||
entrances = relativeBlockVectorsToBlockLocations(gate.getLayout().getEntrances());
|
entrances = relativeBlockVectorsToBlockLocations(gate.getLayout().getEntrances());
|
||||||
@@ -115,7 +115,7 @@ public class PortalStructure {
|
|||||||
* @return <p>The locations of this portal's frame</p>
|
* @return <p>The locations of this portal's frame</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockLocation[] getFrame() {
|
public Block[] getFrame() {
|
||||||
if (frame == null) {
|
if (frame == null) {
|
||||||
//Get the locations of the frame blocks once, and only if necessary as it's an expensive operation
|
//Get the locations of the frame blocks once, and only if necessary as it's an expensive operation
|
||||||
frame = relativeBlockVectorsToBlockLocations(gate.getLayout().getBorder());
|
frame = relativeBlockVectorsToBlockLocations(gate.getLayout().getBorder());
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ package net.knarcraft.stargate.portal.property.gate;
|
|||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.material.BukkitMaterialSpecifier;
|
import net.knarcraft.stargate.config.material.BukkitMaterialSpecifier;
|
||||||
import net.knarcraft.stargate.config.material.MaterialSpecifier;
|
import net.knarcraft.stargate.config.material.MaterialSpecifier;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -181,11 +183,11 @@ public class Gate {
|
|||||||
* Checks whether a portal's gate matches this gate type
|
* Checks whether a portal's gate matches this gate type
|
||||||
*
|
*
|
||||||
* @param topLeft <p>The top-left block of the portal's gate</p>
|
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||||
* @param yaw <p>The yaw when looking directly outwards</p>
|
* @param facing <p>The direction the portal is facing</p>
|
||||||
* @return <p>True if this gate matches the portal</p>
|
* @return <p>True if this gate matches the portal</p>
|
||||||
*/
|
*/
|
||||||
public boolean matches(@NotNull BlockLocation topLeft, double yaw) {
|
public boolean matches(@NotNull Block topLeft, @NotNull BlockFace facing) {
|
||||||
return matches(topLeft, yaw, false);
|
return matches(topLeft, facing, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,34 +198,34 @@ public class Gate {
|
|||||||
* containing AIR or WATER will cause the gate to not match.</p>
|
* containing AIR or WATER will cause the gate to not match.</p>
|
||||||
*
|
*
|
||||||
* @param topLeft <p>The top-left block of the portal's gate</p>
|
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||||
* @param yaw <p>The yaw when looking directly outwards</p>
|
* @param facing <p>The direction the portal is facing</p>
|
||||||
* @param onCreate <p>Whether this is used in the context of creating a new gate</p>
|
* @param onCreate <p>Whether this is used in the context of creating a new gate</p>
|
||||||
* @return <p>True if this gate matches the portal</p>
|
* @return <p>True if this gate matches the portal</p>
|
||||||
*/
|
*/
|
||||||
public boolean matches(@NotNull BlockLocation topLeft, double yaw, boolean onCreate) {
|
public boolean matches(@NotNull Block topLeft, @NotNull BlockFace facing, boolean onCreate) {
|
||||||
return verifyGateEntrancesMatch(topLeft, yaw, onCreate) && verifyGateBorderMatches(topLeft, yaw);
|
return verifyGateEntrancesMatch(topLeft, facing, onCreate) && verifyGateBorderMatches(topLeft, facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that all border blocks of a portal matches this gate type
|
* Verifies that all border blocks of a portal matches this gate type
|
||||||
*
|
*
|
||||||
* @param topLeft <p>The top-left block of the portal</p>
|
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||||
* @param yaw <p>The yaw when looking directly outwards from the portal</p>
|
* @param facing <p>The direction the portal is facing</p>
|
||||||
* @return <p>True if all border blocks of the gate match the layout</p>
|
* @return <p>True if all border blocks of the gate match the layout</p>
|
||||||
*/
|
*/
|
||||||
private boolean verifyGateBorderMatches(@NotNull BlockLocation topLeft, double yaw) {
|
private boolean verifyGateBorderMatches(@NotNull Block topLeft, @NotNull BlockFace facing) {
|
||||||
for (RelativeBlockVector borderVector : layout.getBorder()) {
|
for (BlockVector borderVector : layout.getBorder()) {
|
||||||
int rowIndex = borderVector.right();
|
int rowIndex = borderVector.getBlockX();
|
||||||
int lineIndex = borderVector.down();
|
int lineIndex = borderVector.getBlockY();
|
||||||
Character key = layout.getLayout()[lineIndex][rowIndex];
|
Character key = layout.getLayout()[lineIndex][rowIndex];
|
||||||
|
|
||||||
List<MaterialSpecifier> materialInLayout = characterMaterialMap.get(key);
|
List<MaterialSpecifier> materialInLayout = characterMaterialMap.get(key);
|
||||||
Material materialAtLocation = topLeft.getRelativeLocation(borderVector, yaw).getType();
|
Material type = new SimpleVectorOperation(facing).getRealLocationBlock(topLeft, borderVector).getType();
|
||||||
|
|
||||||
if (materialInLayout != null) {
|
if (materialInLayout != null) {
|
||||||
if (!MaterialHelper.specifiersToMaterials(materialInLayout).contains(materialAtLocation)) {
|
if (!MaterialHelper.specifiersToMaterials(materialInLayout).contains(type)) {
|
||||||
Stargate.debug("Gate::Matches", String.format("Block Type Mismatch: %s != %s",
|
Stargate.debug("Gate::Matches", String.format("Block Type Mismatch: %s != %s",
|
||||||
materialAtLocation, MaterialHelper.specifiersToMaterials(materialInLayout)));
|
type, MaterialHelper.specifiersToMaterials(materialInLayout)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -231,9 +233,9 @@ public class Gate {
|
|||||||
* recognized, but still allowed in previous checks, verify the gate as long as all such instances of
|
* recognized, but still allowed in previous checks, verify the gate as long as all such instances of
|
||||||
* the character correspond to the same material in the physical gate. All subsequent gates will also
|
* the character correspond to the same material in the physical gate. All subsequent gates will also
|
||||||
* need to match the first verified gate. */
|
* need to match the first verified gate. */
|
||||||
this.characterMaterialMap.put(key, List.of(new BukkitMaterialSpecifier(materialAtLocation)));
|
this.characterMaterialMap.put(key, List.of(new BukkitMaterialSpecifier(type)));
|
||||||
Stargate.debug("Gate::Matches", String.format("Missing layout material in %s. Using %s from the" +
|
Stargate.debug("Gate::Matches", String.format("Missing layout material in %s. Using %s from the" +
|
||||||
" physical portal.", getFilename(), materialAtLocation));
|
" physical portal.", getFilename(), type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -242,16 +244,16 @@ public class Gate {
|
|||||||
/**
|
/**
|
||||||
* Verifies that all entrances of a portal gate matches this gate type
|
* Verifies that all entrances of a portal gate matches this gate type
|
||||||
*
|
*
|
||||||
* @param topLeft <p>The top-left block of this portal</p>
|
* @param topLeft <p>The top-left block of the portal's gate</p>
|
||||||
* @param yaw <p>The yaw when looking directly outwards</p>
|
* @param facing <p>The direction the portal is facing</p>
|
||||||
* @param onCreate <p>Whether this is used in the context of creating a new gate</p>
|
* @param onCreate <p>Whether this is used in the context of creating a new gate</p>
|
||||||
* @return <p>Whether this is used in the context of creating a new gate</p>
|
* @return <p>Whether this is used in the context of creating a new gate</p>
|
||||||
*/
|
*/
|
||||||
private boolean verifyGateEntrancesMatch(@NotNull BlockLocation topLeft, double yaw, boolean onCreate) {
|
private boolean verifyGateEntrancesMatch(@NotNull Block topLeft, @NotNull BlockFace facing, boolean onCreate) {
|
||||||
Stargate.debug("verifyGateEntrancesMatch", String.valueOf(topLeft));
|
Stargate.debug("verifyGateEntrancesMatch", String.valueOf(topLeft));
|
||||||
for (RelativeBlockVector entranceVector : layout.getEntrances()) {
|
for (BlockVector entranceVector : layout.getEntrances()) {
|
||||||
Stargate.debug("verifyGateEntrancesMatch", String.valueOf(entranceVector));
|
Stargate.debug("verifyGateEntrancesMatch", String.valueOf(entranceVector));
|
||||||
Material type = topLeft.getRelativeLocation(entranceVector, yaw).getType();
|
Material type = new SimpleVectorOperation(facing).getRealLocationBlock(topLeft, entranceVector).getType();
|
||||||
|
|
||||||
//Ignore entrance if it's air or water, and we're creating a new gate
|
//Ignore entrance if it's air or water, and we're creating a new gate
|
||||||
if (onCreate && (type.isAir() || type == Material.WATER)) {
|
if (onCreate && (type.isAir() || type == Material.WATER)) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.knarcraft.stargate.portal.property.gate;
|
package net.knarcraft.stargate.portal.property.gate;
|
||||||
|
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -19,11 +19,11 @@ import java.util.List;
|
|||||||
public class GateLayout {
|
public class GateLayout {
|
||||||
|
|
||||||
private final Character[][] layout;
|
private final Character[][] layout;
|
||||||
private final List<RelativeBlockVector> exits = new ArrayList<>();
|
private final List<BlockVector> exits = new ArrayList<>();
|
||||||
private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
|
private BlockVector[] entrances = new BlockVector[0];
|
||||||
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
private BlockVector[] border = new BlockVector[0];
|
||||||
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
private BlockVector[] controls = new BlockVector[0];
|
||||||
private RelativeBlockVector exitBlock = null;
|
private BlockVector exitBlock = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new gate layout
|
* Instantiates a new gate layout
|
||||||
@@ -53,7 +53,7 @@ public class GateLayout {
|
|||||||
* @return <p>The locations of entrances for this gate</p>
|
* @return <p>The locations of entrances for this gate</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public RelativeBlockVector[] getEntrances() {
|
public BlockVector[] getEntrances() {
|
||||||
return entrances;
|
return entrances;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class GateLayout {
|
|||||||
* @return <p>The locations of border blocks for this gate</p>
|
* @return <p>The locations of border blocks for this gate</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public RelativeBlockVector[] getBorder() {
|
public BlockVector[] getBorder() {
|
||||||
return border;
|
return border;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class GateLayout {
|
|||||||
* @return <p>The exit block defined in the layout</p>
|
* @return <p>The exit block defined in the layout</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public RelativeBlockVector getExit() {
|
public BlockVector getExit() {
|
||||||
return exitBlock;
|
return exitBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ public class GateLayout {
|
|||||||
* @return <p>All possible exits</p>
|
* @return <p>All possible exits</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<RelativeBlockVector> getExits() {
|
public List<BlockVector> getExits() {
|
||||||
return exits;
|
return exits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public class GateLayout {
|
|||||||
* @return <p>The locations of the control blocks for this gate</p>
|
* @return <p>The locations of the control blocks for this gate</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public RelativeBlockVector[] getControls() {
|
public BlockVector[] getControls() {
|
||||||
return controls;
|
return controls;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,9 +127,9 @@ public class GateLayout {
|
|||||||
* <p>This methods reads the layout and stores exits, entrances, border blocks and control blocks.</p>
|
* <p>This methods reads the layout and stores exits, entrances, border blocks and control blocks.</p>
|
||||||
*/
|
*/
|
||||||
private void readLayout() {
|
private void readLayout() {
|
||||||
List<RelativeBlockVector> entranceList = new ArrayList<>();
|
List<BlockVector> entranceList = new ArrayList<>();
|
||||||
List<RelativeBlockVector> borderList = new ArrayList<>();
|
List<BlockVector> borderList = new ArrayList<>();
|
||||||
List<RelativeBlockVector> controlList = new ArrayList<>();
|
List<BlockVector> controlList = new ArrayList<>();
|
||||||
|
|
||||||
readLayout(controlList, entranceList, borderList);
|
readLayout(controlList, entranceList, borderList);
|
||||||
|
|
||||||
@@ -145,9 +145,9 @@ public class GateLayout {
|
|||||||
* @param entranceList <p>The list of entrances to save to</p>
|
* @param entranceList <p>The list of entrances to save to</p>
|
||||||
* @param borderList <p>The list of border blocks to save to</p>
|
* @param borderList <p>The list of border blocks to save to</p>
|
||||||
*/
|
*/
|
||||||
private void readLayout(@NotNull List<RelativeBlockVector> controlList,
|
private void readLayout(@NotNull List<BlockVector> controlList,
|
||||||
@NotNull List<RelativeBlockVector> entranceList,
|
@NotNull List<BlockVector> entranceList,
|
||||||
@NotNull List<RelativeBlockVector> borderList) {
|
@NotNull List<BlockVector> borderList) {
|
||||||
//Store the lowest opening for each column
|
//Store the lowest opening for each column
|
||||||
int[] exitDepths = new int[layout[0].length];
|
int[] exitDepths = new int[layout[0].length];
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ public class GateLayout {
|
|||||||
for (int x = 0; x < exitDepths.length; x++) {
|
for (int x = 0; x < exitDepths.length; x++) {
|
||||||
//Ignore invalid exits
|
//Ignore invalid exits
|
||||||
if (exitDepths[x] > 0) {
|
if (exitDepths[x] > 0) {
|
||||||
this.exits.add(new RelativeBlockVector(x, exitDepths[x], 0));
|
this.exits.add(new BlockVector(x, exitDepths[x], 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,26 +183,26 @@ public class GateLayout {
|
|||||||
* @param borderList <p>The list of border blocks to save to</p>
|
* @param borderList <p>The list of border blocks to save to</p>
|
||||||
*/
|
*/
|
||||||
private void parseLayoutCharacter(@NotNull Character key, int columnIndex, int rowIndex, int[] exitDepths,
|
private void parseLayoutCharacter(@NotNull Character key, int columnIndex, int rowIndex, int[] exitDepths,
|
||||||
@NotNull List<RelativeBlockVector> controlList,
|
@NotNull List<BlockVector> controlList,
|
||||||
@NotNull List<RelativeBlockVector> entranceList,
|
@NotNull List<BlockVector> entranceList,
|
||||||
@NotNull List<RelativeBlockVector> borderList) {
|
@NotNull List<BlockVector> borderList) {
|
||||||
//Add control blocks to the control block list
|
//Add control blocks to the control block list
|
||||||
if (key.equals(GateHandler.getControlBlockCharacter())) {
|
if (key.equals(GateHandler.getControlBlockCharacter())) {
|
||||||
controlList.add(new RelativeBlockVector(columnIndex, rowIndex, 0));
|
controlList.add(new BlockVector(columnIndex, rowIndex, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOpening(key)) {
|
if (isOpening(key)) {
|
||||||
//Register entrance
|
//Register entrance
|
||||||
entranceList.add(new RelativeBlockVector(columnIndex, rowIndex, 0));
|
entranceList.add(new BlockVector(columnIndex, rowIndex, 0));
|
||||||
//Overwrite the lowest exit location for this column/x-coordinate
|
//Overwrite the lowest exit location for this column/x-coordinate
|
||||||
exitDepths[columnIndex] = rowIndex;
|
exitDepths[columnIndex] = rowIndex;
|
||||||
//Register exit if found
|
//Register exit if found
|
||||||
if (key.equals(GateHandler.getExitCharacter())) {
|
if (key.equals(GateHandler.getExitCharacter())) {
|
||||||
this.exitBlock = new RelativeBlockVector(columnIndex, rowIndex, 0);
|
this.exitBlock = new BlockVector(columnIndex, rowIndex, 0);
|
||||||
}
|
}
|
||||||
} else if (!key.equals(GateHandler.getAnythingCharacter())) {
|
} else if (!key.equals(GateHandler.getAnythingCharacter())) {
|
||||||
//Register border block
|
//Register border block
|
||||||
borderList.add(new RelativeBlockVector(columnIndex, rowIndex, 0));
|
borderList.add(new BlockVector(columnIndex, rowIndex, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class PlayerTeleporter extends Teleporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Calculate the exit velocity of the player
|
//Calculate the exit velocity of the player
|
||||||
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getYaw());
|
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getLocation().getYaw());
|
||||||
Vector newVelocity = newVelocityDirection.multiply(velocity * Stargate.getGateConfig().getExitVelocity());
|
Vector newVelocity = newVelocityDirection.multiply(velocity * Stargate.getGateConfig().getExitVelocity());
|
||||||
|
|
||||||
//Load chunks to make sure not to teleport to the void
|
//Load chunks to make sure not to teleport to the void
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package net.knarcraft.stargate.portal.teleporter;
|
package net.knarcraft.stargate.portal.teleporter;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.container.ChunkUnloadRequest;
|
import net.knarcraft.stargate.container.ChunkUnloadRequest;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||||
import net.knarcraft.stargate.event.StargateTeleportEvent;
|
import net.knarcraft.stargate.event.StargateTeleportEvent;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
|
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||||
import net.knarcraft.stargate.utility.EntityHelper;
|
import net.knarcraft.stargate.utility.EntityHelper;
|
||||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.Bisected;
|
import org.bukkit.block.data.Bisected;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.type.Slab;
|
import org.bukkit.block.data.type.Slab;
|
||||||
@@ -19,6 +21,7 @@ import org.bukkit.entity.AbstractHorse;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -132,7 +135,7 @@ public abstract class Teleporter {
|
|||||||
if (portal.getOptions().isBackwards()) {
|
if (portal.getOptions().isBackwards()) {
|
||||||
adjust = 180;
|
adjust = 180;
|
||||||
}
|
}
|
||||||
float newYaw = (portal.getYaw() + adjust) % 360;
|
float newYaw = (portal.getLocation().getYaw() + adjust) % 360;
|
||||||
Stargate.debug("Portal::adjustRotation", "Setting exit yaw to " + newYaw);
|
Stargate.debug("Portal::adjustRotation", "Setting exit yaw to " + newYaw);
|
||||||
exit.setDirection(DirectionHelper.getDirectionVectorFromYaw(newYaw));
|
exit.setDirection(DirectionHelper.getDirectionVectorFromYaw(newYaw));
|
||||||
}
|
}
|
||||||
@@ -174,7 +177,7 @@ public abstract class Teleporter {
|
|||||||
if (openingWidth > 1) {
|
if (openingWidth > 1) {
|
||||||
newOffset -= 0.5;
|
newOffset -= 0.5;
|
||||||
}
|
}
|
||||||
exitLocation = DirectionHelper.moveLocation(exitLocation, newOffset, 0, 0, portal.getYaw());
|
exitLocation = DirectionHelper.moveLocation(exitLocation, newOffset, 0, 0, portal.getLocation().getYaw());
|
||||||
|
|
||||||
//Move large entities further from the portal
|
//Move large entities further from the portal
|
||||||
return moveExitLocationOutwards(exitLocation, entity);
|
return moveExitLocationOutwards(exitLocation, entity);
|
||||||
@@ -203,7 +206,7 @@ public abstract class Teleporter {
|
|||||||
if (entity instanceof AbstractHorse) {
|
if (entity instanceof AbstractHorse) {
|
||||||
entityOffset += 1;
|
entityOffset += 1;
|
||||||
}
|
}
|
||||||
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0, entityOffset, portal.getYaw());
|
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0, entityOffset, portal.getLocation().getYaw());
|
||||||
}
|
}
|
||||||
return exitLocation;
|
return exitLocation;
|
||||||
}
|
}
|
||||||
@@ -269,17 +272,19 @@ public abstract class Teleporter {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
private Location getExit(@NotNull Entity entity) {
|
private Location getExit(@NotNull Entity entity) {
|
||||||
Location exitLocation = null;
|
Block exitLocation = null;
|
||||||
RelativeBlockVector relativeExit = portal.getGate().getLayout().getExit();
|
BlockVector relativeExit = portal.getGate().getLayout().getExit();
|
||||||
if (relativeExit != null) {
|
if (relativeExit != null) {
|
||||||
BlockLocation exit = portal.getBlockAt(relativeExit);
|
Block exit = portal.getBlockAt(relativeExit);
|
||||||
|
|
||||||
//Move one block out to prevent exiting inside the portal
|
//Move one block out to prevent exiting inside the portal
|
||||||
float portalYaw = portal.getYaw();
|
BlockFace facing = portal.getLocation().getFacing();
|
||||||
if (portal.getOptions().isBackwards()) {
|
if (portal.getOptions().isBackwards()) {
|
||||||
portalYaw += 180;
|
facing = facing.getOppositeFace();
|
||||||
}
|
}
|
||||||
exitLocation = exit.getRelativeLocation(0D, 0D, 1, portalYaw);
|
SimpleVectorOperation operation = new SimpleVectorOperation(facing);
|
||||||
|
exitLocation = operation.getRealLocationBlock(portal.getLocation().getTopLeft(),
|
||||||
|
new BlockVector(0, 0, 1));
|
||||||
|
|
||||||
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
||||||
//Prevent exit suffocation for players riding horses or similar
|
//Prevent exit suffocation for players riding horses or similar
|
||||||
@@ -305,8 +310,8 @@ public abstract class Teleporter {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private List<Chunk> getChunksToLoad() {
|
private List<Chunk> getChunksToLoad() {
|
||||||
List<Chunk> chunksToLoad = new ArrayList<>();
|
List<Chunk> chunksToLoad = new ArrayList<>();
|
||||||
for (RelativeBlockVector vector : portal.getGate().getLayout().getEntrances()) {
|
for (BlockVector vector : portal.getGate().getLayout().getEntrances()) {
|
||||||
BlockLocation entranceLocation = portal.getBlockAt(vector);
|
Block entranceLocation = portal.getBlockAt(vector);
|
||||||
Chunk chunk = entranceLocation.getChunk();
|
Chunk chunk = entranceLocation.getChunk();
|
||||||
//Make sure not to load chunks twice
|
//Make sure not to load chunks twice
|
||||||
if (!chunksToLoad.contains(chunk)) {
|
if (!chunksToLoad.contains(chunk)) {
|
||||||
@@ -315,8 +320,7 @@ public abstract class Teleporter {
|
|||||||
|
|
||||||
//Get the chunk in front of the gate entrance
|
//Get the chunk in front of the gate entrance
|
||||||
int blockOffset = portal.getOptions().isBackwards() ? -5 : 5;
|
int blockOffset = portal.getOptions().isBackwards() ? -5 : 5;
|
||||||
Location fiveBlocksForward = DirectionHelper.moveLocation(entranceLocation, 0, 0, blockOffset,
|
Block fiveBlocksForward = entranceLocation.getRelative(portal.getLocation().getFacing(), blockOffset);
|
||||||
portal.getYaw());
|
|
||||||
//Load the chunk five blocks forward to make sure the teleported entity will never spawn in unloaded chunks
|
//Load the chunk five blocks forward to make sure the teleported entity will never spawn in unloaded chunks
|
||||||
Chunk forwardChunk = fiveBlocksForward.getChunk();
|
Chunk forwardChunk = fiveBlocksForward.getChunk();
|
||||||
if (!chunksToLoad.contains(forwardChunk)) {
|
if (!chunksToLoad.contains(forwardChunk)) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class VehicleTeleporter extends EntityTeleporter {
|
|||||||
teleportingVehicle.setVelocity(new Vector());
|
teleportingVehicle.setVelocity(new Vector());
|
||||||
|
|
||||||
//Get new velocity
|
//Get new velocity
|
||||||
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getYaw());
|
Vector newVelocityDirection = DirectionHelper.getDirectionVectorFromYaw(portal.getLocation().getYaw());
|
||||||
Vector newVelocity = newVelocityDirection.multiply(velocity);
|
Vector newVelocity = newVelocityDirection.multiply(velocity);
|
||||||
|
|
||||||
//Call the StargateEntityPortalEvent to allow plugins to change destination
|
//Call the StargateEntityPortalEvent to allow plugins to change destination
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ package net.knarcraft.stargate.thread;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This thread updates the signs and buttons of Stargates, if deemed necessary
|
* This thread updates the signs and buttons of Stargates, if deemed necessary
|
||||||
@@ -26,7 +25,7 @@ public class ControlBlocksUpdateThread implements Runnable {
|
|||||||
Portal portal = controlBlockUpdateRequest.portal();
|
Portal portal = controlBlockUpdateRequest.portal();
|
||||||
portal.drawSign();
|
portal.drawSign();
|
||||||
|
|
||||||
BlockLocation buttonLocation = PortalFileHelper.getButtonLocation(portal);
|
Block buttonLocation = portal.getLocation().getButtonBlock();
|
||||||
if (buttonLocation == null) {
|
if (buttonLocation == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -42,7 +41,7 @@ public class ControlBlocksUpdateThread implements Runnable {
|
|||||||
} else {
|
} else {
|
||||||
//Replace button if the material is not a button
|
//Replace button if the material is not a button
|
||||||
if (!MaterialHelper.isButtonCompatible(buttonLocation.getType())) {
|
if (!MaterialHelper.isButtonCompatible(buttonLocation.getType())) {
|
||||||
PortalFileHelper.generatePortalButton(portal, DirectionHelper.getBlockFaceFromYaw(portal.getYaw()));
|
PortalFileHelper.generatePortalButton(portal, portal.getLocation().getFacing());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,208 @@
|
|||||||
|
package net.knarcraft.stargate.transformation;
|
||||||
|
|
||||||
|
import org.bukkit.Axis;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for performing rotational operations on vectors
|
||||||
|
*
|
||||||
|
* @author Kristian Knarvik
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class SimpleVectorOperation {
|
||||||
|
|
||||||
|
private static final Map<BlockFace, Double> rotationAngles = new HashMap<>();
|
||||||
|
private static final Map<BlockFace, Vector> rotationAxes = new HashMap<>();
|
||||||
|
private static final Map<BlockFace, Axis> normalAxes = new HashMap<>();
|
||||||
|
private static final BlockFace defaultDirection = BlockFace.SOUTH;
|
||||||
|
private static final Axis defaultVerticalAxis = Axis.Y;
|
||||||
|
|
||||||
|
private final Axis normalAxis;
|
||||||
|
private boolean flipXAxis = false;
|
||||||
|
private final BlockFace facing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a vector operation to rotate vectors in the direction of a sign face
|
||||||
|
*
|
||||||
|
* @param signFace <p>The sign face of a gate's sign</p>
|
||||||
|
*/
|
||||||
|
public SimpleVectorOperation(@NotNull BlockFace signFace) {
|
||||||
|
if (normalAxes.isEmpty()) {
|
||||||
|
initializeIrisNormalAxes();
|
||||||
|
initializeOperations();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.facing = signFace;
|
||||||
|
this.normalAxis = normalAxes.get(signFace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the block face of a sign given upon instantiation
|
||||||
|
*
|
||||||
|
* @return <p>The block face of a sign given upon instantiation</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
return facing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the normal axis orthogonal to the opening plane
|
||||||
|
*
|
||||||
|
* <p>Said another way, get the axis going directly towards or away from a stargate's entrance.</p>
|
||||||
|
*
|
||||||
|
* @return <p>The normal axis orthogonal to the opening plane</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public Axis getNormalAxis() {
|
||||||
|
return normalAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether to flip the X- axis
|
||||||
|
*
|
||||||
|
* @param flipXAxis <p>Whether to flip the X-axis</p>
|
||||||
|
*/
|
||||||
|
public void setFlipXAxis(boolean flipXAxis) {
|
||||||
|
this.flipXAxis = flipXAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs an operation from the real space to the vector space
|
||||||
|
*
|
||||||
|
* @param vector <p>The vector to perform the operation on</p>
|
||||||
|
* @return vector <p>A new vector with the operation applied</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public Vector performToAbstractSpaceOperation(@NotNull Vector vector) {
|
||||||
|
Vector clone = vector.clone();
|
||||||
|
clone.rotateAroundAxis(rotationAxes.get(facing), rotationAngles.get(facing));
|
||||||
|
if (flipXAxis) {
|
||||||
|
clone.setX(-clone.getX());
|
||||||
|
}
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs an operation from the vector space to the real space
|
||||||
|
*
|
||||||
|
* @param vector <p>The vector to perform the inverse operation on</p>
|
||||||
|
* @return vector <p>A new vector with the operation applied</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public Vector performToRealSpaceOperation(@NotNull Vector vector) {
|
||||||
|
Vector clone = vector.clone();
|
||||||
|
if (flipXAxis) {
|
||||||
|
clone.setX(-clone.getX());
|
||||||
|
}
|
||||||
|
return clone.rotateAroundAxis(rotationAxes.get(facing), -rotationAngles.get(facing));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs an operation from the vector space to the real space
|
||||||
|
*
|
||||||
|
* @param vector <p>The vector to perform the inverse operation on</p>
|
||||||
|
* @return vector <p>A new vector with the operation applied</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public BlockVector performToRealSpaceOperation(@NotNull BlockVector vector) {
|
||||||
|
return performToRealSpaceOperation((Vector) vector).toBlockVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the block vector pointing to the real location of the relative block vector
|
||||||
|
*
|
||||||
|
* @param topLeft <p>The vector of the top-left portal block</p>
|
||||||
|
* @param relative <p>The relative vector of a portal block</p>
|
||||||
|
* @return <p>The vector for the true location of the block in the real space</p>
|
||||||
|
*/
|
||||||
|
public BlockVector getRealLocationVector(@NotNull BlockVector topLeft, @NotNull BlockVector relative) {
|
||||||
|
return topLeft.clone().add(this.performToRealSpaceOperation(relative)).toBlockVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the block pointing to the real location of the relative block vector
|
||||||
|
*
|
||||||
|
* @param topLeft <p>The top-left portal block</p>
|
||||||
|
* @param relative <p>The relative vector of a portal block</p>
|
||||||
|
* @return <p>The corresponding block</p>
|
||||||
|
*/
|
||||||
|
public Block getRealLocationBlock(@NotNull Block topLeft, @NotNull BlockVector relative) {
|
||||||
|
return topLeft.getLocation().clone().add(this.performToRealSpaceOperation(relative)).getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the operations used for rotating to each block-face
|
||||||
|
*/
|
||||||
|
private static void initializeOperations() {
|
||||||
|
Map<Axis, Vector> axisVectors = new HashMap<>();
|
||||||
|
axisVectors.put(Axis.Y, new Vector(0, 1, 0));
|
||||||
|
axisVectors.put(Axis.X, new Vector(1, 0, 0));
|
||||||
|
axisVectors.put(Axis.Z, new Vector(0, 0, 1));
|
||||||
|
|
||||||
|
//Use the cross product to find the correct axis
|
||||||
|
for (BlockFace face : normalAxes.keySet()) {
|
||||||
|
Vector crossProduct = face.getDirection().crossProduct(defaultDirection.getDirection());
|
||||||
|
if (face == defaultDirection || face == defaultDirection.getOppositeFace()) {
|
||||||
|
rotationAxes.put(face, axisVectors.get(defaultVerticalAxis));
|
||||||
|
} else if (Math.abs(crossProduct.getZ()) > 0) {
|
||||||
|
rotationAxes.put(face, axisVectors.get(Axis.Z));
|
||||||
|
} else if (Math.abs(crossProduct.getY()) > 0) {
|
||||||
|
rotationAxes.put(face, axisVectors.get(Axis.Y));
|
||||||
|
} else {
|
||||||
|
rotationAxes.put(face, axisVectors.get(Axis.X));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateRotations();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the required rotations based on the default rotation
|
||||||
|
*/
|
||||||
|
private static void calculateRotations() {
|
||||||
|
double halfRotation = Math.PI;
|
||||||
|
double quarterRotation = halfRotation / 2;
|
||||||
|
|
||||||
|
Vector defaultDirectionVector = defaultDirection.getDirection();
|
||||||
|
boolean defaultDirectionPositive = defaultDirectionVector.getX() + defaultDirectionVector.getY() +
|
||||||
|
defaultDirectionVector.getZ() > 0;
|
||||||
|
|
||||||
|
for (BlockFace blockFace : normalAxes.keySet()) {
|
||||||
|
if (defaultDirection == blockFace) {
|
||||||
|
//The default direction requires no rotation
|
||||||
|
rotationAngles.put(blockFace, 0d);
|
||||||
|
} else if (defaultDirection.getOppositeFace() == blockFace) {
|
||||||
|
//The opposite direction requires a half rotation
|
||||||
|
rotationAngles.put(blockFace, halfRotation);
|
||||||
|
} else {
|
||||||
|
//All the other used directions require a quarter rotation
|
||||||
|
Vector faceDirectionVector = blockFace.getDirection();
|
||||||
|
boolean faceDirectionPositive = faceDirectionVector.getX() + faceDirectionVector.getY() +
|
||||||
|
faceDirectionVector.getZ() > 0;
|
||||||
|
double rotation = defaultDirectionPositive && faceDirectionPositive ? quarterRotation : -quarterRotation;
|
||||||
|
rotationAngles.put(blockFace, rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the iris normal axes corresponding to each block face
|
||||||
|
*/
|
||||||
|
private static void initializeIrisNormalAxes() {
|
||||||
|
normalAxes.put(BlockFace.EAST, Axis.Z);
|
||||||
|
normalAxes.put(BlockFace.WEST, Axis.Z);
|
||||||
|
normalAxes.put(BlockFace.NORTH, Axis.X);
|
||||||
|
normalAxes.put(BlockFace.SOUTH, Axis.X);
|
||||||
|
normalAxes.put(BlockFace.UP, Axis.Y);
|
||||||
|
normalAxes.put(BlockFace.DOWN, Axis.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ package net.knarcraft.stargate.utility;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.ConfigOption;
|
import net.knarcraft.stargate.config.ConfigOption;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bstats.charts.SimplePie;
|
import org.bstats.charts.SimplePie;
|
||||||
@@ -40,7 +39,7 @@ public final class BStatsHelper {
|
|||||||
Metrics metrics = new Metrics(plugin, pluginId);
|
Metrics metrics = new Metrics(plugin, pluginId);
|
||||||
|
|
||||||
Map<ConfigOption, Object> configValues = Stargate.getStargateConfig().getConfigOptions();
|
Map<ConfigOption, Object> configValues = Stargate.getStargateConfig().getConfigOptions();
|
||||||
Map<String, List<String>> portalNetworks = PortalHandler.getAllPortalNetworks();
|
Map<String, List<String>> portalNetworks = PortalUtil.getAllPortalNetworks();
|
||||||
int totalPortals = 0;
|
int totalPortals = 0;
|
||||||
for (List<String> portals : portalNetworks.values()) {
|
for (List<String> portals : portalNetworks.values()) {
|
||||||
totalPortals += portals.size();
|
totalPortals += portals.size();
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package net.knarcraft.stargate.utility;
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
@@ -164,7 +163,7 @@ public final class BungeeHelper {
|
|||||||
if (player == null) {
|
if (player == null) {
|
||||||
bungeeQueue.put(playerUUID, destination);
|
bungeeQueue.put(playerUUID, destination);
|
||||||
} else {
|
} else {
|
||||||
Portal destinationPortal = PortalHandler.getBungeePortal(destination);
|
Portal destinationPortal = PortalUtil.getBungeePortal(destination);
|
||||||
//If teleporting to an invalid portal, let the server decide where the player arrives
|
//If teleporting to an invalid portal, let the server decide where the player arrives
|
||||||
if (destinationPortal == null) {
|
if (destinationPortal == null) {
|
||||||
Stargate.logInfo(String.format("Bungee portal %s does not exist", destination));
|
Stargate.logInfo(String.format("Bungee portal %s does not exist", destination));
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package net.knarcraft.stargate.utility;
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.Directional;
|
||||||
|
import org.bukkit.block.data.type.Sign;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class helps with direction-related calculations
|
* This class helps with direction-related calculations
|
||||||
@@ -14,6 +19,22 @@ public final class DirectionHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the direction the given block is facing
|
||||||
|
*
|
||||||
|
* @param block <p>The block to get the direction of</p>
|
||||||
|
* @return <p>The direction the block is facing, or null if the block is not directional</p>
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static BlockFace getFacing(@NotNull Block block) {
|
||||||
|
BlockData blockData = block.getBlockData();
|
||||||
|
if (blockData instanceof Directional directional) {
|
||||||
|
return directional.getFacing();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a yaw by comparing two locations
|
* Gets a yaw by comparing two locations
|
||||||
*
|
*
|
||||||
@@ -39,6 +60,32 @@ public final class DirectionHelper {
|
|||||||
throw new IllegalArgumentException("Locations given are equal or at the same x and y axis");
|
throw new IllegalArgumentException("Locations given are equal or at the same x and y axis");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a block face by comparing two locations
|
||||||
|
*
|
||||||
|
* <p>The block face here is the direction an observer at the from location has to look to face the to location.
|
||||||
|
* The block face is only meant to be calculated for locations where both have either the same x value or the same
|
||||||
|
* z value. Equal locations, or locations with equal x and equal z will throw an exception.</p>
|
||||||
|
*
|
||||||
|
* @param fromLocation <p>The origin location</p>
|
||||||
|
* @param toLocation <p>The target location, which the block face will point towards</p>
|
||||||
|
* @return <p>The yaw pointing from the first location to the second location</p>
|
||||||
|
* @throws IllegalArgumentException <p>If the locations are the same, or equal except y</p>
|
||||||
|
*/
|
||||||
|
public static BlockFace getBlockFaceFromLocationDifference(@NotNull Location fromLocation, @NotNull Location toLocation) throws IllegalArgumentException {
|
||||||
|
Location difference = fromLocation.clone().subtract(toLocation.clone());
|
||||||
|
if (difference.getX() > 0) {
|
||||||
|
return BlockFace.WEST;
|
||||||
|
} else if (difference.getX() < 0) {
|
||||||
|
return BlockFace.EAST;
|
||||||
|
} else if (difference.getZ() > 0) {
|
||||||
|
return BlockFace.NORTH;
|
||||||
|
} else if (difference.getZ() < 0) {
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Locations given are equal or at the same x and y axis");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a block face given a yaw value
|
* Gets a block face given a yaw value
|
||||||
*
|
*
|
||||||
@@ -66,6 +113,23 @@ public final class DirectionHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a yaw from the specified block face
|
||||||
|
*
|
||||||
|
* @param blockFace <p>The block face to convert into a yaw</p>
|
||||||
|
* @return <p>The yaw of the block face</p>
|
||||||
|
* @throws IllegalArgumentException <p>If the block face is not pointing to one of the four primary directions</p>
|
||||||
|
*/
|
||||||
|
public static double getYawFromBlockFace(@NotNull BlockFace blockFace) throws IllegalArgumentException {
|
||||||
|
return switch (blockFace) {
|
||||||
|
case SOUTH -> 0;
|
||||||
|
case WEST -> 90;
|
||||||
|
case NORTH -> 180;
|
||||||
|
case EAST -> 270;
|
||||||
|
default -> throw new IllegalArgumentException("Invalid block face given. It must be one of N,S,W,E");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a direction vector given a yaw
|
* Gets a direction vector given a yaw
|
||||||
*
|
*
|
||||||
@@ -142,6 +206,36 @@ public final class DirectionHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets this block location's parent block
|
||||||
|
*
|
||||||
|
* <p>The parent block is the block the item at this block location is attached to. Usually this is the block a
|
||||||
|
* sign or wall sign is attached to.</p>
|
||||||
|
*
|
||||||
|
* @return <p>This block location's parent block</p>
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static Block getParent(@NotNull Block block) {
|
||||||
|
int offsetX = 0;
|
||||||
|
int offsetY = 0;
|
||||||
|
int offsetZ = 0;
|
||||||
|
|
||||||
|
BlockData blockData = block.getBlockData();
|
||||||
|
if (blockData instanceof Directional) {
|
||||||
|
//Get the offset of the block "behind" this block
|
||||||
|
BlockFace facing = ((Directional) blockData).getFacing().getOppositeFace();
|
||||||
|
offsetX = facing.getModX();
|
||||||
|
offsetZ = facing.getModZ();
|
||||||
|
} else if (blockData instanceof Sign) {
|
||||||
|
//Get offset the block beneath the sign
|
||||||
|
offsetY = -1;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return block.getRelative(offsetX, offsetY, offsetZ);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalizes a yaw to make it positive and no larger than 360 degrees
|
* Normalizes a yaw to make it positive and no larger than 360 degrees
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package net.knarcraft.stargate.utility;
|
|||||||
|
|
||||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.EconomyConfig;
|
import net.knarcraft.stargate.config.Permission;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.addons.EconomyConfig;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
@@ -142,7 +143,7 @@ public final class EconomyHelper {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//Player gets free gate use
|
//Player gets free gate use
|
||||||
if (PermissionHelper.hasPermission(player, "stargate.free.use")) {
|
if (PermissionHelper.hasPermission(player, Permission.FREE_USAGE)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package net.knarcraft.stargate.utility;
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.Permission;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.event.StargateAccessEvent;
|
import net.knarcraft.stargate.event.StargateAccessEvent;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||||
@@ -144,8 +145,7 @@ public final class PermissionHelper {
|
|||||||
//If there is no destination, deny
|
//If there is no destination, deny
|
||||||
Stargate.debug(route, "Portal has no destination");
|
Stargate.debug(route, "Portal has no destination");
|
||||||
deny = true;
|
deny = true;
|
||||||
} else if (destination.getWorld() != null &&
|
} else if (PermissionHelper.cannotAccessWorld(player, destination.getLocation().getWorld().getName())) {
|
||||||
PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
|
||||||
//If the player does not have access to the portal's world, deny
|
//If the player does not have access to the portal's world, deny
|
||||||
Stargate.debug(route, "Cannot access world");
|
Stargate.debug(route, "Cannot access world");
|
||||||
deny = true;
|
deny = true;
|
||||||
@@ -172,6 +172,19 @@ public final class PermissionHelper {
|
|||||||
return player.hasPermission(permission);
|
return player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a player has the given permission
|
||||||
|
*
|
||||||
|
* <p>This is the same as player.hasPermission(), but this function allows for printing permission debugging info.</p>
|
||||||
|
*
|
||||||
|
* @param player <p>The player to check</p>
|
||||||
|
* @param permission <p>The permission to check</p>
|
||||||
|
* @return <p>True if the player has the permission</p>
|
||||||
|
*/
|
||||||
|
public static boolean hasPermission(@NotNull Player player, @NotNull Permission permission) {
|
||||||
|
return hasPermission(player, permission.getNode());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a player has been given a permission implicitly
|
* Check if a player has been given a permission implicitly
|
||||||
*
|
*
|
||||||
@@ -183,13 +196,14 @@ public final class PermissionHelper {
|
|||||||
* @return <p>True if the player has the permission implicitly or explicitly</p>
|
* @return <p>True if the player has the permission implicitly or explicitly</p>
|
||||||
*/
|
*/
|
||||||
public static boolean hasPermissionImplicit(@NotNull Player player, @NotNull String permission) {
|
public static boolean hasPermissionImplicit(@NotNull Player player, @NotNull String permission) {
|
||||||
|
boolean debug = Stargate.getStargateConfig().isPermissionDebuggingEnabled();
|
||||||
if (!player.isPermissionSet(permission)) {
|
if (!player.isPermissionSet(permission)) {
|
||||||
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
if (debug) {
|
||||||
Stargate.debug("hasPermissionImplicit::Permission", permission + " => implicitly true");
|
Stargate.debug("hasPermissionImplicit::Permission", permission + " => implicitly true");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) {
|
if (debug) {
|
||||||
Stargate.debug("hasPermissionImplicit::Permission", permission + " => " +
|
Stargate.debug("hasPermissionImplicit::Permission", permission + " => " +
|
||||||
player.hasPermission(permission));
|
player.hasPermission(permission));
|
||||||
}
|
}
|
||||||
@@ -204,13 +218,7 @@ public final class PermissionHelper {
|
|||||||
* @return <p>False if the player should be allowed to access the world</p>
|
* @return <p>False if the player should be allowed to access the world</p>
|
||||||
*/
|
*/
|
||||||
public static boolean cannotAccessWorld(@NotNull Player player, @NotNull String world) {
|
public static boolean cannotAccessWorld(@NotNull Player player, @NotNull String world) {
|
||||||
//The player can access all worlds
|
return hasPermission(player, Permission.ACCESS_WORLD, world);
|
||||||
if (hasPermission(player, "stargate.world")) {
|
|
||||||
//Check if the world permission has been explicitly denied
|
|
||||||
return !hasPermissionImplicit(player, "stargate.world." + world);
|
|
||||||
}
|
|
||||||
//The player can access the destination world
|
|
||||||
return !hasPermission(player, "stargate.world." + world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,21 +229,16 @@ public final class PermissionHelper {
|
|||||||
* @return <p>True if the player is denied from accessing the network</p>
|
* @return <p>True if the player is denied from accessing the network</p>
|
||||||
*/
|
*/
|
||||||
public static boolean cannotAccessNetwork(@NotNull Player player, @NotNull String network) {
|
public static boolean cannotAccessNetwork(@NotNull Player player, @NotNull String network) {
|
||||||
//The player can access all networks
|
if (hasPermission(player, Permission.ACCESS_NETWORK, network)) {
|
||||||
if (hasPermission(player, "stargate.network")) {
|
|
||||||
//Check if the world permission has been explicitly denied
|
|
||||||
return !hasPermissionImplicit(player, "stargate.network." + network);
|
|
||||||
}
|
|
||||||
//Check if the player can access this network
|
|
||||||
if (hasPermission(player, "stargate.network." + network)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Is able to create personal gates (Assumption is made they can also access them)
|
//Is able to create personal gates (Assumption is made they can also access them)
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
if (playerName.length() > getMaxNameNetworkLength()) {
|
if (playerName.length() > getMaxNameNetworkLength()) {
|
||||||
playerName = playerName.substring(0, getMaxNameNetworkLength());
|
playerName = playerName.substring(0, getMaxNameNetworkLength());
|
||||||
}
|
}
|
||||||
return !network.equals(playerName) || !hasPermission(player, "stargate.create.personal");
|
return !network.equals(playerName) || !hasPermission(player, Permission.CREATE_PERSONAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,13 +249,7 @@ public final class PermissionHelper {
|
|||||||
* @return <p>True if the player is allowed to access the given server</p>
|
* @return <p>True if the player is allowed to access the given server</p>
|
||||||
*/
|
*/
|
||||||
public static boolean canAccessServer(@NotNull Player player, @NotNull String server) {
|
public static boolean canAccessServer(@NotNull Player player, @NotNull String server) {
|
||||||
//The player can access all servers
|
return hasPermission(player, Permission.ACCESS_SERVER, server);
|
||||||
if (hasPermission(player, "stargate.server")) {
|
|
||||||
//Check if the server permission has been explicitly denied
|
|
||||||
return hasPermissionImplicit(player, "stargate.server." + server);
|
|
||||||
}
|
|
||||||
//The player can access the destination server
|
|
||||||
return hasPermission(player, "stargate.server." + server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,7 +266,7 @@ public final class PermissionHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//Player can use this portal for free
|
//Player can use this portal for free
|
||||||
if (hasPermission(player, "stargate.free.use")) {
|
if (hasPermission(player, Permission.FREE_USAGE)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//Don't charge for free destinations unless specified in the config
|
//Don't charge for free destinations unless specified in the config
|
||||||
@@ -291,7 +288,7 @@ public final class PermissionHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//The player can see all hidden portals
|
//The player can see all hidden portals
|
||||||
if (hasPermission(player, "stargate.admin.hidden")) {
|
if (hasPermission(player, Permission.SEE_HIDDEN)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//The player is the owner of the portal
|
//The player is the owner of the portal
|
||||||
@@ -311,7 +308,7 @@ public final class PermissionHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//The player is an admin with the ability to use private gates
|
//The player is an admin with the ability to use private gates
|
||||||
return hasPermission(player, "stargate.admin.private");
|
return hasPermission(player, Permission.USE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -322,7 +319,7 @@ public final class PermissionHelper {
|
|||||||
* @return <p>True if the player is allowed to create a portal with the given option</p>
|
* @return <p>True if the player is allowed to create a portal with the given option</p>
|
||||||
*/
|
*/
|
||||||
public static boolean canUseOption(@NotNull Player player, @NotNull PortalOption option) {
|
public static boolean canUseOption(@NotNull Player player, @NotNull PortalOption option) {
|
||||||
return hasPermission(player, option.getPermissionString());
|
return hasPermission(player, option.getPermission());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -333,13 +330,7 @@ public final class PermissionHelper {
|
|||||||
* @return <p>True if the player is allowed to create the new gate</p>
|
* @return <p>True if the player is allowed to create the new gate</p>
|
||||||
*/
|
*/
|
||||||
public static boolean canCreateNetworkGate(@NotNull Player player, @NotNull String network) {
|
public static boolean canCreateNetworkGate(@NotNull Player player, @NotNull String network) {
|
||||||
//Check if the player is allowed to create a portal on any network
|
return hasPermission(player, Permission.CREATE_NETWORK, network);
|
||||||
if (hasPermission(player, "stargate.create.network")) {
|
|
||||||
//Check if the network has been explicitly denied
|
|
||||||
return hasPermissionImplicit(player, "stargate.create.network." + network);
|
|
||||||
}
|
|
||||||
//Check if the player is allowed to create on this specific network
|
|
||||||
return hasPermission(player, "stargate.create.network." + network);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,7 +340,7 @@ public final class PermissionHelper {
|
|||||||
* @return <p>True if the player is allowed</p>
|
* @return <p>True if the player is allowed</p>
|
||||||
*/
|
*/
|
||||||
public static boolean canCreatePersonalPortal(@NotNull Player player) {
|
public static boolean canCreatePersonalPortal(@NotNull Player player) {
|
||||||
return hasPermission(player, "stargate.create.personal");
|
return hasPermission(player, Permission.CREATE_PERSONAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,13 +351,7 @@ public final class PermissionHelper {
|
|||||||
* @return <p>True if the player is allowed to create a portal with the given gate layout</p>
|
* @return <p>True if the player is allowed to create a portal with the given gate layout</p>
|
||||||
*/
|
*/
|
||||||
public static boolean canCreatePortal(@NotNull Player player, @NotNull String gate) {
|
public static boolean canCreatePortal(@NotNull Player player, @NotNull String gate) {
|
||||||
//Check if the player is allowed to create all gates
|
return hasPermission(player, Permission.CREATE_GATE, gate);
|
||||||
if (hasPermission(player, "stargate.create.gate")) {
|
|
||||||
//Check if the gate type has been explicitly denied
|
|
||||||
return hasPermissionImplicit(player, "stargate.create.gate." + gate);
|
|
||||||
}
|
|
||||||
//Check if the player can create the specific gate type
|
|
||||||
return hasPermission(player, "stargate.create.gate." + gate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -381,20 +366,14 @@ public final class PermissionHelper {
|
|||||||
|
|
||||||
//Use a special check for bungee portals
|
//Use a special check for bungee portals
|
||||||
if (portal.getOptions().isBungee()) {
|
if (portal.getOptions().isBungee()) {
|
||||||
return hasPermission(player, "stargate.admin.bungee");
|
return hasPermission(player, Permission.CREATE_BUNGEE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if the player is allowed to destroy on all networks
|
if (hasPermission(player, Permission.DESTROY_NETWORK, network)) {
|
||||||
if (hasPermission(player, "stargate.destroy.network")) {
|
|
||||||
//Check if the network has been explicitly denied
|
|
||||||
return hasPermissionImplicit(player, "stargate.destroy.network." + network);
|
|
||||||
}
|
|
||||||
//Check if the player is allowed to destroy on the network
|
|
||||||
if (hasPermission(player, "stargate.destroy.network." + network)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//Check if personal portal and if the player is allowed to destroy it
|
//Check if personal portal and if the player is allowed to destroy it
|
||||||
return portal.isOwner(player) && hasPermission(player, "stargate.destroy.personal");
|
return portal.isOwner(player) && hasPermission(player, Permission.DESTROY_PERSONAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -448,4 +427,23 @@ public final class PermissionHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given player has a permission for the given value, or has the catch-all permission
|
||||||
|
*
|
||||||
|
* @param player <p>The player trying to create a portal</p>
|
||||||
|
* @param permission <p>The parent permission to check</p>
|
||||||
|
* @param value <p>The child node to check</p>
|
||||||
|
* @return <p>True if the player has the explicit child node, or gets the permission implicitly from the parent</p>
|
||||||
|
*/
|
||||||
|
private static boolean hasPermission(@NotNull Player player, @NotNull Permission permission, @NotNull String value) {
|
||||||
|
String fullNode = permission.getNode() + "." + value;
|
||||||
|
//Check if the player is allowed to create all gates
|
||||||
|
if (hasPermission(player, permission)) {
|
||||||
|
//Check if the gate type has been explicitly denied
|
||||||
|
return hasPermissionImplicit(player, fullNode);
|
||||||
|
}
|
||||||
|
//Check if the player can create the specific gate type
|
||||||
|
return hasPermission(player, fullNode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,8 @@ package net.knarcraft.stargate.utility;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
|
||||||
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOptions;
|
import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||||
@@ -14,16 +11,19 @@ import net.knarcraft.stargate.portal.property.PortalOwner;
|
|||||||
import net.knarcraft.stargate.portal.property.PortalStrings;
|
import net.knarcraft.stargate.portal.property.PortalStrings;
|
||||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||||
|
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
import org.bukkit.block.data.Waterlogged;
|
import org.bukkit.block.data.Waterlogged;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -57,17 +57,12 @@ public final class PortalFileHelper {
|
|||||||
|
|
||||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||||
//Skip portals in other worlds
|
//Skip portals in other worlds
|
||||||
if (portal.getWorld() == null) {
|
String worldName = portal.getLocation().getWorld().getName();
|
||||||
Stargate.logSevere(String.format("Could not save portal %s because its world is null",
|
if (!worldName.equalsIgnoreCase(world.getName())) {
|
||||||
portal.getName()));
|
continue;
|
||||||
} else {
|
|
||||||
String worldName = portal.getWorld().getName();
|
|
||||||
if (!worldName.equalsIgnoreCase(world.getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//Save the portal
|
|
||||||
savePortal(bufferedWriter, portal);
|
|
||||||
}
|
}
|
||||||
|
//Save the portal
|
||||||
|
savePortal(bufferedWriter, portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferedWriter.close();
|
bufferedWriter.close();
|
||||||
@@ -85,19 +80,19 @@ public final class PortalFileHelper {
|
|||||||
*/
|
*/
|
||||||
private static void savePortal(@NotNull BufferedWriter bufferedWriter, @NotNull Portal portal) throws IOException {
|
private static void savePortal(@NotNull BufferedWriter bufferedWriter, @NotNull Portal portal) throws IOException {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
BlockLocation button = portal.getStructure().getButton();
|
Block button = portal.getStructure().getButton();
|
||||||
|
|
||||||
//WARNING: Because of the primitive save format, any change in order will break everything!
|
//WARNING: Because of the primitive save format, any change in order will break everything!
|
||||||
builder.append(portal.getName()).append(':');
|
builder.append(portal.getName()).append(':');
|
||||||
builder.append(portal.getSignLocation()).append(':');
|
builder.append(portal.getLocation().getSignBlock()).append(':');
|
||||||
builder.append((button != null) ? button.toString() : "").append(':');
|
builder.append((button != null) ? button.toString() : "").append(':');
|
||||||
|
|
||||||
//Add removes config values to keep indices consistent
|
//Add removes config values to keep indices consistent
|
||||||
builder.append(0).append(':');
|
builder.append(0).append(':');
|
||||||
builder.append(0).append(':');
|
builder.append(0).append(':');
|
||||||
|
|
||||||
builder.append(portal.getYaw()).append(':');
|
builder.append(DirectionHelper.getYawFromBlockFace(portal.getLocation().getFacing())).append(':');
|
||||||
builder.append(portal.getTopLeft()).append(':');
|
builder.append(portal.getLocation().getTopLeft()).append(':');
|
||||||
builder.append(portal.getGate().getFilename()).append(':');
|
builder.append(portal.getGate().getFilename()).append(':');
|
||||||
|
|
||||||
//Only save the destination name if the gate is fixed as it doesn't matter otherwise
|
//Only save the destination name if the gate is fixed as it doesn't matter otherwise
|
||||||
@@ -127,11 +122,7 @@ public final class PortalFileHelper {
|
|||||||
builder.append(options.isHidden()).append(':');
|
builder.append(options.isHidden()).append(':');
|
||||||
builder.append(options.isAlwaysOn()).append(':');
|
builder.append(options.isAlwaysOn()).append(':');
|
||||||
builder.append(options.isPrivate()).append(':');
|
builder.append(options.isPrivate()).append(':');
|
||||||
if (portal.getWorld() != null) {
|
builder.append(portal.getLocation().getWorld().getName()).append(':');
|
||||||
builder.append(portal.getWorld().getName()).append(':');
|
|
||||||
} else {
|
|
||||||
builder.append(':');
|
|
||||||
}
|
|
||||||
builder.append(options.isFree()).append(':');
|
builder.append(options.isFree()).append(':');
|
||||||
builder.append(options.isBackwards()).append(':');
|
builder.append(options.isBackwards()).append(':');
|
||||||
builder.append(options.isShown()).append(':');
|
builder.append(options.isShown()).append(':');
|
||||||
@@ -229,9 +220,9 @@ public final class PortalFileHelper {
|
|||||||
*/
|
*/
|
||||||
private static void doPostLoadTasks(@NotNull World world, boolean needsToSaveDatabase) {
|
private static void doPostLoadTasks(@NotNull World world, boolean needsToSaveDatabase) {
|
||||||
//Open any always-on portals. Do this here as it should be more efficient than in the loop.
|
//Open any always-on portals. Do this here as it should be more efficient than in the loop.
|
||||||
PortalHandler.verifyAllPortals();
|
PortalUtil.verifyAllPortals();
|
||||||
int portalCount = PortalRegistry.getAllPortals().size();
|
int portalCount = PortalRegistry.getAllPortals().size();
|
||||||
int openCount = PortalHandler.openAlwaysOpenPortals();
|
int openCount = PortalUtil.openAlwaysOpenPortals();
|
||||||
|
|
||||||
//Print info about loaded stargates so that admins can see if all stargates loaded
|
//Print info about loaded stargates so that admins can see if all stargates loaded
|
||||||
Stargate.logInfo(String.format("{%s} Loaded %d stargates with %d set as always-on", world.getName(),
|
Stargate.logInfo(String.format("{%s} Loaded %d stargates with %d set as always-on", world.getName(),
|
||||||
@@ -242,8 +233,8 @@ public final class PortalFileHelper {
|
|||||||
Stargate.debug("PortalFileHelper::doPostLoadTasks::update",
|
Stargate.debug("PortalFileHelper::doPostLoadTasks::update",
|
||||||
String.format("Queueing portal sign/button updates for %s", world));
|
String.format("Queueing portal sign/button updates for %s", world));
|
||||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||||
if (portal.isRegistered() && portal.getWorld() != null && portal.getWorld().equals(world) &&
|
if (portal.isRegistered() && portal.getLocation().getWorld().equals(world) &&
|
||||||
world.getWorldBorder().isInside(portal.getSignLocation())) {
|
world.getWorldBorder().isInside(portal.getLocation().getSignBlock().getLocation())) {
|
||||||
Stargate.addControlBlockUpdateRequest(new ControlBlockUpdateRequest(portal));
|
Stargate.addControlBlockUpdateRequest(new ControlBlockUpdateRequest(portal));
|
||||||
Stargate.debug("UpdateSignsButtons", String.format("Queued sign and button updates for portal %s",
|
Stargate.debug("UpdateSignsButtons", String.format("Queued sign and button updates for portal %s",
|
||||||
portal.getName()));
|
portal.getName()));
|
||||||
@@ -267,13 +258,13 @@ public final class PortalFileHelper {
|
|||||||
private static boolean loadPortal(@NotNull String[] portalData, @NotNull World world, int lineIndex) {
|
private static boolean loadPortal(@NotNull String[] portalData, @NotNull World world, int lineIndex) {
|
||||||
//Load min. required portal data
|
//Load min. required portal data
|
||||||
String name = portalData[0];
|
String name = portalData[0];
|
||||||
BlockLocation button = (!portalData[2].isEmpty()) ? new BlockLocation(world, portalData[2]) : null;
|
Block button = (!portalData[2].isEmpty()) ? getBlock(world, portalData[2]) : null;
|
||||||
|
|
||||||
//Load the portal's location
|
//Load the portal's location
|
||||||
PortalLocation portalLocation = new PortalLocation();
|
|
||||||
portalLocation.setSignLocation(new BlockLocation(world, portalData[1]));
|
|
||||||
portalLocation.setYaw(Float.parseFloat(portalData[5]));
|
PortalLocation portalLocation = new PortalLocation(getBlock(world, portalData[6]),
|
||||||
portalLocation.setTopLeft(new BlockLocation(world, portalData[6]));
|
DirectionHelper.getBlockFaceFromYaw(Float.parseFloat(portalData[5])), getBlock(world, portalData[1]), button);
|
||||||
|
|
||||||
//Check if the portal's gate type exists and is loaded
|
//Check if the portal's gate type exists and is loaded
|
||||||
Gate gate = GateHandler.getGateByName(portalData[7]);
|
Gate gate = GateHandler.getGateByName(portalData[7]);
|
||||||
@@ -295,11 +286,11 @@ public final class PortalFileHelper {
|
|||||||
//Create the new portal
|
//Create the new portal
|
||||||
PortalStrings portalStrings = new PortalStrings(name, network, destination);
|
PortalStrings portalStrings = new PortalStrings(name, network, destination);
|
||||||
Portal portal = new Portal(portalLocation, button, portalStrings, gate, owner,
|
Portal portal = new Portal(portalLocation, button, portalStrings, gate, owner,
|
||||||
PortalHandler.getPortalOptions(portalData));
|
PortalUtil.getPortalOptions(portalData));
|
||||||
|
|
||||||
//Register the portal, and close it in case it wasn't properly closed when the server stopped
|
//Register the portal, and close it in case it wasn't properly closed when the server stopped
|
||||||
boolean buttonLocationChanged = updateButtonVector(portal);
|
boolean buttonLocationChanged = updateButtonVector(portal);
|
||||||
PortalHandler.registerPortal(portal);
|
PortalUtil.registerPortal(portal);
|
||||||
portal.getPortalOpener().closePortal(true);
|
portal.getPortalOpener().closePortal(true);
|
||||||
return buttonLocationChanged;
|
return buttonLocationChanged;
|
||||||
}
|
}
|
||||||
@@ -307,15 +298,16 @@ public final class PortalFileHelper {
|
|||||||
/**
|
/**
|
||||||
* Decides the material to use for removing a portal's button/sign
|
* Decides the material to use for removing a portal's button/sign
|
||||||
*
|
*
|
||||||
* @param location <p>The location of the button/sign to replace</p>
|
* @param block <p>The location of the button/sign to replace</p>
|
||||||
* @param portal <p>The portal the button/sign belongs to</p>
|
* @param portal <p>The portal the button/sign belongs to</p>
|
||||||
* @return <p>The material to use for removing the button/sign</p>
|
* @return <p>The material to use for removing the button/sign</p>
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Material decideRemovalMaterial(@NotNull BlockLocation location, @NotNull Portal portal) {
|
public static Material decideRemovalMaterial(@NotNull Block block, @NotNull Portal portal) {
|
||||||
//Get the blocks to each side of the location
|
//Get the blocks to each side of the location
|
||||||
Location leftLocation = location.getRelativeLocation(-1, 0, 0, portal.getYaw());
|
SimpleVectorOperation vectorOperation = portal.getLocation().getVectorOperation();
|
||||||
Location rightLocation = location.getRelativeLocation(1, 0, 0, portal.getYaw());
|
Location leftLocation = block.getLocation().clone().add(vectorOperation.performToRealSpaceOperation(new Vector(-1, 0, 0)));
|
||||||
|
Location rightLocation = block.getLocation().clone().add(vectorOperation.performToRealSpaceOperation(new Vector(1, 0, 0)));
|
||||||
|
|
||||||
//If the block is water or is waterlogged, assume the portal is underwater
|
//If the block is water or is waterlogged, assume the portal is underwater
|
||||||
if (isUnderwater(leftLocation) || isUnderwater(rightLocation)) {
|
if (isUnderwater(leftLocation) || isUnderwater(rightLocation)) {
|
||||||
@@ -349,15 +341,12 @@ public final class PortalFileHelper {
|
|||||||
* @return <p>True if the calculated button location is not the same as the one in the portal file</p>
|
* @return <p>True if the calculated button location is not the same as the one in the portal file</p>
|
||||||
*/
|
*/
|
||||||
private static boolean updateButtonVector(@NotNull Portal portal) {
|
private static boolean updateButtonVector(@NotNull Portal portal) {
|
||||||
for (RelativeBlockVector control : portal.getGate().getLayout().getControls()) {
|
for (BlockVector control : portal.getGate().getLayout().getControls()) {
|
||||||
BlockLocation controlLocation = portal.getLocation().getTopLeft().getRelativeLocation(control,
|
Block buttonLocation = portal.getLocation().getRelative(control.clone().add(new Vector(0, 0, 1)).toBlockVector());
|
||||||
portal.getYaw());
|
if (!buttonLocation.equals(portal.getLocation().getSignBlock())) {
|
||||||
BlockLocation buttonLocation = controlLocation.getRelativeLocation(
|
portal.getLocation().setButtonBlock(buttonLocation);
|
||||||
new RelativeBlockVector(0, 0, 1), portal.getYaw());
|
|
||||||
if (!buttonLocation.equals(portal.getLocation().getSignLocation())) {
|
|
||||||
portal.getLocation().setButtonVector(control);
|
|
||||||
|
|
||||||
BlockLocation oldButtonLocation = portal.getStructure().getButton();
|
Block oldButtonLocation = portal.getStructure().getButton();
|
||||||
if (oldButtonLocation != null && !oldButtonLocation.equals(buttonLocation)) {
|
if (oldButtonLocation != null && !oldButtonLocation.equals(buttonLocation)) {
|
||||||
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(oldButtonLocation, Material.AIR, null));
|
Stargate.addControlBlockUpdateRequest(new BlockChangeRequest(oldButtonLocation, Material.AIR, null));
|
||||||
portal.getStructure().setButton(buttonLocation);
|
portal.getStructure().setButton(buttonLocation);
|
||||||
@@ -376,7 +365,7 @@ public final class PortalFileHelper {
|
|||||||
*/
|
*/
|
||||||
public static void generatePortalButton(@NotNull Portal portal, @NotNull BlockFace buttonFacing) {
|
public static void generatePortalButton(@NotNull Portal portal, @NotNull BlockFace buttonFacing) {
|
||||||
//Go one block outwards to find the button's location rather than the control block's location
|
//Go one block outwards to find the button's location rather than the control block's location
|
||||||
BlockLocation button = getButtonLocation(portal);
|
Block button = portal.getLocation().getButtonBlock();
|
||||||
|
|
||||||
// If the button location is null here, it is assumed that the button generation wasn't necessary
|
// If the button location is null here, it is assumed that the button generation wasn't necessary
|
||||||
if (button == null) {
|
if (button == null) {
|
||||||
@@ -390,27 +379,24 @@ public final class PortalFileHelper {
|
|||||||
|
|
||||||
Directional buttonData = (Directional) Bukkit.createBlockData(buttonType);
|
Directional buttonData = (Directional) Bukkit.createBlockData(buttonType);
|
||||||
buttonData.setFacing(buttonFacing);
|
buttonData.setFacing(buttonFacing);
|
||||||
button.getBlock().setBlockData(buttonData);
|
button.setBlockData(buttonData);
|
||||||
}
|
}
|
||||||
portal.getStructure().setButton(button);
|
portal.getStructure().setButton(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the location of a portal's button
|
* Gets the block specified in the input
|
||||||
*
|
*
|
||||||
* @param portal <p>The portal to find the button for</p>
|
* @param world <p>The world the block belongs to</p>
|
||||||
* @return <p>The location of the portal's button</p>
|
* @param string <p>Comma-separated coordinate string</p>
|
||||||
|
* @return <p>The specified block</p>
|
||||||
|
* @throws NumberFormatException <p>If non-numeric values are encountered</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@NotNull
|
||||||
public static BlockLocation getButtonLocation(@NotNull Portal portal) {
|
private static Block getBlock(@NotNull World world, @NotNull String string) throws NumberFormatException {
|
||||||
BlockLocation topLeft = portal.getTopLeft();
|
String[] parts = string.split(",");
|
||||||
RelativeBlockVector buttonVector = portal.getLocation().getButtonVector();
|
return new Location(world, Integer.parseInt(parts[0]), Integer.parseInt(parts[1]),
|
||||||
|
Integer.parseInt(parts[2])).getBlock();
|
||||||
if (buttonVector == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return topLeft.getRelativeLocation(buttonVector.addOut(1), portal.getYaw());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
package net.knarcraft.stargate.portal;
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.Permission;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||||
import net.knarcraft.stargate.container.BlockLocation;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Keeps track of all loaded portals, and handles portal creation
|
* Keeps track of all loaded portals, and handles portal creation
|
||||||
*/
|
*/
|
||||||
public class PortalHandler {
|
public final class PortalUtil {
|
||||||
|
|
||||||
private PortalHandler() {
|
private PortalUtil() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,8 +117,7 @@ public class PortalHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//Check if this player can access the destination world
|
//Check if this player can access the destination world
|
||||||
if (destinationPortal.getWorld() != null && PermissionHelper.cannotAccessWorld(player,
|
if (PermissionHelper.cannotAccessWorld(player, destinationPortal.getLocation().getWorld().getName())) {
|
||||||
destinationPortal.getWorld().getName())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//The portal is visible to the player
|
//The portal is visible to the player
|
||||||
@@ -148,7 +147,7 @@ public class PortalHandler {
|
|||||||
if (!portalOptions.get(PortalOption.BUNGEE)) {
|
if (!portalOptions.get(PortalOption.BUNGEE)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!PermissionHelper.hasPermission(player, "stargate.admin.bungee")) {
|
if (!PermissionHelper.hasPermission(player, Permission.CREATE_BUNGEE)) {
|
||||||
new SGFormatBuilder(Message.BUNGEE_CREATION_DENIED).error(player);
|
new SGFormatBuilder(Message.BUNGEE_CREATION_DENIED).error(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (!Stargate.getGateConfig().enableBungee()) {
|
} else if (!Stargate.getGateConfig().enableBungee()) {
|
||||||
@@ -165,36 +164,33 @@ public class PortalHandler {
|
|||||||
* Tries to find a gate matching the portal the user is trying to create
|
* Tries to find a gate matching the portal the user is trying to create
|
||||||
*
|
*
|
||||||
* @param portalLocation <p>The location data for the new portal</p>
|
* @param portalLocation <p>The location data for the new portal</p>
|
||||||
* @param world <p>The world the player is located in</p>
|
|
||||||
* @return <p>The matching gate type, or null if no such gate could be found</p>
|
* @return <p>The matching gate type, or null if no such gate could be found</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Gate findMatchingGate(@NotNull PortalLocation portalLocation, @NotNull World world) {
|
public static Gate findMatchingGate(@NotNull PortalLocation portalLocation) {
|
||||||
Block signParent = portalLocation.getSignLocation().getParent();
|
Block signParent = DirectionHelper.getParent(portalLocation.getSignBlock());
|
||||||
if (signParent == null) {
|
if (signParent == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
BlockLocation parent = new BlockLocation(world, signParent.getX(), signParent.getY(),
|
|
||||||
signParent.getZ());
|
|
||||||
|
|
||||||
//Get all gates with the used type of control blocks
|
//Get all gates with the used type of control blocks
|
||||||
List<Gate> possibleGates = GateHandler.getGatesByControlBlock(signParent);
|
List<Gate> possibleGates = GateHandler.getGatesByControlBlock(signParent);
|
||||||
double yaw = portalLocation.getYaw();
|
|
||||||
Gate gate = null;
|
Gate gate = null;
|
||||||
|
|
||||||
for (Gate possibleGate : possibleGates) {
|
for (Gate possibleGate : possibleGates) {
|
||||||
//Get gate controls
|
//Get gate controls
|
||||||
RelativeBlockVector[] vectors = possibleGate.getLayout().getControls();
|
BlockVector[] vectors = possibleGate.getLayout().getControls();
|
||||||
|
|
||||||
portalLocation.setButtonVector(null);
|
portalLocation.setButtonBlock(null);
|
||||||
for (RelativeBlockVector controlVector : vectors) {
|
for (BlockVector controlVector : vectors) {
|
||||||
//Assuming the top-left location is pointing to the gate's top-left location, check if it's a match
|
//Assuming the top-left location is pointing to the gate's top-left location, check if it's a match
|
||||||
BlockLocation possibleTopLocation = parent.getRelativeLocation(controlVector.invert(), yaw);
|
Block possibleTopLocation = portalLocation.getRelative(controlVector);
|
||||||
if (possibleGate.matches(possibleTopLocation, portalLocation.getYaw(), true)) {
|
|
||||||
|
if (possibleGate.matches(possibleTopLocation, portalLocation.getFacing(), true)) {
|
||||||
gate = possibleGate;
|
gate = possibleGate;
|
||||||
portalLocation.setTopLeft(possibleTopLocation);
|
portalLocation.setTopLeft(possibleTopLocation);
|
||||||
} else {
|
} else {
|
||||||
portalLocation.setButtonVector(controlVector);
|
portalLocation.setButtonBlock(possibleTopLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +217,7 @@ public class PortalHandler {
|
|||||||
Portal origin = getByName(originName, portal.getCleanNetwork());
|
Portal origin = getByName(originName, portal.getCleanNetwork());
|
||||||
if (origin == null ||
|
if (origin == null ||
|
||||||
!Portal.cleanString(origin.getDestinationName()).equals(portal.getCleanName()) ||
|
!Portal.cleanString(origin.getDestinationName()).equals(portal.getCleanName()) ||
|
||||||
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignLocation().getType())) {
|
!new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(origin.getLocation().getSignBlock().getType())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Update sign of fixed gates pointing at this gate
|
//Update sign of fixed gates pointing at this gate
|
||||||
@@ -299,8 +295,7 @@ public class PortalHandler {
|
|||||||
if (location.getWorld() == null) {
|
if (location.getWorld() == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return PortalRegistry.getPortalFromEntrance(new BlockLocation(location.getWorld(), location.getBlockX(),
|
return PortalRegistry.getPortalFromEntrance(location.getBlock());
|
||||||
location.getBlockY(), location.getBlockZ()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -311,7 +306,7 @@ public class PortalHandler {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Portal getByEntrance(@NotNull Block block) {
|
public static Portal getByEntrance(@NotNull Block block) {
|
||||||
return PortalRegistry.getPortalFromEntrance(new BlockLocation(block));
|
return PortalRegistry.getPortalFromEntrance(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,24 +329,24 @@ public class PortalHandler {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Portal getByAdjacentEntrance(@NotNull Location location, int range) {
|
public static Portal getByAdjacentEntrance(@NotNull Location location, int range) {
|
||||||
List<BlockLocation> adjacentPositions = new ArrayList<>();
|
List<Block> adjacentPositions = new ArrayList<>();
|
||||||
BlockLocation centerLocation = new BlockLocation(location.getBlock());
|
Block centerLocation = location.getBlock();
|
||||||
adjacentPositions.add(centerLocation);
|
adjacentPositions.add(centerLocation);
|
||||||
|
|
||||||
for (int index = 1; index <= range; index++) {
|
for (int index = 1; index <= range; index++) {
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, 0));
|
adjacentPositions.add(location.clone().add(new Vector(index, 0, 0)).getBlock());
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, 0));
|
adjacentPositions.add(location.clone().add(new Vector(-index, 0, 0)).getBlock());
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, index));
|
adjacentPositions.add(location.clone().add(new Vector(0, 0, index)).getBlock());
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(0, 0, -index));
|
adjacentPositions.add(location.clone().add(new Vector(0, 0, -index)).getBlock());
|
||||||
if (index < range) {
|
if (index < range) {
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, index));
|
adjacentPositions.add(location.clone().add(new Vector(index, 0, index)).getBlock());
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, -index));
|
adjacentPositions.add(location.clone().add(new Vector(-index, 0, -index)).getBlock());
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(index, 0, -index));
|
adjacentPositions.add(location.clone().add(new Vector(index, 0, -index)).getBlock());
|
||||||
adjacentPositions.add(centerLocation.makeRelativeBlockLocation(-index, 0, index));
|
adjacentPositions.add(location.clone().add(new Vector(-index, 0, index)).getBlock());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (BlockLocation adjacentPosition : adjacentPositions) {
|
for (Block adjacentPosition : adjacentPositions) {
|
||||||
Portal portal = PortalRegistry.getPortalFromEntrance(adjacentPosition);
|
Portal portal = PortalRegistry.getPortalFromEntrance(adjacentPosition);
|
||||||
if (portal != null) {
|
if (portal != null) {
|
||||||
return portal;
|
return portal;
|
||||||
@@ -368,7 +363,7 @@ public class PortalHandler {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Portal getByControl(@NotNull Block block) {
|
public static Portal getByControl(@NotNull Block block) {
|
||||||
return PortalRegistry.getPortalFromControl(new BlockLocation(block));
|
return PortalRegistry.getPortalFromControl(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,7 +374,7 @@ public class PortalHandler {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Portal getByBlock(@NotNull Block block) {
|
public static Portal getByBlock(@NotNull Block block) {
|
||||||
return PortalRegistry.getPortalFromFrame(new BlockLocation(block));
|
return PortalRegistry.getPortalFromFrame(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -440,11 +435,12 @@ public class PortalHandler {
|
|||||||
|
|
||||||
Stargate.debug("PortalHandler::verifyAllPortals", "Checking portal: " + portal.getName() + " | " + portal.getNetwork());
|
Stargate.debug("PortalHandler::verifyAllPortals", "Checking portal: " + portal.getName() + " | " + portal.getNetwork());
|
||||||
if (!portal.getOptions().hasNoSign() && !(new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(
|
if (!portal.getOptions().hasNoSign() && !(new BukkitTagSpecifier(Tag.WALL_SIGNS).asMaterials().contains(
|
||||||
portal.getLocation().getSignLocation().getType()))) {
|
portal.getLocation().getSignBlock().getType()))) {
|
||||||
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate is missing its sign");
|
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate is missing its sign");
|
||||||
invalidPortals.add(portal);
|
invalidPortals.add(portal);
|
||||||
} else if (!portal.getOptions().isAlwaysOn() && portal.getLocation().getButtonVector() != null &&
|
} else if (!portal.getOptions().isAlwaysOn() && portal.getLocation().getButtonBlock() != null &&
|
||||||
!MaterialHelper.isButtonCompatible(portal.getBlockAt(portal.getLocation().getButtonVector().addOut(1)).getType())) {
|
!MaterialHelper.isButtonCompatible(portal.getLocation().getButtonBlock().getLocation().add(
|
||||||
|
new Vector(0, 0, 1)).getBlock().getType())) {
|
||||||
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate is missing a valid button");
|
Stargate.debug("PortalHandler::verifyAllPortals", "Stargate is missing a valid button");
|
||||||
invalidPortals.add(portal);
|
invalidPortals.add(portal);
|
||||||
} else if (!structure.checkIntegrity()) {
|
} else if (!structure.checkIntegrity()) {
|
||||||
@@ -466,8 +462,8 @@ public class PortalHandler {
|
|||||||
*/
|
*/
|
||||||
private static void unregisterInvalidPortal(@NotNull Portal portal) {
|
private static void unregisterInvalidPortal(@NotNull Portal portal) {
|
||||||
//Show debug information
|
//Show debug information
|
||||||
for (RelativeBlockVector control : portal.getGate().getLayout().getControls()) {
|
for (BlockVector control : portal.getGate().getLayout().getControls()) {
|
||||||
Block block = portal.getBlockAt(control).getBlock();
|
Block block = portal.getLocation().getRelative(control);
|
||||||
//Log control blocks not matching the gate layout
|
//Log control blocks not matching the gate layout
|
||||||
if (!MaterialHelper.specifiersToMaterials(portal.getGate().getControlBlockMaterials()).contains(
|
if (!MaterialHelper.specifiersToMaterials(portal.getGate().getControlBlockMaterials()).contains(
|
||||||
block.getType())) {
|
block.getType())) {
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
|
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper class for saving and loading Stargates from or to YML files
|
||||||
|
*/
|
||||||
|
public final class PortalYMLHelper {
|
||||||
|
|
||||||
|
private PortalYMLHelper() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves all portals
|
||||||
|
*
|
||||||
|
* @throws IOException <p>If unable to read or write a portal file</p>
|
||||||
|
*/
|
||||||
|
public void savePortals() throws IOException {
|
||||||
|
Map<World, File> worldFiles = new HashMap<>();
|
||||||
|
Map<World, FileConfiguration> configurations = new HashMap<>();
|
||||||
|
|
||||||
|
// Get and alter each configuration without saving
|
||||||
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||||
|
World world = portal.getLocation().getWorld();
|
||||||
|
|
||||||
|
File file = worldFiles.get(world);
|
||||||
|
FileConfiguration configuration = configurations.get(world);
|
||||||
|
if (file == null) {
|
||||||
|
file = new File(Stargate.getStargateConfig().getPortalFolder(), world.getUID() + ".yml");
|
||||||
|
worldFiles.put(world, file);
|
||||||
|
}
|
||||||
|
if (configuration == null) {
|
||||||
|
configuration = new YamlConfiguration();
|
||||||
|
configurations.put(world, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
savePortal(portal, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save each configuration
|
||||||
|
for (Map.Entry<World, FileConfiguration> configuration : configurations.entrySet()) {
|
||||||
|
configuration.getValue().save(worldFiles.get(configuration.getKey()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the given portal
|
||||||
|
*
|
||||||
|
* @param portal <p>The portal to save</p>
|
||||||
|
*/
|
||||||
|
public void savePortal(@NotNull Portal portal, @NotNull FileConfiguration configuration) {
|
||||||
|
|
||||||
|
String root = portal.getNetwork() + "." + portal.getName();
|
||||||
|
ConfigurationSection portalSection = configuration.createSection(root);
|
||||||
|
|
||||||
|
portalSection.set("name", portal.getName());
|
||||||
|
portalSection.set("network", portal.getNetwork());
|
||||||
|
portalSection.set("destination", portal.getOptions().isFixed() ? portal.getDestinationName() : null);
|
||||||
|
portalSection.set("owner", portal.getOwner().getIdentifier());
|
||||||
|
portalSection.set("gate", portal.getGate().getFilename());
|
||||||
|
portalSection.set("topLeft", portal.getLocation().getTopLeft());
|
||||||
|
portalSection.set("signLocation", portal.getLocation().getSignBlock());
|
||||||
|
portalSection.set("buttonLocation", portal.getLocation().getButtonBlock());
|
||||||
|
portalSection.set("facing", portal.getLocation().getFacing());
|
||||||
|
|
||||||
|
for (PortalOption option : PortalOption.values()) {
|
||||||
|
portalSection.set("options." + option.getCharacterRepresentation(), portal.getOptions().checkOption(option));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Portal loadPortal(@NotNull ConfigurationSection portalSection) {
|
||||||
|
|
||||||
|
/* PortalLocation location = new PortalLocation();
|
||||||
|
BlockLocation signLocation = (BlockLocation) portalSection.get("signLocation");
|
||||||
|
BlockLocation topLeft = (BlockLocation) portalSection.get("topLeft");
|
||||||
|
if (signLocation == null || topLeft == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockFace facing = (BlockFace) Objects.requireNonNull(portalSection.get("facing"));
|
||||||
|
location.setSignLocation(signLocation).setButtonFacing(facing).setYaw(BlockFace.);
|
||||||
|
|
||||||
|
BlockLocation button;
|
||||||
|
PortalStrings portalStrings = new PortalStrings();
|
||||||
|
Gate gate = GateHandler.getGateByName();
|
||||||
|
PortalOwner owner;
|
||||||
|
Map<PortalOption, Boolean> options;
|
||||||
|
return new Portal(location, button, portalStrings, gate, owner, options);*/
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.knarcraft.stargate.utility;
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.config.Message;
|
import net.knarcraft.stargate.config.formatting.Message;
|
||||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.teleporter.EntityTeleporter;
|
import net.knarcraft.stargate.portal.teleporter.EntityTeleporter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package net.knarcraft.stargate.utility;
|
|||||||
|
|
||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
|
||||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@@ -69,10 +68,10 @@ public final class UUIDMigrationHelper {
|
|||||||
|
|
||||||
//Get the real portal from the copy and set UUID
|
//Get the real portal from the copy and set UUID
|
||||||
for (Portal portalCopy : portals) {
|
for (Portal portalCopy : portals) {
|
||||||
Portal portal = PortalHandler.getByName(portalCopy.getCleanName(), portalCopy.getCleanNetwork());
|
Portal portal = PortalUtil.getByName(portalCopy.getCleanName(), portalCopy.getCleanNetwork());
|
||||||
if (portal != null) {
|
if (portal != null) {
|
||||||
portal.getOwner().setUUID(uniqueId);
|
portal.getOwner().setUUID(uniqueId);
|
||||||
worldsToSave.add(portal.getWorld());
|
worldsToSave.add(portal.getLocation().getWorld());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ version: '${project.version}'
|
|||||||
description: The original, and still the best, MineCraft transportation solution (Legacy Version)
|
description: The original, and still the best, MineCraft transportation solution (Legacy Version)
|
||||||
author: EpicKnarvik97
|
author: EpicKnarvik97
|
||||||
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
||||||
website: https://sgrewritten.org/legacygit
|
website: https://www.spigotmc.org/resources/97784/
|
||||||
|
dev-url: https://git.knarcraft.net/EpicKnarvik97/Stargate
|
||||||
api-version: 1.20
|
api-version: 1.20
|
||||||
softdepend: [ Vault, dynmap, Geyser-Spigot, floodgate ]
|
softdepend: [ Vault, dynmap, Geyser-Spigot, floodgate ]
|
||||||
commands:
|
commands:
|
||||||
@@ -98,7 +99,7 @@ permissions:
|
|||||||
stargate.option.nonetwork: true
|
stargate.option.nonetwork: true
|
||||||
stargate.option.random: true
|
stargate.option.random: true
|
||||||
stargate.option.quiet: true
|
stargate.option.quiet: true
|
||||||
stargate.option.nosign: true
|
stargate.option.invisible: true
|
||||||
stargate.option.hidden:
|
stargate.option.hidden:
|
||||||
description: Allows the creation of a hidden stargate
|
description: Allows the creation of a hidden stargate
|
||||||
default: false
|
default: false
|
||||||
@@ -126,7 +127,7 @@ permissions:
|
|||||||
stargate.option.quiet:
|
stargate.option.quiet:
|
||||||
description: Allows the creation of a stargate which does not output anything to the chat
|
description: Allows the creation of a stargate which does not output anything to the chat
|
||||||
default: false
|
default: false
|
||||||
stargate.option.nosign:
|
stargate.option.invisible:
|
||||||
description: Allows the creation of a stargate which has no sign
|
description: Allows the creation of a stargate which has no sign
|
||||||
default: false
|
default: false
|
||||||
stargate.admin.hidden:
|
stargate.admin.hidden:
|
||||||
|
|||||||
21
src/main/resources/portal.yml
Normal file
21
src/main/resources/portal.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
name: gdgdfg
|
||||||
|
network: central
|
||||||
|
ownerUUID: a62cd062-517c-4894-b00c-a5bfa8910369
|
||||||
|
gate: nether.gate
|
||||||
|
topLeft: -457,72,427
|
||||||
|
signLocation: -456,70,427
|
||||||
|
buttonLocation: -456,70,424
|
||||||
|
# Change this to block face?
|
||||||
|
facing: NORTH
|
||||||
|
options:
|
||||||
|
bungee: false
|
||||||
|
alwaysOn: false
|
||||||
|
hidden: false
|
||||||
|
private: false
|
||||||
|
free: false
|
||||||
|
backwards: false
|
||||||
|
show: false
|
||||||
|
noNetwork: false
|
||||||
|
random: false
|
||||||
|
quiet: false
|
||||||
|
invisible: false
|
||||||
Reference in New Issue
Block a user