Optimizations

This commit is contained in:
mathiascode 2020-04-16 19:43:57 +03:00
parent a30bae3c3c
commit 0a3c44db89
8 changed files with 24 additions and 15 deletions

View File

@ -1,13 +1,13 @@
<?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:/C:/Users/default.DESKTOP-T6B8368/.m2/repository/com/puppycrawl/tools/checkstyle/8.19/checkstyle-8.19.jar!/sun_checks.xml" type="remote" description="maven-checkstyle-plugin configuration checkstyle">
<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="C:\Users\default.DESKTOP-T6B8368\Documents\Java\eclipse-workspace\.metadata\.plugins\org.eclipse.core.resources\.projects\commandspy\com.basistech.m2e.code.quality.checkstyleConfigurator\checkstyle-suppressions-checkstyle.xml"/>
<property name="checkstyle.header.file" value="C:\Users\default.DESKTOP-T6B8368\Documents\Java\eclipse-workspace\.metadata\.plugins\org.eclipse.core.resources\.projects\commandspy\com.basistech.m2e.code.quality.checkstyleConfigurator\checkstyle-header-checkstyle.txt"/>
<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/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>

0
.gitignore vendored Normal file → Executable file
View File

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
pom.xml Normal file → Executable file
View File

31
src/main/java/pw/kaboom/commandspy/Main.java Normal file → Executable file
View File

@ -1,11 +1,14 @@
package pw.kaboom.commandspy;
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;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -14,8 +17,11 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin implements CommandExecutor, Listener {
private FileConfiguration config;
@Override
public void onEnable() {
config = getConfig();
this.getCommand("commandspy").setExecutor(this);
this.getServer().getPluginManager().registerEvents(this, this);
}
@ -37,46 +43,49 @@ public final class Main extends JavaPlugin implements CommandExecutor, Listener
plugin.saveConfig();
player.sendMessage("Successfully enabled CommandSpy");
}
config = plugin.getConfig();
}
return true;
}
@EventHandler
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final Player commandRunner = event.getPlayer();
for (String uuidString : config.getKeys(false)) {
UUID uuid = UUID.fromString(uuidString);
for (Player messageTarget: Bukkit.getOnlinePlayers()) {
if (getConfig().contains(messageTarget.getUniqueId().toString())) {
if (Bukkit.getPlayer(uuid) != null) {
final Player commandRunner = event.getPlayer();
final ChatColor color;
if (getConfig().contains(commandRunner.getUniqueId().toString())) {
if (config.contains(commandRunner.getUniqueId().toString())) {
color = ChatColor.GREEN;
} else {
color = ChatColor.RED;
}
messageTarget.sendMessage(color + "" + commandRunner.getName() + "" + color + ": " + event.getMessage());
Bukkit.getPlayer(uuid).sendMessage(color + "" + commandRunner.getName() + "" + color + ": " + event.getMessage());
}
}
}
@EventHandler
void onSignChange(final SignChangeEvent event) {
final Player signPlacer = event.getPlayer();
for (String uuidString : config.getKeys(false)) {
UUID uuid = UUID.fromString(uuidString);
for (Player messageTarget: Bukkit.getOnlinePlayers()) {
if (getConfig().contains(messageTarget.getUniqueId().toString())) {
if (Bukkit.getPlayer(uuid) != null) {
final Player signPlacer = event.getPlayer();
final ChatColor color;
if (getConfig().contains(signPlacer.getUniqueId().toString())) {
if (config.contains(signPlacer.getUniqueId().toString())) {
color = ChatColor.GREEN;
} else {
color = ChatColor.RED;
}
messageTarget.sendMessage(color + "" + signPlacer.getName() + "" + color + " created a sign with contents:");
Bukkit.getPlayer(uuid).sendMessage(color + "" + signPlacer.getName() + "" + color + " created a sign with contents:");
for (String line: event.getLines()) {
messageTarget.sendMessage(color + " " + line);
Bukkit.getPlayer(uuid).sendMessage(color + " " + line);
}
}
}

0
src/main/resources/plugin.yml Normal file → Executable file
View File

0
suppressions.xml Normal file → Executable file
View File