Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
3c4d10ae3f | |||
aff0082906 | |||
20c3c93c06 | |||
dab9378a67 | |||
62661f65f4 | |||
b8d98c26d4 | |||
8bb9c464d6 | |||
2b5d791581 | |||
2a61480684 | |||
91a0316e6e | |||
b98aec4a20 | |||
89956cf359 | |||
0655d85356 | |||
06cb99de44 | |||
99f8a92857 | |||
01df8db0bf |
26
README.md
26
README.md
@ -292,7 +292,8 @@ gates:
|
||||
cosmetic:
|
||||
rememberDestination - Whether to set the first destination as the last used destination for all gates
|
||||
sortNetworkDestinations - If true, network lists will be sorted alphabetically.
|
||||
signColor - This allows you to specify the color of the gate signs.
|
||||
mainSignColor - This allows you to specify the color of the gate signs.
|
||||
highlightSignColor - This allows you to specify the color of the sign markings.
|
||||
integrity:
|
||||
destroyedByExplosion - Whether to destroy a stargate with explosions, or stop an explosion if it contains a gates controls.
|
||||
verifyPortals - Whether or not all the non-sign blocks are checked to match the gate layout when an old stargate is loaded at startup.
|
||||
@ -300,6 +301,7 @@ gates:
|
||||
functionality:
|
||||
enableBungee - Enable this for BungeeCord support. This allows portals across Bungee servers.
|
||||
handleVehicles - Whether or not to handle vehicles going through gates. Set to false to disallow vehicles (Manned or not) going through gates.
|
||||
handleLeashedCreatures - Whether or not to handle creatures leashed by a player going through gates. Set to false to disallow leashed creatures going through gates.
|
||||
economy:
|
||||
useEconomy - Whether or not to enable Economy using Vault (must have the Vault plugin)
|
||||
createCost - The cost to create a stargate
|
||||
@ -366,6 +368,28 @@ bungeeSign=Teleport to
|
||||
|
||||
# Changes
|
||||
|
||||
#### \[Version 0.9.0.4] EpicKnarvik97 fork
|
||||
|
||||
- Adds teleportation of leashed creatures. By default, any creature connected to a player by a lead will be teleported
|
||||
with the player through stargates, even if the player is in a vehicle. This behavior can be disabled in the config
|
||||
file.
|
||||
|
||||
#### \[Version 0.9.0.3] EpicKnarvik97 fork
|
||||
|
||||
- Adds a missing error message when a player in a vehicle cannot pay the teleportation fee
|
||||
- Adds UUID migration to automatically update player names to UUID when possible
|
||||
|
||||
#### \[Version 0.9.0.2] EpicKnarvik97 fork
|
||||
|
||||
- Fixes a bug causing Stargates using NETHER_PORTAL blocks to generate nether portals in the nether.
|
||||
|
||||
#### \[Version 0.9.0.1] EpicKnarvik97 fork
|
||||
|
||||
- Adds the highlightSignColor option and renames the signColor option to mainSignColor
|
||||
- Fixes some inconsistencies in sign coloring by using the highlight color for all markings
|
||||
- Fixes the order in which configs are loaded to prevent an exception
|
||||
- Adds migrations for the config change
|
||||
|
||||
#### \[Version 0.9.0.0] EpicKnarvik97 fork
|
||||
|
||||
- Changes entire path structure to a more modern and maven-compliant one
|
||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>Stargate</artifactId>
|
||||
<version>0.9.0.0</version>
|
||||
<version>0.9.0.4</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
|
@ -60,19 +60,19 @@ public final class StargateConfig {
|
||||
portalFolder = dataFolderPath + "/portals/";
|
||||
gateFolder = dataFolderPath + "/gates/";
|
||||
languageLoader = new LanguageLoader(dataFolderPath + "/lang/");
|
||||
|
||||
this.loadConfig();
|
||||
|
||||
//Enable the required channels for Bungee support
|
||||
if (stargateGateConfig.enableBungee()) {
|
||||
startStopBungeeListener(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the config setup by loading languages, gates and portals, and loading economy if vault is loaded
|
||||
*/
|
||||
public void finishSetup() {
|
||||
this.loadConfig();
|
||||
|
||||
//Enable the required channels for Bungee support
|
||||
if (stargateGateConfig.enableBungee()) {
|
||||
startStopBungeeListener(true);
|
||||
}
|
||||
|
||||
//Set the chosen language and reload the language loader
|
||||
languageLoader.setChosenLanguage(languageName);
|
||||
languageLoader.reload();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
@ -12,12 +13,12 @@ public final class StargateGateConfig {
|
||||
private int maxGatesEachNetwork = 0;
|
||||
private boolean rememberDestination = false;
|
||||
private boolean handleVehicles = true;
|
||||
private boolean handleLeashedCreatures = true;
|
||||
private boolean sortNetworkDestinations = false;
|
||||
private boolean protectEntrance = false;
|
||||
private boolean enableBungee = true;
|
||||
private boolean verifyPortals = true;
|
||||
private boolean destroyExplosion = false;
|
||||
private ChatColor signColor;
|
||||
private String defaultGateNetwork = "central";
|
||||
private static final int activeTime = 10;
|
||||
private static final int openTime = 10;
|
||||
@ -76,6 +77,15 @@ public final class StargateGateConfig {
|
||||
return handleVehicles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether leashed creatures should be teleported with a teleporting player
|
||||
*
|
||||
* @return <p>Whether leashed creatures should be handled</p>
|
||||
*/
|
||||
public boolean handleLeashedCreatures() {
|
||||
return handleLeashedCreatures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the list of destinations within a network should be sorted
|
||||
*
|
||||
@ -121,17 +131,6 @@ public final class StargateGateConfig {
|
||||
return destroyExplosion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color to use for drawing signs
|
||||
*
|
||||
* <p>Highlighting may use other colors. This is just the base color for portal names and such.</p>
|
||||
*
|
||||
* @return <p>The color to use for drawing signs</p>
|
||||
*/
|
||||
public ChatColor getSignColor() {
|
||||
return signColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default portal network to use if no other network is given
|
||||
*
|
||||
@ -153,6 +152,7 @@ public final class StargateGateConfig {
|
||||
|
||||
//Functionality
|
||||
handleVehicles = newConfig.getBoolean("gates.functionality.handleVehicles");
|
||||
handleLeashedCreatures = newConfig.getBoolean("gates.functionality.handleLeashedCreatures");
|
||||
enableBungee = newConfig.getBoolean("gates.functionality.enableBungee");
|
||||
|
||||
//Integrity
|
||||
@ -163,24 +163,25 @@ public final class StargateGateConfig {
|
||||
//Cosmetic
|
||||
sortNetworkDestinations = newConfig.getBoolean("gates.cosmetic.sortNetworkDestinations");
|
||||
rememberDestination = newConfig.getBoolean("gates.cosmetic.rememberDestination");
|
||||
loadSignColor(newConfig.getString("gates.cosmetic.signColor"));
|
||||
loadSignColor(newConfig.getString("gates.cosmetic.mainSignColor"),
|
||||
newConfig.getString("gates.cosmetic.highlightSignColor"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the correct sign color given a sign color string
|
||||
*
|
||||
* @param signColor <p>A string representing a sign color</p>
|
||||
* @param mainSignColor <p>A string representing the main sign color</p>
|
||||
*/
|
||||
private void loadSignColor(String signColor) {
|
||||
if (signColor != null) {
|
||||
private void loadSignColor(String mainSignColor, String highlightSignColor) {
|
||||
if (mainSignColor != null) {
|
||||
try {
|
||||
this.signColor = ChatColor.valueOf(signColor.toUpperCase());
|
||||
PortalSignDrawer.setColors(ChatColor.valueOf(mainSignColor.toUpperCase()),
|
||||
ChatColor.valueOf(highlightSignColor.toUpperCase()));
|
||||
return;
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK");
|
||||
this.signColor = ChatColor.BLACK;
|
||||
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE");
|
||||
PortalSignDrawer.setColors(ChatColor.BLACK, ChatColor.WHITE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import net.knarcraft.stargate.portal.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
@ -42,6 +43,9 @@ public class PlayerEventListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
//Migrate player name to UUID if necessary
|
||||
UUIDMigrationHelper.migrateUUID(event.getPlayer());
|
||||
|
||||
if (!Stargate.getGateConfig().enableBungee()) {
|
||||
return;
|
||||
}
|
||||
@ -154,7 +158,7 @@ public class PlayerEventListener implements Listener {
|
||||
|
||||
//Decide if the user should be teleported to another bungee server
|
||||
if (entrancePortal.getOptions().isBungee()) {
|
||||
if (bungeeTeleport(player, entrancePortal, event)) {
|
||||
if (BungeeHelper.bungeeTeleport(player, entrancePortal, event)) {
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
||||
}
|
||||
return false;
|
||||
@ -306,39 +310,4 @@ public class PlayerEventListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player to a bungee gate
|
||||
*
|
||||
* @param player <p>The player to teleport</p>
|
||||
* @param entrancePortal <p>The gate the player is entering from</p>
|
||||
* @param event <p>The event causing the teleportation</p>
|
||||
* @return <p>True if the teleportation was successful</p>
|
||||
*/
|
||||
private boolean bungeeTeleport(Player player, Portal entrancePortal, PlayerMoveEvent event) {
|
||||
//Check if bungee is actually enabled
|
||||
if (!Stargate.getGateConfig().enableBungee()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("bungeeDisabled"));
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Teleport the player back to this gate, for sanity's sake
|
||||
new PlayerTeleporter(entrancePortal, player).teleport(entrancePortal, event);
|
||||
|
||||
//Send the SGBungee packet first, it will be queued by BC if required
|
||||
if (!BungeeHelper.sendTeleportationMessage(player, entrancePortal)) {
|
||||
Stargate.debug("bungeeTeleport", "Unable to send teleportation message");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Send the connect-message to make the player change server
|
||||
if (!BungeeHelper.changeServer(player, entrancePortal)) {
|
||||
Stargate.debug("bungeeTeleport", "Unable to change server");
|
||||
return false;
|
||||
}
|
||||
|
||||
Stargate.debug("bungeeTeleport", "Teleported player to another server");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
||||
import net.knarcraft.stargate.portal.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
@ -8,7 +9,6 @@ import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -37,11 +37,14 @@ public class PortalEventListener implements Listener {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
//Cancel nether portal creation when the portal is a StarGate portal
|
||||
for (BlockState block : event.getBlocks()) {
|
||||
if (PortalHandler.getByBlock(block.getBlock()) != null) {
|
||||
//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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,9 +154,13 @@ public class VehicleEventListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Transfer payment if necessary
|
||||
//Check if the player is able to afford the teleport fee
|
||||
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destinationPortal);
|
||||
return cost <= 0 || Stargate.getEconomyConfig().canAffordFee(player, cost);
|
||||
boolean canAffordFee = cost <= 0 || Stargate.getEconomyConfig().canAffordFee(player, cost);
|
||||
if (!canAffordFee) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
||||
}
|
||||
return canAffordFee;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.event.StargateEntityPortalEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/**
|
||||
* The portal teleporter takes care of the actual portal teleportation for any entities
|
||||
*/
|
||||
public class EntityTeleporter extends Teleporter {
|
||||
|
||||
private final Entity teleportingEntity;
|
||||
|
||||
/**
|
||||
* Instantiates a new portal teleporter
|
||||
*
|
||||
* @param portal <p>The portal which is the target of the teleportation</p>
|
||||
*/
|
||||
public EntityTeleporter(Portal portal, Entity teleportingEntity) {
|
||||
super(portal);
|
||||
this.teleportingEntity = teleportingEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports an entity to this teleporter's portal
|
||||
*
|
||||
* @param origin <p>The portal the entity is teleporting from</p>
|
||||
*/
|
||||
public void teleport(Portal origin) {
|
||||
Location traveller = teleportingEntity.getLocation();
|
||||
Location exit = getExit(teleportingEntity, traveller);
|
||||
|
||||
//Rotate the entity to face out from the portal
|
||||
adjustRotation(exit);
|
||||
|
||||
//Call the StargateEntityPortalEvent to allow plugins to change destination
|
||||
if (!origin.equals(portal)) {
|
||||
exit = triggerEntityPortalEvent(origin, exit);
|
||||
if (exit == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Load chunks to make sure not to teleport to the void
|
||||
loadChunks();
|
||||
|
||||
teleportingEntity.teleport(exit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the entity portal event to allow plugins to change the exit location
|
||||
*
|
||||
* @param origin <p>The origin portal teleported from</p>
|
||||
* @param exit <p>The exit location to teleport the entity to</p>
|
||||
* @return <p>The location the entity should be teleported to, or null if the event was cancelled</p>
|
||||
*/
|
||||
protected Location triggerEntityPortalEvent(Portal origin, Location exit) {
|
||||
StargateEntityPortalEvent stargateEntityPortalEvent = new StargateEntityPortalEvent(teleportingEntity, origin,
|
||||
portal, exit);
|
||||
Stargate.getInstance().getServer().getPluginManager().callEvent(stargateEntityPortalEvent);
|
||||
//Teleport is cancelled. Teleport the entity back to where it came from just for sanity's sake
|
||||
if (stargateEntityPortalEvent.isCancelled()) {
|
||||
new EntityTeleporter(origin, teleportingEntity).teleport(origin);
|
||||
return null;
|
||||
}
|
||||
return stargateEntityPortalEvent.getExit();
|
||||
}
|
||||
}
|
@ -48,6 +48,9 @@ public class PlayerTeleporter extends Teleporter {
|
||||
//Load chunks to make sure not to teleport to the void
|
||||
loadChunks();
|
||||
|
||||
//Teleport any creatures leashed by the player in a 15-block range
|
||||
teleportLeashedCreatures(player, origin);
|
||||
|
||||
//If no event is passed in, assume it's a teleport, and act as such
|
||||
if (event == null) {
|
||||
player.teleport(exit);
|
||||
|
@ -43,6 +43,22 @@ public class PortalOwner {
|
||||
return ownerUUID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the unique id for a portal owner without one
|
||||
*
|
||||
* <p>This method is only meant to be used to set the unique id for an owner without one. If the owner already has
|
||||
* an unique id, an exception will be thrown.</p>
|
||||
*
|
||||
* @param uniqueId <p>The new unique id for the portal owner</p>
|
||||
*/
|
||||
public void setUUID(UUID uniqueId) {
|
||||
if (ownerUUID == null) {
|
||||
ownerUUID = uniqueId;
|
||||
} else {
|
||||
throw new IllegalArgumentException("An existing UUID cannot be overwritten.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this owner
|
||||
*
|
||||
|
@ -13,9 +13,10 @@ import org.bukkit.block.Sign;
|
||||
public class PortalSignDrawer {
|
||||
|
||||
private final Portal portal;
|
||||
private final static ChatColor highlightColor = ChatColor.WHITE;
|
||||
private final static ChatColor errorColor = ChatColor.DARK_RED;
|
||||
private final static ChatColor freeColor = ChatColor.DARK_GREEN;
|
||||
private static ChatColor mainColor;
|
||||
private static ChatColor highlightColor;
|
||||
|
||||
/**
|
||||
* Instantiates a new portal sign drawer
|
||||
@ -26,6 +27,20 @@ public class PortalSignDrawer {
|
||||
this.portal = portal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main sign color
|
||||
*
|
||||
* <p>The main sign color is used for most text on the sign, while the highlighting color is used for the markings
|
||||
* around portal names and network names ('>','<','-',')','(')</p>
|
||||
*
|
||||
* @param newMainColor <p>The new main sign color</p>
|
||||
* @param newHighlightColor <p>The new highlight color</p>
|
||||
*/
|
||||
public static void setColors(ChatColor newMainColor, ChatColor newHighlightColor) {
|
||||
mainColor = newMainColor;
|
||||
highlightColor = newHighlightColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the sign of the portal this sign drawer is responsible for
|
||||
*/
|
||||
@ -47,12 +62,12 @@ public class PortalSignDrawer {
|
||||
*
|
||||
* @param sign <p>The sign re-draw</p>
|
||||
*/
|
||||
public void drawSign(Sign sign) {
|
||||
private void drawSign(Sign sign) {
|
||||
//Clear sign
|
||||
for (int index = 0; index <= 3; index++) {
|
||||
sign.setLine(index, "");
|
||||
}
|
||||
setLine(sign, 0, highlightColor + "-" + Stargate.getGateConfig().getSignColor() +
|
||||
setLine(sign, 0, highlightColor + "-" + mainColor +
|
||||
portal.getName() + highlightColor + "-");
|
||||
|
||||
if (!portal.getPortalActivator().isActive()) {
|
||||
@ -118,11 +133,12 @@ public class PortalSignDrawer {
|
||||
if (freeGatesGreen) {
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
setLine(sign, signLineIndex, (green ? freeColor : "") + ">" +
|
||||
portal.getDestinationName() + (green ? freeColor : "") + "<");
|
||||
ChatColor nameColor = (green ? freeColor : highlightColor);
|
||||
setLine(sign, signLineIndex, nameColor + ">" + (green ? freeColor : mainColor) +
|
||||
portal.getDestinationName() + nameColor + "<");
|
||||
} else {
|
||||
setLine(sign, signLineIndex, highlightColor + ">" + Stargate.getGateConfig().getSignColor() +
|
||||
portal.getDestinationName() + highlightColor + "<");
|
||||
setLine(sign, signLineIndex, highlightColor + ">" + mainColor + portal.getDestinationName() +
|
||||
highlightColor + "<");
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +150,7 @@ public class PortalSignDrawer {
|
||||
* @param text <p>The new text on the sign</p>
|
||||
*/
|
||||
public void setLine(Sign sign, int index, String text) {
|
||||
sign.setLine(index, Stargate.getGateConfig().getSignColor() + text);
|
||||
sign.setLine(index, mainColor + text);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,14 +163,13 @@ public class PortalSignDrawer {
|
||||
*/
|
||||
private void drawNetworkSignLine(boolean freeGatesGreen, Sign sign, int signLineIndex, int destinationIndex) {
|
||||
PortalActivator destinations = portal.getPortalActivator();
|
||||
String destinationName = destinations.getDestinations().get(destinationIndex);
|
||||
if (freeGatesGreen) {
|
||||
Portal destination = PortalHandler.getByName(destinations.getDestinations().get(destinationIndex),
|
||||
portal.getNetwork());
|
||||
Portal destination = PortalHandler.getByName(destinationName, portal.getNetwork());
|
||||
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
setLine(sign, signLineIndex, (green ? freeColor : "") +
|
||||
destinations.getDestinations().get(destinationIndex));
|
||||
setLine(sign, signLineIndex, (green ? freeColor : mainColor) + destinationName);
|
||||
} else {
|
||||
setLine(sign, signLineIndex, destinations.getDestinations().get(destinationIndex));
|
||||
setLine(sign, signLineIndex, mainColor + destinationName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,8 +180,8 @@ public class PortalSignDrawer {
|
||||
*/
|
||||
private void drawBungeeSign(Sign sign) {
|
||||
setLine(sign, 1, Stargate.getString("bungeeSign"));
|
||||
setLine(sign, 2, ">" + portal.getDestinationName() + "<");
|
||||
setLine(sign, 3, "[" + portal.getNetwork() + "]");
|
||||
setLine(sign, 2, highlightColor + ">" + mainColor + portal.getDestinationName() + highlightColor + "<");
|
||||
setLine(sign, 3, highlightColor + "[" + mainColor + portal.getNetwork() + highlightColor + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,7 +193,7 @@ public class PortalSignDrawer {
|
||||
setLine(sign, 1, Stargate.getString("signRightClick"));
|
||||
setLine(sign, 2, Stargate.getString("signToUse"));
|
||||
if (!portal.getOptions().isNoNetwork()) {
|
||||
setLine(sign, 3, "(" + portal.getNetwork() + ")");
|
||||
setLine(sign, 3, highlightColor + "(" + mainColor + portal.getNetwork() + highlightColor + ")");
|
||||
} else {
|
||||
setLine(sign, 3, "");
|
||||
}
|
||||
@ -190,15 +205,14 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign to re-draw</p>
|
||||
*/
|
||||
private void drawFixedSign(Sign sign) {
|
||||
if (portal.getOptions().isRandom()) {
|
||||
setLine(sign, 1, ">" + Stargate.getString("signRandom") + "<");
|
||||
} else {
|
||||
setLine(sign, 1, ">" + portal.getDestinationName() + "<");
|
||||
}
|
||||
String destinationName = portal.getOptions().isRandom() ? Stargate.getString("signRandom") :
|
||||
portal.getDestinationName();
|
||||
setLine(sign, 1, highlightColor + ">" + mainColor + destinationName + highlightColor + "<");
|
||||
|
||||
if (portal.getOptions().isNoNetwork()) {
|
||||
setLine(sign, 2, "");
|
||||
} else {
|
||||
setLine(sign, 2, "(" + portal.getNetwork() + ")");
|
||||
setLine(sign, 2, highlightColor + "(" + mainColor + portal.getNetwork() + highlightColor + ")");
|
||||
}
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
if (destination == null && !portal.getOptions().isRandom()) {
|
||||
|
@ -13,7 +13,9 @@ import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Slab;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -247,4 +249,47 @@ public abstract class Teleporter {
|
||||
return chunksToLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports any creatures leashed by the player
|
||||
*
|
||||
* @param player <p>The player which is teleported</p>
|
||||
* @param origin <p>The portal the player is teleporting from</p>
|
||||
*/
|
||||
protected void teleportLeashedCreatures(Player player, Portal origin) {
|
||||
//If this feature is disabled, just return
|
||||
if (!Stargate.getGateConfig().handleLeashedCreatures()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Creature> nearbyEntities = getLeashedCreatures(player);
|
||||
//Teleport all creatures leashed by the player to the portal the player is to exit from
|
||||
for (Creature creature : nearbyEntities) {
|
||||
creature.setLeashHolder(null);
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> {
|
||||
new EntityTeleporter(portal, creature).teleport(origin);
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> creature.setLeashHolder(player), 3);
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all creatures leashed by a player within the given range
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>A list of all creatures the player is holding in a leash (lead)</p>
|
||||
*/
|
||||
protected List<Creature> getLeashedCreatures(Player player) {
|
||||
List<Creature> leashedCreatures = new ArrayList<>();
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
|
||||
//Teleport all creatures leashed by the player to the portal the player is to exit from
|
||||
for (Entity entity : nearbyEntities) {
|
||||
if (entity instanceof Creature creature && creature.isLeashed() && creature.getLeashHolder() == player) {
|
||||
leashedCreatures.add(creature);
|
||||
}
|
||||
}
|
||||
return leashedCreatures;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.event.StargateEntityPortalEvent;
|
||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -15,7 +15,7 @@ import java.util.List;
|
||||
/**
|
||||
* The portal teleporter takes care of the actual portal teleportation for any vehicles
|
||||
*/
|
||||
public class VehicleTeleporter extends Teleporter {
|
||||
public class VehicleTeleporter extends EntityTeleporter {
|
||||
|
||||
private final Vehicle teleportingVehicle;
|
||||
|
||||
@ -26,7 +26,7 @@ public class VehicleTeleporter extends Teleporter {
|
||||
* @param teleportingVehicle <p>The teleporting vehicle</p>
|
||||
*/
|
||||
public VehicleTeleporter(Portal portal, Vehicle teleportingVehicle) {
|
||||
super(portal);
|
||||
super(portal, teleportingVehicle);
|
||||
this.teleportingVehicle = teleportingVehicle;
|
||||
}
|
||||
|
||||
@ -36,8 +36,9 @@ public class VehicleTeleporter extends Teleporter {
|
||||
* <p>It is assumed that if a vehicle contains any players, their permissions have already been validated before
|
||||
* calling this method.</p>
|
||||
*
|
||||
* @param origin <p>The portal the vehicle teleports from</p>
|
||||
* @param origin <p>The portal the vehicle is teleporting from</p>
|
||||
*/
|
||||
@Override
|
||||
public void teleport(Portal origin) {
|
||||
Location traveller = teleportingVehicle.getLocation();
|
||||
Location exit = getExit(teleportingVehicle, traveller);
|
||||
@ -63,7 +64,7 @@ public class VehicleTeleporter extends Teleporter {
|
||||
}
|
||||
|
||||
//Teleport the vehicle
|
||||
teleportVehicle(exit, newVelocity);
|
||||
teleportVehicle(exit, newVelocity, origin);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,8 +72,9 @@ public class VehicleTeleporter extends Teleporter {
|
||||
*
|
||||
* @param exit <p>The location the vehicle should be teleported to</p>
|
||||
* @param newVelocity <p>The velocity to give the vehicle right after teleportation</p>
|
||||
* @param origin <p>The portal the vehicle teleported from</p>
|
||||
*/
|
||||
private void teleportVehicle(Location exit, Vector newVelocity) {
|
||||
private void teleportVehicle(Location exit, Vector newVelocity, Portal origin) {
|
||||
//Load chunks to make sure not to teleport to the void
|
||||
loadChunks();
|
||||
|
||||
@ -80,10 +82,10 @@ public class VehicleTeleporter extends Teleporter {
|
||||
if (!passengers.isEmpty()) {
|
||||
if (!(teleportingVehicle instanceof LivingEntity)) {
|
||||
//Teleport a normal vehicle with passengers (minecart or boat)
|
||||
putPassengersInNewVehicle(passengers, exit, newVelocity);
|
||||
putPassengersInNewVehicle(passengers, exit, newVelocity, origin);
|
||||
} else {
|
||||
//Teleport a living vehicle with passengers (pig, horse, donkey, strider)
|
||||
teleportLivingVehicle(exit, passengers);
|
||||
teleportLivingVehicle(exit, passengers, origin);
|
||||
}
|
||||
} else {
|
||||
//Teleport an empty vehicle
|
||||
@ -93,35 +95,17 @@ public class VehicleTeleporter extends Teleporter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the entity portal event to allow plugins to change the exit location
|
||||
*
|
||||
* @param origin <p>The origin portal teleported from</p>
|
||||
* @param exit <p>The exit location to teleport the vehicle to</p>
|
||||
* @return <p>The location the vehicle should be teleported to, or null if the event was cancelled</p>
|
||||
*/
|
||||
private Location triggerEntityPortalEvent(Portal origin, Location exit) {
|
||||
StargateEntityPortalEvent stargateEntityPortalEvent = new StargateEntityPortalEvent(teleportingVehicle, origin,
|
||||
portal, exit);
|
||||
Stargate.getInstance().getServer().getPluginManager().callEvent(stargateEntityPortalEvent);
|
||||
//Teleport is cancelled. Teleport the entity back to where it came from just for sanity's sake
|
||||
if (stargateEntityPortalEvent.isCancelled()) {
|
||||
new VehicleTeleporter(origin, teleportingVehicle).teleport(origin);
|
||||
return null;
|
||||
}
|
||||
return stargateEntityPortalEvent.getExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a vehicle which is not a minecart or a boat
|
||||
*
|
||||
* @param exit <p>The location the vehicle will exit</p>
|
||||
* @param passengers <p>The passengers of the vehicle</p>
|
||||
* @param origin <p>The portal the vehicle teleported from</p>
|
||||
*/
|
||||
private void teleportLivingVehicle(Location exit, List<Entity> passengers) {
|
||||
private void teleportLivingVehicle(Location exit, List<Entity> passengers, Portal origin) {
|
||||
teleportingVehicle.eject();
|
||||
teleportingVehicle.teleport(exit);
|
||||
handleVehiclePassengers(passengers, teleportingVehicle, 2);
|
||||
handleVehiclePassengers(passengers, teleportingVehicle, 2, origin);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,9 +118,10 @@ public class VehicleTeleporter extends Teleporter {
|
||||
* @param passengers <p>A list of all passengers in the vehicle</p>
|
||||
* @param exit <p>The exit location to spawn the new vehicle on</p>
|
||||
* @param newVelocity <p>The new velocity of the new vehicle</p>
|
||||
* @param origin <p>The portal the vehicle teleported from</p>
|
||||
*/
|
||||
private void putPassengersInNewVehicle(List<Entity> passengers, Location exit,
|
||||
Vector newVelocity) {
|
||||
Vector newVelocity, Portal origin) {
|
||||
World vehicleWorld = exit.getWorld();
|
||||
if (vehicleWorld == null) {
|
||||
Stargate.logWarning("Unable to get the world to teleport the vehicle to");
|
||||
@ -149,7 +134,7 @@ public class VehicleTeleporter extends Teleporter {
|
||||
teleportingVehicle.remove();
|
||||
//Set rotation, add passengers and restore velocity
|
||||
newVehicle.setRotation(exit.getYaw(), exit.getPitch());
|
||||
handleVehiclePassengers(passengers, newVehicle, 1);
|
||||
handleVehiclePassengers(passengers, newVehicle, 1, origin);
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> newVehicle.setVelocity(newVelocity), 1);
|
||||
}
|
||||
|
||||
@ -159,12 +144,18 @@ public class VehicleTeleporter extends Teleporter {
|
||||
* @param passengers <p>The passengers to handle</p>
|
||||
* @param vehicle <p>The vehicle the passengers should be put into</p>
|
||||
* @param delay <p>The amount of milliseconds to wait before adding the vehicle passengers</p>
|
||||
* @param origin <p>The portal the vehicle teleported from</p>
|
||||
*/
|
||||
private void handleVehiclePassengers(List<Entity> passengers, Vehicle vehicle, long delay) {
|
||||
private void handleVehiclePassengers(List<Entity> passengers, Vehicle vehicle, long delay, Portal origin) {
|
||||
for (Entity passenger : passengers) {
|
||||
passenger.eject();
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> teleportAndAddPassenger(vehicle, passenger),
|
||||
delay);
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), () -> {
|
||||
if (passenger instanceof Player player) {
|
||||
//Teleport any creatures leashed by the player in a 15-block range
|
||||
teleportLeashedCreatures(player, origin);
|
||||
}
|
||||
teleportAndAddPassenger(vehicle, passenger);
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import net.knarcraft.stargate.portal.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -169,4 +170,39 @@ public final class BungeeHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player to a bungee gate
|
||||
*
|
||||
* @param player <p>The player to teleport</p>
|
||||
* @param entrancePortal <p>The gate the player is entering from</p>
|
||||
* @param event <p>The event causing the teleportation</p>
|
||||
* @return <p>True if the teleportation was successful</p>
|
||||
*/
|
||||
public static boolean bungeeTeleport(Player player, Portal entrancePortal, PlayerMoveEvent event) {
|
||||
//Check if bungee is actually enabled
|
||||
if (!Stargate.getGateConfig().enableBungee()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("bungeeDisabled"));
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Teleport the player back to this gate, for sanity's sake
|
||||
new PlayerTeleporter(entrancePortal, player).teleport(entrancePortal, event);
|
||||
|
||||
//Send the SGBungee packet first, it will be queued by BC if required
|
||||
if (!BungeeHelper.sendTeleportationMessage(player, entrancePortal)) {
|
||||
Stargate.debug("bungeeTeleport", "Unable to send teleportation message");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Send the connect-message to make the player change server
|
||||
if (!BungeeHelper.changeServer(player, entrancePortal)) {
|
||||
Stargate.debug("bungeeTeleport", "Unable to change server");
|
||||
return false;
|
||||
}
|
||||
|
||||
Stargate.debug("bungeeTeleport", "Teleported player to another server");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,111 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalOwner;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Helps migrate player names to UUID where necessary
|
||||
*/
|
||||
public class UUIDMigrationHelper {
|
||||
|
||||
private static Map<String, List<Portal>> playerNamesToMigrate;
|
||||
|
||||
/**
|
||||
* Migrates the player's name to a UUID
|
||||
*
|
||||
* <p>If any portals are missing a UUID for their owner, and the given player is the owner of those portals, the
|
||||
* given player's UUID will be used as UUID for the portals' owner.</p>
|
||||
*
|
||||
* @param player <p>The player to migrate</p>
|
||||
*/
|
||||
public static void migrateUUID(OfflinePlayer player) {
|
||||
Map<String, List<Portal>> playersToMigrate = getPlayersToMigrate();
|
||||
String playerName = player.getName();
|
||||
|
||||
//Nothing to do
|
||||
if (!playersToMigrate.containsKey(playerName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.debug("PlayerEventListener::migrateUUID", String.format("Migrating name to UUID for player %s",
|
||||
playerName));
|
||||
List<Portal> portalsOwned = playersToMigrate.get(playerName);
|
||||
if (portalsOwned == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
migratePortalsToUUID(portalsOwned, player.getUniqueId());
|
||||
|
||||
//Remove the player to prevent the migration to happen every time the player joins
|
||||
playersToMigrate.remove(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates a list of portals to use UUID instead of only player name
|
||||
*
|
||||
* @param portals <p>The portals to migrate</p>
|
||||
* @param uniqueId <p>The unique ID of the portals' owner</p>
|
||||
*/
|
||||
private static void migratePortalsToUUID(List<Portal> portals, UUID uniqueId) {
|
||||
Set<World> worldsToSave = new HashSet<>();
|
||||
|
||||
//Get the real portal from the copy and set UUID
|
||||
for (Portal portalCopy : portals) {
|
||||
Portal portal = PortalHandler.getByName(portalCopy.getName(), portalCopy.getNetwork());
|
||||
if (portal != null) {
|
||||
portal.getOwner().setUUID(uniqueId);
|
||||
worldsToSave.add(portal.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
//Need to make sure the changes are saved
|
||||
for (World world : worldsToSave) {
|
||||
PortalFileHelper.saveAllPortals(world);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all player names which need to be migrated to UUIDs
|
||||
*
|
||||
* @return <p>The player names to migrate</p>
|
||||
*/
|
||||
private static Map<String, List<Portal>> getPlayersToMigrate() {
|
||||
//Make sure to only go through portals once
|
||||
if (playerNamesToMigrate != null) {
|
||||
return playerNamesToMigrate;
|
||||
}
|
||||
|
||||
playerNamesToMigrate = new HashMap<>();
|
||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||
PortalOwner owner = portal.getOwner();
|
||||
String ownerName = owner.getName();
|
||||
|
||||
//If a UUID is missing, add the portal to the list owned by the player
|
||||
if (owner.getUUID() == null) {
|
||||
List<Portal> portalList = playerNamesToMigrate.get(ownerName);
|
||||
if (portalList == null) {
|
||||
List<Portal> newList = new ArrayList<>();
|
||||
newList.add(portal);
|
||||
playerNamesToMigrate.put(ownerName, newList);
|
||||
} else {
|
||||
portalList.add(portal);
|
||||
}
|
||||
}
|
||||
}
|
||||
return playerNamesToMigrate;
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,7 @@ protectEntrance=gates.integrity.protectEntrance
|
||||
enableBungee=gates.functionality.enableBungee
|
||||
verifyPortals=gates.integrity.verifyPortals
|
||||
signColor=gates.cosmetic.signColor
|
||||
gates.cosmetic.signColor=gates.cosmetic.mainSignColor
|
||||
debug=debugging.debug
|
||||
permdebug=debugging.permissionDebug
|
||||
useiconomy=economy.useEconomy
|
||||
|
@ -9,9 +9,11 @@
|
||||
# language - The language file to load for messages
|
||||
# rememberDestination - Whether to remember the cursor location between uses
|
||||
# handleVehicles - Whether to allow vehicles through gates
|
||||
# handleLeashedCreatures - Whether to allow creatures lead by a player to teleport with the player
|
||||
# sortNetworkDestinations - Whether to sort network lists alphabetically
|
||||
# protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using destroyable open/closed material)
|
||||
# signColor - The color used for drawing signs (Default: BLACK).
|
||||
# mainSignColor - The color used for drawing signs (Default: BLACK).
|
||||
# highlightSignColor - The color used for sign markings (Default: WHITE)
|
||||
# verifyPortals - Whether all the non-sign blocks are checked to match the gate layout when a stargate is loaded.
|
||||
# I------------I-------------I #
|
||||
# stargate economy options #
|
||||
@ -39,7 +41,8 @@ gates:
|
||||
cosmetic:
|
||||
rememberDestination: false
|
||||
sortNetworkDestinations: false
|
||||
signColor: BLACK
|
||||
mainSignColor: BLACK
|
||||
highlightSignColor: WHITE
|
||||
integrity:
|
||||
destroyedByExplosion: false
|
||||
verifyPortals: false
|
||||
@ -47,6 +50,7 @@ gates:
|
||||
functionality:
|
||||
enableBungee: false
|
||||
handleVehicles: true
|
||||
handleLeashedCreatures: true
|
||||
economy:
|
||||
useEconomy: false
|
||||
createCost: 0
|
||||
|
@ -1,10 +1,10 @@
|
||||
name: Stargate
|
||||
main: net.knarcraft.stargate.Stargate
|
||||
version: 0.9.0.0
|
||||
description: Stargate mod for Bukkit
|
||||
version: 0.9.0.4
|
||||
description: Stargate mod for Bukkit Revived
|
||||
author: EpicKnarvik97
|
||||
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
||||
website: https://knarcraft.net
|
||||
website: https://git.knarcraft.net/EpicKnarvik97/Stargate
|
||||
api-version: 1.17
|
||||
softdepend: [ Vault ]
|
||||
commands:
|
||||
|
Reference in New Issue
Block a user