Compare commits

...

5 commits

Author SHA1 Message Date
kaboom 21e3c43b14 Remove unnecessary .checkstyle file 2022-05-20 05:18:28 +03:00
kaboom 2c43271355 Set maximum line length to 100 characters 2022-05-20 05:15:47 +03:00
kaboom 7762bd56f5 Use spaces instead of tabs 2022-05-20 05:10:07 +03:00
kaboom 849895747e Remove 'NewlineAtEndOfFile' checkstyle suppression 2022-05-20 04:34:30 +03:00
kaboom d90ebc4393 Update maven-checkstyle-plugin to 3.1.2 2022-05-20 04:34:30 +03:00
5 changed files with 141 additions and 147 deletions

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
<local-check-config name="maven-checkstyle-plugin checkstyle" location="jar:file:/home/default/.m2/repository/com/puppycrawl/tools/checkstyle/8.19/checkstyle-8.19.jar!/sun_checks.xml" type="remote" description="maven-checkstyle-plugin configuration checkstyle">
<property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/>
<property name="checkstyle.suppressions.file" value="/home/default/Documents/Java/.metadata/.plugins/org.eclipse.core.resources/.projects/commandspy/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-suppressions-checkstyle.xml"/>
<property name="checkstyle.header.file" value="/home/default/Documents/Java/.metadata/.plugins/org.eclipse.core.resources/.projects/commandspy/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-checkstyle.txt"/>
</local-check-config>
<fileset name="java-sources-checkstyle" enabled="true" check-config-name="maven-checkstyle-plugin checkstyle" local="true">
<file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/>
<file-match-pattern match-pattern="^src/main/resources/.*\.properties" include-pattern="true"/>
<file-match-pattern match-pattern="^src/test/resources.*\.properties" include-pattern="true"/>
</fileset>
</fileset-config>

10
checkstyle.xml Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="LineLength">
<property name="max" value="100"/>
</module>
</module>

95
pom.xml
View file

