pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,15 +18,14 @@
|
||||
|
||||
package appeng.server;
|
||||
|
||||
import static net.minecraft.command.Commands.literal;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import static net.minecraft.command.Commands.literal;
|
||||
|
||||
|
||||
public final class AECommand {
|
||||
|
||||
public void register(CommandDispatcher<CommandSource> dispatcher) {
|
||||
@@ -41,8 +40,7 @@ public final class AECommand {
|
||||
|
||||
private void add(LiteralArgumentBuilder<net.minecraft.command.CommandSource> builder, Commands subCommand) {
|
||||
|
||||
builder.then(literal(subCommand.name().toLowerCase())
|
||||
.requires(src -> src.hasPermissionLevel(subCommand.level))
|
||||
builder.then(literal(subCommand.name().toLowerCase()).requires(src -> src.hasPermissionLevel(subCommand.level))
|
||||
.executes(ctx -> {
|
||||
subCommand.command.call(ServerLifecycleHooks.getCurrentServer(), new String[0], ctx.getSource());
|
||||
return 1;
|
||||
|
||||
@@ -18,36 +18,34 @@
|
||||
|
||||
package appeng.server;
|
||||
|
||||
public enum AccessType {
|
||||
/**
|
||||
* allows basic access to manipulate the block via gui, or other.
|
||||
*/
|
||||
BLOCK_ACCESS,
|
||||
|
||||
public enum AccessType
|
||||
{
|
||||
/**
|
||||
* allows basic access to manipulate the block via gui, or other.
|
||||
*/
|
||||
BLOCK_ACCESS,
|
||||
/**
|
||||
* Can player deposit items into the network.
|
||||
*/
|
||||
NETWORK_DEPOSIT,
|
||||
|
||||
/**
|
||||
* Can player deposit items into the network.
|
||||
*/
|
||||
NETWORK_DEPOSIT,
|
||||
/**
|
||||
* can player withdraw items from the network.
|
||||
*/
|
||||
NETWORK_WITHDRAW,
|
||||
|
||||
/**
|
||||
* can player withdraw items from the network.
|
||||
*/
|
||||
NETWORK_WITHDRAW,
|
||||
/**
|
||||
* can player issue crafting requests?
|
||||
*/
|
||||
NETWORK_CRAFT,
|
||||
|
||||
/**
|
||||
* can player issue crafting requests?
|
||||
*/
|
||||
NETWORK_CRAFT,
|
||||
/**
|
||||
* can player add new blocks to the network.
|
||||
*/
|
||||
NETWORK_BUILD,
|
||||
|
||||
/**
|
||||
* can player add new blocks to the network.
|
||||
*/
|
||||
NETWORK_BUILD,
|
||||
|
||||
/**
|
||||
* can player manipulate security settings.
|
||||
*/
|
||||
NETWORK_SECURITY
|
||||
/**
|
||||
* can player manipulate security settings.
|
||||
*/
|
||||
NETWORK_SECURITY
|
||||
}
|
||||
|
||||
@@ -18,28 +18,23 @@
|
||||
|
||||
package appeng.server;
|
||||
|
||||
|
||||
import appeng.server.subcommands.ChunkLogger;
|
||||
import appeng.server.subcommands.Supporters;
|
||||
|
||||
public enum Commands {
|
||||
Chunklogger(4, new ChunkLogger()), Supporters(0, new Supporters());
|
||||
|
||||
public enum Commands
|
||||
{
|
||||
Chunklogger( 4, new ChunkLogger() ), Supporters( 0, new Supporters() );
|
||||
public final int level;
|
||||
public final ISubCommand command;
|
||||
|
||||
public final int level;
|
||||
public final ISubCommand command;
|
||||
Commands(final int level, final ISubCommand w) {
|
||||
this.level = level;
|
||||
this.command = w;
|
||||
}
|
||||
|
||||
Commands( final int level, final ISubCommand w )
|
||||
{
|
||||
this.level = level;
|
||||
this.command = w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.name();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,16 +18,12 @@
|
||||
|
||||
package appeng.server;
|
||||
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public interface ISubCommand {
|
||||
|
||||
public interface ISubCommand
|
||||
{
|
||||
String getHelp(MinecraftServer srv);
|
||||
|
||||
String getHelp( MinecraftServer srv );
|
||||
|
||||
void call( MinecraftServer srv, String[] args, CommandSource sender );
|
||||
void call(MinecraftServer srv, String[] args, CommandSource sender);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
|
||||
package appeng.server;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.items.tools.ToolNetworkTool;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -43,137 +40,115 @@ import appeng.client.ActionKey;
|
||||
import appeng.client.EffectType;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.items.tools.ToolNetworkTool;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ServerHelper extends CommonHelper {
|
||||
|
||||
public class ServerHelper extends CommonHelper
|
||||
{
|
||||
private PlayerEntity renderModeBased;
|
||||
|
||||
private PlayerEntity renderModeBased;
|
||||
@Override
|
||||
public World getWorld() {
|
||||
throw new UnsupportedOperationException("This is a server...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
throw new UnsupportedOperationException( "This is a server..." );
|
||||
}
|
||||
@Override
|
||||
public void bindTileEntitySpecialRenderer(final Class<? extends TileEntity> tile, final AEBaseBlock blk) {
|
||||
throw new UnsupportedOperationException("This is a server...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTileEntitySpecialRenderer( final Class<? extends TileEntity> tile, final AEBaseBlock blk )
|
||||
{
|
||||
throw new UnsupportedOperationException( "This is a server..." );
|
||||
}
|
||||
@Override
|
||||
public List<? extends PlayerEntity> getPlayers() {
|
||||
if (!Platform.isClient()) {
|
||||
final MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
|
||||
@Override
|
||||
public List<? extends PlayerEntity> getPlayers()
|
||||
{
|
||||
if( !Platform.isClient() )
|
||||
{
|
||||
final MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
if (server != null) {
|
||||
return server.getPlayerList().getPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
if( server != null )
|
||||
{
|
||||
return server.getPlayerList().getPlayers();
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@Override
|
||||
public void sendToAllNearExcept(final PlayerEntity p, final double x, final double y, final double z,
|
||||
final double dist, final World w, final AppEngPacket packet) {
|
||||
if (Platform.isClient()) {
|
||||
return;
|
||||
}
|
||||
for (final PlayerEntity o : this.getPlayers()) {
|
||||
final ServerPlayerEntity entityplayermp = (ServerPlayerEntity) o;
|
||||
if (entityplayermp != p && entityplayermp.world == w) {
|
||||
final double dX = x - entityplayermp.getPosX();
|
||||
final double dY = y - entityplayermp.getPosY();
|
||||
final double dZ = z - entityplayermp.getPosZ();
|
||||
if (dX * dX + dY * dY + dZ * dZ < dist * dist) {
|
||||
NetworkHandler.instance().sendTo(packet, entityplayermp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToAllNearExcept( final PlayerEntity p, final double x, final double y, final double z, final double dist, final World w, final AppEngPacket packet )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
for( final PlayerEntity o : this.getPlayers() )
|
||||
{
|
||||
final ServerPlayerEntity entityplayermp = (ServerPlayerEntity) o;
|
||||
if( entityplayermp != p && entityplayermp.world == w )
|
||||
{
|
||||
final double dX = x - entityplayermp.getPosX();
|
||||
final double dY = y - entityplayermp.getPosY();
|
||||
final double dZ = z - entityplayermp.getPosZ();
|
||||
if( dX * dX + dY * dY + dZ * dZ < dist * dist )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( packet, entityplayermp );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void spawnEffect(final EffectType type, final World world, final double posX, final double posY,
|
||||
final double posZ, final Object o) {
|
||||
// :P
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnEffect( final EffectType type, final World world, final double posX, final double posY, final double posZ, final Object o )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
@Override
|
||||
public boolean shouldAddParticles(final Random r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAddParticles( final Random r )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public RayTraceResult getRTR() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RayTraceResult getRTR()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void postInit() {
|
||||
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public CableRenderMode getRenderMode() {
|
||||
if (this.renderModeBased == null) {
|
||||
return CableRenderMode.STANDARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CableRenderMode getRenderMode()
|
||||
{
|
||||
if( this.renderModeBased == null )
|
||||
{
|
||||
return CableRenderMode.STANDARD;
|
||||
}
|
||||
return this.renderModeForPlayer(this.renderModeBased);
|
||||
}
|
||||
|
||||
return this.renderModeForPlayer( this.renderModeBased );
|
||||
}
|
||||
@Override
|
||||
public void triggerUpdates() {
|
||||
|
||||
@Override
|
||||
public void triggerUpdates()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void updateRenderMode(final PlayerEntity player) {
|
||||
this.renderModeBased = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRenderMode( final PlayerEntity player )
|
||||
{
|
||||
this.renderModeBased = player;
|
||||
}
|
||||
protected CableRenderMode renderModeForPlayer(final PlayerEntity player) {
|
||||
if (player != null) {
|
||||
for (int x = 0; x < PlayerInventory.getHotbarSize(); x++) {
|
||||
final ItemStack is = player.inventory.getStackInSlot(x);
|
||||
|
||||
protected CableRenderMode renderModeForPlayer( final PlayerEntity player )
|
||||
{
|
||||
if( player != null )
|
||||
{
|
||||
for(int x = 0; x < PlayerInventory.getHotbarSize(); x++ )
|
||||
{
|
||||
final ItemStack is = player.inventory.getStackInSlot( x );
|
||||
if (!is.isEmpty() && is.getItem() instanceof ToolNetworkTool) {
|
||||
final CompoundNBT c = is.getTag();
|
||||
if (c != null && c.getBoolean("hideFacades")) {
|
||||
return CableRenderMode.CABLE_VIEW;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !is.isEmpty() && is.getItem() instanceof ToolNetworkTool)
|
||||
{
|
||||
final CompoundNBT c = is.getTag();
|
||||
if( c != null && c.getBoolean( "hideFacades" ) )
|
||||
{
|
||||
return CableRenderMode.CABLE_VIEW;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return CableRenderMode.STANDARD;
|
||||
}
|
||||
|
||||
return CableRenderMode.STANDARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActionKey( ActionKey key, InputMappings.Input input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isActionKey(ActionKey key, InputMappings.Input input) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.server.subcommands;
|
||||
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
@@ -26,76 +25,60 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.server.ISubCommand;
|
||||
|
||||
public class ChunkLogger implements ISubCommand {
|
||||
|
||||
public class ChunkLogger implements ISubCommand
|
||||
{
|
||||
private boolean enabled = false;
|
||||
|
||||
private boolean enabled = false;
|
||||
private void displayStack() {
|
||||
if (AEConfig.instance().isFeatureEnabled(AEFeature.CHUNK_LOGGER_TRACE)) {
|
||||
boolean output = false;
|
||||
for (final StackTraceElement e : Thread.currentThread().getStackTrace()) {
|
||||
if (output) {
|
||||
AELog.info(
|
||||
" " + e.getClassName() + '.' + e.getMethodName() + " (" + e.getLineNumber() + ')');
|
||||
} else {
|
||||
output = e.getClassName().contains("EventBus") && e.getMethodName().contains("post");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayStack()
|
||||
{
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.CHUNK_LOGGER_TRACE ) )
|
||||
{
|
||||
boolean output = false;
|
||||
for( final StackTraceElement e : Thread.currentThread().getStackTrace() )
|
||||
{
|
||||
if( output )
|
||||
{
|
||||
AELog.info( " " + e.getClassName() + '.' + e.getMethodName() + " (" + e.getLineNumber() + ')' );
|
||||
}
|
||||
else
|
||||
{
|
||||
output = e.getClassName().contains( "EventBus" ) && e.getMethodName().contains( "post" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onChunkLoadEvent(final ChunkEvent.Load event) {
|
||||
if (!event.getWorld().isRemote()) {
|
||||
AELog.info("Chunk Loaded: " + event.getChunk().getPos().x + ", " + event.getChunk().getPos().z);
|
||||
this.displayStack();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChunkLoadEvent( final ChunkEvent.Load event )
|
||||
{
|
||||
if( !event.getWorld().isRemote() )
|
||||
{
|
||||
AELog.info( "Chunk Loaded: " + event.getChunk().getPos().x + ", " + event.getChunk().getPos().z );
|
||||
this.displayStack();
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onChunkUnloadEvent(final ChunkEvent.Unload unload) {
|
||||
if (!unload.getWorld().isRemote()) {
|
||||
AELog.info("Chunk Unloaded: " + unload.getChunk().getPos().x + ", " + unload.getChunk().getPos().z);
|
||||
this.displayStack();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChunkUnloadEvent( final ChunkEvent.Unload unload )
|
||||
{
|
||||
if( !unload.getWorld().isRemote() )
|
||||
{
|
||||
AELog.info( "Chunk Unloaded: " + unload.getChunk().getPos().x + ", " + unload.getChunk().getPos().z );
|
||||
this.displayStack();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getHelp(final MinecraftServer srv) {
|
||||
return "commands.ae2.ChunkLogger";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp( final MinecraftServer srv )
|
||||
{
|
||||
return "commands.ae2.ChunkLogger";
|
||||
}
|
||||
@Override
|
||||
public void call(final MinecraftServer srv, final String[] data, final CommandSource sender) {
|
||||
this.enabled = !this.enabled;
|
||||
|
||||
@Override
|
||||
public void call( final MinecraftServer srv, final String[] data, final CommandSource sender )
|
||||
{
|
||||
this.enabled = !this.enabled;
|
||||
|
||||
if( this.enabled )
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register( this );
|
||||
sender.sendFeedback( new TranslationTextComponent( "commands.ae2.ChunkLoggerOn" ), true );
|
||||
}
|
||||
else
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.unregister( this );
|
||||
sender.sendFeedback( new TranslationTextComponent( "commands.ae2.ChunkLoggerOff" ), true );
|
||||
}
|
||||
}
|
||||
if (this.enabled) {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
sender.sendFeedback(new TranslationTextComponent("commands.ae2.ChunkLoggerOn"), true);
|
||||
} else {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
sender.sendFeedback(new TranslationTextComponent("commands.ae2.ChunkLoggerOff"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.server.subcommands;
|
||||
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
@@ -27,20 +26,17 @@ import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
import appeng.server.ISubCommand;
|
||||
|
||||
public class Supporters implements ISubCommand {
|
||||
|
||||
public class Supporters implements ISubCommand
|
||||
{
|
||||
@Override
|
||||
public String getHelp(final MinecraftServer srv) {
|
||||
return "commands.ae2.Supporters";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp( final MinecraftServer srv )
|
||||
{
|
||||
return "commands.ae2.Supporters";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call( final MinecraftServer srv, final String[] data, final CommandSource sender )
|
||||
{
|
||||
final String[] who = { "Stig Halvorsen", "Josh Ricker", "Jenny \"Othlon\" Sutherland", "Hristo Bogdanov", "BevoLJ" };
|
||||
sender.sendFeedback( new StringTextComponent( "Special thanks to " + Joiner.on( ", " ).join( who ) ), true );
|
||||
}
|
||||
@Override
|
||||
public void call(final MinecraftServer srv, final String[] data, final CommandSource sender) {
|
||||
final String[] who = { "Stig Halvorsen", "Josh Ricker", "Jenny \"Othlon\" Sutherland", "Hristo Bogdanov",
|
||||
"BevoLJ" };
|
||||
sender.sendFeedback(new StringTextComponent("Special thanks to " + Joiner.on(", ").join(who)), true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user