More style fixes

This commit is contained in:
mathiascode 2019-12-21 16:12:26 +02:00
parent 164f6b5524
commit b688a2793b
17 changed files with 136 additions and 132 deletions

View file

@ -49,14 +49,6 @@
</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

@ -1,8 +1,6 @@
package pw.kaboom.extras;
import java.util.Collections;
import java.util.HashSet;
import java.util.UUID;
import org.bukkit.block.BlockFace;
import org.bukkit.plugin.java.JavaPlugin;
@ -36,9 +34,7 @@ import pw.kaboom.extras.modules.player.PlayerTeleport;
import pw.kaboom.extras.modules.server.ServerCommand;
import pw.kaboom.extras.modules.server.ServerPing;
public class Main extends JavaPlugin {
public static HashSet<UUID> skinInProgress = new HashSet<UUID>();
public final class Main extends JavaPlugin {
@Override
public void onLoad() {
/* Fill lists */

View file

@ -45,8 +45,8 @@ public final class CommandServerInfo implements CommandExecutor {
);
sendInfoMessage(sender, "Java version",
ManagementFactory.getRuntimeMXBean().getSpecVersion()
+ " " +
ManagementFactory.getRuntimeMXBean().getVmVersion()
+ " "
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
);
try {
@ -103,8 +103,8 @@ public final class CommandServerInfo implements CommandExecutor {
final long seconds = (ManagementFactory.getRuntimeMXBean().getUptime() / 1000) % 60;
sendInfoMessage(sender, "Server uptime",
minutes + " minute(s) " +
seconds + " second(s)"
minutes + " minute(s) "
+ seconds + " second(s)"
);
return true;
}

View file

@ -3,6 +3,8 @@ package pw.kaboom.extras.helpers;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashSet;
import java.util.UUID;
import javax.net.ssl.HttpsURLConnection;
@ -18,6 +20,8 @@ import com.google.gson.JsonParser;
import pw.kaboom.extras.Main;
public final class SkinDownloader {
public static HashSet<UUID> skinInProgress = new HashSet<UUID>();
private HttpsURLConnection skinConnection;
private InputStreamReader skinStream;
@ -28,7 +32,7 @@ public final class SkinDownloader {
new BukkitRunnable() {
@Override
public void run() {
Main.skinInProgress.add(player.getUniqueId());
skinInProgress.add(player.getUniqueId());
final PlayerProfile profile = player.getPlayerProfile();
@ -48,14 +52,14 @@ public final class SkinDownloader {
try {
skinStream.close();
skinConnection.disconnect();
} catch (Exception e) {
} catch (Exception ignored) {
}
if (!shouldChangeName && shouldSendMessage) {
player.sendMessage("A player with that username doesn't exist");
}
Main.skinInProgress.remove(player.getUniqueId());
skinInProgress.remove(player.getUniqueId());
if (!shouldChangeName) {
return;
@ -75,7 +79,7 @@ public final class SkinDownloader {
// Do nothing
}
Main.skinInProgress.remove(player.getUniqueId());
skinInProgress.remove(player.getUniqueId());
}
}.runTask(JavaPlugin.getPlugin(Main.class));
}

View file

@ -6,10 +6,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
public class BlockCheck implements Listener {
public final class BlockCheck implements Listener {
@EventHandler
void onBlockPlace(BlockPlaceEvent event) {
if (event.getItemInHand().toString().length() > 3019) {
void onBlockPlace(final BlockPlaceEvent event) {
final int maxItemStringLength = 3019;
if (event.getItemInHand().toString().length() > maxItemStringLength) {
event.setCancelled(true);
}
@ -21,7 +23,7 @@ public class BlockCheck implements Listener {
}
@EventHandler
void onSignChange(SignChangeEvent event) {
void onSignChange(final SignChangeEvent event) {
try {
event.getLines();
} catch (Exception exception) {

View file

@ -16,16 +16,16 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
public class BlockPhysics implements Listener {
public final class BlockPhysics implements Listener {
public static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
@EventHandler
void onBlockForm(BlockFormEvent event) {
if (event.getBlock().getType() == Material.LAVA ||
event.getBlock().getType() == Material.WATER) {
void onBlockForm(final BlockFormEvent event) {
if (event.getBlock().getType() == Material.LAVA
|| event.getBlock().getType() == Material.WATER) {
for (BlockFace face : blockFaces) {
if (event.getBlock().getRelative(face).getType() != Material.LAVA &&
event.getBlock().getRelative(face).getType() != Material.WATER) {
if (event.getBlock().getRelative(face).getType() != Material.LAVA
&& event.getBlock().getRelative(face).getType() != Material.WATER) {
return;
}
event.setCancelled(true);
@ -34,9 +34,9 @@ public class BlockPhysics implements Listener {
}
@EventHandler
void onBlockFromTo(BlockFromToEvent event) {
if (event.getBlock().getType() == Material.LAVA ||
event.getBlock().getType() == Material.WATER) {
void onBlockFromTo(final BlockFromToEvent event) {
if (event.getBlock().getType() == Material.LAVA
|| event.getBlock().getType() == Material.WATER) {
boolean lavaFound = false;
boolean waterFound = false;
@ -55,7 +55,7 @@ public class BlockPhysics implements Listener {
}
@EventHandler
void onBlockDestroy(BlockDestroyEvent event) {
void onBlockDestroy(final BlockDestroyEvent event) {
if (!event.getBlock().getType().isSolid()) {
for (BlockFace face : blockFaces) {
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
@ -68,7 +68,7 @@ public class BlockPhysics implements Listener {
}
@EventHandler
void onBlockPhysics(BlockPhysicsEvent event) {
void onBlockPhysics(final BlockPhysicsEvent event) {
switch (event.getChangedType()) {
case COMPARATOR:
case REDSTONE_TORCH:
@ -99,23 +99,26 @@ public class BlockPhysics implements Listener {
}
@EventHandler
void onBlockRedstone(BlockRedstoneEvent event) {
void onBlockRedstone(final BlockRedstoneEvent event) {
final double tps = Bukkit.getServer().getTPS()[0];
final int maxTps = 10;
if (tps < 10) {
if (tps < maxTps) {
event.setNewCurrent(0);
}
}
int fallingBlockCount;
private int fallingBlockCount;
@EventHandler
void onEntityChangeBlock(EntityChangeBlockEvent event) {
if (event.getEntityType() == EntityType.FALLING_BLOCK &&
event.getTo() == Material.AIR) {
void onEntityChangeBlock(final EntityChangeBlockEvent event) {
if (event.getEntityType() == EntityType.FALLING_BLOCK
&& event.getTo() == Material.AIR) {
fallingBlockCount++;
if (fallingBlockCount == 10) {
final int maxFallingBlockCount = 10;
if (fallingBlockCount == maxFallingBlockCount) {
event.setCancelled(true);
fallingBlockCount = 0;
}

View file

@ -7,15 +7,19 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.ExplosionPrimeEvent;
public class EntityExplosion implements Listener {
public final class EntityExplosion implements Listener {
@EventHandler
void onExplosionPrime(ExplosionPrimeEvent event) {
if (event.getRadius() > 20) {
event.setRadius(20);
void onExplosionPrime(final ExplosionPrimeEvent event) {
final int maxRadius = 20;
if (event.getRadius() > maxRadius) {
event.setRadius(maxRadius);
}
if (event.getEntity().getWorld().getEntitiesByClass(Fireball.class).size() > 30 &&
event.getRadius() > 1) {
final int maxFireballCount = 30;
if (event.getEntity().getWorld().getEntitiesByClass(Fireball.class).size() > maxFireballCount
&& event.getRadius() > 1) {
event.setRadius(1);
}
}

View file

@ -5,9 +5,9 @@ import org.bukkit.event.Listener;
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
public class EntityKnockback implements Listener {
public final class EntityKnockback implements Listener {
@EventHandler
void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) {
void onEntityKnockbackByEntity(final EntityKnockbackByEntityEvent event) {
final int knockbackLimit = 60;
if (event.getKnockbackStrength() > knockbackLimit) {

View file

@ -5,9 +5,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityTeleportEvent;
public class EntityTeleport implements Listener {
public final class EntityTeleport implements Listener {
@EventHandler
void onEntityTeleport(EntityTeleportEvent event) {
void onEntityTeleport(final EntityTeleportEvent event) {
event.setTo(EntitySpawn.limitLocation(event.getTo()));
}
}

View file

@ -19,9 +19,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
public class PlayerChat implements Listener {
public final class PlayerChat implements Listener {
@EventHandler
void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
void onAsyncPlayerChat(final AsyncPlayerChatEvent event) {
final Player player = event.getPlayer();
final UUID playerUuid = event.getPlayer().getUniqueId();

View file

@ -10,11 +10,11 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import pw.kaboom.extras.modules.server.ServerCommand;
public class PlayerCommand implements Listener {
public final class PlayerCommand implements Listener {
static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
@EventHandler
void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();
if (commandMillisList.get(playerUuid) != null) {

View file

@ -1,7 +1,5 @@
package pw.kaboom.extras.modules.player;
import java.io.IOException;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.BlockState;
@ -19,17 +17,16 @@ import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.helpers.SkinDownloader;
public class PlayerConnection implements Listener {
public final class PlayerConnection implements Listener {
@EventHandler
void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) throws IOException {
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
if (event.getName().length() > 16) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Your username can't be longer than 16 characters");
return;
}
}
@EventHandler
void onPlayerJoin(PlayerJoinEvent event) {
void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
final String title = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinTitle");
final String subtitle = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinSubtitle");
@ -37,8 +34,8 @@ public class PlayerConnection implements Listener {
final int stay = 160;
final int fadeOut = 5;
if (title != null ||
subtitle != null) {
if (title != null
|| subtitle != null) {
player.sendTitle(
title,
subtitle,
@ -50,16 +47,16 @@ public class PlayerConnection implements Listener {
}
@EventHandler
void onPlayerKick(PlayerKickEvent event) {
void onPlayerKick(final PlayerKickEvent event) {
if (!JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableKick")) {
event.setCancelled(true);
}
}
@EventHandler
void onPlayerLogin(PlayerLoginEvent event) {
if (event.getHostname().startsWith("play.flame.ga") &&
event.getHostname().endsWith(":25565")) {
void onPlayerLogin(final PlayerLoginEvent event) {
if (event.getHostname().startsWith("play.flame.ga")
&& event.getHostname().endsWith(":25565")) {
event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw");
return;
}
@ -70,8 +67,8 @@ public class PlayerConnection implements Listener {
event.allow();
}
if (event.getResult() == Result.KICK_FULL &&
JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("allowJoinOnFullServer")) {
if (event.getResult() == Result.KICK_FULL
&& JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("allowJoinOnFullServer")) {
event.allow();
}
@ -92,7 +89,7 @@ public class PlayerConnection implements Listener {
void onPlayerQuit(PlayerQuitEvent event) {
PlayerCommand.commandMillisList.remove(event.getPlayer().getUniqueId());
PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
Main.skinInProgress.remove(event.getPlayer().getUniqueId());
SkinDownloader.skinInProgress.remove(event.getPlayer().getUniqueId());
final World world = event.getPlayer().getWorld();

View file

@ -23,19 +23,19 @@ import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
public class PlayerDamage implements Listener {
public final class PlayerDamage implements Listener {
@EventHandler
void onEntityDamage(EntityDamageEvent event) {
void onEntityDamage(final EntityDamageEvent event) {
if (event.getEntityType() == EntityType.PLAYER) {
if (event.getCause() == DamageCause.VOID &&
event.getDamage() == Float.MAX_VALUE) {
if (event.getCause() == DamageCause.VOID
&& event.getDamage() == Float.MAX_VALUE) {
event.setCancelled(true);
}
}
}
@EventHandler
void onPlayerDeath(PlayerDeathEvent event) {
void onPlayerDeath(final PlayerDeathEvent event) {
final Player player = event.getEntity();
final AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
@ -70,8 +70,8 @@ public class PlayerDamage implements Listener {
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

@ -7,11 +7,11 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
public class PlayerInteract implements Listener {
public final class PlayerInteract implements Listener {
static HashMap<UUID, Long> interactMillisList = new HashMap<UUID, Long>();
@EventHandler
void onPlayerInteract(PlayerInteractEvent event) {
void onPlayerInteract(final PlayerInteractEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();
if (interactMillisList.get(playerUuid) != null) {

View file

@ -7,9 +7,9 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import pw.kaboom.extras.modules.entity.EntitySpawn;
public class PlayerTeleport implements Listener {
public final class PlayerTeleport implements Listener {
@EventHandler
void onPlayerTeleport(PlayerTeleportEvent event) {
void onPlayerTeleport(final PlayerTeleportEvent event) {
event.setTo(EntitySpawn.limitLocation(event.getTo()));
}
}

View file

@ -10,10 +10,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerCommandEvent;
public class ServerCommand implements Listener {
public final class ServerCommand implements Listener {
public static HashSet<String> consoleCommandBlacklist = new HashSet<String>();
public static String checkCommand(CommandSender sender, String command, boolean isConsoleCommand) {
public static String checkCommand(final CommandSender sender, final String command, final boolean isConsoleCommand) {
final String[] arr = command.split(" ");
String commandName = arr[0].toLowerCase();
@ -30,26 +30,26 @@ public class ServerCommand implements Listener {
for (int i = 1; i < arr.length; i++) {
if ("run".equalsIgnoreCase(arr[i])) {
if (i+1 < arr.length) {
if ("execute".equalsIgnoreCase(arr[i+1]) ||
"particle".equalsIgnoreCase(arr[i+1]) ||
"save-off".equalsIgnoreCase(arr[i+1]) ||
"spreadplayers".equalsIgnoreCase(arr[i+1]) ||
"stop".equalsIgnoreCase(arr[i+1])) {
if (i + 1 < arr.length) {
if ("execute".equalsIgnoreCase(arr[i + 1])
|| "particle".equalsIgnoreCase(arr[i + 1])
|| "save-off".equalsIgnoreCase(arr[i + 1])
|| "spreadplayers".equalsIgnoreCase(arr[i + 1])
|| "stop".equalsIgnoreCase(arr[i + 1])) {
Command.broadcastCommandMessage(sender, "Forbidden execute command detected");
return "cancel";
} else if (i+3 < arr.length &&
"gamerule".equalsIgnoreCase(arr[i+1])) {
if ("randomTickSpeed".equalsIgnoreCase(arr[i+2]) &&
Double.parseDouble(arr[i+3]) > 6) {
return command.replaceFirst("(?i)" + "randomTickSpeed " + arr[i+3], "randomTickSpeed 6");
} else if ("spawnRadius".equalsIgnoreCase(arr[i+2]) &&
Double.parseDouble(arr[i+3]) > 100) {
return command.replaceFirst("(?i)" + "spawnRadius " + arr[i+3], "spawnRadius 100");
} else if (i + 3 < arr.length
&& "gamerule".equalsIgnoreCase(arr[i + 1])) {
if ("randomTickSpeed".equalsIgnoreCase(arr[i + 2])
&& Double.parseDouble(arr[i + 3]) > 6) {
return command.replaceFirst("(?i)" + "randomTickSpeed " + arr[i + 3], "randomTickSpeed 6");
} else if ("spawnRadius".equalsIgnoreCase(arr[i + 2])
&& Double.parseDouble(arr[i + 3]) > 100) {
return command.replaceFirst("(?i)" + "spawnRadius " + arr[i + 3], "spawnRadius 100");
}
} else if ("give".equalsIgnoreCase(arr[i+1])) {
if (Double.parseDouble(arr[arr.length-1]) > 64) {
arr[arr.length-1] = "64";
} else if ("give".equalsIgnoreCase(arr[i + 1])) {
if (Double.parseDouble(arr[arr.length - 1]) > 64) {
arr[arr.length - 1] = "64";
return String.join(" ", arr);
}
}
@ -57,8 +57,8 @@ public class ServerCommand implements Listener {
break;
}
if ("as".equalsIgnoreCase(arr[i]) ||
"at".equalsIgnoreCase(arr[i])) {
if ("as".equalsIgnoreCase(arr[i])
|| "at".equalsIgnoreCase(arr[i])) {
asAtCount++;
}
}
@ -72,26 +72,26 @@ public class ServerCommand implements Listener {
case "/minecraft:gamerule":
case "/gamerule":
if (arr.length >= 3) {
if ("randomTickSpeed".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 6) {
if ("randomTickSpeed".equalsIgnoreCase(arr[1])
&& Double.parseDouble(arr[2]) > 6) {
return command.replaceFirst(arr[2], "6");
} else if ("spawnRadius".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 100) {
} else if ("spawnRadius".equalsIgnoreCase(arr[1])
&& Double.parseDouble(arr[2]) > 100) {
return command.replaceFirst(arr[2], "100");
}
}
break;
case "/minecraft:give":
case "/give":
if (Double.parseDouble(arr[arr.length-1]) > 64) {
arr[arr.length-1] = "64";
if (Double.parseDouble(arr[arr.length - 1]) > 64) {
arr[arr.length - 1] = "64";
return String.join(" ", arr);
}
break;
case "/minecraft:particle":
case "/particle":
if (arr.length >= 10 &&
Double.parseDouble(arr[9]) > 10) {
if (arr.length >= 10
&& Double.parseDouble(arr[9]) > 10) {
arr[9] = "10";
return String.join(" ", arr);
}
@ -100,9 +100,9 @@ public class ServerCommand implements Listener {
case "/bukkit:rl":
case "/reload":
case "/rl":
if (sender.hasPermission("bukkit.command.reload") &&
arr.length >= 2 &&
"confirm".equalsIgnoreCase(arr[1])) {
if (sender.hasPermission("bukkit.command.reload")
&& arr.length >= 2
&& "confirm".equalsIgnoreCase(arr[1])) {
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
@ -125,12 +125,15 @@ public class ServerCommand implements Listener {
case "/minecraft:spreadplayers":
case "/spreadplayers":
if (arr.length >= 5) {
if (Double.parseDouble(arr[3]) > 0)
if (Double.parseDouble(arr[3]) > 0) {
arr[3] = "0";
if (Double.parseDouble(arr[4]) < 8)
}
if (Double.parseDouble(arr[4]) < 8) {
arr[4] = "8";
if (Double.parseDouble(arr[4]) > 50)
}
if (Double.parseDouble(arr[4]) > 50) {
arr[4] = "50";
}
return String.join(" ", arr);
}
@ -141,6 +144,8 @@ public class ServerCommand implements Listener {
Command.broadcastCommandMessage(sender, "Stopping the server");
return "cancel";
}
default:
break;
}
} catch (NumberFormatException exception) {
// Do nothing
@ -149,7 +154,7 @@ public class ServerCommand implements Listener {
}
@EventHandler
void onServerCommand(ServerCommandEvent event) {
void onServerCommand(final ServerCommandEvent event) {
final CommandSender sender = event.getSender();
final String[] arr = event.getCommand().split(" ");

View file

@ -5,11 +5,12 @@ import org.bukkit.event.Listener;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
public class ServerPing implements Listener {
public final class ServerPing implements Listener {
@EventHandler
void onServerListPing(PaperServerListPingEvent event) {
void onServerListPing(final PaperServerListPingEvent event) {
if (event.getClient().getProtocolVersion() == -1) {
event.setProtocolVersion(573);
final int protocol = 573;
event.setProtocolVersion(protocol);
} else {
event.setProtocolVersion(event.getClient().getProtocolVersion());
}