@ -1,55 +1,54 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pw.kaboom</groupId>
<artifactId>CommandSpy</artifactId>
<version>master</version>
<modelVersion>4.0.0</modelVersion>
<groupId>pw.kaboom</groupId>
<artifactId>CommandSpy</artifactId>
<version>master</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.test.skip>true</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</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>
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<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>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<suppressionsLocation>suppressions.xml</suppressionsLocation>
<failOnViolation>true</failOnViolation>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -19,94 +19,97 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin implements CommandExecutor, Listener {
private FileConfiguration config;
private FileConfiguration config;
@Override
public void onEnable() {
config = getConfig();
this.getCommand("commandspy").setExecutor(this);
this.getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onEnable() {
config = getConfig();
this.getCommand("commandspy").setExecutor(this);
this.getServer().getPluginManager().registerEvents(this, this);
}
private void enableCommandSpy(final Player player, final Plugin plugin) {
plugin.getConfig().set(player.getUniqueId().toString(), true);
plugin.saveConfig();
player.sendMessage("Successfully enabled CommandSpy");
}
private void enableCommandSpy(final Player player, final Plugin plugin) {
plugin.getConfig().set(player.getUniqueId().toString(), true);
plugin.saveConfig();
player.sendMessage("Successfully enabled CommandSpy");
}
private void disableCommandSpy(final Player player, final Plugin plugin) {
plugin.getConfig().set(player.getUniqueId().toString(), null);
plugin.saveConfig();
player.sendMessage("Successfully disabled CommandSpy");
}
private void disableCommandSpy(final Player player, final Plugin plugin) {
plugin.getConfig().set(player.getUniqueId().toString(), null);
plugin.saveConfig();
player.sendMessage("Successfully disabled CommandSpy");
}
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("Command has to be run by a player");
return true;
}
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String label,
final String[] args) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("Command has to be run by a player");
return true;
}
final Player player = (Player) sender;
final JavaPlugin plugin = JavaPlugin.getPlugin(Main.class);
final Player player = (Player) sender;
final JavaPlugin plugin = JavaPlugin.getPlugin(Main.class);
if (args.length == 0) {
if (config.contains(player.getUniqueId().toString())) {
disableCommandSpy(player, plugin);
} else {
enableCommandSpy(player, plugin);
}
} else if ("on".equalsIgnoreCase(args[0])) {
enableCommandSpy(player, plugin);
} else if ("off".equalsIgnoreCase(args[0])) {
disableCommandSpy(player, plugin);
}
config = plugin.getConfig();
return true;
}
if (args.length == 0) {
if (config.contains(player.getUniqueId().toString())) {
disableCommandSpy(player, plugin);
} else {
enableCommandSpy(player, plugin);
}
} else if ("on".equalsIgnoreCase(args[0])) {
enableCommandSpy(player, plugin);
} else if ("off".equalsIgnoreCase(args[0])) {
disableCommandSpy(player, plugin);
}
config = plugin.getConfig();
return true;
}
@EventHandler
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
if (event.isCancelled()) {
return;
}
@EventHandler
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
if (event.isCancelled()) {
return;
}
Set<String> uuids = config.getKeys(false);
ChatColor color = (uuids.contains(event.getPlayer().getUniqueId().toString())) ? ChatColor.YELLOW : ChatColor.AQUA;
Set<String> uuids = config.getKeys(false);
ChatColor color = (uuids.contains(event.getPlayer().getUniqueId().toString()))
? ChatColor.YELLOW : ChatColor.AQUA;
for (String uuidString : uuids) {
UUID uuid = UUID.fromString(uuidString);
for (String uuidString : uuids) {
UUID uuid = UUID.fromString(uuidString);
if (Bukkit.getPlayer(uuid) != null) {
Bukkit.getPlayer(uuid).sendMessage(
color + ""
+ event.getPlayer().getName() + ""
+ color + ": "
+ event.getMessage()
);
}
}
}
if (Bukkit.getPlayer(uuid) != null) {
Bukkit.getPlayer(uuid).sendMessage(
color + ""
+ event.getPlayer().getName() + ""
+ color + ": "
+ event.getMessage()
);
}
}
}
@EventHandler
void onSignChange(final SignChangeEvent event) {
Set<String> uuids = config.getKeys(false);
ChatColor color = (uuids.contains(event.getPlayer().getUniqueId().toString())) ? ChatColor.YELLOW : ChatColor.AQUA;
@EventHandler
void onSignChange(final SignChangeEvent event) {
Set<String> uuids = config.getKeys(false);
ChatColor color = (uuids.contains(event.getPlayer().getUniqueId().toString()))
? ChatColor.YELLOW : ChatColor.AQUA;
for (String uuidString : uuids) {
UUID uuid = UUID.fromString(uuidString);
for (String uuidString : uuids) {
UUID uuid = UUID.fromString(uuidString);
if (Bukkit.getPlayer(uuid) != null) {
Bukkit.getPlayer(uuid).sendMessage(
color + ""
+ event.getPlayer().getName() + ""
+ color
+ " created a sign with contents:"
);
for (String line: event.getLines()) {
Bukkit.getPlayer(uuid).sendMessage(color + " " + line);
}
}
}
}
if (Bukkit.getPlayer(uuid) != null) {
Bukkit.getPlayer(uuid).sendMessage(
color + ""
+ event.getPlayer().getName() + ""
+ color
+ " created a sign with contents:"
);
for (String line: event.getLines()) {
Bukkit.getPlayer(uuid).sendMessage(color + " " + line);
}
}
}
}
}

View file

@ -1,12 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="FileTabCharacter" files="."/>
<suppress checks="Javadoc" files="."/>
<suppress checks="LineLength" files="."/>
<suppress checks="NewlineAtEndOfFile" files="."/>
</suppressions>
<suppress checks="Javadoc" files="."/>
</suppressions>