Allow controller to chat as the target

Closes #2
This commit is contained in:
mathiascode 2020-12-13 18:39:52 +02:00
parent fa9104e9af
commit b3313b399b
3 changed files with 23 additions and 12 deletions

View File

@ -5,8 +5,8 @@
<version>master</version>
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.test.skip>true</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

View File

@ -104,16 +104,23 @@ class ControlPlayer implements Listener {
final Player player = event.getPlayer();
if (PlayerList.getController(player.getUniqueId()) != null) {
event.setCancelled(true);
}
if (event.getMessage().startsWith("§iControlUChat§")) {
final int prefixLength = "§iControlUChat§".length();
if (PlayerList.getTarget(player.getUniqueId()) != null) {
event.setMessage(
event.getMessage().substring(prefixLength)
);
} else {
event.setCancelled(true);
}
} else if (PlayerList.getTarget(player.getUniqueId()) != null) {
final Player target = PlayerList.getTarget(player.getUniqueId());
new BukkitRunnable() {
@Override
public void run() {
target.chat(event.getMessage());
target.chat("§iControlUChat§" + event.getMessage()); // Add prefix to prevent messages from being cancelled
}
}.runTask(JavaPlugin.getPlugin(Main.class));
@ -163,9 +170,8 @@ class ControlPlayer implements Listener {
if (PlayerList.getController(player.getUniqueId()) != null) {
event.setCancelled(true);
}
if ((event.getAction() == Action.LEFT_CLICK_AIR
} else if ((event.getAction() == Action.LEFT_CLICK_AIR
|| event.getAction() == Action.LEFT_CLICK_BLOCK)
&& PlayerList.getTarget(player.getUniqueId()) != null) {
final Player target = PlayerList.getTarget(player.getUniqueId());
@ -192,9 +198,11 @@ class ControlPlayer implements Listener {
final Player player = event.getPlayer();
for (Player otherPlayer: Bukkit.getOnlinePlayers()) {
/* Target disconnects */
if (PlayerList.getController(player.getUniqueId()) != null
&& PlayerList.getController(player.getUniqueId()).equals(otherPlayer)) {
/*
Target disconnects
*/
PlayerList.removeTarget(otherPlayer.getUniqueId());
PlayerList.removeController(player.getUniqueId());
@ -222,11 +230,12 @@ class ControlPlayer implements Listener {
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
otherPlayer.sendMessage("The player you were controlling has disconnected. You are invisible for 10 seconds.");
}
/* Controller disconnects */
if (PlayerList.getTarget(player.getUniqueId()) != null
} else if (PlayerList.getTarget(player.getUniqueId()) != null
&& PlayerList.getTarget(player.getUniqueId()).equals(otherPlayer)) {
/*
Controller disconnects
*/
PlayerList.removeTarget(player.getUniqueId());
PlayerList.removeController(otherPlayer.getUniqueId());
}

View File

@ -24,9 +24,11 @@ public final class CommandIcu implements CommandExecutor {
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " control <player>");
} else {
Player target = Bukkit.getPlayer(args[1]);
if (target == null && args[1].matches("([a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8})")) {
target = Bukkit.getPlayer(UUID.fromString(args[1]));
}
if (target != null) {
if (target == controller) {
controller.sendMessage("You are already controlling yourself");