Added leavedesti

This commit is contained in:
Sekwah 2020-04-08 17:28:26 +01:00
parent d9928a60bb
commit 36a75a2bd6
7 changed files with 46 additions and 17 deletions

View File

@ -257,6 +257,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
} else if (startsWithPortalArg("cooldowndelay:", args[i])) {
String cooldownDelay = parseArgVariable(args, i, "cooldowndelay:");
extraData.add(new PortalArg("cooldowndelay", cooldownDelay));
} else if (startsWithPortalArg("leavedesti:", args[i])) {
String leaveDesti = parseArgVariable(args, i, "leavedesti:");
extraData.add(new PortalArg("leavedesti", leaveDesti));
}
}
if (!hasName) {
@ -373,7 +376,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
break;
case "variables":
sender.sendMessage(PluginMessages.customPrefix
+ " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay");
+ " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay, leavedesti");
sender.sendMessage("");
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
break;
@ -782,6 +785,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean needsPermission = false;
boolean hasCommand = false;
boolean hasCooldownDelay = false;
boolean hasLeaveDesti = false;
// TODO change auto complete when quotes are opened and closed. Such as
// autocomplete @Player and stuff when specifying commands
@ -847,6 +851,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (!hasCooldownDelay) {
autoComplete.add("cooldowndelay:");
}
if (!hasLeaveDesti) {
autoComplete.add("leavedesti:");
}
}
}
if (args.length == 2 && args[0].equalsIgnoreCase("warp")) {

View File

@ -104,7 +104,11 @@ public class Destination {
return warp(player, name, false);
}
public static boolean warp(Player player, String name, boolean hideActionbar) {
public static boolean warp(Player player, String name, boolean hideActionBar) {
return warp(player, name, false, false);
}
public static boolean warp(Player player, String name, boolean hideActionbar, boolean noEffects) {
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
if (config.getConfig().getString(name + ".world") != null) {
Location loc = player.getLocation();
@ -118,8 +122,10 @@ public class Destination {
loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch"));
loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw"));
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
if(!noEffects) {
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
}
Chunk c = loc.getChunk();
Entity riding = player.getVehicle();
if (!c.isLoaded()) c.load();
@ -134,8 +140,10 @@ public class Destination {
} else {
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
if(!noEffects) {
WarpEffects.activateParticles(player);
WarpEffects.activateSound(player);
}
if (PORTAL_MESSAGE_DISPLAY == 1) {
player.sendMessage("");

View File

@ -80,15 +80,18 @@ public class Listeners implements Listener {
Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
}
@EventHandler
public void onLeaveEvent(PlayerQuitEvent event) {
Player player = event.getPlayer();
if(player.hasMetadata("leaveDesti")) {
Destination.warp(player, player.getMetadata("leaveDesti").get(0).asString(),
false, true);
}
}
@EventHandler
public void onJoinEvent(PlayerJoinEvent event) {
Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
/*
* if (plugin.PlayerDestiMap.containsKey(event.getPlayer())) { String desti =
* plugin.PlayerDestiMap.get(event.getPlayer());
*
* Destination.warp(event.getPlayer(), desti); }
*/
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -36,7 +36,7 @@ public class PluginMessageReceiver implements PluginMessageListener {
if (msgPlayer != null) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
() -> Destination.warp(msgPlayer, targetDestination),
() -> Destination.warp(msgPlayer, targetDestination, false, true),
20L
);
}

View File

@ -8,9 +8,11 @@ import com.sekwah.advancedportals.bukkit.PluginMessages;
import com.sekwah.advancedportals.bukkit.api.portaldata.PortalArg;
import com.sekwah.advancedportals.bukkit.destinations.Destination;
import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
import com.sekwah.advancedportals.bukkit.listeners.Listeners;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.util.Vector;
@ -441,7 +443,7 @@ public class Portal {
int portalCooldown = 0; // default cooldowndelay when cooldowndelay is not specified
try {
portalCooldown = Integer.parseInt(portal.getArg("cooldowndelay"));
} catch (Exception e) {
} catch (Exception ignored) {
}
if (diff < portalCooldown) {
int time = (portalCooldown - diff);
@ -473,6 +475,13 @@ public class Portal {
+ "\u00A7a.");
}
if(portal.hasArg("leavedesti")) {
player.setMetadata("leaveDesti", new FixedMetadataValue(plugin, portal.getArg("leavedesti")));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
player.removeMetadata("leaveDesti", plugin);
}, 20 * 10);
}
if (portal.getDestiation() != null) {
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
outForList.writeUTF("PortalEnter");
@ -487,6 +496,8 @@ public class Portal {
outForSend.writeUTF("Connect");
outForSend.writeUTF(bungeeServer);
portal.inPortal.add(player.getUniqueId());
player.sendPluginMessage(plugin, "BungeeCord", outForSend.toByteArray());
// Down to bungee to sort out the teleporting but yea theoretically they should

View File

@ -1,4 +1,4 @@
main: com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.3.0
author: sekwah41
version: 0.4.0
author: sekwah41

View File

@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.3.0
version: 0.4.0
author: sekwah41
description: An advanced portals plugin for bukkit.
api-version: 1.13