base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,142 @@
package net.minecraft.server.management;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.SPacketChangeGameState;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
public class DemoPlayerInteractionManager extends PlayerInteractionManager
{
private boolean displayedIntro;
private boolean demoTimeExpired;
private int demoEndedReminder;
private int gameModeTicks;
public DemoPlayerInteractionManager(World worldIn)
{
super(worldIn);
}
public void updateBlockRemoving()
{
super.updateBlockRemoving();
++this.gameModeTicks;
long i = this.world.getTotalWorldTime();
long j = i / 24000L + 1L;
if (!this.displayedIntro && this.gameModeTicks > 20)
{
this.displayedIntro = true;
this.player.connection.sendPacket(new SPacketChangeGameState(5, 0.0F));
}
this.demoTimeExpired = i > 120500L;
if (this.demoTimeExpired)
{
++this.demoEndedReminder;
}
if (i % 24000L == 500L)
{
if (j <= 6L)
{
this.player.sendMessage(new TextComponentTranslation("demo.day." + j, new Object[0]));
}
}
else if (j == 1L)
{
if (i == 100L)
{
this.player.connection.sendPacket(new SPacketChangeGameState(5, 101.0F));
}
else if (i == 175L)
{
this.player.connection.sendPacket(new SPacketChangeGameState(5, 102.0F));
}
else if (i == 250L)
{
this.player.connection.sendPacket(new SPacketChangeGameState(5, 103.0F));
}
}
else if (j == 5L && i % 24000L == 22000L)
{
this.player.sendMessage(new TextComponentTranslation("demo.day.warning", new Object[0]));
}
}
/**
* Sends a message to the player reminding them that this is the demo version
*/
private void sendDemoReminder()
{
if (this.demoEndedReminder > 100)
{
this.player.sendMessage(new TextComponentTranslation("demo.reminder", new Object[0]));
this.demoEndedReminder = 0;
}
}
/**
* If not creative, it calls sendBlockBreakProgress until the block is broken first. tryHarvestBlock can also be the
* result of this call.
*/
public void onBlockClicked(BlockPos pos, EnumFacing side)
{
if (this.demoTimeExpired)
{
this.sendDemoReminder();
}
else
{
super.onBlockClicked(pos, side);
}
}
public void blockRemoving(BlockPos pos)
{
if (!this.demoTimeExpired)
{
super.blockRemoving(pos);
}
}
/**
* Attempts to harvest a block
*/
public boolean tryHarvestBlock(BlockPos pos)
{
return this.demoTimeExpired ? false : super.tryHarvestBlock(pos);
}
public EnumActionResult processRightClick(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand)
{
if (this.demoTimeExpired)
{
this.sendDemoReminder();
return EnumActionResult.PASS;
}
else
{
return super.processRightClick(player, worldIn, stack, hand);
}
}
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (this.demoTimeExpired)
{
this.sendDemoReminder();
return EnumActionResult.PASS;
}
else
{
return super.processRightClickBlock(player, worldIn, stack, hand, pos, facing, hitX, hitY, hitZ);
}
}
}

View File

@@ -0,0 +1,498 @@
package net.minecraft.server.management;
import com.google.common.base.Predicate;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
public class PlayerChunkMap
{
private static final Predicate<EntityPlayerMP> NOT_SPECTATOR = new Predicate<EntityPlayerMP>()
{
public boolean apply(@Nullable EntityPlayerMP p_apply_1_)
{
return p_apply_1_ != null && !p_apply_1_.isSpectator();
}
};
private static final Predicate<EntityPlayerMP> CAN_GENERATE_CHUNKS = new Predicate<EntityPlayerMP>()
{
public boolean apply(@Nullable EntityPlayerMP p_apply_1_)
{
return p_apply_1_ != null && (!p_apply_1_.isSpectator() || p_apply_1_.getServerWorld().getGameRules().getBoolean("spectatorsGenerateChunks"));
}
};
private final WorldServer world;
/** players in the current instance */
private final List<EntityPlayerMP> players = Lists.<EntityPlayerMP>newArrayList();
/** the hash of all playerInstances created */
private final Long2ObjectMap<PlayerChunkMapEntry> entryMap = new Long2ObjectOpenHashMap<PlayerChunkMapEntry>(4096);
/** the playerInstances(chunks) that need to be updated */
private final Set<PlayerChunkMapEntry> dirtyEntries = Sets.<PlayerChunkMapEntry>newHashSet();
private final List<PlayerChunkMapEntry> pendingSendToPlayers = Lists.<PlayerChunkMapEntry>newLinkedList();
/** List of player instances whose chunk field is unassigned, and need the chunk at their pos to be loaded. */
private final List<PlayerChunkMapEntry> entriesWithoutChunks = Lists.<PlayerChunkMapEntry>newLinkedList();
/** This field is using when chunk should be processed (every 8000 ticks) */
private final List<PlayerChunkMapEntry> entries = Lists.<PlayerChunkMapEntry>newArrayList();
/** Number of chunks the server sends to the client. Valid 3<=x<=15. In server.properties. */
private int playerViewRadius;
/** time what is using to check if InhabitedTime should be calculated */
private long previousTotalWorldTime;
private boolean sortMissingChunks = true;
private boolean sortSendToPlayers = true;
public PlayerChunkMap(WorldServer serverWorld)
{
this.world = serverWorld;
this.setPlayerViewRadius(serverWorld.getMinecraftServer().getPlayerList().getViewDistance());
}
/**
* Returns the WorldServer associated with this PlayerManager
*/
public WorldServer getWorldServer()
{
return this.world;
}
public Iterator<Chunk> getChunkIterator()
{
final Iterator<PlayerChunkMapEntry> iterator = this.entries.iterator();
return new AbstractIterator<Chunk>()
{
protected Chunk computeNext()
{
while (true)
{
if (iterator.hasNext())
{
PlayerChunkMapEntry playerchunkmapentry = iterator.next();
Chunk chunk = playerchunkmapentry.getChunk();
if (chunk == null)
{
continue;
}
if (!chunk.isLightPopulated() && chunk.isTerrainPopulated())
{
return chunk;
}
if (!chunk.wasTicked())
{
return chunk;
}
if (!playerchunkmapentry.hasPlayerMatchingInRange(128.0D, PlayerChunkMap.NOT_SPECTATOR))
{
continue;
}
return chunk;
}
return (Chunk)this.endOfData();
}
}
};
}
/**
* updates all the player instances that need to be updated
*/
public void tick()
{
long i = this.world.getTotalWorldTime();
if (i - this.previousTotalWorldTime > 8000L)
{
this.previousTotalWorldTime = i;
for (int j = 0; j < this.entries.size(); ++j)
{
PlayerChunkMapEntry playerchunkmapentry = this.entries.get(j);
playerchunkmapentry.update();
playerchunkmapentry.updateChunkInhabitedTime();
}
}
if (!this.dirtyEntries.isEmpty())
{
for (PlayerChunkMapEntry playerchunkmapentry2 : this.dirtyEntries)
{
playerchunkmapentry2.update();
}
this.dirtyEntries.clear();
}
if (this.sortMissingChunks && i % 4L == 0L)
{
this.sortMissingChunks = false;
Collections.sort(this.entriesWithoutChunks, new Comparator<PlayerChunkMapEntry>()
{
public int compare(PlayerChunkMapEntry p_compare_1_, PlayerChunkMapEntry p_compare_2_)
{
return ComparisonChain.start().compare(p_compare_1_.getClosestPlayerDistance(), p_compare_2_.getClosestPlayerDistance()).result();
}
});
}
if (this.sortSendToPlayers && i % 4L == 2L)
{
this.sortSendToPlayers = false;
Collections.sort(this.pendingSendToPlayers, new Comparator<PlayerChunkMapEntry>()
{
public int compare(PlayerChunkMapEntry p_compare_1_, PlayerChunkMapEntry p_compare_2_)
{
return ComparisonChain.start().compare(p_compare_1_.getClosestPlayerDistance(), p_compare_2_.getClosestPlayerDistance()).result();
}
});
}
if (!this.entriesWithoutChunks.isEmpty())
{
long l = System.nanoTime() + 50000000L;
int k = 49;
Iterator<PlayerChunkMapEntry> iterator = this.entriesWithoutChunks.iterator();
while (iterator.hasNext())
{
PlayerChunkMapEntry playerchunkmapentry1 = iterator.next();
if (playerchunkmapentry1.getChunk() == null)
{
boolean flag = playerchunkmapentry1.hasPlayerMatching(CAN_GENERATE_CHUNKS);
if (playerchunkmapentry1.providePlayerChunk(flag))
{
iterator.remove();
if (playerchunkmapentry1.sendToPlayers())
{
this.pendingSendToPlayers.remove(playerchunkmapentry1);
}
--k;
if (k < 0 || System.nanoTime() > l)
{
break;
}
}
}
}
}
if (!this.pendingSendToPlayers.isEmpty())
{
int i1 = 81;
Iterator<PlayerChunkMapEntry> iterator1 = this.pendingSendToPlayers.iterator();
while (iterator1.hasNext())
{
PlayerChunkMapEntry playerchunkmapentry3 = iterator1.next();
if (playerchunkmapentry3.sendToPlayers())
{
iterator1.remove();
--i1;
if (i1 < 0)
{
break;
}
}
}
}
if (this.players.isEmpty())
{
WorldProvider worldprovider = this.world.provider;
if (!worldprovider.canRespawnHere())
{
this.world.getChunkProvider().queueUnloadAll();
}
}
}
public boolean contains(int chunkX, int chunkZ)
{
long i = getIndex(chunkX, chunkZ);
return this.entryMap.get(i) != null;
}
@Nullable
public PlayerChunkMapEntry getEntry(int x, int z)
{
return (PlayerChunkMapEntry)this.entryMap.get(getIndex(x, z));
}
private PlayerChunkMapEntry getOrCreateEntry(int chunkX, int chunkZ)
{
long i = getIndex(chunkX, chunkZ);
PlayerChunkMapEntry playerchunkmapentry = (PlayerChunkMapEntry)this.entryMap.get(i);
if (playerchunkmapentry == null)
{
playerchunkmapentry = new PlayerChunkMapEntry(this, chunkX, chunkZ);
this.entryMap.put(i, playerchunkmapentry);
this.entries.add(playerchunkmapentry);
if (playerchunkmapentry.getChunk() == null)
{
this.entriesWithoutChunks.add(playerchunkmapentry);
}
if (!playerchunkmapentry.sendToPlayers())
{
this.pendingSendToPlayers.add(playerchunkmapentry);
}
}
return playerchunkmapentry;
}
public void markBlockForUpdate(BlockPos pos)
{
int i = pos.getX() >> 4;
int j = pos.getZ() >> 4;
PlayerChunkMapEntry playerchunkmapentry = this.getEntry(i, j);
if (playerchunkmapentry != null)
{
playerchunkmapentry.blockChanged(pos.getX() & 15, pos.getY(), pos.getZ() & 15);
}
}
/**
* Adds an EntityPlayerMP to the PlayerManager and to all player instances within player visibility
*/
public void addPlayer(EntityPlayerMP player)
{
int i = (int)player.posX >> 4;
int j = (int)player.posZ >> 4;
player.managedPosX = player.posX;
player.managedPosZ = player.posZ;
for (int k = i - this.playerViewRadius; k <= i + this.playerViewRadius; ++k)
{
for (int l = j - this.playerViewRadius; l <= j + this.playerViewRadius; ++l)
{
this.getOrCreateEntry(k, l).addPlayer(player);
}
}
this.players.add(player);
this.markSortPending();
}
/**
* Removes an EntityPlayerMP from the PlayerManager.
*/
public void removePlayer(EntityPlayerMP player)
{
int i = (int)player.managedPosX >> 4;
int j = (int)player.managedPosZ >> 4;
for (int k = i - this.playerViewRadius; k <= i + this.playerViewRadius; ++k)
{
for (int l = j - this.playerViewRadius; l <= j + this.playerViewRadius; ++l)
{
PlayerChunkMapEntry playerchunkmapentry = this.getEntry(k, l);
if (playerchunkmapentry != null)
{
playerchunkmapentry.removePlayer(player);
}
}
}
this.players.remove(player);
this.markSortPending();
}
/**
* Determine if two rectangles centered at the given points overlap for the provided radius. Arguments: x1, z1, x2,
* z2, radius.
*/
private boolean overlaps(int x1, int z1, int x2, int z2, int radius)
{
int i = x1 - x2;
int j = z1 - z2;
if (i >= -radius && i <= radius)
{
return j >= -radius && j <= radius;
}
else
{
return false;
}
}
/**
* Update chunks around a player that moved
*/
public void updateMovingPlayer(EntityPlayerMP player)
{
int i = (int)player.posX >> 4;
int j = (int)player.posZ >> 4;
double d0 = player.managedPosX - player.posX;
double d1 = player.managedPosZ - player.posZ;
double d2 = d0 * d0 + d1 * d1;
if (d2 >= 64.0D)
{
int k = (int)player.managedPosX >> 4;
int l = (int)player.managedPosZ >> 4;
int i1 = this.playerViewRadius;
int j1 = i - k;
int k1 = j - l;
if (j1 != 0 || k1 != 0)
{
for (int l1 = i - i1; l1 <= i + i1; ++l1)
{
for (int i2 = j - i1; i2 <= j + i1; ++i2)
{
if (!this.overlaps(l1, i2, k, l, i1))
{
this.getOrCreateEntry(l1, i2).addPlayer(player);
}
if (!this.overlaps(l1 - j1, i2 - k1, i, j, i1))
{
PlayerChunkMapEntry playerchunkmapentry = this.getEntry(l1 - j1, i2 - k1);
if (playerchunkmapentry != null)
{
playerchunkmapentry.removePlayer(player);
}
}
}
}
player.managedPosX = player.posX;
player.managedPosZ = player.posZ;
this.markSortPending();
}
}
}
public boolean isPlayerWatchingChunk(EntityPlayerMP player, int chunkX, int chunkZ)
{
PlayerChunkMapEntry playerchunkmapentry = this.getEntry(chunkX, chunkZ);
return playerchunkmapentry != null && playerchunkmapentry.containsPlayer(player) && playerchunkmapentry.isSentToPlayers();
}
public void setPlayerViewRadius(int radius)
{
radius = MathHelper.clamp(radius, 3, 32);
if (radius != this.playerViewRadius)
{
int i = radius - this.playerViewRadius;
for (EntityPlayerMP entityplayermp : Lists.newArrayList(this.players))
{
int j = (int)entityplayermp.posX >> 4;
int k = (int)entityplayermp.posZ >> 4;
if (i > 0)
{
for (int j1 = j - radius; j1 <= j + radius; ++j1)
{
for (int k1 = k - radius; k1 <= k + radius; ++k1)
{
PlayerChunkMapEntry playerchunkmapentry = this.getOrCreateEntry(j1, k1);
if (!playerchunkmapentry.containsPlayer(entityplayermp))
{
playerchunkmapentry.addPlayer(entityplayermp);
}
}
}
}
else
{
for (int l = j - this.playerViewRadius; l <= j + this.playerViewRadius; ++l)
{
for (int i1 = k - this.playerViewRadius; i1 <= k + this.playerViewRadius; ++i1)
{
if (!this.overlaps(l, i1, j, k, radius))
{
this.getOrCreateEntry(l, i1).removePlayer(entityplayermp);
}
}
}
}
}
this.playerViewRadius = radius;
this.markSortPending();
}
}
private void markSortPending()
{
this.sortMissingChunks = true;
this.sortSendToPlayers = true;
}
/**
* Get the furthest viewable block given player's view distance
*/
public static int getFurthestViewableBlock(int distance)
{
return distance * 16 - 16;
}
private static long getIndex(int p_187307_0_, int p_187307_1_)
{
return (long)p_187307_0_ + 2147483647L | (long)p_187307_1_ + 2147483647L << 32;
}
/**
* Marks an entry as dirty
*/
public void entryChanged(PlayerChunkMapEntry entry)
{
this.dirtyEntries.add(entry);
}
public void removeEntry(PlayerChunkMapEntry entry)
{
ChunkPos chunkpos = entry.getPos();
long i = getIndex(chunkpos.x, chunkpos.z);
entry.updateChunkInhabitedTime();
this.entryMap.remove(i);
this.entries.remove(entry);
this.dirtyEntries.remove(entry);
this.pendingSendToPlayers.remove(entry);
this.entriesWithoutChunks.remove(entry);
Chunk chunk = entry.getChunk();
if (chunk != null)
{
this.getWorldServer().getChunkProvider().queueUnload(chunk);
}
}
}

