Skip to content

Commit dc8a301

Browse files
author
Sekwah
committed
Fixed #187 as well as adds bungeecommand
1 parent 36a75a2 commit dc8a301

File tree

10 files changed

+593
-540
lines changed

10 files changed

+593
-540
lines changed

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

+504-499
Large diffs are not rendered by default.

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

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.sekwah.advancedportals.bukkit;
22

3+
import static com.sekwah.advancedportals.bukkit.Settings.PortalConfigOption.*;
4+
35
/**
46
* This contains generally used settings mostly
57
*/
@@ -11,12 +13,34 @@ public class Settings {
1113

1214
private String commandLevels = "n";
1315

16+
public enum PortalConfigOption {
17+
COMMAND_LEVELS("CommandLevels"),
18+
WARP_PARTICLES("WarpParticles"),
19+
WARP_SOUND("WarpSound");
20+
21+
private final String target;
22+
23+
PortalConfigOption(String target) {
24+
this.target = target;
25+
}
26+
27+
public String value() {
28+
return this.target;
29+
}
30+
}
31+
1432
public Settings(AdvancedPortalsPlugin plugin) {
1533
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
16-
currentWarpParticles = config.getConfig().getInt("WarpParticles");
17-
currentWarpSound = config.getConfig().getInt("WarpSound");
34+
currentWarpParticles = config.getConfig().getInt(WARP_PARTICLES.value());
35+
currentWarpSound = config.getConfig().getInt(WARP_SOUND.value());
1836

19-
commandLevels = config.getConfig().getString("CommandLevels", "opchek");
37+
commandLevels = config.getConfig().getString(COMMAND_LEVELS.value(), "opcb");
38+
39+
assert commandLevels != null;
40+
if(commandLevels.equals("opchek")) {
41+
commandLevels = "opcb";
42+
config.getConfig().set(COMMAND_LEVELS.value(), "opcb");
43+
}
2044
if(commandLevels.contains("n") || commandLevels.equals("")) {
2145
commandLevels = "n";
2246
}
@@ -26,7 +50,7 @@ public String getCommandLevels(){
2650
return this.commandLevels;
2751
}
2852

29-
public boolean hasCommandLevel(String level){
53+
public boolean enabledCommandLevel(String level){
3054
return this.commandLevels.contains(level);
3155
}
3256

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag
2929
String subchannel = in.readUTF();
3030

3131
if (subchannel.equals("BungeePortal")) {
32-
String targetPlayerUUID = in.readUTF();
3332
String targetDestination = in.readUTF();
3433

35-
Player msgPlayer = plugin.getServer().getPlayer(UUID.fromString(targetPlayerUUID));
36-
37-
if (msgPlayer != null) {
34+
if (player != null) {
3835
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
39-
() -> Destination.warp(msgPlayer, targetDestination, false, true),
36+
() -> Destination.warp(player, targetDestination, false, true),
4037
20L
4138
);
4239
}

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
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;
1211
import org.bukkit.*;
1312
import org.bukkit.configuration.ConfigurationSection;
1413
import org.bukkit.entity.Player;
@@ -486,7 +485,6 @@ public static boolean activate(Player player, AdvancedPortal portal) {
486485
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
487486
outForList.writeUTF("PortalEnter");
488487
outForList.writeUTF(bungeeServer);
489-
outForList.writeUTF(player.getUniqueId().toString());
490488
outForList.writeUTF(portal.getDestiation());
491489

492490
player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray());
@@ -530,15 +528,15 @@ public static boolean activate(Player player, AdvancedPortal portal) {
530528
// (?i) makes the search case insensitive
531529
command = command.replaceAll("@player", player.getName());
532530
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
533-
if (command.startsWith("#") && plugin.getSettings().hasCommandLevel("c")) {
531+
if (command.startsWith("#") && plugin.getSettings().enabledCommandLevel("c")) {
534532
command = command.substring(1);
535533
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
536534
try {
537535
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
538536
} catch (Exception e) {
539537
plugin.getLogger().warning("Error while executing: " + command);
540538
}
541-
} else if (command.startsWith("!") && plugin.getSettings().hasCommandLevel("o")) {
539+
} else if (command.startsWith("!") && plugin.getSettings().enabledCommandLevel("o")) {
542540
command = command.substring(1);
543541
boolean wasOp = player.isOp();
544542
try {
@@ -548,7 +546,7 @@ public static boolean activate(Player player, AdvancedPortal portal) {
548546
} finally {
549547
player.setOp(wasOp);
550548
}
551-
} else if (command.startsWith("^")) {
549+
} else if (command.startsWith("^") && plugin.getSettings().enabledCommandLevel("p")) {
552550
command = command.substring(1);
553551
PermissionAttachment permissionAttachment = null;
554552
try {
@@ -558,9 +556,16 @@ public static boolean activate(Player player, AdvancedPortal portal) {
558556
} finally {
559557
player.removeAttachment(permissionAttachment);
560558
}
559+
} else if (command.startsWith("%") && plugin.getSettings().enabledCommandLevel("b")) {
560+
command = command.substring(1);
561+
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
562+
outForList.writeUTF("BungeeCommand");
563+
outForList.writeUTF(player.getUniqueId().toString());
564+
outForList.writeUTF(command);
565+
player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray());
561566
} else {
562-
player.chat("/" + command);
563-
// player.performCommand(command);
567+
player.chat("/" + command);
568+
// player.performCommand(command);
564569
}
565570
command = portal.getArg("command." + ++commandLine);
566571
} while (command != null);

src/main/java/com/sekwah/advancedportals/bungee/AdvancedPortalsPlugin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import net.md_5.bungee.api.plugin.Plugin;
66

77
import java.util.HashMap;
8+
import java.util.UUID;
89

910
public class AdvancedPortalsPlugin extends Plugin {
1011

1112
public String channelName = "mc:advancedportals";
1213

13-
public HashMap<String, String[]> PlayerDestiMap = new HashMap<>();
14+
public HashMap<UUID, String[]> PlayerDestiMap = new HashMap<>();
1415
// key: UUID (string)
1516
// value: [0] targetServer, [1] targetDestination
1617

src/main/java/com/sekwah/advancedportals/bungee/listener/EventListener.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
import net.md_5.bungee.api.plugin.Listener;
88
import net.md_5.bungee.event.EventHandler;
99

10+
import java.util.UUID;
11+
1012
public class EventListener implements Listener {
1113
private AdvancedPortalsPlugin plugin;
1214

1315
public EventListener(AdvancedPortalsPlugin plugin) { this.plugin = plugin; }
1416

1517
@EventHandler
1618
public void onPlayerSwitchServer(ServerSwitchEvent event) {
17-
String uuid = event.getPlayer().getUniqueId().toString();
19+
UUID uuid = event.getPlayer().getUniqueId();
1820

1921
if (plugin.PlayerDestiMap.containsKey(uuid)) {
2022
String[] val = plugin.PlayerDestiMap.get(uuid);
23+
2124
// key: UUID (string)
2225
// value: [0] targetServer, [1] targetDestination
2326

@@ -26,7 +29,6 @@ public void onPlayerSwitchServer(ServerSwitchEvent event) {
2629
ByteArrayDataOutput out = ByteStreams.newDataOutput();
2730

2831
out.writeUTF("BungeePortal");
29-
out.writeUTF(uuid);
3032
out.writeUTF(val[1]);
3133

3234
event.getPlayer().getServer().getInfo().sendData(plugin.channelName, out.toByteArray());

src/main/java/com/sekwah/advancedportals/bungee/listener/PluginMessageReceiver.java

+27-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import com.google.common.io.ByteArrayDataInput;
44
import com.google.common.io.ByteStreams;
55
import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin;
6+
import net.md_5.bungee.api.connection.ProxiedPlayer;
7+
import net.md_5.bungee.api.connection.Server;
68
import net.md_5.bungee.api.event.PluginMessageEvent;
79
import net.md_5.bungee.api.plugin.Listener;
810
import net.md_5.bungee.event.EventHandler;
11+
12+
import java.util.UUID;
913
import java.util.concurrent.TimeUnit;
1014

1115
public class PluginMessageReceiver implements Listener {
@@ -22,16 +26,33 @@ public void onMessageReceived(PluginMessageEvent event) {
2226

2327
if (subChannel.equalsIgnoreCase("PortalEnter")) {
2428
String targetServer = in.readUTF();
25-
String targetPlayerUUID = in.readUTF();
2629
String targetDestination = in.readUTF();
27-
28-
plugin.PlayerDestiMap.put(targetPlayerUUID, new String[]{targetServer, targetDestination});
30+
UUID uuid;
31+
32+
if ( event.getReceiver() instanceof ProxiedPlayer )
33+
{
34+
ProxiedPlayer receiver = (ProxiedPlayer) event.getReceiver();
35+
uuid = receiver.getUniqueId();
36+
}
37+
else {
38+
plugin.getLogger().warning("There has been an issue getting the player for the teleport request.");
39+
return;
40+
}
41+
plugin.PlayerDestiMap.put(uuid, new String[]{targetServer, targetDestination});
2942

3043
plugin.getProxy().getScheduler().schedule(plugin, () -> {
31-
if (plugin.PlayerDestiMap.containsKey(targetPlayerUUID)) {
32-
plugin.PlayerDestiMap.remove(targetPlayerUUID);
33-
}
44+
plugin.PlayerDestiMap.remove(uuid);
3445
}, 20, TimeUnit.SECONDS);
3546
}
47+
else if (subChannel.equalsIgnoreCase("BungeeCommand")) {
48+
String targetPlayerUUID = in.readUTF();
49+
String command = in.readUTF();
50+
ProxiedPlayer player = plugin.getProxy().getPlayer(UUID.fromString(targetPlayerUUID));
51+
if (player != null) {
52+
// To send command to server the player is currently on
53+
//player.chat("/" + command);
54+
plugin.getProxy().getPluginManager().dispatchCommand(player, command);
55+
}
56+
}
3657
}
3758
}

src/main/resources/bungee.yml

+1-1
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.4.0
3+
version: 0.5.0
44
author: sekwah41

src/main/resources/config.yml

+6-12
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,12 @@ ThrowbackAmount: 0.7 # How fast to throw them back, 0 or lower to disable throwb
7373
# We have no plans to further this but if anyone has any tips feel free to contact us here https://discord.gg/25QZVVn
7474
DisableGatewayBeam: false
7575

76-
# Letters are flags. Include them to activate. n always disables everything, remove if you want it to work.
77-
# Lettering may not make too much sense but meh its useful. Examples are "ocpk" or "cop" (doesnt matter order)
78-
#
79-
# Remember enabling this means potentially admins could leave a portal lying around which could let them reop themselves.
80-
# If you think this may be an issue use a permission plugin and specifically give the users you trust permissions.
76+
# Enable or disable special command portals
8177
#
8278
# n Disabled none, best just put this to really make sure the fact none are here is specified. It disables any others too
83-
# o Admin Heighten Enabled Permission advancedportals.createportal.commandlevel.op
84-
# p Perm Heighten Enabled Permission advancedportals.createportal.commandlevel.perms
85-
# c Console Heighten Enabled Permission advancedportals.createportal.commandlevel.console
86-
# h Ops can create admin commands without special perms
87-
# e Ops can create all perm commands without special perms
88-
# k Ops can create console commands without special perms
79+
# o enable op command portals
80+
# p enable permission command portals
81+
# c enable console command portals
82+
# b enable bungee command portals
8983
#
90-
CommandLevels: opchek
84+
CommandLevels: opcb

src/main/resources/plugin.yml

+7-3
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.4.0
3+
version: 0.5.0
44
author: sekwah41
55
description: An advanced portals plugin for bukkit.
66
api-version: 1.13
@@ -30,14 +30,18 @@ permissions:
3030
default: false
3131
children:
3232
advancedportals.createportal.commandlevel.op: true
33+
advancedportals.createportal.commandlevel.bungee: true
3334
advancedportals.createportal.commandlevel.perms: true
3435
advancedportals.createportal.commandlevel.console: true
3536
advancedportals.createportal.commandlevel.op:
36-
description: Allows you to increase the users level temporaily to op
37+
description: Allows you to run portal commands as op
3738
default: false
3839
advancedportals.createportal.commandlevel.perms:
39-
description: Allows you to increase the users level temporaily to have all perms
40+
description: Allows you to run portal commands with * permission
4041
default: false
42+
advancedportals.createportal.commandlevel.bungee:
43+
description: Allows you to run portal commands through bungee
44+
default: false
4145
advancedportals.createportal.commandlevel.console:
4246
description: Executes command in the console
4347
default: false

0 commit comments

Comments
 (0)