mirror of
https://github.com/kaboomserver/icontrolu.git
synced 2024-11-28 10:25:33 -05:00
Enforce checkstyle
This commit is contained in:
parent
27c0caa435
commit
b6c804ae10
9 changed files with 184 additions and 101 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,2 +1,6 @@
|
|||
.gradle/
|
||||
.settings/
|
||||
bin/
|
||||
target/
|
||||
.checkstyle
|
||||
.classpath
|
||||
.project
|
||||
|
|
23
README.md
23
README.md
|
@ -1,3 +1,22 @@
|
|||
# icontrolu
|
||||
# iControlU
|
||||
|
||||
Source code for the iControlU plugin on the Kaboom server
|
||||
Weapons is a Bukkit plugin that allows players to control other players.
|
||||
|
||||
The plugin is created for the Kaboom server.
|
||||
|
||||
## Commands
|
||||
|
||||
| Command | Permission | Description |
|
||||
| ------- | ---------- | ----------- |
|
||||
|/icu | icu.command | Control another player's movements, inventory and chat|
|
||||
|
||||
## Compiling
|
||||
|
||||
Use [Maven](https://maven.apache.org/) to compile the plugin.
|
||||
```bash
|
||||
mvn package
|
||||
```
|
||||
The generated .jar file will be located in the target/ folder.
|
||||
|
||||
## License
|
||||
[Unlicense](https://unlicense.org/)
|
2
build.sh
2
build.sh
|
@ -1,2 +0,0 @@
|
|||
#!/bin/bash
|
||||
mvn package
|
30
pom.xml
30
pom.xml
|
@ -5,8 +5,10 @@
|
|||
<version>master</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.0</maven.compiler.source>
|
||||
<maven.compiler.target>1.0</maven.compiler.target>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -29,13 +31,23 @@
|
|||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:all</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>checkstyle</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<suppressionsLocation>
|
||||
suppressions.xml
|
||||
</suppressionsLocation>
|
||||
<failOnViolation>true</failOnViolation>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package pw.kaboom.icontrolu;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
@ -17,25 +15,20 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.bukkit.scoreboard.Team.Option;
|
||||
import org.bukkit.scoreboard.Team.OptionStatus;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import pw.kaboom.icontrolu.utilities.PlayerList;
|
||||
|
||||
class Tick extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player target: Bukkit.getOnlinePlayers()) {
|
||||
final Player controller = Main.controllerFor.get(target.getUniqueId());
|
||||
final Player controller = PlayerList.getController(target.getUniqueId());
|
||||
|
||||
if (controller != null) {
|
||||
for (int i = 0; i < controller.getInventory().getSize(); i++) {
|
||||
|
@ -52,11 +45,14 @@ class Tick extends BukkitRunnable {
|
|||
target.teleportAsync(controller.getLocation());
|
||||
}
|
||||
|
||||
AttributeInstance controllerMaxHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
AttributeInstance targetMaxHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
targetMaxHealth.setBaseValue(controllerMaxHealth.getBaseValue());
|
||||
|
||||
target.setAllowFlight(controller.getAllowFlight());
|
||||
target.setExhaustion(controller.getExhaustion());
|
||||
target.setFlying(controller.isFlying());
|
||||
target.setFoodLevel(controller.getFoodLevel());
|
||||
target.setMaxHealth(controller.getMaxHealth());
|
||||
target.setHealth(controller.getHealth());
|
||||
target.setLevel(controller.getLevel());
|
||||
target.setSneaking(controller.isSneaking());
|
||||
|
@ -73,20 +69,25 @@ class Tick extends BukkitRunnable {
|
|||
team = scoreboard.registerNewTeam("icuDisableCollision");
|
||||
}
|
||||
|
||||
team.setCanSeeFriendlyInvisibles(false);
|
||||
team.setCanSeeFriendlyInvisibles(false);
|
||||
team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
|
||||
|
||||
if (!team.hasEntry(controller.getName())) {
|
||||
team.addEntry(controller.getName());
|
||||
}
|
||||
|
||||
final int duration = 99999;
|
||||
final int amplifier = 0;
|
||||
final boolean ambient = false;
|
||||
final boolean particles = false;
|
||||
|
||||
controller.addPotionEffect(
|
||||
new PotionEffect(
|
||||
PotionEffectType.INVISIBILITY,
|
||||
99999,
|
||||
0,
|
||||
false,
|
||||
false
|
||||
duration,
|
||||
amplifier,
|
||||
ambient,
|
||||
particles
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -94,17 +95,17 @@ class Tick extends BukkitRunnable {
|
|||
}
|
||||
}
|
||||
|
||||
class Events implements Listener {
|
||||
class ControlPlayer implements Listener {
|
||||
@EventHandler
|
||||
void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||
private void onAsyncPlayerChat(final AsyncPlayerChatEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (Main.controllerFor.containsKey(player.getUniqueId())) {
|
||||
if (PlayerList.getController(player.getUniqueId()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (Main.targetFor.containsKey(player.getUniqueId())) {
|
||||
final Player target = Main.targetFor.get(player.getUniqueId());
|
||||
if (PlayerList.getTarget(player.getUniqueId()) != null) {
|
||||
final Player target = PlayerList.getTarget(player.getUniqueId());
|
||||
|
||||
target.chat(event.getMessage());
|
||||
event.setCancelled(true);
|
||||
|
@ -112,64 +113,66 @@ class Events implements Listener {
|
|||
}
|
||||
|
||||
@EventHandler
|
||||
void onEntityDamage(EntityDamageEvent event) {
|
||||
private void onEntityDamage(final EntityDamageEvent event) {
|
||||
final Entity player = event.getEntity();
|
||||
|
||||
if (Main.targetFor.containsKey(player.getUniqueId())) {
|
||||
if (PlayerList.getTarget(player.getUniqueId()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
private void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (Main.controllerFor.containsKey(player.getUniqueId())) {
|
||||
if (PlayerList.getController(player.getUniqueId()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
private void onPlayerDropItem(final PlayerDropItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (Main.controllerFor.containsKey(player.getUniqueId())) {
|
||||
if (PlayerList.getController(player.getUniqueId()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerInteract(PlayerInteractEvent event) {
|
||||
private void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (Main.controllerFor.containsKey(player.getUniqueId())) {
|
||||
if (PlayerList.getController(player.getUniqueId()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerMove(PlayerMoveEvent event) {
|
||||
private void onPlayerMove(final PlayerMoveEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (Main.controllerFor.containsKey(player.getUniqueId())) {
|
||||
if (PlayerList.getController(player.getUniqueId()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerQuit(PlayerQuitEvent event) {
|
||||
private void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
for (Player otherPlayer: Bukkit.getOnlinePlayers()) {
|
||||
/* Target disconnects */
|
||||
if (Main.controllerFor.containsKey(player.getUniqueId()) &&
|
||||
Main.controllerFor.get(player.getUniqueId()).equals(otherPlayer)) {
|
||||
Main.targetFor.remove(otherPlayer.getUniqueId());
|
||||
Main.controllerFor.remove(player.getUniqueId());
|
||||
if (PlayerList.getController(player.getUniqueId()) != null
|
||||
&& PlayerList.getController(player.getUniqueId()).equals(otherPlayer)) {
|
||||
PlayerList.removeTarget(otherPlayer.getUniqueId());
|
||||
PlayerList.removeController(player.getUniqueId());
|
||||
|
||||
final Player controller = otherPlayer;
|
||||
final int tickDelay = 200;
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player allPlayers: Bukkit.getOnlinePlayers()) {
|
||||
allPlayers.showPlayer(JavaPlugin.getPlugin(Main.class), controller);
|
||||
|
@ -178,34 +181,34 @@ class Events implements Listener {
|
|||
final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
final Team team = scoreboard.getTeam("icuDisableCollision");
|
||||
|
||||
if (team != null &&
|
||||
team.hasEntry(controller.getName()) == true) {
|
||||
if (team != null
|
||||
&& team.hasEntry(controller.getName())) {
|
||||
team.removeEntry(controller.getName());
|
||||
}
|
||||
|
||||
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
controller.sendMessage("You are now visible");
|
||||
}
|
||||
}.runTaskLater(JavaPlugin.getPlugin(Main.class), 200);
|
||||
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
|
||||
|
||||
otherPlayer.sendMessage("The player you were controlling has disconnected. You are invisible for 10 seconds.");
|
||||
}
|
||||
|
||||
/* Controller disconnects */
|
||||
if (Main.targetFor.containsKey(player.getUniqueId()) &&
|
||||
Main.targetFor.get(player.getUniqueId()).equals(otherPlayer)) {
|
||||
Main.targetFor.remove(player.getUniqueId());
|
||||
Main.controllerFor.remove(otherPlayer.getUniqueId());
|
||||
if (PlayerList.getTarget(player.getUniqueId()) != null
|
||||
&& PlayerList.getTarget(player.getUniqueId()).equals(otherPlayer)) {
|
||||
PlayerList.removeTarget(player.getUniqueId());
|
||||
PlayerList.removeController(otherPlayer.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
private void onPlayerRespawn(final PlayerRespawnEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (Main.controllerFor.containsKey(player.getUniqueId())) {
|
||||
final Player controller = Main.controllerFor.get(player.getUniqueId());
|
||||
if (PlayerList.getController(player.getUniqueId()) != null) {
|
||||
final Player controller = PlayerList.getController(player.getUniqueId());
|
||||
|
||||
controller.teleportAsync(player.getLocation());
|
||||
}
|
|
@ -1,23 +1,17 @@
|
|||
package pw.kaboom.icontrolu;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
static HashMap<UUID, Player> controllerFor = new HashMap<>();
|
||||
static HashMap<UUID, Player> targetFor = new HashMap<>();
|
||||
import pw.kaboom.icontrolu.commands.CommandIcu;
|
||||
import pw.kaboom.icontrolu.utilities.PlayerList;
|
||||
|
||||
public final class Main extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
/* Setup scoreboard team to prevent player collisions */
|
||||
final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
|
@ -30,12 +24,13 @@ public class Main extends JavaPlugin {
|
|||
this.getCommand("icu").setExecutor(new CommandIcu());
|
||||
|
||||
new Tick().runTaskTimer(this, 0, 1);
|
||||
this.getServer().getPluginManager().registerEvents(new Events(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ControlPlayer(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (Player controller: Bukkit.getOnlinePlayers()) {
|
||||
final Player target = Main.targetFor.get(controller.getUniqueId());
|
||||
final Player target = PlayerList.getTarget(controller.getUniqueId());
|
||||
|
||||
if (target != null) {
|
||||
for (Player player: Bukkit.getOnlinePlayers()) {
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
package pw.kaboom.icontrolu;
|
||||
package pw.kaboom.icontrolu.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
class CommandIcu implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
import pw.kaboom.icontrolu.Main;
|
||||
import pw.kaboom.icontrolu.utilities.PlayerList;
|
||||
|
||||
public final class CommandIcu implements CommandExecutor {
|
||||
@Override
|
||||
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");
|
||||
} else {
|
||||
|
@ -37,11 +35,11 @@ class CommandIcu implements CommandExecutor {
|
|||
if (target != null) {
|
||||
if (target == controller) {
|
||||
controller.sendMessage("You are already controlling yourself");
|
||||
} else if (Main.targetFor.containsKey(controller.getUniqueId())) {
|
||||
} else if (PlayerList.getTarget(controller.getUniqueId()) != null) {
|
||||
controller.sendMessage("You are already controlling \"" + target.getName() + "\"");
|
||||
} else if (Main.controllerFor.containsKey(target.getUniqueId())) {
|
||||
} else if (PlayerList.getController(target.getUniqueId()) != null) {
|
||||
controller.sendMessage("Player \"" + target.getName() + "\" is already being controlled");
|
||||
} else if (Main.targetFor.containsKey(target.getUniqueId())) {
|
||||
} else if (PlayerList.getTarget(target.getUniqueId()) != null) {
|
||||
controller.sendMessage("Player \"" + target.getName() + "\" is already controlling another player");
|
||||
} else if (!controller.canSee(target)) {
|
||||
controller.sendMessage("You may not control this player");
|
||||
|
@ -50,8 +48,8 @@ class CommandIcu implements CommandExecutor {
|
|||
|
||||
controller.getInventory().setContents(target.getInventory().getContents());
|
||||
|
||||
Main.targetFor.put(controller.getUniqueId(), target);
|
||||
Main.controllerFor.put(target.getUniqueId(), controller);
|
||||
PlayerList.setTarget(controller.getUniqueId(), target);
|
||||
PlayerList.setController(target.getUniqueId(), controller);
|
||||
|
||||
controller.sendMessage("You are now controlling \"" + target.getName() + "\"");
|
||||
}
|
||||
|
@ -60,13 +58,16 @@ class CommandIcu implements CommandExecutor {
|
|||
}
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||
final Player target = Main.targetFor.get(controller.getUniqueId());
|
||||
final Player target = PlayerList.getTarget(controller.getUniqueId());
|
||||
|
||||
if (target != null) {
|
||||
Main.targetFor.remove(controller.getUniqueId());
|
||||
Main.controllerFor.remove(target.getUniqueId());
|
||||
PlayerList.removeTarget(controller.getUniqueId());
|
||||
PlayerList.removeController(target.getUniqueId());
|
||||
|
||||
final int tickDelay = 200;
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player: Bukkit.getOnlinePlayers()) {
|
||||
player.showPlayer(JavaPlugin.getPlugin(Main.class), controller);
|
||||
|
@ -81,7 +82,7 @@ class CommandIcu implements CommandExecutor {
|
|||
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
controller.sendMessage("You are now visible");
|
||||
}
|
||||
}.runTaskLater(JavaPlugin.getPlugin(Main.class), 200);
|
||||
}.runTaskLater(JavaPlugin.getPlugin(Main.class), tickDelay);
|
||||
|
||||
controller.sendMessage("You are no longer controlling \"" + target.getName() + "\". You are invisible for 10 seconds.");
|
||||
} else {
|
38
src/main/java/pw/kaboom/icontrolu/utilities/PlayerList.java
Normal file
38
src/main/java/pw/kaboom/icontrolu/utilities/PlayerList.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package pw.kaboom.icontrolu.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class PlayerList {
|
||||
private PlayerList() {
|
||||
}
|
||||
|
||||
private static HashMap<UUID, Player> controllerFor = new HashMap<UUID, Player>();
|
||||
private static HashMap<UUID, Player> targetFor = new HashMap<UUID, Player>();
|
||||
|
||||
public static Player getController(final UUID playerUuid) {
|
||||
return controllerFor.get(playerUuid);
|
||||
}
|
||||
|
||||
public static Player getTarget(final UUID playerUuid) {
|
||||
return targetFor.get(playerUuid);
|
||||
}
|
||||
|
||||
public static void removeController(final UUID playerUuid) {
|
||||
controllerFor.remove(playerUuid);
|
||||
}
|
||||
|
||||
public static void removeTarget(final UUID playerUuid) {
|
||||
targetFor.remove(playerUuid);
|
||||
}
|
||||
|
||||
public static void setController(final UUID playerUuid, final Player player) {
|
||||
controllerFor.put(playerUuid, player);
|
||||
}
|
||||
|
||||
public static void setTarget(final UUID playerUuid, final Player player) {
|
||||
targetFor.put(playerUuid, player);
|
||||
}
|
||||
}
|
13
suppressions.xml
Normal file
13
suppressions.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE suppressions PUBLIC
|
||||
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
|
||||
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
|
||||
|
||||
<suppressions>
|
||||
<suppress checks="AvoidStarImport" files="."/>
|
||||
<suppress checks="FileTabCharacter" files="."/>
|
||||
<suppress checks="Javadoc" files="."/>
|
||||
<suppress checks="LineLength" files="."/>
|
||||
<suppress checks="NewlineAtEndOfFile" files="."/>
|
||||
</suppressions>
|
Loading…
Reference in a new issue