View File

@@ -0,0 +1,364 @@
package net.minecraft.server.management;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.SPacketBlockChange;
import net.minecraft.network.play.server.SPacketChunkData;
import net.minecraft.network.play.server.SPacketMultiBlockChange;
import net.minecraft.network.play.server.SPacketUnloadChunk;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class PlayerChunkMapEntry
{
private static final Logger LOGGER = LogManager.getLogger();
private final PlayerChunkMap playerChunkMap;
private final List<EntityPlayerMP> players = Lists.<EntityPlayerMP>newArrayList();
private final ChunkPos pos;
private short[] changedBlocks = new short[64];
@Nullable
private Chunk chunk;
private int changes;
private int changedSectionFilter;
private long lastUpdateInhabitedTime;
private boolean sentToPlayers;
private Runnable loadedRunnable = new Runnable()
{
public void run()
{
PlayerChunkMapEntry.this.chunk = PlayerChunkMapEntry.this.playerChunkMap.getWorldServer().getChunkProvider().loadChunk(PlayerChunkMapEntry.this.pos.x, PlayerChunkMapEntry.this.pos.z);
PlayerChunkMapEntry.this.loading = false;
}
};
private boolean loading = true;
public PlayerChunkMapEntry(PlayerChunkMap mapIn, int chunkX, int chunkZ)
{
this.playerChunkMap = mapIn;
this.pos = new ChunkPos(chunkX, chunkZ);
mapIn.getWorldServer().getChunkProvider().loadChunk(chunkX, chunkZ, this.loadedRunnable);
}
public ChunkPos getPos()
{
return this.pos;
}
public void addPlayer(EntityPlayerMP player)
{
if (this.players.contains(player))
{
LOGGER.debug("Failed to add player. {} already is in chunk {}, {}", player, Integer.valueOf(this.pos.x), Integer.valueOf(this.pos.z));
}
else
{
if (this.players.isEmpty())
{
this.lastUpdateInhabitedTime = this.playerChunkMap.getWorldServer().getTotalWorldTime();
}
this.players.add(player);
if (this.sentToPlayers)
{
this.sendToPlayer(player);
// chunk watch event - the chunk is ready
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.Watch(this.chunk, player));
}
}
}
public void removePlayer(EntityPlayerMP player)
{
if (this.players.contains(player))
{
// If we haven't loaded yet don't load the chunk just so we can clean it up
if (this.chunk == null)
{
this.players.remove(player);
if (this.players.isEmpty())
{
if (this.loading) net.minecraftforge.common.chunkio.ChunkIOExecutor.dropQueuedChunkLoad(this.playerChunkMap.getWorldServer(), this.pos.x, this.pos.z, this.loadedRunnable);
this.playerChunkMap.removeEntry(this);
}
return;
}
if (this.sentToPlayers)
{
player.connection.sendPacket(new SPacketUnloadChunk(this.pos.x, this.pos.z));
}
this.players.remove(player);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.UnWatch(this.chunk, player));
if (this.players.isEmpty())
{
this.playerChunkMap.removeEntry(this);
}
}
}
/**
* Provide the chunk at the player's location. Can fail, returning false, if the player is a spectator floating
* outside of any pre-existing chunks, and the server is not configured to allow chunk generation for spectators.
*/
public boolean providePlayerChunk(boolean canGenerate)
{
if (this.loading) return false;
if (this.chunk != null)
{
return true;
}
else
{
if (canGenerate)
{
this.chunk = this.playerChunkMap.getWorldServer().getChunkProvider().provideChunk(this.pos.x, this.pos.z);
}
else
{
this.chunk = this.playerChunkMap.getWorldServer().getChunkProvider().loadChunk(this.pos.x, this.pos.z);
}
return this.chunk != null;
}
}
public boolean sendToPlayers()
{
if (this.sentToPlayers)
{
return true;
}
else if (this.chunk == null)
{
return false;
}
else if (!this.chunk.isPopulated())
{
return false;
}
else
{
this.changes = 0;
this.changedSectionFilter = 0;
this.sentToPlayers = true;
if (this.players.isEmpty()) return true; // Forge: fix MC-120780
Packet<?> packet = new SPacketChunkData(this.chunk, 65535);
for (EntityPlayerMP entityplayermp : this.players)
{
entityplayermp.connection.sendPacket(packet);
this.playerChunkMap.getWorldServer().getEntityTracker().sendLeashedEntitiesInChunk(entityplayermp, this.chunk);
// chunk watch event - delayed to here as the chunk wasn't ready in addPlayer
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.Watch(this.chunk, entityplayermp));
}
return true;
}
}
/**
* Fully resyncs this chunk's blocks, tile entities, and entity attachments (passengers and leashes) to all tracking
* players
*/
public void sendToPlayer(EntityPlayerMP player)
{
if (this.sentToPlayers)
{
player.connection.sendPacket(new SPacketChunkData(this.chunk, 65535));
this.playerChunkMap.getWorldServer().getEntityTracker().sendLeashedEntitiesInChunk(player, this.chunk);
}
}
public void updateChunkInhabitedTime()
{
long i = this.playerChunkMap.getWorldServer().getTotalWorldTime();
if (this.chunk != null)
{
this.chunk.setInhabitedTime(this.chunk.getInhabitedTime() + i - this.lastUpdateInhabitedTime);
}
this.lastUpdateInhabitedTime = i;
}
public void blockChanged(int x, int y, int z)
{
if (this.sentToPlayers)
{
if (this.changes == 0)
{
this.playerChunkMap.entryChanged(this);
}
this.changedSectionFilter |= 1 << (y >> 4);
//Forge; Cache everything, so always run
{
short short1 = (short)(x << 12 | z << 8 | y);
for (int i = 0; i < this.changes; ++i)
{
if (this.changedBlocks[i] == short1)
{
return;
}
}
if (this.changes == this.changedBlocks.length)
this.changedBlocks = java.util.Arrays.copyOf(this.changedBlocks, this.changedBlocks.length << 1);
this.changedBlocks[this.changes++] = short1;
}
}
}
public void sendPacket(Packet<?> packetIn)
{
if (this.sentToPlayers)
{
for (int i = 0; i < this.players.size(); ++i)
{
(this.players.get(i)).connection.sendPacket(packetIn);
}
}
}
@SuppressWarnings("unused")
public void update()
{
if (this.sentToPlayers && this.chunk != null)
{
if (this.changes != 0)
{
if (this.changes == 1)
{
int i = (this.changedBlocks[0] >> 12 & 15) + this.pos.x * 16;
int j = this.changedBlocks[0] & 255;
int k = (this.changedBlocks[0] >> 8 & 15) + this.pos.z * 16;
BlockPos blockpos = new BlockPos(i, j, k);
this.sendPacket(new SPacketBlockChange(this.playerChunkMap.getWorldServer(), blockpos));
net.minecraft.block.state.IBlockState state = this.playerChunkMap.getWorldServer().getBlockState(blockpos);
if (state.getBlock().hasTileEntity(state))
{
this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos));
}
}
else if (this.changes >= net.minecraftforge.common.ForgeModContainer.clumpingThreshold)
{
this.sendPacket(new SPacketChunkData(this.chunk, this.changedSectionFilter));
//TODO: FDix Mojang's fuckup to modded by combining all TE data into the chunk data packet... seriously... packet size explosion!
}
else
{
this.sendPacket(new SPacketMultiBlockChange(this.changes, this.changedBlocks, this.chunk));
//} Keep this in the else until we figure out a fix for mojang's derpitude on the data packet so we don't double send crap.
//{// Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small
for (int l = 0; l < this.changes; ++l)
{
int i1 = (this.changedBlocks[l] >> 12 & 15) + this.pos.x * 16;
int j1 = this.changedBlocks[l] & 255;
int k1 = (this.changedBlocks[l] >> 8 & 15) + this.pos.z * 16;
BlockPos blockpos1 = new BlockPos(i1, j1, k1);
net.minecraft.block.state.IBlockState state = this.playerChunkMap.getWorldServer().getBlockState(blockpos1);
if (state.getBlock().hasTileEntity(state))
{
this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos1));
}
}
}
this.changes = 0;
this.changedSectionFilter = 0;
}
}
}
private void sendBlockEntity(@Nullable TileEntity be)
{
if (be != null)
{
SPacketUpdateTileEntity spacketupdatetileentity = be.getUpdatePacket();
if (spacketupdatetileentity != null)
{
this.sendPacket(spacketupdatetileentity);
}
}
}
public boolean containsPlayer(EntityPlayerMP player)
{
return this.players.contains(player);
}
public boolean hasPlayerMatching(Predicate<EntityPlayerMP> predicate)
{
return Iterables.tryFind(this.players, predicate).isPresent();
}
public boolean hasPlayerMatchingInRange(double range, Predicate<EntityPlayerMP> predicate)
{
int i = 0;
for (int j = this.players.size(); i < j; ++i)
{
EntityPlayerMP entityplayermp = this.players.get(i);
if (predicate.apply(entityplayermp) && this.pos.getDistanceSq(entityplayermp) < range * range)
{
return true;
}
}
return false;
}
public boolean isSentToPlayers()
{
return this.sentToPlayers;
}
@Nullable
public Chunk getChunk()
{
return this.chunk;
}
public double getClosestPlayerDistance()
{
double d0 = Double.MAX_VALUE;
for (EntityPlayerMP entityplayermp : this.players)
{
double d1 = this.pos.getDistanceSq(entityplayermp);
if (d1 < d0)
{
d0 = d1;
}
}
return d0;
}
public List<EntityPlayerMP> getWatchingPlayers()
{
return isSentToPlayers() ? java.util.Collections.unmodifiableList(players) : java.util.Collections.emptyList();
}
}

