mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-01-27 10:31:34 +01:00
Fixed #187 as well as adds bungeecommand
This commit is contained in:
parent
36a75a2bd6
commit
dc8a301ff2
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,7 @@
|
||||
package com.sekwah.advancedportals.bukkit;
|
||||
|
||||
import static com.sekwah.advancedportals.bukkit.Settings.PortalConfigOption.*;
|
||||
|
||||
/**
|
||||
* This contains generally used settings mostly
|
||||
*/
|
||||
@ -11,12 +13,34 @@ public class Settings {
|
||||
|
||||
private String commandLevels = "n";
|
||||
|
||||
public enum PortalConfigOption {
|
||||
COMMAND_LEVELS("CommandLevels"),
|
||||
WARP_PARTICLES("WarpParticles"),
|
||||
WARP_SOUND("WarpSound");
|
||||
|
||||
private final String target;
|
||||
|
||||
PortalConfigOption(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return this.target;
|
||||
}
|
||||
}
|
||||
|
||||
public Settings(AdvancedPortalsPlugin plugin) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||
currentWarpParticles = config.getConfig().getInt("WarpParticles");
|
||||
currentWarpSound = config.getConfig().getInt("WarpSound");
|
||||
currentWarpParticles = config.getConfig().getInt(WARP_PARTICLES.value());
|
||||
currentWarpSound = config.getConfig().getInt(WARP_SOUND.value());
|
||||
|
||||
commandLevels = config.getConfig().getString("CommandLevels", "opchek");
|
||||
commandLevels = config.getConfig().getString(COMMAND_LEVELS.value(), "opcb");
|
||||
|
||||
assert commandLevels != null;
|
||||
if(commandLevels.equals("opchek")) {
|
||||
commandLevels = "opcb";
|
||||
config.getConfig().set(COMMAND_LEVELS.value(), "opcb");
|
||||
}
|
||||
if(commandLevels.contains("n") || commandLevels.equals("")) {
|
||||
commandLevels = "n";
|
||||
}
|
||||
@ -26,7 +50,7 @@ public class Settings {
|
||||
return this.commandLevels;
|
||||
}
|
||||
|
||||
public boolean hasCommandLevel(String level){
|
||||
public boolean enabledCommandLevel(String level){
|
||||
return this.commandLevels.contains(level);
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,11 @@ public class PluginMessageReceiver implements PluginMessageListener {
|
||||
String subchannel = in.readUTF();
|
||||
|
||||
if (subchannel.equals("BungeePortal")) {
|
||||
String targetPlayerUUID = in.readUTF();
|
||||
String targetDestination = in.readUTF();
|
||||
|
||||
Player msgPlayer = plugin.getServer().getPlayer(UUID.fromString(targetPlayerUUID));
|
||||
|
||||
if (msgPlayer != null) {
|
||||
if (player != null) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
() -> Destination.warp(msgPlayer, targetDestination, false, true),
|
||||
() -> Destination.warp(player, targetDestination, false, true),
|
||||
20L
|
||||
);
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ 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;
|
||||
@ -486,7 +485,6 @@ public class Portal {
|
||||
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
|
||||
outForList.writeUTF("PortalEnter");
|
||||
outForList.writeUTF(bungeeServer);
|
||||
outForList.writeUTF(player.getUniqueId().toString());
|
||||
outForList.writeUTF(portal.getDestiation());
|
||||
|
||||
player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray());
|
||||
@ -530,7 +528,7 @@ public class Portal {
|
||||
// (?i) makes the search case insensitive
|
||||
command = command.replaceAll("@player", player.getName());
|
||||
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
|
||||
if (command.startsWith("#") && plugin.getSettings().hasCommandLevel("c")) {
|
||||
if (command.startsWith("#") && plugin.getSettings().enabledCommandLevel("c")) {
|
||||
command = command.substring(1);
|
||||
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
|
||||
try {
|
||||
@ -538,7 +536,7 @@ public class Portal {
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("Error while executing: " + command);
|
||||
}
|
||||
} else if (command.startsWith("!") && plugin.getSettings().hasCommandLevel("o")) {
|
||||
} else if (command.startsWith("!") && plugin.getSettings().enabledCommandLevel("o")) {
|
||||
command = command.substring(1);
|
||||
boolean wasOp = player.isOp();
|
||||
try {
|
||||
@ -548,7 +546,7 @@ public class Portal {
|
||||
} finally {
|
||||
player.setOp(wasOp);
|
||||
}
|
||||
} else if (command.startsWith("^")) {
|
||||
} else if (command.startsWith("^") && plugin.getSettings().enabledCommandLevel("p")) {
|
||||
command = command.substring(1);
|
||||
PermissionAttachment permissionAttachment = null;
|
||||
try {
|
||||
@ -558,9 +556,16 @@ public class Portal {
|
||||
} finally {
|
||||
player.removeAttachment(permissionAttachment);
|
||||
}
|
||||
} else if (command.startsWith("%") && plugin.getSettings().enabledCommandLevel("b")) {
|
||||
command = command.substring(1);
|
||||
ByteArrayDataOutput outForList = ByteStreams.newDataOutput();
|
||||
outForList.writeUTF("BungeeCommand");
|
||||
outForList.writeUTF(player.getUniqueId().toString());
|
||||
outForList.writeUTF(command);
|
||||
player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray());
|
||||
} else {
|
||||
player.chat("/" + command);
|
||||
// player.performCommand(command);
|
||||
player.chat("/" + command);
|
||||
// player.performCommand(command);
|
||||
}
|
||||
command = portal.getArg("command." + ++commandLine);
|
||||
} while (command != null);
|
||||
|
@ -5,12 +5,13 @@ import com.sekwah.advancedportals.bungee.listener.PluginMessageReceiver;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AdvancedPortalsPlugin extends Plugin {
|
||||
|
||||
public String channelName = "mc:advancedportals";
|
||||
|
||||
public HashMap<String, String[]> PlayerDestiMap = new HashMap<>();
|
||||
public HashMap<UUID, String[]> PlayerDestiMap = new HashMap<>();
|
||||
// key: UUID (string)
|
||||
// value: [0] targetServer, [1] targetDestination
|
||||
|
||||
|
@ -7,6 +7,8 @@ import net.md_5.bungee.api.event.ServerSwitchEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class EventListener implements Listener {
|
||||
private AdvancedPortalsPlugin plugin;
|
||||
|
||||
@ -14,10 +16,11 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerSwitchServer(ServerSwitchEvent event) {
|
||||
String uuid = event.getPlayer().getUniqueId().toString();
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
|
||||
if (plugin.PlayerDestiMap.containsKey(uuid)) {
|
||||
String[] val = plugin.PlayerDestiMap.get(uuid);
|
||||
|
||||
// key: UUID (string)
|
||||
// value: [0] targetServer, [1] targetDestination
|
||||
|
||||
@ -26,7 +29,6 @@ public class EventListener implements Listener {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
out.writeUTF("BungeePortal");
|
||||
out.writeUTF(uuid);
|
||||
out.writeUTF(val[1]);
|
||||
|
||||
event.getPlayer().getServer().getInfo().sendData(plugin.channelName, out.toByteArray());
|
||||
|
@ -3,9 +3,13 @@ package com.sekwah.advancedportals.bungee.listener;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PluginMessageReceiver implements Listener {
|
||||
@ -22,16 +26,33 @@ public class PluginMessageReceiver implements Listener {
|
||||
|
||||
if (subChannel.equalsIgnoreCase("PortalEnter")) {
|
||||
String targetServer = in.readUTF();
|
||||
String targetPlayerUUID = in.readUTF();
|
||||
String targetDestination = in.readUTF();
|
||||
UUID uuid;
|
||||
|
||||
plugin.PlayerDestiMap.put(targetPlayerUUID, new String[]{targetServer, targetDestination});
|
||||
if ( event.getReceiver() instanceof ProxiedPlayer )
|
||||
{
|
||||
ProxiedPlayer receiver = (ProxiedPlayer) event.getReceiver();
|
||||
uuid = receiver.getUniqueId();
|
||||
}
|
||||
else {
|
||||
plugin.getLogger().warning("There has been an issue getting the player for the teleport request.");
|
||||
return;
|
||||
}
|
||||
plugin.PlayerDestiMap.put(uuid, new String[]{targetServer, targetDestination});
|
||||
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
if (plugin.PlayerDestiMap.containsKey(targetPlayerUUID)) {
|
||||
plugin.PlayerDestiMap.remove(targetPlayerUUID);
|
||||
}
|
||||
plugin.PlayerDestiMap.remove(uuid);
|
||||
}, 20, TimeUnit.SECONDS);
|
||||
}
|
||||
else if (subChannel.equalsIgnoreCase("BungeeCommand")) {
|
||||
String targetPlayerUUID = in.readUTF();
|
||||
String command = in.readUTF();
|
||||
ProxiedPlayer player = plugin.getProxy().getPlayer(UUID.fromString(targetPlayerUUID));
|
||||
if (player != null) {
|
||||
// To send command to server the player is currently on
|
||||
//player.chat("/" + command);
|
||||
plugin.getProxy().getPluginManager().dispatchCommand(player, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
main: com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin
|
||||
name: AdvancedPortals
|
||||
version: 0.4.0
|
||||
version: 0.5.0
|
||||
author: sekwah41
|
||||
|
@ -73,18 +73,12 @@ ThrowbackAmount: 0.7 # How fast to throw them back, 0 or lower to disable throwb
|
||||
# We have no plans to further this but if anyone has any tips feel free to contact us here https://discord.gg/25QZVVn
|
||||
DisableGatewayBeam: false
|
||||
|
||||
# Letters are flags. Include them to activate. n always disables everything, remove if you want it to work.
|
||||
# Lettering may not make too much sense but meh its useful. Examples are "ocpk" or "cop" (doesnt matter order)
|
||||
#
|
||||
# Remember enabling this means potentially admins could leave a portal lying around which could let them reop themselves.
|
||||
# If you think this may be an issue use a permission plugin and specifically give the users you trust permissions.
|
||||
# Enable or disable special command portals
|
||||
#
|
||||
# n Disabled none, best just put this to really make sure the fact none are here is specified. It disables any others too
|
||||
# o Admin Heighten Enabled Permission advancedportals.createportal.commandlevel.op
|
||||
# p Perm Heighten Enabled Permission advancedportals.createportal.commandlevel.perms
|
||||
# c Console Heighten Enabled Permission advancedportals.createportal.commandlevel.console
|
||||
# h Ops can create admin commands without special perms
|
||||
# e Ops can create all perm commands without special perms
|
||||
# k Ops can create console commands without special perms
|
||||
# o enable op command portals
|
||||
# p enable permission command portals
|
||||
# c enable console command portals
|
||||
# b enable bungee command portals
|
||||
#
|
||||
CommandLevels: opchek
|
||||
CommandLevels: opcb
|
||||
|
@ -1,6 +1,6 @@
|
||||
main: com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin
|
||||
name: AdvancedPortals
|
||||
version: 0.4.0
|
||||
version: 0.5.0
|
||||
author: sekwah41
|
||||
description: An advanced portals plugin for bukkit.
|
||||
api-version: 1.13
|
||||
@ -30,14 +30,18 @@ permissions:
|
||||
default: false
|
||||
children:
|
||||
advancedportals.createportal.commandlevel.op: true
|
||||
advancedportals.createportal.commandlevel.bungee: true
|
||||
advancedportals.createportal.commandlevel.perms: true
|
||||
advancedportals.createportal.commandlevel.console: true
|
||||
advancedportals.createportal.commandlevel.op:
|
||||
description: Allows you to increase the users level temporaily to op
|
||||
description: Allows you to run portal commands as op
|
||||
default: false
|
||||
advancedportals.createportal.commandlevel.perms:
|
||||
description: Allows you to increase the users level temporaily to have all perms
|
||||
description: Allows you to run portal commands with * permission
|
||||
default: false
|
||||
advancedportals.createportal.commandlevel.bungee:
|
||||
description: Allows you to run portal commands through bungee
|
||||
default: false
|
||||
advancedportals.createportal.commandlevel.console:
|
||||
description: Executes command in the console
|
||||
default: false
|
||||
|
Loading…
Reference in New Issue
Block a user