mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-27 23:33:08 +00:00
Formatting and code readability cleanup (#5467)
* First pass reformatting code to be more readable (common still not done) * Replace google common collect calls with Java calls where possible * Remove a bunch of unnecessary parenthesis leaving clarifying ones * Add some missing @Nonnull annotations * Fix checking wrong type * Remove unnecessary continue/return statements and simplify comparision check * Pass exception instead of directly printing stack trace * Work on cleaning up common, through config so far * Work on cleaning up common, through integration so far * Work on cleaning up common, through network so far * Work on cleaning up common, through tier so far * Remove empty constructors that get created by default anyways * Work on cleaning up common, through transmitters so far * Work on cleaning up common, through utils so far * Finish cleaning up spacing for common
This commit is contained in:
1 parent
91ef2a5c3d
commit
0d4b50908f
909 files changed
+6234
-15623
No files matched your search
@@ -2,9 +2,9 @@ package mekanism.common.command;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.common.command.CommandMek.Cmd;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
@@ -24,17 +24,18 @@ public class CommandChunk extends CommandTreeBase {
|
||||
addSubcommand(new Cmd("unwatch", "cmd.mek.chunk.unwatch", this::removeWatcher));
|
||||
addSubcommand(new Cmd("clear", "cmd.mek.chunk.clear", this::clearWatchers));
|
||||
addSubcommand(new Cmd("flush", "cmd.mek.chunk.flush", this::flushChunks));
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "chunk";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
public String getUsage(@Nonnull ICommandSender sender) {
|
||||
return "cmd.mek.chunk.usage";
|
||||
}
|
||||
|
||||
@@ -52,42 +53,43 @@ public class CommandChunk extends CommandTreeBase {
|
||||
if (event.getWorld().isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChunkPos pos = event.getChunk().getPos();
|
||||
long key = ChunkPos.asLong(pos.x, pos.z);
|
||||
if (chunkWatchers.contains(key)) {
|
||||
String msg = String.format("%s chunk %d, %d", direction, pos.x, pos.z);
|
||||
event.getWorld().getMinecraftServer().getPlayerList().sendMessage(new TextComponentString(msg));
|
||||
MinecraftServer server = event.getWorld().getMinecraftServer();
|
||||
if (server != null) {
|
||||
server.getPlayerList().sendMessage(new TextComponentString(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addWatcher(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void addWatcher(MinecraftServer server, ICommandSender sender, String[] args) {
|
||||
ChunkPos cpos = new ChunkPos(sender.getPosition());
|
||||
chunkWatchers.add(ChunkPos.asLong(cpos.x, cpos.z));
|
||||
CommandBase.notifyCommandListener(sender, this, "cmd.mek.chunk.watch", cpos.x, cpos.z);
|
||||
}
|
||||
|
||||
public void removeWatcher(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void removeWatcher(MinecraftServer server, ICommandSender sender, String[] args) {
|
||||
ChunkPos cpos = new ChunkPos(sender.getPosition());
|
||||
chunkWatchers.remove(ChunkPos.asLong(cpos.x, cpos.z));
|
||||
CommandBase.notifyCommandListener(sender, this, "cmd.mek.chunk.unwatch", cpos.x, cpos.z);
|
||||
}
|
||||
|
||||
public void clearWatchers(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void clearWatchers(MinecraftServer server, ICommandSender sender, String[] args) {
|
||||
int count = chunkWatchers.size();
|
||||
chunkWatchers.clear();
|
||||
CommandBase.notifyCommandListener(sender, this, "cmd.mek.chunk.clear", count);
|
||||
}
|
||||
|
||||
public void flushChunks(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void flushChunks(MinecraftServer server, ICommandSender sender, String[] args) {
|
||||
if (sender.getEntityWorld().isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChunkProviderServer sp = (ChunkProviderServer)sender.getEntityWorld().getChunkProvider();
|
||||
ChunkProviderServer sp = (ChunkProviderServer) sender.getEntityWorld().getChunkProvider();
|
||||
int startCount = sp.getLoadedChunkCount();
|
||||
sp.queueUnloadAll();
|
||||
sp.tick();
|
||||
notifyCommandListener(sender, this, "cmd.mek.chunk.flush", startCount - sp.getLoadedChunkCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.command.CommandBase;
|
||||
@@ -38,23 +39,25 @@ public class CommandMek extends CommandTreeBase {
|
||||
event.registerServerCommand(new Cmd("mtpop", "cmd.mek.tpop", cmd::teleportPop));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "mek";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
public String getUsage(@Nonnull ICommandSender sender) {
|
||||
return "cmd.mek.usage";
|
||||
}
|
||||
|
||||
|
||||
public void toggleDebug(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void toggleDebug(MinecraftServer server, ICommandSender sender, String[] args) {
|
||||
MekanismAPI.debug = !MekanismAPI.debug;
|
||||
CommandBase.notifyCommandListener(sender, this, "cmd.mek.debug", MekanismAPI.debug);
|
||||
}
|
||||
|
||||
public void setupTestRules(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void setupTestRules(MinecraftServer server, ICommandSender sender, String[] args) {
|
||||
GameRules rules = server.getEntityWorld().getGameRules();
|
||||
rules.setOrCreateGameRule("doMobSpawning", "false");
|
||||
rules.setOrCreateGameRule("doDaylightCycle", "false");
|
||||
@@ -77,7 +80,7 @@ public class CommandMek extends CommandTreeBase {
|
||||
|
||||
// Save the current location on the stack
|
||||
UUID player = sender.getCommandSenderEntity().getUniqueID();
|
||||
Stack<BlockPos> playerLocations = tpStack.getOrDefault(player, new Stack<BlockPos>());
|
||||
Stack<BlockPos> playerLocations = tpStack.getOrDefault(player, new Stack<>());
|
||||
playerLocations.push(sender.getPosition());
|
||||
tpStack.put(player, playerLocations);
|
||||
|
||||
@@ -86,18 +89,17 @@ public class CommandMek extends CommandTreeBase {
|
||||
notifyCommandListener(sender, this, "cmd.mek.tp", args[0], args[1], args[2]);
|
||||
}
|
||||
|
||||
public void teleportPop(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void teleportPop(MinecraftServer server, ICommandSender sender, String[] args) {
|
||||
UUID player = sender.getCommandSenderEntity().getUniqueID();
|
||||
|
||||
// Get stack of locations for the user; if there's at least one entry, pop it off
|
||||
// and send the user back there
|
||||
Stack<BlockPos> playerLocations = tpStack.getOrDefault(player, new Stack<BlockPos>());
|
||||
Stack<BlockPos> playerLocations = tpStack.getOrDefault(player, new Stack<>());
|
||||
if (!playerLocations.isEmpty()) {
|
||||
BlockPos lastPos = playerLocations.pop();
|
||||
tpStack.put(player, playerLocations);
|
||||
teleport(sender.getCommandSenderEntity(), lastPos.getX(), lastPos.getY(), lastPos.getZ());
|
||||
notifyCommandListener(sender, this, "cmd.mek.tpop",
|
||||
lastPos.getX(), lastPos.getY(), lastPos.getZ(), playerLocations.size());
|
||||
notifyCommandListener(sender, this, "cmd.mek.tpop", lastPos.getX(), lastPos.getY(), lastPos.getZ(), playerLocations.size());
|
||||
} else {
|
||||
notifyCommandListener(sender, this, "cmd.mek.tpop.empty.stack");
|
||||
}
|
||||
@@ -105,10 +107,10 @@ public class CommandMek extends CommandTreeBase {
|
||||
|
||||
private void teleport(Entity player, double x, double y, double z) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP mp = (EntityPlayerMP)player;
|
||||
EntityPlayerMP mp = (EntityPlayerMP) player;
|
||||
mp.connection.setPlayerLocation(x, y, z, mp.rotationYaw, mp.rotationPitch);
|
||||
} else {
|
||||
EntityPlayerSP sp = (EntityPlayerSP)player;
|
||||
EntityPlayerSP sp = (EntityPlayerSP) player;
|
||||
sp.setLocationAndAngles(x, y, z, sp.rotationYaw, sp.rotationPitch);
|
||||
}
|
||||
}
|
||||
@@ -126,23 +128,26 @@ public class CommandMek extends CommandTreeBase {
|
||||
this.ex = ex;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
public String getUsage(@Nonnull ICommandSender sender) {
|
||||
return usage + ".usage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException {
|
||||
ex.execute(server, sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
interface CmdExecute {
|
||||
|
||||
void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user