View File

@@ -0,0 +1,545 @@
package net.minecraft.server.management;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.block.BlockCommandBlock;
import net.minecraft.block.BlockStructure;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.network.play.server.SPacketBlockChange;
import net.minecraft.network.play.server.SPacketPlayerListItem;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameType;
import net.minecraft.world.ILockableContainer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
public class PlayerInteractionManager
{
/** The world object that this object is connected to. */
public World world;
/** The EntityPlayerMP object that this object is connected to. */
public EntityPlayerMP player;
private GameType gameType = GameType.NOT_SET;
/** True if the player is destroying a block */
private boolean isDestroyingBlock;
private int initialDamage;
private BlockPos destroyPos = BlockPos.ORIGIN;
private int curblockDamage;
/**
* Set to true when the "finished destroying block" packet is received but the block wasn't fully damaged yet. The
* block will not be destroyed while this is false.
*/
private boolean receivedFinishDiggingPacket;
private BlockPos delayedDestroyPos = BlockPos.ORIGIN;
private int initialBlockDamage;
private int durabilityRemainingOnBlock = -1;
public PlayerInteractionManager(World worldIn)
{
this.world = worldIn;
}
public void setGameType(GameType type)
{
this.gameType = type;
type.configurePlayerCapabilities(this.player.capabilities);
this.player.sendPlayerAbilities();
this.player.mcServer.getPlayerList().sendPacketToAllPlayers(new SPacketPlayerListItem(SPacketPlayerListItem.Action.UPDATE_GAME_MODE, new EntityPlayerMP[] {this.player}));
this.world.updateAllPlayersSleepingFlag();
}
public GameType getGameType()
{
return this.gameType;
}
public boolean survivalOrAdventure()
{
return this.gameType.isSurvivalOrAdventure();
}
/**
* Get if we are in creative game mode.
*/
public boolean isCreative()
{
return this.gameType.isCreative();
}
/**
* if the gameType is currently NOT_SET then change it to par1
*/
public void initializeGameType(GameType type)
{
if (this.gameType == GameType.NOT_SET)
{
this.gameType = type;
}
this.setGameType(this.gameType);
}
public void updateBlockRemoving()
{
++this.curblockDamage;
if (this.receivedFinishDiggingPacket)
{
int i = this.curblockDamage - this.initialBlockDamage;
IBlockState iblockstate = this.world.getBlockState(this.delayedDestroyPos);
if (iblockstate.getBlock().isAir(iblockstate, world, delayedDestroyPos))
{
this.receivedFinishDiggingPacket = false;
}
else
{
float f = iblockstate.getPlayerRelativeBlockHardness(this.player, this.player.world, this.delayedDestroyPos) * (float)(i + 1);
int j = (int)(f * 10.0F);
if (j != this.durabilityRemainingOnBlock)
{
this.world.sendBlockBreakProgress(this.player.getEntityId(), this.delayedDestroyPos, j);
this.durabilityRemainingOnBlock = j;
}
if (f >= 1.0F)
{
this.receivedFinishDiggingPacket = false;
this.tryHarvestBlock(this.delayedDestroyPos);
}
}
}
else if (this.isDestroyingBlock)
{
IBlockState iblockstate1 = this.world.getBlockState(this.destroyPos);
if (iblockstate1.getBlock().isAir(iblockstate1, world, destroyPos))
{
this.world.sendBlockBreakProgress(this.player.getEntityId(), this.destroyPos, -1);
this.durabilityRemainingOnBlock = -1;
this.isDestroyingBlock = false;
}
else
{
int k = this.curblockDamage - this.initialDamage;
float f1 = iblockstate1.getPlayerRelativeBlockHardness(this.player, this.player.world, this.destroyPos) * (float)(k + 1); // Forge: Fix network break progress using wrong position
int l = (int)(f1 * 10.0F);
if (l != this.durabilityRemainingOnBlock)
{
this.world.sendBlockBreakProgress(this.player.getEntityId(), this.destroyPos, l);
this.durabilityRemainingOnBlock = l;
}
}
}
}
/**
* If not creative, it calls sendBlockBreakProgress until the block is broken first. tryHarvestBlock can also be the
* result of this call.
*/
public void onBlockClicked(BlockPos pos, EnumFacing side)
{
double reachDist = player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(player, pos, side, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(player, reachDist + 1));
if (event.isCanceled())
{
// Restore block and te data
player.connection.sendPacket(new SPacketBlockChange(world, pos));
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
return;
}
if (this.isCreative())
{
if (!this.world.extinguishFire((EntityPlayer)null, pos, side))
{
this.tryHarvestBlock(pos);
}
}
else
{
IBlockState iblockstate = this.world.getBlockState(pos);
Block block = iblockstate.getBlock();
if (this.gameType.hasLimitedInteractions())
{
if (this.gameType == GameType.SPECTATOR)
{
return;
}
if (!this.player.isAllowEdit())
{
ItemStack itemstack = this.player.getHeldItemMainhand();
if (itemstack.isEmpty())
{
return;
}
if (!itemstack.canDestroy(block))
{
return;
}
}
}
this.initialDamage = this.curblockDamage;
float f = 1.0F;
if (!iblockstate.getBlock().isAir(iblockstate, world, pos))
{
if (event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
{
block.onBlockClicked(this.world, pos, this.player);
this.world.extinguishFire((EntityPlayer)null, pos, side);
}
else
{
// Restore block and te data
player.connection.sendPacket(new SPacketBlockChange(world, pos));
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
}
f = iblockstate.getPlayerRelativeBlockHardness(this.player, this.player.world, pos);
}
if (event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
{
if (f >= 1.0F)
{
// Restore block and te data
player.connection.sendPacket(new SPacketBlockChange(world, pos));
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
}
return;
}
if (!iblockstate.getBlock().isAir(iblockstate, world, pos) && f >= 1.0F)
{
this.tryHarvestBlock(pos);
}
else
{
this.isDestroyingBlock = true;
this.destroyPos = pos;
int i = (int)(f * 10.0F);
this.world.sendBlockBreakProgress(this.player.getEntityId(), pos, i);
this.durabilityRemainingOnBlock = i;
}
}
}
public void blockRemoving(BlockPos pos)
{
if (pos.equals(this.destroyPos))
{
int i = this.curblockDamage - this.initialDamage;
IBlockState iblockstate = this.world.getBlockState(pos);
if (!iblockstate.getBlock().isAir(iblockstate, world, pos))
{
float f = iblockstate.getPlayerRelativeBlockHardness(this.player, this.player.world, pos) * (float)(i + 1);
if (f >= 0.7F)
{
this.isDestroyingBlock = false;
this.world.sendBlockBreakProgress(this.player.getEntityId(), pos, -1);
this.tryHarvestBlock(pos);
}
else if (!this.receivedFinishDiggingPacket)
{
this.isDestroyingBlock = false;
this.receivedFinishDiggingPacket = true;
this.delayedDestroyPos = pos;
this.initialBlockDamage = this.initialDamage;
}
}
}
}
/**
* Stops the block breaking process
*/
public void cancelDestroyingBlock()
{
this.isDestroyingBlock = false;
this.world.sendBlockBreakProgress(this.player.getEntityId(), this.destroyPos, -1);
}
/**
* Removes a block and triggers the appropriate events
*/
private boolean removeBlock(BlockPos pos)
{
return removeBlock(pos, false);
}
private boolean removeBlock(BlockPos pos, boolean canHarvest)
{
IBlockState iblockstate = this.world.getBlockState(pos);
boolean flag = iblockstate.getBlock().removedByPlayer(iblockstate, world, pos, player, canHarvest);
if (flag)
{
iblockstate.getBlock().onBlockDestroyedByPlayer(this.world, pos, iblockstate);
}
return flag;
}
/**
* Attempts to harvest a block
*/
public boolean tryHarvestBlock(BlockPos pos)
{
int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
if (exp == -1)
{
return false;
}
else
{
IBlockState iblockstate = this.world.getBlockState(pos);
TileEntity tileentity = this.world.getTileEntity(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.player.canUseCommandBlock())
{
this.world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
return false;
}
else
{
ItemStack stack = player.getHeldItemMainhand();
if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;
this.world.playEvent(this.player, 2001, pos, Block.getStateId(iblockstate));
boolean flag1 = false;
if (this.isCreative())
{
flag1 = this.removeBlock(pos);
this.player.connection.sendPacket(new SPacketBlockChange(this.world, pos));
}
else
{
ItemStack itemstack1 = this.player.getHeldItemMainhand();
ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
boolean flag = iblockstate.getBlock().canHarvestBlock(world, pos, player);
if (!itemstack1.isEmpty())
{
itemstack1.onBlockDestroyed(this.world, iblockstate, pos, this.player);
if (itemstack1.isEmpty()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.player, itemstack2, EnumHand.MAIN_HAND);
}
flag1 = this.removeBlock(pos, flag);
if (flag1 && flag)
{
iblockstate.getBlock().harvestBlock(this.world, this.player, pos, iblockstate, tileentity, itemstack2);
}
}
// Drop experience
if (!this.isCreative() && flag1 && exp > 0)
{
iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
}
return flag1;
}
}
}
public EnumActionResult processRightClick(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand)
{
if (this.gameType == GameType.SPECTATOR)
{
return EnumActionResult.PASS;
}
else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
{
return EnumActionResult.PASS;
}
else
{
EnumActionResult cancelResult = net.minecraftforge.common.ForgeHooks.onItemRightClick(player, hand);
if (cancelResult != null) return cancelResult;
int i = stack.getCount();
int j = stack.getMetadata();
ItemStack copyBeforeUse = stack.copy();
ActionResult<ItemStack> actionresult = stack.useItemRightClick(worldIn, player, hand);
ItemStack itemstack = actionresult.getResult();
if (itemstack == stack && itemstack.getCount() == i && itemstack.getMaxItemUseDuration() <= 0 && itemstack.getMetadata() == j)
{
return actionresult.getType();
}
else if (actionresult.getType() == EnumActionResult.FAIL && itemstack.getMaxItemUseDuration() > 0 && !player.isHandActive())
{
return actionresult.getType();
}
else
{
player.setHeldItem(hand, itemstack);
if (this.isCreative())
{
itemstack.setCount(i);
if (itemstack.isItemStackDamageable())
{
itemstack.setItemDamage(j);
}
}
if (itemstack.isEmpty())
{
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, hand);
player.setHeldItem(hand, ItemStack.EMPTY);
}
if (!player.isHandActive())
{
((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
}
return actionresult.getType();
}
}
}
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (this.gameType == GameType.SPECTATOR)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof ILockableContainer)
{
Block block1 = worldIn.getBlockState(pos).getBlock();
ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;
if (ilockablecontainer instanceof TileEntityChest && block1 instanceof BlockChest)
{
ilockablecontainer = ((BlockChest)block1).getLockableContainer(worldIn, pos);
}
if (ilockablecontainer != null)
{
player.displayGUIChest(ilockablecontainer);
return EnumActionResult.SUCCESS;
}
}
else if (tileentity instanceof IInventory)
{
player.displayGUIChest((IInventory)tileentity);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
else
{
double reachDist = player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = net.minecraftforge.common.ForgeHooks
.onRightClickBlock(player, hand, pos, facing, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(player, reachDist + 1));
if (event.isCanceled()) return event.getCancellationResult();
EnumActionResult result = EnumActionResult.PASS;
if (event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
{
result = stack.onItemUseFirst(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
if (result != EnumActionResult.PASS) return result ;
}
boolean bypass = player.getHeldItemMainhand().doesSneakBypassUse(worldIn, pos, player) && player.getHeldItemOffhand().doesSneakBypassUse(worldIn, pos, player);
if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ))
{
result = EnumActionResult.SUCCESS;
}
}
if (stack.isEmpty())
{
return EnumActionResult.PASS;
}
else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
{
return EnumActionResult.PASS;
}
else
{
if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
{
Block block = ((ItemBlock)stack.getItem()).getBlock();
if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
{
return EnumActionResult.FAIL;
}
}
if (this.isCreative())
{
int j = stack.getMetadata();
int i = stack.getCount();
if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|| result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
stack.setItemDamage(j);
stack.setCount(i);
return enumactionresult;
} else return result;
}
else
{
if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|| result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
ItemStack copyBeforeUse = stack.copy();
result = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
if (stack.isEmpty()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, hand);
} return result;
}
}
}
}
/**
* Sets the world instance.
*/
public void setWorld(WorldServer serverWorld)
{
this.world = serverWorld;
}
@Deprecated // use the attribute directly
public double getBlockReachDistance()
{
return player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
}
@Deprecated // use an attribute modifier
public void setBlockReachDistance(double distance)
{
player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).setBaseValue(distance);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,425 @@
package net.minecraft.server.management;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.ProfileLookupCallback;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Deque;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.JsonUtils;
import org.apache.commons.io.IOUtils;
public class PlayerProfileCache
{
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
private static boolean onlineMode;
/** A map between player usernames and {@link ProfileEntry profile entries} */
private final Map<String, PlayerProfileCache.ProfileEntry> usernameToProfileEntryMap = Maps.<String, PlayerProfileCache.ProfileEntry>newHashMap();
/** A map between {@link UUID UUID's} and {@link ProfileEntry ProfileEntries} */
private final Map<UUID, PlayerProfileCache.ProfileEntry> uuidToProfileEntryMap = Maps.<UUID, PlayerProfileCache.ProfileEntry>newHashMap();
/** A list of all the cached {@link GameProfile GameProfiles} */
private final Deque<GameProfile> gameProfiles = Lists.<GameProfile>newLinkedList();
private final GameProfileRepository profileRepo;
protected final Gson gson;
private final File usercacheFile;
private static final ParameterizedType TYPE = new ParameterizedType()
{
public Type[] getActualTypeArguments()
{
return new Type[] {PlayerProfileCache.ProfileEntry.class};
}
public Type getRawType()
{
return List.class;
}
public Type getOwnerType()
{
return null;
}
};
public PlayerProfileCache(GameProfileRepository profileRepoIn, File usercacheFileIn)
{
this.profileRepo = profileRepoIn;
this.usercacheFile = usercacheFileIn;
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeHierarchyAdapter(PlayerProfileCache.ProfileEntry.class, new PlayerProfileCache.Serializer());
this.gson = gsonbuilder.create();
this.load();
}
private static GameProfile lookupProfile(GameProfileRepository profileRepoIn, String name)
{
final GameProfile[] agameprofile = new GameProfile[1];
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback()
{
public void onProfileLookupSucceeded(GameProfile p_onProfileLookupSucceeded_1_)
{
agameprofile[0] = p_onProfileLookupSucceeded_1_;
}
public void onProfileLookupFailed(GameProfile p_onProfileLookupFailed_1_, Exception p_onProfileLookupFailed_2_)
{
agameprofile[0] = null;
}
};
profileRepoIn.findProfilesByNames(new String[] {name}, Agent.MINECRAFT, profilelookupcallback);
if (!isOnlineMode() && agameprofile[0] == null)
{
UUID uuid = EntityPlayer.getUUID(new GameProfile((UUID)null, name));
GameProfile gameprofile = new GameProfile(uuid, name);
profilelookupcallback.onProfileLookupSucceeded(gameprofile);
}
return agameprofile[0];
}
public static void setOnlineMode(boolean onlineModeIn)
{
onlineMode = onlineModeIn;
}
private static boolean isOnlineMode()
{
return onlineMode;
}
/**
* Add an entry to this cache
*/
public void addEntry(GameProfile gameProfile)
{
this.addEntry(gameProfile, (Date)null);
}
/**
* Add an entry to this cache
*/
private void addEntry(GameProfile gameProfile, Date expirationDate)
{
UUID uuid = gameProfile.getId();
if (expirationDate == null)
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(2, 1);
expirationDate = calendar.getTime();
}
String s = gameProfile.getName().toLowerCase(Locale.ROOT);
PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = new PlayerProfileCache.ProfileEntry(gameProfile, expirationDate);
if (this.uuidToProfileEntryMap.containsKey(uuid))
{
PlayerProfileCache.ProfileEntry playerprofilecache$profileentry1 = this.uuidToProfileEntryMap.get(uuid);
this.usernameToProfileEntryMap.remove(playerprofilecache$profileentry1.getGameProfile().getName().toLowerCase(Locale.ROOT));
this.gameProfiles.remove(gameProfile);
}
this.usernameToProfileEntryMap.put(gameProfile.getName().toLowerCase(Locale.ROOT), playerprofilecache$profileentry);
this.uuidToProfileEntryMap.put(uuid, playerprofilecache$profileentry);
this.gameProfiles.addFirst(gameProfile);
this.save();
}
/**
* Get a player's GameProfile given their username. Mojang's server's will be contacted if the entry is not cached
* locally.
*/
@Nullable
public GameProfile getGameProfileForUsername(String username)
{
String s = username.toLowerCase(Locale.ROOT);
PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.usernameToProfileEntryMap.get(s);
if (playerprofilecache$profileentry != null && (new Date()).getTime() >= playerprofilecache$profileentry.expirationDate.getTime())
{
this.uuidToProfileEntryMap.remove(playerprofilecache$profileentry.getGameProfile().getId());
this.usernameToProfileEntryMap.remove(playerprofilecache$profileentry.getGameProfile().getName().toLowerCase(Locale.ROOT));
this.gameProfiles.remove(playerprofilecache$profileentry.getGameProfile());
playerprofilecache$profileentry = null;
}
if (playerprofilecache$profileentry != null)
{
GameProfile gameprofile = playerprofilecache$profileentry.getGameProfile();
this.gameProfiles.remove(gameprofile);
this.gameProfiles.addFirst(gameprofile);
}
else
{
GameProfile gameprofile1 = lookupProfile(this.profileRepo, s);
if (gameprofile1 != null)
{
this.addEntry(gameprofile1);
playerprofilecache$profileentry = this.usernameToProfileEntryMap.get(s);
}
}
this.save();
return playerprofilecache$profileentry == null ? null : playerprofilecache$profileentry.getGameProfile();
}
/**
* Get an array of the usernames that are cached in this cache
*/
public String[] getUsernames()
{
List<String> list = Lists.newArrayList(this.usernameToProfileEntryMap.keySet());
return (String[])list.toArray(new String[list.size()]);
}
/**
* Get a player's {@link GameProfile} given their UUID
*/
@Nullable
public GameProfile getProfileByUUID(UUID uuid)
{
PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.uuidToProfileEntryMap.get(uuid);
return playerprofilecache$profileentry == null ? null : playerprofilecache$profileentry.getGameProfile();
}
/**
* Get a {@link ProfileEntry} by UUID
*/
private PlayerProfileCache.ProfileEntry getByUUID(UUID uuid)
{
PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.uuidToProfileEntryMap.get(uuid);
if (playerprofilecache$profileentry != null)
{
GameProfile gameprofile = playerprofilecache$profileentry.getGameProfile();
this.gameProfiles.remove(gameprofile);
this.gameProfiles.addFirst(gameprofile);
}
return playerprofilecache$profileentry;
}
/**
* Load the cached profiles from disk
*/
public void load()
{
BufferedReader bufferedreader = null;
try
{
bufferedreader = Files.newReader(this.usercacheFile, StandardCharsets.UTF_8);
List<PlayerProfileCache.ProfileEntry> list = (List)JsonUtils.fromJson(this.gson, bufferedreader, TYPE);
this.usernameToProfileEntryMap.clear();
this.uuidToProfileEntryMap.clear();
this.gameProfiles.clear();
if (list != null)
{
for (PlayerProfileCache.ProfileEntry playerprofilecache$profileentry : Lists.reverse(list))
{
if (playerprofilecache$profileentry != null)
{
this.addEntry(playerprofilecache$profileentry.getGameProfile(), playerprofilecache$profileentry.getExpirationDate());
}
}
}
}
catch (FileNotFoundException var9)
{
;
}
catch (JsonParseException var10)
{
;
}
finally
{
IOUtils.closeQuietly((Reader)bufferedreader);
}
}
/**
* Save the cached profiles to disk
*/
public void save()
{
String s = this.gson.toJson(this.getEntriesWithLimit(1000));
BufferedWriter bufferedwriter = null;
try
{
bufferedwriter = Files.newWriter(this.usercacheFile, StandardCharsets.UTF_8);
bufferedwriter.write(s);
return;
}
catch (FileNotFoundException var8)
{
;
}
catch (IOException var9)
{
return;
}
finally
{
IOUtils.closeQuietly((Writer)bufferedwriter);
}
}
/**
* Get the {@link PlayerProfileCache.ProfileEntry entries} of this cache with a given limit
*/
private List<PlayerProfileCache.ProfileEntry> getEntriesWithLimit(int limitSize)
{
List<PlayerProfileCache.ProfileEntry> list = Lists.<PlayerProfileCache.ProfileEntry>newArrayList();
for (GameProfile gameprofile : Lists.newArrayList(Iterators.limit(this.gameProfiles.iterator(), limitSize)))
{
PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.getByUUID(gameprofile.getId());
if (playerprofilecache$profileentry != null)
{
list.add(playerprofilecache$profileentry);
}
}
return list;
}
class ProfileEntry
{
/** The player's GameProfile */
private final GameProfile gameProfile;
/** The date that this entry will expire */
private final Date expirationDate;
private ProfileEntry(GameProfile gameProfileIn, Date expirationDateIn)
{
this.gameProfile = gameProfileIn;
this.expirationDate = expirationDateIn;
}
/**
* Get the player's GameProfile
*/
public GameProfile getGameProfile()
{
return this.gameProfile;
}
/**
* Get the date that this entry will expire
*/
public Date getExpirationDate()
{
return this.expirationDate;
}
}
class Serializer implements JsonDeserializer<PlayerProfileCache.ProfileEntry>, JsonSerializer<PlayerProfileCache.ProfileEntry>
{
private Serializer()
{
}
public JsonElement serialize(PlayerProfileCache.ProfileEntry p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
JsonObject jsonobject = new JsonObject();
jsonobject.addProperty("name", p_serialize_1_.getGameProfile().getName());
UUID uuid = p_serialize_1_.getGameProfile().getId();
jsonobject.addProperty("uuid", uuid == null ? "" : uuid.toString());
jsonobject.addProperty("expiresOn", PlayerProfileCache.DATE_FORMAT.format(p_serialize_1_.getExpirationDate()));
return jsonobject;
}
public PlayerProfileCache.ProfileEntry deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
if (p_deserialize_1_.isJsonObject())
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
JsonElement jsonelement = jsonobject.get("name");
JsonElement jsonelement1 = jsonobject.get("uuid");
JsonElement jsonelement2 = jsonobject.get("expiresOn");
if (jsonelement != null && jsonelement1 != null)
{
String s = jsonelement1.getAsString();
String s1 = jsonelement.getAsString();
Date date = null;
if (jsonelement2 != null)
{
try
{
date = PlayerProfileCache.DATE_FORMAT.parse(jsonelement2.getAsString());
}
catch (ParseException var14)
{
date = null;
}
}
if (s1 != null && s != null)
{
UUID uuid;
try
{
uuid = UUID.fromString(s);
}
catch (Throwable var13)
{
return null;
}
return PlayerProfileCache.this.new ProfileEntry(new GameProfile(uuid, s1), date);
}
else
{
return null;
}
}
else
{
return null;
}
}
else
{
return null;
}
}
}
}

