Fix style errors in command code

This commit is contained in:
mathiascode 2019-12-21 15:39:31 +02:00
parent 1d9f62f556
commit 164f6b5524
19 changed files with 108 additions and 120 deletions

2
.gitignore vendored
View file

@ -1,6 +1,8 @@
.idea/
.settings/
bin/
target/
.checkstyle
.classpath
.project
*.iml

12
pom.xml
View file

@ -5,8 +5,8 @@
<version>master</version>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<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>
@ -49,6 +49,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -9,10 +9,12 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandClearChat implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandClearChat implements CommandExecutor {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
final int maxMessages = 100;
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < maxMessages; ++i) {
onlinePlayer.sendMessage("");
}
onlinePlayer.sendMessage(ChatColor.DARK_GREEN + "The chat has been cleared");

View file

@ -7,8 +7,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class CommandConsole implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandConsole implements CommandExecutor {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
} else {

View file

@ -10,8 +10,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
public class CommandDestroyEntities implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandDestroyEntities implements CommandExecutor {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
int entityCount = 0;
int worldCount = 0;

View file

@ -13,8 +13,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CommandEnchantAll implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandEnchantAll 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");
} else {
@ -24,36 +24,9 @@ public class CommandEnchantAll implements CommandExecutor {
if (item.getType() == Material.AIR) {
player.sendMessage("Please hold an item in your hand to enchant it");
} else {
item.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 32767);
item.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 32767);
item.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 32767);
item.addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, 32767);
item.addUnsafeEnchantment(Enchantment.BINDING_CURSE, 32767);
item.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 32767);
item.addUnsafeEnchantment(Enchantment.DAMAGE_ARTHROPODS, 32767);
item.addUnsafeEnchantment(Enchantment.DAMAGE_UNDEAD, 32767);
item.addUnsafeEnchantment(Enchantment.DEPTH_STRIDER, 32767);
item.addUnsafeEnchantment(Enchantment.DIG_SPEED, 32767);
item.addUnsafeEnchantment(Enchantment.DURABILITY, 32767);
item.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 32767);
item.addUnsafeEnchantment(Enchantment.FROST_WALKER, 32767);
item.addUnsafeEnchantment(Enchantment.KNOCKBACK, 32767);
item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 32767);
item.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 32767);
item.addUnsafeEnchantment(Enchantment.LUCK, 32767);
item.addUnsafeEnchantment(Enchantment.LURE, 32767);
item.addUnsafeEnchantment(Enchantment.MENDING, 32767);
item.addUnsafeEnchantment(Enchantment.OXYGEN, 32767);
item.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 32767);
item.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 32767);
item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 32767);
item.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 32767);
item.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 32767);
item.addUnsafeEnchantment(Enchantment.SILK_TOUCH, 32767);
item.addUnsafeEnchantment(Enchantment.SWEEPING_EDGE, 32767);
item.addUnsafeEnchantment(Enchantment.THORNS, 32767);
item.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, 32767);
item.addUnsafeEnchantment(Enchantment.WATER_WORKER, 32767);
for (Enchantment enchantment : Enchantment.values()) {
item.addUnsafeEnchantment(enchantment, Short.MAX_VALUE);
}
player.sendMessage("I killed Tim.");
}
}

View file

@ -11,15 +11,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandJumpscare implements CommandExecutor {
private void createJumpscare(Player player) {
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), 4);
for (int i = 0; i < 10; i++) {
public final class CommandJumpscare implements CommandExecutor {
private void createJumpscare(final Player player) {
final int count = 4;
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), count);
final int maxIterator = 10;
for (int i = 0; i <= maxIterator; i++) {
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0);
}
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
} else {
@ -34,7 +37,7 @@ public class CommandJumpscare implements CommandExecutor {
createJumpscare(target);
sender.sendMessage("Successfully created jumpscare for player \"" + target.getName() + "\"");
} else {
sender.sendMessage("Player \"" + target.getName() + "\" not found");
sender.sendMessage("Player \"" + args[0] + "\" not found");
}
}
}

View file

