Skip to content

Commit 36a75a2

Browse files
author
Sekwah
committed
Added leavedesti
1 parent d9928a6 commit 36a75a2

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String command, Stri
257257
} else if (startsWithPortalArg("cooldowndelay:", args[i])) {
258258
String cooldownDelay = parseArgVariable(args, i, "cooldowndelay:");
259259
extraData.add(new PortalArg("cooldowndelay", cooldownDelay));
260+
} else if (startsWithPortalArg("leavedesti:", args[i])) {
261+
String leaveDesti = parseArgVariable(args, i, "leavedesti:");
262+
extraData.add(new PortalArg("leavedesti", leaveDesti));
260263
}
261264
}
262265
if (!hasName) {
@@ -373,7 +376,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String command, Stri
373376
break;
374377
case "variables":
375378
sender.sendMessage(PluginMessages.customPrefix
376-
+ " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay");
379+
+ " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, desti, destination, bungee, permission, command, cooldowndelay, leavedesti");
377380
sender.sendMessage("");
378381
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
379382
break;
@@ -782,6 +785,7 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String comm
782785
boolean needsPermission = false;
783786
boolean hasCommand = false;
784787
boolean hasCooldownDelay = false;
788+
boolean hasLeaveDesti = false;
785789

786790
// TODO change auto complete when quotes are opened and closed. Such as
787791
// autocomplete @Player and stuff when specifying commands
@@ -847,6 +851,9 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String comm
847851
if (!hasCooldownDelay) {
848852
autoComplete.add("cooldowndelay:");
849853
}
854+
if (!hasLeaveDesti) {
855+
autoComplete.add("leavedesti:");
856+
}
850857
}
851858
}
852859
if (args.length == 2 && args[0].equalsIgnoreCase("warp")) {

src/main/java/com/sekwah/advancedportals/bukkit/destinations/Destination.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ public static boolean warp(Player player, String name) {
104104
return warp(player, name, false);
105105
}
106106

107-
public static boolean warp(Player player, String name, boolean hideActionbar) {
107+
public static boolean warp(Player player, String name, boolean hideActionBar) {
108+
return warp(player, name, false, false);
109+
}
110+
111+
public static boolean warp(Player player, String name, boolean hideActionbar, boolean noEffects) {
108112
ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml");
109113
if (config.getConfig().getString(name + ".world") != null) {
110114
Location loc = player.getLocation();
@@ -118,8 +122,10 @@ public static boolean warp(Player player, String name, boolean hideActionbar) {
118122
loc.setPitch((float) config.getConfig().getDouble(name + ".pos.pitch"));
119123
loc.setYaw((float) config.getConfig().getDouble(name + ".pos.yaw"));
120124

121-
WarpEffects.activateParticles(player);
122-
WarpEffects.activateSound(player);
125+
if(!noEffects) {
126+
WarpEffects.activateParticles(player);
127+
WarpEffects.activateSound(player);
128+
}
123129
Chunk c = loc.getChunk();
124130
Entity riding = player.getVehicle();
125131
if (!c.isLoaded()) c.load();
@@ -134,8 +140,10 @@ public static boolean warp(Player player, String name, boolean hideActionbar) {
134140
} else {
135141
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
136142
}
137-
WarpEffects.activateParticles(player);
138-
WarpEffects.activateSound(player);
143+
if(!noEffects) {
144+
WarpEffects.activateParticles(player);
145+
WarpEffects.activateSound(player);
146+
}
139147

140148
if (PORTAL_MESSAGE_DISPLAY == 1) {
141149
player.sendMessage("");

src/main/java/com/sekwah/advancedportals/bukkit/listeners/Listeners.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ public void onWorldChangeEvent(PlayerChangedWorldEvent event) {
8080
Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
8181
}
8282

83+
@EventHandler
84+
public void onLeaveEvent(PlayerQuitEvent event) {
85+
Player player = event.getPlayer();
86+
if(player.hasMetadata("leaveDesti")) {
87+
Destination.warp(player, player.getMetadata("leaveDesti").get(0).asString(),
88+
false, true);
89+
}
90+
}
91+
8392
@EventHandler
8493
public void onJoinEvent(PlayerJoinEvent event) {
8594
Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
86-
/*
87-
* if (plugin.PlayerDestiMap.containsKey(event.getPlayer())) { String desti =
88-
* plugin.PlayerDestiMap.get(event.getPlayer());
89-
*
90-
* Destination.warp(event.getPlayer(), desti); }
91-
*/
9295
}
9396

9497
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag
3636

3737
if (msgPlayer != null) {
3838
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
39-
() -> Destination.warp(msgPlayer, targetDestination),
39+
() -> Destination.warp(msgPlayer, targetDestination, false, true),
4040
20L
4141
);
4242
}

src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import com.sekwah.advancedportals.bukkit.api.portaldata.PortalArg;
99
import com.sekwah.advancedportals.bukkit.destinations.Destination;
1010
import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
11+
import com.sekwah.advancedportals.bukkit.listeners.Listeners;
1112
import org.bukkit.*;
1213
import org.bukkit.configuration.ConfigurationSection;
1314
import org.bukkit.entity.Player;
15+
import org.bukkit.metadata.FixedMetadataValue;
1416
import org.bukkit.permissions.PermissionAttachment;
1517
import org.bukkit.util.Vector;
1618

@@ -441,7 +443,7 @@ public static boolean activate(Player player, AdvancedPortal portal) {
441443
int portalCooldown = 0; // default cooldowndelay when cooldowndelay is not specified
442444
try {
443445
portalCooldown = Integer.parseInt(portal.getArg("cooldowndelay"));
444-
} catch (Exception e) {
446+
} catch (Exception ignored) {
445447
}
446448
if (diff < portalCooldown) {
447449
int time = (portalCooldown - diff);
@@ -473,6 +475,13 @@ public static boolean activate(Player player, AdvancedPortal portal) {
473475
+ "\u00A7a.");
474476
}
475477

478+
if(portal.hasArg("leavedesti")) {
479+
player.setMetadata("leaveDesti", new FixedMetadataValue(plugin, portal.getArg("leavedesti")));
480+
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
481+
player.removeMetadata("leaveDesti", plugin);
482+
}, 20 * 10);
483+
}
484+
476485
if (portal.getDestiation() != null) {
477486
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
478487
outForList.writeUTF("PortalEnter");
@@ -487,6 +496,8 @@ public static boolean activate(Player player, AdvancedPortal portal) {
487496
outForSend.writeUTF("Connect");
488497
outForSend.writeUTF(bungeeServer);
489498

499+
500+
490501
portal.inPortal.add(player.getUniqueId());
491502
player.sendPluginMessage(plugin, "BungeeCord", outForSend.toByteArray());
492503
// Down to bungee to sort out the teleporting but yea theoretically they should

src/main/resources/bungee.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
main: com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin
22
name: AdvancedPortals
3-
version: 0.3.0
4-
author: sekwah41
3+
version: 0.4.0
4+
author: sekwah41

src/main/resources/plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
main: com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin
22
name: AdvancedPortals
3-
version: 0.3.0
3+
version: 0.4.0
44
author: sekwah41
55
description: An advanced portals plugin for bukkit.
66
api-version: 1.13

0 commit comments

Comments
 (0)