View File

@@ -0,0 +1,633 @@
package net.minecraft.server.management;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.yggdrasil.ProfileNotFoundException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.dedicated.PropertyManager;
import net.minecraft.util.StringUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class PreYggdrasilConverter
{
private static final Logger LOGGER = LogManager.getLogger();
public static final File OLD_IPBAN_FILE = new File("banned-ips.txt");
public static final File OLD_PLAYERBAN_FILE = new File("banned-players.txt");
public static final File OLD_OPS_FILE = new File("ops.txt");
public static final File OLD_WHITELIST_FILE = new File("white-list.txt");
private static void lookupNames(MinecraftServer server, Collection<String> names, ProfileLookupCallback callback)
{
String[] astring = (String[])Iterators.toArray(Iterators.filter(names.iterator(), new Predicate<String>()
{
public boolean apply(@Nullable String p_apply_1_)
{
return !StringUtils.isNullOrEmpty(p_apply_1_);
}
}), String.class);
if (server.isServerInOnlineMode())
{
server.getGameProfileRepository().findProfilesByNames(astring, Agent.MINECRAFT, callback);
}
else
{
for (String s : astring)
{
UUID uuid = EntityPlayer.getUUID(new GameProfile((UUID)null, s));
GameProfile gameprofile = new GameProfile(uuid, s);
callback.onProfileLookupSucceeded(gameprofile);
}
}
}
public static String convertMobOwnerIfNeeded(final MinecraftServer server, String username)
{
if (!StringUtils.isNullOrEmpty(username) && username.length() <= 16)
{
GameProfile gameprofile = server.getPlayerProfileCache().getGameProfileForUsername(username);
if (gameprofile != null && gameprofile.getId() != null)
{
return gameprofile.getId().toString();
}
else if (!server.isSinglePlayer() && server.isServerInOnlineMode())
{
final List<GameProfile> list = Lists.<GameProfile>newArrayList();
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback()
{
public void onProfileLookupSucceeded(GameProfile p_onProfileLookupSucceeded_1_)
{
server.getPlayerProfileCache().addEntry(p_onProfileLookupSucceeded_1_);
list.add(p_onProfileLookupSucceeded_1_);
}
public void onProfileLookupFailed(GameProfile p_onProfileLookupFailed_1_, Exception p_onProfileLookupFailed_2_)
{
PreYggdrasilConverter.LOGGER.warn("Could not lookup user whitelist entry for {}", p_onProfileLookupFailed_1_.getName(), p_onProfileLookupFailed_2_);
}
};
lookupNames(server, Lists.newArrayList(username), profilelookupcallback);
return !list.isEmpty() && ((GameProfile)list.get(0)).getId() != null ? ((GameProfile)list.get(0)).getId().toString() : "";
}
else
{
return EntityPlayer.getUUID(new GameProfile((UUID)null, username)).toString();
}
}
else
{
return username;
}
}
@SideOnly(Side.SERVER)
static List<String> readFile(File inFile, Map<String, String[]> read) throws IOException
{
List<String> list = Files.readLines(inFile, StandardCharsets.UTF_8);
for (String s : list)
{
s = s.trim();
if (!s.startsWith("#") && s.length() >= 1)
{
String[] astring = s.split("\\|");
read.put(astring[0].toLowerCase(Locale.ROOT), astring);
}
}
return list;
}
@SideOnly(Side.SERVER)
public static boolean convertUserBanlist(final MinecraftServer server) throws IOException
{
final UserListBans userlistbans = new UserListBans(PlayerList.FILE_PLAYERBANS);
if (OLD_PLAYERBAN_FILE.exists() && OLD_PLAYERBAN_FILE.isFile())
{
if (userlistbans.getSaveFile().exists())
{
try
{
userlistbans.readSavedFile();
}
catch (FileNotFoundException filenotfoundexception)
{
LOGGER.warn("Could not load existing file {}", userlistbans.getSaveFile().getName(), filenotfoundexception);
}
}
try
{
final Map<String, String[]> map = Maps.<String, String[]>newHashMap();
readFile(OLD_PLAYERBAN_FILE, map);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback()
{
public void onProfileLookupSucceeded(GameProfile p_onProfileLookupSucceeded_1_)
{
server.getPlayerProfileCache().addEntry(p_onProfileLookupSucceeded_1_);
String[] astring = map.get(p_onProfileLookupSucceeded_1_.getName().toLowerCase(Locale.ROOT));
if (astring == null)
{
PreYggdrasilConverter.LOGGER.warn("Could not convert user banlist entry for {}", (Object)p_onProfileLookupSucceeded_1_.getName());
throw new PreYggdrasilConverter.ConversionError("Profile not in the conversionlist");
}
else
{
Date date = astring.length > 1 ? PreYggdrasilConverter.parseDate(astring[1], (Date)null) : null;
String s = astring.length > 2 ? astring[2] : null;
Date date1 = astring.length > 3 ? PreYggdrasilConverter.parseDate(astring[3], (Date)null) : null;
String s1 = astring.length > 4 ? astring[4] : null;
userlistbans.addEntry(new UserListBansEntry(p_onProfileLookupSucceeded_1_, date, s, date1, s1));
}
}
public void onProfileLookupFailed(GameProfile p_onProfileLookupFailed_1_, Exception p_onProfileLookupFailed_2_)
{
PreYggdrasilConverter.LOGGER.warn("Could not lookup user banlist entry for {}", p_onProfileLookupFailed_1_.getName(), p_onProfileLookupFailed_2_);
if (!(p_onProfileLookupFailed_2_ instanceof ProfileNotFoundException))
{
throw new PreYggdrasilConverter.ConversionError("Could not request user " + p_onProfileLookupFailed_1_.getName() + " from backend systems", p_onProfileLookupFailed_2_);
}
}
};
lookupNames(server, map.keySet(), profilelookupcallback);
userlistbans.writeChanges();
backupConverted(OLD_PLAYERBAN_FILE);
return true;
}
catch (IOException ioexception)
{
LOGGER.warn("Could not read old user banlist to convert it!", (Throwable)ioexception);
return false;
}
catch (PreYggdrasilConverter.ConversionError preyggdrasilconverter$conversionerror)
{
LOGGER.error("Conversion failed, please try again later", (Throwable)preyggdrasilconverter$conversionerror);
return false;
}
}
else
{
return true;
}
}
@SideOnly(Side.SERVER)
public static boolean convertIpBanlist(MinecraftServer server) throws IOException
{
UserListIPBans userlistipbans = new UserListIPBans(PlayerList.FILE_IPBANS);
if (OLD_IPBAN_FILE.exists() && OLD_IPBAN_FILE.isFile())
{
if (userlistipbans.getSaveFile().exists())
{
try
{
userlistipbans.readSavedFile();
}
catch (FileNotFoundException filenotfoundexception)
{
LOGGER.warn("Could not load existing file {}", userlistipbans.getSaveFile().getName(), filenotfoundexception);
}
}
try
{
Map<String, String[]> map = Maps.<String, String[]>newHashMap();
readFile(OLD_IPBAN_FILE, map);
for (String s : map.keySet())
{
String[] astring = map.get(s);
Date date = astring.length > 1 ? parseDate(astring[1], (Date)null) : null;
String s1 = astring.length > 2 ? astring[2] : null;
Date date1 = astring.length > 3 ? parseDate(astring[3], (Date)null) : null;
String s2 = astring.length > 4 ? astring[4] : null;
userlistipbans.addEntry(new UserListIPBansEntry(s, date, s1, date1, s2));
}
userlistipbans.writeChanges();
backupConverted(OLD_IPBAN_FILE);
return true;
}
catch (IOException ioexception)
{
LOGGER.warn("Could not parse old ip banlist to convert it!", (Throwable)ioexception);
return false;
}
}
else
{
return true;
}
}
@SideOnly(Side.SERVER)
public static boolean convertOplist(final MinecraftServer server) throws IOException
{
final UserListOps userlistops = new UserListOps(PlayerList.FILE_OPS);
if (OLD_OPS_FILE.exists() && OLD_OPS_FILE.isFile())
{
if (userlistops.getSaveFile().exists())
{
try
{
userlistops.readSavedFile();
}
catch (FileNotFoundException filenotfoundexception)
{
LOGGER.warn("Could not load existing file {}", userlistops.getSaveFile().getName(), filenotfoundexception);
}
}
try
{
List<String> list = Files.readLines(OLD_OPS_FILE, StandardCharsets.UTF_8);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback()
{
public void onProfileLookupSucceeded(GameProfile p_onProfileLookupSucceeded_1_)
{
server.getPlayerProfileCache().addEntry(p_onProfileLookupSucceeded_1_);
userlistops.addEntry(new UserListOpsEntry(p_onProfileLookupSucceeded_1_, server.getOpPermissionLevel(), false));
}
public void onProfileLookupFailed(GameProfile p_onProfileLookupFailed_1_, Exception p_onProfileLookupFailed_2_)
{
PreYggdrasilConverter.LOGGER.warn("Could not lookup oplist entry for {}", p_onProfileLookupFailed_1_.getName(), p_onProfileLookupFailed_2_);
if (!(p_onProfileLookupFailed_2_ instanceof ProfileNotFoundException))
{
throw new PreYggdrasilConverter.ConversionError("Could not request user " + p_onProfileLookupFailed_1_.getName() + " from backend systems", p_onProfileLookupFailed_2_);
}
}
};
lookupNames(server, list, profilelookupcallback);
userlistops.writeChanges();
backupConverted(OLD_OPS_FILE);
return true;
}
catch (IOException ioexception)
{
LOGGER.warn("Could not read old oplist to convert it!", (Throwable)ioexception);
return false;
}
catch (PreYggdrasilConverter.ConversionError preyggdrasilconverter$conversionerror)
{
LOGGER.error("Conversion failed, please try again later", (Throwable)preyggdrasilconverter$conversionerror);
return false;
}
}
else
{
return true;
}
}
@SideOnly(Side.SERVER)
public static boolean convertWhitelist(final MinecraftServer server) throws IOException
{
final UserListWhitelist userlistwhitelist = new UserListWhitelist(PlayerList.FILE_WHITELIST);
if (OLD_WHITELIST_FILE.exists() && OLD_WHITELIST_FILE.isFile())
{
if (userlistwhitelist.getSaveFile().exists())
{
try
{
userlistwhitelist.readSavedFile();
}
catch (FileNotFoundException filenotfoundexception)
{
LOGGER.warn("Could not load existing file {}", userlistwhitelist.getSaveFile().getName(), filenotfoundexception);
}
}
try
{
List<String> list = Files.readLines(OLD_WHITELIST_FILE, StandardCharsets.UTF_8);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback()
{
public void onProfileLookupSucceeded(GameProfile p_onProfileLookupSucceeded_1_)
{
server.getPlayerProfileCache().addEntry(p_onProfileLookupSucceeded_1_);
userlistwhitelist.addEntry(new UserListWhitelistEntry(p_onProfileLookupSucceeded_1_));
}
public void onProfileLookupFailed(GameProfile p_onProfileLookupFailed_1_, Exception p_onProfileLookupFailed_2_)
{
PreYggdrasilConverter.LOGGER.warn("Could not lookup user whitelist entry for {}", p_onProfileLookupFailed_1_.getName(), p_onProfileLookupFailed_2_);
if (!(p_onProfileLookupFailed_2_ instanceof ProfileNotFoundException))
{
throw new PreYggdrasilConverter.ConversionError("Could not request user " + p_onProfileLookupFailed_1_.getName() + " from backend systems", p_onProfileLookupFailed_2_);
}
}
};
lookupNames(server, list, profilelookupcallback);
userlistwhitelist.writeChanges();
backupConverted(OLD_WHITELIST_FILE);
return true;
}
catch (IOException ioexception)
{
LOGGER.warn("Could not read old whitelist to convert it!", (Throwable)ioexception);
return false;
}
catch (PreYggdrasilConverter.ConversionError preyggdrasilconverter$conversionerror)
{
LOGGER.error("Conversion failed, please try again later", (Throwable)preyggdrasilconverter$conversionerror);
return false;
}
}
else
{
return true;
}
}
@SideOnly(Side.SERVER)
public static boolean convertSaveFiles(final DedicatedServer server, PropertyManager p_152723_1_)
{
final File file1 = getPlayersDirectory(p_152723_1_);
final File file2 = new File(file1.getParentFile(), "playerdata");
final File file3 = new File(file1.getParentFile(), "unknownplayers");
if (file1.exists() && file1.isDirectory())
{
File[] afile = file1.listFiles();
List<String> list = Lists.<String>newArrayList();
for (File file4 : afile)
{
String s = file4.getName();
if (s.toLowerCase(Locale.ROOT).endsWith(".dat"))
{
String s1 = s.substring(0, s.length() - ".dat".length());
if (!s1.isEmpty())
{
list.add(s1);
}
}
}
try
{
final String[] astring = (String[])list.toArray(new String[list.size()]);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback()
{
public void onProfileLookupSucceeded(GameProfile p_onProfileLookupSucceeded_1_)
{
server.getPlayerProfileCache().addEntry(p_onProfileLookupSucceeded_1_);
UUID uuid = p_onProfileLookupSucceeded_1_.getId();
if (uuid == null)
{
throw new PreYggdrasilConverter.ConversionError("Missing UUID for user profile " + p_onProfileLookupSucceeded_1_.getName());
}
else
{
this.renamePlayerFile(file2, this.getFileNameForProfile(p_onProfileLookupSucceeded_1_), uuid.toString());
}
}
public void onProfileLookupFailed(GameProfile p_onProfileLookupFailed_1_, Exception p_onProfileLookupFailed_2_)
{
PreYggdrasilConverter.LOGGER.warn("Could not lookup user uuid for {}", p_onProfileLookupFailed_1_.getName(), p_onProfileLookupFailed_2_);
if (p_onProfileLookupFailed_2_ instanceof ProfileNotFoundException)
{
String s2 = this.getFileNameForProfile(p_onProfileLookupFailed_1_);
this.renamePlayerFile(file3, s2, s2);
}
else
{
throw new PreYggdrasilConverter.ConversionError("Could not request user " + p_onProfileLookupFailed_1_.getName() + " from backend systems", p_onProfileLookupFailed_2_);
}
}
private void renamePlayerFile(File p_152743_1_, String p_152743_2_, String p_152743_3_)
{
File file5 = new File(file1, p_152743_2_ + ".dat");
File file6 = new File(p_152743_1_, p_152743_3_ + ".dat");
PreYggdrasilConverter.mkdir(p_152743_1_);
if (!file5.renameTo(file6))
{
throw new PreYggdrasilConverter.ConversionError("Could not convert file for " + p_152743_2_);
}
}
private String getFileNameForProfile(GameProfile p_152744_1_)
{
String s2 = null;
for (String s3 : astring)
{
if (s3 != null && s3.equalsIgnoreCase(p_152744_1_.getName()))
{
s2 = s3;
break;
}
}
if (s2 == null)
{
throw new PreYggdrasilConverter.ConversionError("Could not find the filename for " + p_152744_1_.getName() + " anymore");
}
else
{
return s2;
}
}
};
lookupNames(server, Lists.newArrayList(astring), profilelookupcallback);
return true;
}
catch (PreYggdrasilConverter.ConversionError preyggdrasilconverter$conversionerror)
{
LOGGER.error("Conversion failed, please try again later", (Throwable)preyggdrasilconverter$conversionerror);
return false;
}
}
else
{
return true;
}
}
@SideOnly(Side.SERVER)
private static void mkdir(File dir)
{
if (dir.exists())
{
if (!dir.isDirectory())
{
throw new PreYggdrasilConverter.ConversionError("Can't create directory " + dir.getName() + " in world save directory.");
}
}
else if (!dir.mkdirs())
{
throw new PreYggdrasilConverter.ConversionError("Can't create directory " + dir.getName() + " in world save directory.");
}
}
@SideOnly(Side.SERVER)
public static boolean tryConvert(PropertyManager properties)
{
boolean flag = hasUnconvertableFiles(properties);
flag = flag && hasUnconvertablePlayerFiles(properties);
return flag;
}
@SideOnly(Side.SERVER)
private static boolean hasUnconvertableFiles(PropertyManager properties)
{
boolean flag = false;
if (OLD_PLAYERBAN_FILE.exists() && OLD_PLAYERBAN_FILE.isFile())
{
flag = true;
}
boolean flag1 = false;
if (OLD_IPBAN_FILE.exists() && OLD_IPBAN_FILE.isFile())
{
flag1 = true;
}
boolean flag2 = false;
if (OLD_OPS_FILE.exists() && OLD_OPS_FILE.isFile())
{
flag2 = true;
}
boolean flag3 = false;
if (OLD_WHITELIST_FILE.exists() && OLD_WHITELIST_FILE.isFile())
{
flag3 = true;
}
if (!flag && !flag1 && !flag2 && !flag3)
{
return true;
}
else
{
LOGGER.warn("**** FAILED TO START THE SERVER AFTER ACCOUNT CONVERSION!");
LOGGER.warn("** please remove the following files and restart the server:");
if (flag)
{
LOGGER.warn("* {}", (Object)OLD_PLAYERBAN_FILE.getName());
}
if (flag1)
{
LOGGER.warn("* {}", (Object)OLD_IPBAN_FILE.getName());
}
if (flag2)
{
LOGGER.warn("* {}", (Object)OLD_OPS_FILE.getName());
}
if (flag3)
{
LOGGER.warn("* {}", (Object)OLD_WHITELIST_FILE.getName());
}
return false;
}
}
@SideOnly(Side.SERVER)
private static boolean hasUnconvertablePlayerFiles(PropertyManager properties)
{
File file1 = getPlayersDirectory(properties);
if (!file1.exists() || !file1.isDirectory() || file1.list().length <= 0 && file1.delete())
{
return true;
}
else
{
LOGGER.warn("**** DETECTED OLD PLAYER DIRECTORY IN THE WORLD SAVE");
LOGGER.warn("**** THIS USUALLY HAPPENS WHEN THE AUTOMATIC CONVERSION FAILED IN SOME WAY");
LOGGER.warn("** please restart the server and if the problem persists, remove the directory '{}'", (Object)file1.getPath());
return false;
}
}
@SideOnly(Side.SERVER)
private static File getPlayersDirectory(PropertyManager properties)
{
String s = properties.getStringProperty("level-name", "world");
File file1 = new File(s);
return new File(file1, "players");
}
@SideOnly(Side.SERVER)
private static void backupConverted(File convertedFile)
{
File file1 = new File(convertedFile.getName() + ".converted");
convertedFile.renameTo(file1);
}
@SideOnly(Side.SERVER)
private static Date parseDate(String input, Date defaultValue)
{
Date date;
try
{
date = UserListEntryBan.DATE_FORMAT.parse(input);
}
catch (ParseException var4)
{
date = defaultValue;
}
return date;
}
@SideOnly(Side.SERVER)
static class ConversionError extends RuntimeException
{
private ConversionError(String message, Throwable cause)
{
super(message, cause);
}
private ConversionError(String message)
{
super(message);
}
}
}

