Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
62661f65f4 | |||
2a61480684 | |||
91a0316e6e | |||
b98aec4a20 |
@ -367,6 +367,15 @@ bungeeSign=Teleport to
|
|||||||
|
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
#### \[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
|
#### \[Version 0.9.0.1] EpicKnarvik97 fork
|
||||||
|
|
||||||
- Adds the highlightSignColor option and renames the signColor option to mainSignColor
|
- Adds the highlightSignColor option and renames the signColor option to mainSignColor
|
||||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>net.knarcraft</groupId>
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>Stargate</artifactId>
|
<artifactId>Stargate</artifactId>
|
||||||
<version>0.9.0.1</version>
|
<version>0.9.0.3</version>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
|
@ -10,6 +10,7 @@ import net.knarcraft.stargate.portal.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.UUIDMigrationHelper;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.type.WallSign;
|
import org.bukkit.block.data.type.WallSign;
|
||||||
@ -42,6 +43,9 @@ public class PlayerEventListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
//Migrate player name to UUID if necessary
|
||||||
|
UUIDMigrationHelper.migrateUUID(event.getPlayer());
|
||||||
|
|
||||||
if (!Stargate.getGateConfig().enableBungee()) {
|
if (!Stargate.getGateConfig().enableBungee()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -154,7 +158,7 @@ public class PlayerEventListener implements Listener {
|
|||||||
|
|
||||||
//Decide if the user should be teleported to another bungee server
|
//Decide if the user should be teleported to another bungee server
|
||||||
if (entrancePortal.getOptions().isBungee()) {
|
if (entrancePortal.getOptions().isBungee()) {
|
||||||
if (bungeeTeleport(player, entrancePortal, event)) {
|
if (BungeeHelper.bungeeTeleport(player, entrancePortal, event)) {
|
||||||
Stargate.getMessageSender().sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
Stargate.getMessageSender().sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -306,39 +310,4 @@ public class PlayerEventListener implements Listener {
|
|||||||
return false;
|
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;
|
package net.knarcraft.stargate.listener;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
||||||
import net.knarcraft.stargate.portal.PlayerTeleporter;
|
import net.knarcraft.stargate.portal.PlayerTeleporter;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
@ -8,7 +9,6 @@ import net.knarcraft.stargate.utility.PermissionHelper;
|
|||||||
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.BlockState;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -37,11 +37,14 @@ public class PortalEventListener implements Listener {
|
|||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Cancel nether portal creation when the portal is a StarGate portal
|
//Unnecessary nether portal creation is only triggered by nether pairing
|
||||||
for (BlockState block : event.getBlocks()) {
|
if (event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR) {
|
||||||
if (PortalHandler.getByBlock(block.getBlock()) != null) {
|
//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);
|
event.setCancelled(true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,9 +154,13 @@ public class VehicleEventListener implements Listener {
|
|||||||
return false;
|
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);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,22 @@ public class PortalOwner {
|
|||||||
return ownerUUID;
|
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
|
* Gets the name of this owner
|
||||||
*
|
*
|
||||||
|
@ -5,6 +5,7 @@ import net.knarcraft.stargate.portal.PlayerTeleporter;
|
|||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
name: Stargate
|
name: Stargate
|
||||||
main: net.knarcraft.stargate.Stargate
|
main: net.knarcraft.stargate.Stargate
|
||||||
version: 0.9.0.1
|
version: 0.9.0.3
|
||||||
description: Stargate mod for Bukkit Revived
|
description: Stargate mod for Bukkit Revived
|
||||||
author: EpicKnarvik97
|
author: EpicKnarvik97
|
||||||
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
||||||
|
Reference in New Issue
Block a user