@ -18,8 +18,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
public class CommandPrefix implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
public final class CommandPrefix implements CommandExecutor {
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");
} else {

View file

@ -12,12 +12,12 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CommandPumpkin implements CommandExecutor {
private void placePumpkin(Player player) {
public final class CommandPumpkin implements CommandExecutor {
private void placePumpkin(final Player player) {
player.getInventory().setHelmet(new ItemStack(Material.CARVED_PUMPKIN));
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <player>");
} else {

View file

@ -12,15 +12,15 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class CommandServerInfo implements CommandExecutor {
private void sendInfoMessage(CommandSender target, String description, String value) {
public final class CommandServerInfo implements CommandExecutor {
private void sendInfoMessage(final CommandSender target, final String description, final String value) {
target.sendMessage(
ChatColor.GRAY + description + ": " +
ChatColor.WHITE + value
ChatColor.GRAY + description + ": "
+ ChatColor.WHITE + value
);
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
try {
sendInfoMessage(sender, "Hostname",
InetAddress.getLocalHost().getHostName()
@ -28,7 +28,7 @@ public class CommandServerInfo implements CommandExecutor {
sendInfoMessage(sender, "IP address",
InetAddress.getLocalHost().getHostAddress()
);
} catch (Exception exception) {
} catch (Exception ignored) {
}
sendInfoMessage(sender, "OS name",
@ -44,21 +44,21 @@ public class CommandServerInfo implements CommandExecutor {
ManagementFactory.getRuntimeMXBean().getVmName()
);
sendInfoMessage(sender, "Java version",
ManagementFactory.getRuntimeMXBean().getSpecVersion() +
" " +
ManagementFactory.getRuntimeMXBean().getVmVersion()
ManagementFactory.getRuntimeMXBean().getSpecVersion()
+ " " +
ManagementFactory.getRuntimeMXBean().getVmVersion()
);
try {
String[] shCommand = {
final String[] shCommand = {
"/bin/sh",
"-c",
"cat /proc/cpuinfo | grep 'model name' | cut -f 2 -d ':' | awk '{$1=$1}1' | head -1"
};
Process process = Runtime.getRuntime().exec(shCommand);
InputStreamReader isr = new InputStreamReader(process.getInputStream());
BufferedReader br = new BufferedReader(isr);
final Process process = Runtime.getRuntime().exec(shCommand);
final InputStreamReader isr = new InputStreamReader(process.getInputStream());
final BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
@ -68,7 +68,7 @@ public class CommandServerInfo implements CommandExecutor {
}
br.close();
} catch (Exception exception) {
} catch (Exception ignored) {
}
sendInfoMessage(sender, "CPU cores",
@ -78,13 +78,13 @@ public class CommandServerInfo implements CommandExecutor {
String.valueOf(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())
);
long heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
long nonHeapUsage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed();
long memoryMax = (
ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() +
ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getMax()
final long heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
final long nonHeapUsage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed();
final long memoryMax = (
ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()
+ ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getMax()
);
long memoryUsage = (heapUsage + nonHeapUsage);
final long memoryUsage = (heapUsage + nonHeapUsage);
sendInfoMessage(sender, "Available memory",
(memoryMax / 1024 / 1024) + " MB"
@ -99,8 +99,8 @@ public class CommandServerInfo implements CommandExecutor {
(memoryUsage / 1024 / 1024) + " MB"
);
long minutes = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) / 60;
long seconds = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) % 60;
final long minutes = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) / 60;
final long seconds = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) % 60;
sendInfoMessage(sender, "Server uptime",
minutes + " minute(s) " +

View file

@ -1,19 +1,18 @@
package pw.kaboom.extras.commands;
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 pw.kaboom.extras.Main;
import pw.kaboom.extras.helpers.SkinDownloader;
public class CommandSkin implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) {
public final class CommandSkin 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 {

View file

@ -14,21 +14,22 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class CommandSpawn implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandSpawn 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");
} else {
final Player player = (Player) sender;
final World world = Bukkit.getWorld("world");
final Location spawnLocation = world.getSpawnLocation();
final int maxWorldHeight = 256;
for (double y = spawnLocation.getY(); y <= 256; y++) {
for (double y = spawnLocation.getY(); y <= maxWorldHeight; y++) {
final Location yLocation = new Location(world, spawnLocation.getX(), y, spawnLocation.getZ());
final Block coordBlock = world.getBlockAt(yLocation);
if (!coordBlock.getType().isSolid() &&
!coordBlock.getRelative(BlockFace.UP).getType().isSolid()) {
if (!coordBlock.getType().isSolid()
&& !coordBlock.getRelative(BlockFace.UP).getType().isSolid()) {
player.teleportAsync(yLocation);
break;
}

View file

@ -13,8 +13,8 @@ import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector;
public class CommandSpidey implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandSpidey 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");
} else {
@ -33,9 +33,9 @@ public class CommandSpidey implements CommandExecutor {
distance
);
while (blockIterator.hasNext() &&
(blockIterator.next().getType() == Material.AIR ||
blockIterator.next().getType() == Material.CAVE_AIR)) {
while (blockIterator.hasNext()
&& (blockIterator.next().getType() == Material.AIR
|| blockIterator.next().getType() == Material.CAVE_AIR)) {
blockIterator.next().setType(Material.COBWEB);
}
}

View file

@ -9,8 +9,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandTellraw implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandTellraw implements CommandExecutor {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <message ..>");
} else {

View file

@ -8,8 +8,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class CommandUnloadChunks implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public final class CommandUnloadChunks implements CommandExecutor {
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
int chunkCount = 0;
for (World world : Bukkit.getServer().getWorlds()) {

View file

@ -1,19 +1,18 @@
package pw.kaboom.extras.commands;
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 pw.kaboom.extras.Main;
import pw.kaboom.extras.helpers.SkinDownloader;
public class CommandUsername implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) {
public final class CommandUsername 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 {

View file

@ -17,14 +17,14 @@ import com.google.gson.JsonParser;
import pw.kaboom.extras.Main;
public class SkinDownloader {
public final class SkinDownloader {
private HttpsURLConnection skinConnection;
private InputStreamReader skinStream;
private String texture;
private String signature;
public void applySkin(Player player, String name, boolean shouldChangeName, boolean shouldSendMessage) {
public void applySkin(final Player player, final String name, final boolean shouldChangeName, final boolean shouldSendMessage) {
new BukkitRunnable() {
@Override
public void run() {
@ -66,16 +66,15 @@ public class SkinDownloader {
@Override
public void run() {
try {
if (player.isOnline()) {
player.setPlayerProfile(profile);
player.setPlayerProfile(profile);
if (shouldChangeName && shouldSendMessage) {
player.sendMessage("Successfully set your username to \"" + name + "\"");
}
if (shouldChangeName && shouldSendMessage) {
player.sendMessage("Successfully set your username to \"" + name + "\"");
}
} catch (Exception exception) {
// Do nothing
}
Main.skinInProgress.remove(player.getUniqueId());
}
}.runTask(JavaPlugin.getPlugin(Main.class));
@ -83,7 +82,7 @@ public class SkinDownloader {
}.runTaskAsynchronously(JavaPlugin.getPlugin(Main.class));
}
private void fetchSkinData(String playerName) throws IOException {
private void fetchSkinData(final String playerName) throws IOException {
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + playerName);
skinConnection = (HttpsURLConnection) skinUrl.openConnection();
skinConnection.setConnectTimeout(0);

View file

@ -1,5 +1,7 @@
package pw.kaboom.extras.modules.player;
import java.io.IOException;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.BlockState;
@ -19,7 +21,7 @@ import pw.kaboom.extras.helpers.SkinDownloader;
public class PlayerConnection implements Listener {
@EventHandler
void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) throws IOException {
if (event.getName().length() > 16) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Your username can't be longer than 16 characters");
return;
@ -77,11 +79,12 @@ public class PlayerConnection implements Listener {
player.setOp(true);
}
final String name = player.getName();
final boolean shouldChangeUsername = false;
final boolean shouldSendMessage = false;
SkinDownloader skinDownloader = new SkinDownloader();
skinDownloader.applySkin(player, player.getName(), shouldChangeUsername, shouldSendMessage);
skinDownloader.applySkin(player, name, shouldChangeUsername, shouldSendMessage);
}
@SuppressWarnings("deprecation")

View file

@ -5,7 +5,6 @@
"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="."/>