View File

@@ -0,0 +1,250 @@
package net.minecraft.server.management;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class UserList<K, V extends UserListEntry<K>>
{
protected static final Logger LOGGER = LogManager.getLogger();
protected final Gson gson;
private final File saveFile;
private final Map<String, V> values = Maps.<String, V>newHashMap();
private boolean lanServer = true;
private static final ParameterizedType USER_LIST_ENTRY_TYPE = new ParameterizedType()
{
public Type[] getActualTypeArguments()
{
return new Type[] {UserListEntry.class};
}
public Type getRawType()
{
return List.class;
}
public Type getOwnerType()
{
return null;
}
};
public UserList(File saveFile)
{
this.saveFile = saveFile;
GsonBuilder gsonbuilder = (new GsonBuilder()).setPrettyPrinting();
gsonbuilder.registerTypeHierarchyAdapter(UserListEntry.class, new UserList.Serializer());
this.gson = gsonbuilder.create();
}
public boolean isLanServer()
{
return this.lanServer;
}
public void setLanServer(boolean state)
{
this.lanServer = state;
}
/**
* Adds an entry to the list
*/
public void addEntry(V entry)
{
this.values.put(this.getObjectKey(entry.getValue()), entry);
try
{
this.writeChanges();
}
catch (IOException ioexception)
{
LOGGER.warn("Could not save the list after adding a user.", (Throwable)ioexception);
}
}
public V getEntry(K obj)
{
this.removeExpired();
return (V)(this.values.get(this.getObjectKey(obj)));
}
public void removeEntry(K entry)
{
this.values.remove(this.getObjectKey(entry));
try
{
this.writeChanges();
}
catch (IOException ioexception)
{
LOGGER.warn("Could not save the list after removing a user.", (Throwable)ioexception);
}
}
@SideOnly(Side.SERVER)
public File getSaveFile()
{
return this.saveFile;
}
public String[] getKeys()
{
return (String[])this.values.keySet().toArray(new String[this.values.size()]);
}
/**
* Gets the key value for the given object
*/
protected String getObjectKey(K obj)
{
return obj.toString();
}
protected boolean hasEntry(K entry)
{
return this.values.containsKey(this.getObjectKey(entry));
}
/**
* Removes expired bans from the list. See {@link BanEntry#hasBanExpired}
*/
private void removeExpired()
{
List<K> list = Lists.<K>newArrayList();
for (V v : this.values.values())
{
if (v.hasBanExpired())
{
list.add(v.getValue());
}
}
for (K k : list)
{
this.values.remove(k);
}
}
protected UserListEntry<K> createEntry(JsonObject entryData)
{
return new UserListEntry<K>(null, entryData);
}
protected Map<String, V> getValues()
{
return this.values;
}
public void writeChanges() throws IOException
{
Collection<V> collection = this.values.values();
String s = this.gson.toJson(collection);
BufferedWriter bufferedwriter = null;
try
{
bufferedwriter = Files.newWriter(this.saveFile, StandardCharsets.UTF_8);
bufferedwriter.write(s);
}
finally
{
IOUtils.closeQuietly((Writer)bufferedwriter);
}
}
@SideOnly(Side.SERVER)
public boolean isEmpty()
{
return this.values.size() < 1;
}
@SideOnly(Side.SERVER)
public void readSavedFile() throws IOException, FileNotFoundException
{
if (this.saveFile.exists())
{
Collection<UserListEntry<K>> collection = null;
BufferedReader bufferedreader = null;
try
{
bufferedreader = Files.newReader(this.saveFile, StandardCharsets.UTF_8);
collection = (Collection)JsonUtils.fromJson(this.gson, bufferedreader, USER_LIST_ENTRY_TYPE);
}
finally
{
IOUtils.closeQuietly((Reader)bufferedreader);
}
if (collection != null)
{
this.values.clear();
for (UserListEntry<K> userlistentry : collection)
{
if (userlistentry.getValue() != null)
{
this.values.put(this.getObjectKey(userlistentry.getValue()), (V)userlistentry);
}
}
}
}
}
class Serializer implements JsonDeserializer<UserListEntry<K>>, JsonSerializer<UserListEntry<K>>
{
private Serializer()
{
}
public JsonElement serialize(UserListEntry<K> p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
JsonObject jsonobject = new JsonObject();
p_serialize_1_.onSerialization(jsonobject);
return jsonobject;
}
public UserListEntry<K> deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
if (p_deserialize_1_.isJsonObject())
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
return UserList.this.createEntry(jsonobject);
}
else
{
return null;
}
}
}
}

