mirror of
https://github.com/kaboomserver/icontrolu.git
synced 2024-11-24 08:27:57 -05:00
Update Paper API & Use adventure for messages (#9)
* Update Paper API & Use adventure for messages * Compile with Java 17 i almost forgor * Remove the unused `ChatColor` import (which i probably should have removed before) * oops i messed up the usage
This commit is contained in:
parent
c18d750bf8
commit
b80b443de3
5 changed files with 62 additions and 28 deletions
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
|
@ -15,7 +15,7 @@ jobs:
|
|||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 8
|
||||
java-version: 17
|
||||
|
||||
- name: Cache maven packages to speed up build
|
||||
uses: actions/cache@v1
|
||||
|
|
9
pom.xml
9
pom.xml
|
@ -5,17 +5,18 @@
|
|||
<version>master</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import pw.kaboom.icontrolu.utilities.PlayerList;
|
||||
|
||||
class Tick extends BukkitRunnable {
|
||||
|
@ -228,12 +230,12 @@ class ControlPlayer implements Listener {
|
|||
}
|
||||
|
||||
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
controller.sendMessage("You are now visible");
|
||||
controller.sendMessage(Component.text("You are now visible"));
|
||||
}
|
||||
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
|
||||
|
||||
otherPlayer.sendMessage("The player you were controlling has disconnected. "
|
||||
+ "You are invisible for 10 seconds.");
|
||||
otherPlayer.sendMessage(Component.text("The player you were controlling has "
|
||||
+ "disconnected. You are invisible for 10 seconds."));
|
||||
|
||||
} else if (PlayerList.getTarget(player.getUniqueId()) != null
|
||||
&& PlayerList.getTarget(player.getUniqueId()).equals(otherPlayer)) {
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.bukkit.potion.PotionEffectType;
|
|||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import pw.kaboom.icontrolu.commands.CommandIcu;
|
||||
import pw.kaboom.icontrolu.utilities.PlayerList;
|
||||
|
||||
|
@ -45,8 +47,11 @@ public final class Main extends JavaPlugin {
|
|||
}
|
||||
|
||||
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
controller.sendMessage("You are no longer controlling \"" + target.getName()
|
||||
+ "\" due to server reload");
|
||||
controller.sendMessage(
|
||||
Component.text("You are no longer controlling \"")
|
||||
.append(Component.text(target.getName()))
|
||||
.append(Component.text("\" due to server reload"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package pw.kaboom.icontrolu.commands;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -15,13 +14,17 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import pw.kaboom.icontrolu.Main;
|
||||
import pw.kaboom.icontrolu.utilities.PlayerList;
|
||||
|
||||
public final class CommandIcu implements CommandExecutor {
|
||||
private void controlCommand(final Player controller, final String label, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " control <player>");
|
||||
controller.sendMessage(Component
|
||||
.text("Usage: /" + label + " control <player>", NamedTextColor.RED));
|
||||
} else {
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
|
||||
|
@ -31,18 +34,27 @@ public final class CommandIcu implements CommandExecutor {
|
|||
|
||||
if (target != null) {
|
||||
if (target == controller) {
|
||||
controller.sendMessage("You are already controlling yourself");
|
||||
controller.sendMessage(Component.text("You are already controlling yourself"));
|
||||
} else if (PlayerList.getTarget(controller.getUniqueId()) != null) {
|
||||
controller.sendMessage("You are already controlling \""
|
||||
+ target.getName() + "\"");
|
||||
controller.sendMessage(
|
||||
Component.text("You are already controlling \"")
|
||||
.append(Component.text(target.getName()))
|
||||
.append(Component.text("\""))
|
||||
);
|
||||
} else if (PlayerList.getController(target.getUniqueId()) != null) {
|
||||
controller.sendMessage("Player \"" + target.getName()
|
||||
+ "\" is already being controlled");
|
||||
controller.sendMessage(
|
||||
Component.text("Player \"")
|
||||
.append(Component.text(target.getName()))
|
||||
.append(Component.text("\" is already being controlled"))
|
||||
);
|
||||
} else if (PlayerList.getTarget(target.getUniqueId()) != null) {
|
||||
controller.sendMessage("Player \"" + target.getName()
|
||||
+ "\" is already controlling another player");
|
||||
controller.sendMessage(
|
||||
Component.text("Player \"")
|
||||
.append(Component.text(target.getName()))
|
||||
.append(Component.text("\" is already controlling another player"))
|
||||
);
|
||||
} else if (!controller.canSee(target)) {
|
||||
controller.sendMessage("You may not control this player");
|
||||
controller.sendMessage(Component.text("You may not control this player"));
|
||||
} else {
|
||||
controller.teleportAsync(target.getLocation());
|
||||
|
||||
|
@ -51,10 +63,18 @@ public final class CommandIcu implements CommandExecutor {
|
|||
PlayerList.setTarget(controller.getUniqueId(), target);
|
||||
PlayerList.setController(target.getUniqueId(), controller);
|
||||
|
||||
controller.sendMessage("You are now controlling \"" + target.getName() + "\"");
|
||||
controller.sendMessage(
|
||||
Component.text("You are now controlling \"")
|
||||
.append(Component.text(target.getName()))
|
||||
.append(Component.text("\""))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
controller.sendMessage("Player \"" + args[1] + "\" not found");
|
||||
controller.sendMessage(
|
||||
Component.text("Player \"")
|
||||
.append(Component.text(args[1]))
|
||||
.append(Component.text("\" not found"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,16 +102,21 @@ public final class CommandIcu implements CommandExecutor {
|
|||
}
|
||||
|
||||
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
controller.sendMessage("You are now visible");
|
||||
controller.sendMessage(Component.text("You are now visible"));
|
||||
}
|
||||
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
|
||||
|
||||
final int seconds = tickDelay / 20;
|
||||
|
||||
controller.sendMessage("You are no longer controlling \"" + target.getName()
|
||||
+ "\". You are invisible for " + seconds + " seconds.");
|
||||
controller.sendMessage(
|
||||
Component.text("You are no longer controlling \"")
|
||||
.append(Component.text(target.getName()))
|
||||
.append(Component.text("\". You are invisible for "))
|
||||
.append(Component.text(seconds))
|
||||
.append(Component.text(" seconds."))
|
||||
);
|
||||
} else {
|
||||
controller.sendMessage("You are not controlling anyone at the moment");
|
||||
controller.sendMessage(Component.text("You are not controlling anyone at the moment"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,14 +124,15 @@ public final class CommandIcu implements CommandExecutor {
|
|||
public boolean onCommand(final CommandSender sender, final Command command, final String label,
|
||||
final String[] args) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage("Command has to be run by a player");
|
||||
sender.sendMessage(Component.text("Command has to be run by a player"));
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player controller = (Player) sender;
|
||||
|
||||
if (args.length == 0) {
|
||||
controller.sendMessage(ChatColor.RED + "Usage: /" + label + " <control|stop>");
|
||||
controller.sendMessage(Component
|
||||
.text("Usage: /" + label + " <control|stop>", NamedTextColor.RED));
|
||||
} else if (args[0].equalsIgnoreCase("control")) {
|
||||
controlCommand(controller, label, args);
|
||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||
|
|
Loading…
Reference in a new issue