View File

@@ -0,0 +1,61 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import java.io.File;
public class UserListBans extends UserList<GameProfile, UserListBansEntry>
{
public UserListBans(File bansFile)
{
super(bansFile);
}
protected UserListEntry<GameProfile> createEntry(JsonObject entryData)
{
return new UserListBansEntry(entryData);
}
public boolean isBanned(GameProfile profile)
{
return this.hasEntry(profile);
}
public String[] getKeys()
{
String[] astring = new String[this.getValues().size()];
int i = 0;
for (UserListBansEntry userlistbansentry : this.getValues().values())
{
astring[i++] = ((GameProfile)userlistbansentry.getValue()).getName();
}
return astring;
}
/**
* Gets the key value for the given object
*/
protected String getObjectKey(GameProfile obj)
{
return obj.getId().toString();
}
/**
* Get a {@link GameProfile} that is a member of this list by its user name. Returns {@code null} if no entry was
* found.
*/
public GameProfile getBannedProfile(String username)
{
for (UserListBansEntry userlistbansentry : this.getValues().values())
{
if (username.equalsIgnoreCase(((GameProfile)userlistbansentry.getValue()).getName()))
{
return (GameProfile)userlistbansentry.getValue();
}
}
return null;
}
}

View File

@@ -0,0 +1,62 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import java.util.Date;
import java.util.UUID;
public class UserListBansEntry extends UserListEntryBan<GameProfile>
{
public UserListBansEntry(GameProfile profile)
{
this(profile, (Date)null, (String)null, (Date)null, (String)null);
}
public UserListBansEntry(GameProfile profile, Date startDate, String banner, Date endDate, String banReason)
{
super(profile, endDate, banner, endDate, banReason);
}
public UserListBansEntry(JsonObject json)
{
super(toGameProfile(json), json);
}
protected void onSerialization(JsonObject data)
{
if (this.getValue() != null)
{
data.addProperty("uuid", ((GameProfile)this.getValue()).getId() == null ? "" : ((GameProfile)this.getValue()).getId().toString());
data.addProperty("name", ((GameProfile)this.getValue()).getName());
super.onSerialization(data);
}
}
/**
* Convert a {@linkplain com.google.gson.JsonObject JsonObject} into a {@linkplain com.mojang.authlib.GameProfile}.
* The json object must have {@code uuid} and {@code name} attributes or {@code null} will be returned.
*/
private static GameProfile toGameProfile(JsonObject json)
{
if (json.has("uuid") && json.has("name"))
{
String s = json.get("uuid").getAsString();
UUID uuid;
try
{
uuid = UUID.fromString(s);
}
catch (Throwable var4)
{
return null;
}
return new GameProfile(uuid, json.get("name").getAsString());
}
else
{
return null;
}
}
}

View File

@@ -0,0 +1,32 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
public class UserListEntry<T>
{
private final T value;
public UserListEntry(T valueIn)
{
this.value = valueIn;
}
protected UserListEntry(T valueIn, JsonObject json)
{
this.value = valueIn;
}
T getValue()
{
return this.value;
}
boolean hasBanExpired()
{
return false;
}
protected void onSerialization(JsonObject data)
{
}
}

View File

@@ -0,0 +1,78 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public abstract class UserListEntryBan<T> extends UserListEntry<T>
{
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
protected final Date banStartDate;
protected final String bannedBy;
protected final Date banEndDate;
protected final String reason;
public UserListEntryBan(T valueIn, Date startDate, String banner, Date endDate, String banReason)
{
super(valueIn);
this.banStartDate = startDate == null ? new Date() : startDate;
this.bannedBy = banner == null ? "(Unknown)" : banner;
this.banEndDate = endDate;
this.reason = banReason == null ? "Banned by an operator." : banReason;
}
protected UserListEntryBan(T valueIn, JsonObject json)
{
super(valueIn, json);
Date date;
try
{
date = json.has("created") ? DATE_FORMAT.parse(json.get("created").getAsString()) : new Date();
}
catch (ParseException var7)
{
date = new Date();
}
this.banStartDate = date;
this.bannedBy = json.has("source") ? json.get("source").getAsString() : "(Unknown)";
Date date1;
try
{
date1 = json.has("expires") ? DATE_FORMAT.parse(json.get("expires").getAsString()) : null;
}
catch (ParseException var6)
{
date1 = null;
}
this.banEndDate = date1;
this.reason = json.has("reason") ? json.get("reason").getAsString() : "Banned by an operator.";
}
public Date getBanEndDate()
{
return this.banEndDate;
}
public String getBanReason()
{
return this.reason;
}
boolean hasBanExpired()
{
return this.banEndDate == null ? false : this.banEndDate.before(new Date());
}
protected void onSerialization(JsonObject data)
{
data.addProperty("created", DATE_FORMAT.format(this.banStartDate));
data.addProperty("source", this.bannedBy);
data.addProperty("expires", this.banEndDate == null ? "forever" : DATE_FORMAT.format(this.banEndDate));
data.addProperty("reason", this.reason);
}
}

View File

@@ -0,0 +1,47 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import java.io.File;
import java.net.SocketAddress;
public class UserListIPBans extends UserList<String, UserListIPBansEntry>
{
public UserListIPBans(File bansFile)
{
super(bansFile);
}
protected UserListEntry<String> createEntry(JsonObject entryData)
{
return new UserListIPBansEntry(entryData);
}
public boolean isBanned(SocketAddress address)
{
String s = this.addressToString(address);
return this.hasEntry(s);
}
public UserListIPBansEntry getBanEntry(SocketAddress address)
{
String s = this.addressToString(address);
return (UserListIPBansEntry)this.getEntry(s);
}
private String addressToString(SocketAddress address)
{
String s = address.toString();
if (s.contains("/"))
{
s = s.substring(s.indexOf(47) + 1);
}
if (s.contains(":"))
{
s = s.substring(0, s.indexOf(58));
}
return s;
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import java.util.Date;
public class UserListIPBansEntry extends UserListEntryBan<String>
{
public UserListIPBansEntry(String valueIn)
{
this(valueIn, (Date)null, (String)null, (Date)null, (String)null);
}
public UserListIPBansEntry(String valueIn, Date startDate, String banner, Date endDate, String banReason)
{
super(valueIn, startDate, banner, endDate, banReason);
}
public UserListIPBansEntry(JsonObject json)
{
super(getIPFromJson(json), json);
}
private static String getIPFromJson(JsonObject json)
{
return json.has("ip") ? json.get("ip").getAsString() : null;
}
protected void onSerialization(JsonObject data)
{
if (this.getValue() != null)
{
data.addProperty("ip", (String)this.getValue());
super.onSerialization(data);
}
}
}

View File

@@ -0,0 +1,70 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import java.io.File;
public class UserListOps extends UserList<GameProfile, UserListOpsEntry>
{
public UserListOps(File saveFile)
{
super(saveFile);
}
protected UserListEntry<GameProfile> createEntry(JsonObject entryData)
{
return new UserListOpsEntry(entryData);
}
public String[] getKeys()
{
String[] astring = new String[this.getValues().size()];
int i = 0;
for (UserListOpsEntry userlistopsentry : this.getValues().values())
{
astring[i++] = ((GameProfile)userlistopsentry.getValue()).getName();
}
return astring;
}
/**
* Get the OP permission level this player has
*/
public int getPermissionLevel(GameProfile profile)
{
UserListOpsEntry userlistopsentry = (UserListOpsEntry)this.getEntry(profile);
return userlistopsentry != null ? userlistopsentry.getPermissionLevel() : 0;
}
public boolean bypassesPlayerLimit(GameProfile profile)
{
UserListOpsEntry userlistopsentry = (UserListOpsEntry)this.getEntry(profile);
return userlistopsentry != null ? userlistopsentry.bypassesPlayerLimit() : false;
}
/**
* Gets the key value for the given object
*/
protected String getObjectKey(GameProfile obj)
{
return obj.getId().toString();
}
/**
* Gets the GameProfile of based on the provided username.
*/
public GameProfile getGameProfileFromName(String username)
{
for (UserListOpsEntry userlistopsentry : this.getValues().values())
{
if (username.equalsIgnoreCase(((GameProfile)userlistopsentry.getValue()).getName()))
{
return (GameProfile)userlistopsentry.getValue();
}
}
return null;
}
}

View File

@@ -0,0 +1,74 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import java.util.UUID;
public class UserListOpsEntry extends UserListEntry<GameProfile>
{
private final int permissionLevel;
private final boolean bypassesPlayerLimit;
public UserListOpsEntry(GameProfile player, int permissionLevelIn, boolean bypassesPlayerLimitIn)
{
super(player);
this.permissionLevel = permissionLevelIn;
this.bypassesPlayerLimit = bypassesPlayerLimitIn;
}
public UserListOpsEntry(JsonObject p_i1150_1_)
{
super(constructProfile(p_i1150_1_), p_i1150_1_);
this.permissionLevel = p_i1150_1_.has("level") ? p_i1150_1_.get("level").getAsInt() : 0;
this.bypassesPlayerLimit = p_i1150_1_.has("bypassesPlayerLimit") && p_i1150_1_.get("bypassesPlayerLimit").getAsBoolean();
}
/**
* Gets the permission level of the user, as defined in the "level" attribute of the ops.json file
*/
public int getPermissionLevel()
{
return this.permissionLevel;
}
public boolean bypassesPlayerLimit()
{
return this.bypassesPlayerLimit;
}
protected void onSerialization(JsonObject data)
{
if (this.getValue() != null)
{
data.addProperty("uuid", ((GameProfile)this.getValue()).getId() == null ? "" : ((GameProfile)this.getValue()).getId().toString());
data.addProperty("name", ((GameProfile)this.getValue()).getName());
super.onSerialization(data);
data.addProperty("level", Integer.valueOf(this.permissionLevel));
data.addProperty("bypassesPlayerLimit", Boolean.valueOf(this.bypassesPlayerLimit));
}
}
private static GameProfile constructProfile(JsonObject p_152643_0_)
{
if (p_152643_0_.has("uuid") && p_152643_0_.has("name"))
{
String s = p_152643_0_.get("uuid").getAsString();
UUID uuid;
try
{
uuid = UUID.fromString(s);
}
catch (Throwable var4)
{
return null;
}
return new GameProfile(uuid, p_152643_0_.get("name").getAsString());
}
else
{
return null;
}
}
}

View File

@@ -0,0 +1,66 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import java.io.File;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class UserListWhitelist extends UserList<GameProfile, UserListWhitelistEntry>
{
public UserListWhitelist(File p_i1132_1_)
{
super(p_i1132_1_);
}
protected UserListEntry<GameProfile> createEntry(JsonObject entryData)
{
return new UserListWhitelistEntry(entryData);
}
public String[] getKeys()
{
String[] astring = new String[this.getValues().size()];
int i = 0;
for (UserListWhitelistEntry userlistwhitelistentry : this.getValues().values())
{
astring[i++] = ((GameProfile)userlistwhitelistentry.getValue()).getName();
}
return astring;
}
/**
* Returns true if the profile is in the whitelist.
*/
@SideOnly(Side.SERVER)
public boolean isWhitelisted(GameProfile profile)
{
return this.hasEntry(profile);
}
/**
* Gets the key value for the given object
*/
protected String getObjectKey(GameProfile obj)
{
return obj.getId().toString();
}
/**
* Get a GameProfile entry by its name
*/
public GameProfile getByName(String profileName)
{
for (UserListWhitelistEntry userlistwhitelistentry : this.getValues().values())
{
if (profileName.equalsIgnoreCase(((GameProfile)userlistwhitelistentry.getValue()).getName()))
{
return (GameProfile)userlistwhitelistentry.getValue();
}
}
return null;
}
}

View File

@@ -0,0 +1,52 @@
package net.minecraft.server.management;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import java.util.UUID;
public class UserListWhitelistEntry extends UserListEntry<GameProfile>
{
public UserListWhitelistEntry(GameProfile profile)
{
super(profile);
}
public UserListWhitelistEntry(JsonObject json)
{
super(gameProfileFromJsonObject(json), json);
}
protected void onSerialization(JsonObject data)
{
if (this.getValue() != null)
{
data.addProperty("uuid", ((GameProfile)this.getValue()).getId() == null ? "" : ((GameProfile)this.getValue()).getId().toString());
data.addProperty("name", ((GameProfile)this.getValue()).getName());
super.onSerialization(data);
}
}
private static GameProfile gameProfileFromJsonObject(JsonObject json)
{
if (json.has("uuid") && json.has("name"))
{
String s = json.get("uuid").getAsString();
UUID uuid;
try
{
uuid = UUID.fromString(s);
}
catch (Throwable var4)
{
return null;
}
return new GameProfile(uuid, json.get("name").getAsString());
}
else
{
return null;
}
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.server.management;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;