Revert "Changes for 1.13 compatibility"

This reverts commit 201c285091.
This commit is contained in:
AlexTheCoder 2018-06-14 01:36:54 -04:00
parent c72f6c00a7
commit 6fb86c264d
8 changed files with 74 additions and 93 deletions

View File

@ -31,39 +31,37 @@ import net.minecraft.server.v1_8_R3.WorldServer;
public class MultiBlockUpdaterAgent public class MultiBlockUpdaterAgent
{ {
private Map<Chunk, List<BlockVector>> _chunks = new HashMap<>(); private Map<Chunk, List<BlockVector>> _chunks = new HashMap<>();
/** /**
* Add a block to the list of blocks to send to the player. The agent supports blocks across different chunks and * Add a block to the list of blocks to send to the player. The agent supports blocks across different chunks and
* will not send duplicates. * will not send duplicates.
*
* @param block The block to send. The block is stored using a BlockVector, meaning that when the send method is called, it will use * @param block The block to send. The block is stored using a BlockVector, meaning that when the send method is called, it will use
* the material and data found for the block at the moment you call the send method. * the material and data found for the block at the moment you call the send method.
* @see #send(Collection) * @see #send(Collection)
*/ */
public void addBlock(Block block) public void addBlock(Block block)
{ {
Chunk c = ((CraftChunk) block.getChunk()).getHandle(); Chunk c = ((CraftChunk)block.getChunk()).getHandle();
List<BlockVector> list = _chunks.computeIfAbsent(c, chunk -> new ArrayList<>()); List<BlockVector> list = _chunks.computeIfAbsent(c,chunk -> new ArrayList<>());
if (list.size() >= 64) return; if(list.size() >= 64) return;
BlockVector bv = block.getLocation().toVector().toBlockVector(); BlockVector bv = block.getLocation().toVector().toBlockVector();
if (list.contains(bv)) return; if(list.contains(bv)) return;
list.add(bv); list.add(bv);
} }
/** /**
* Sends all the record blocks to all online players. Players out of range will not receive packets. * Sends all the record blocks to all online players. Players out of range will not receive packets.
*
* @see #send(Collection) * @see #send(Collection)
*/ */
public void send() public void send()
{ {
send(UtilServer.getPlayersCollection()); send(UtilServer.getPlayersCollection());
} }
/** /**
* Clear all blocks for this agent. * Clear all blocks for this agent.
*/ */
@ -71,81 +69,81 @@ public class MultiBlockUpdaterAgent
{ {
_chunks.clear(); _chunks.clear();
} }
/** /**
* Send all the recorded blocks to the provided players. This will only send packets to players in range. If the blocks span multiple * Send all the recorded blocks to the provided players. This will only send packets to players in range. If the blocks span multiple
* chunks then players will only receive block updates for chunks close to them. * chunks then players will only receive block updates for chunks close to them.
*
* @param players The players which will the packets will be sent to. * @param players The players which will the packets will be sent to.
*/ */
public void send(Collection<? extends Player> players) public void send(Collection<? extends Player> players)
{ {
for (Player p : players) for(Player p : players)
{ {
for (Chunk c : _chunks.keySet()) for(Chunk c : _chunks.keySet())
{ {
if (!p.getWorld().equals(c.bukkitChunk.getWorld())) continue; if(!p.getWorld().equals(c.bukkitChunk.getWorld())) continue;
int x = p.getLocation().getChunk().getX(); int x = p.getLocation().getChunk().getX();
int z = p.getLocation().getChunk().getZ(); int z = p.getLocation().getChunk().getZ();
int chunkDist = Math.max(Math.abs(c.locX - x), Math.abs(c.locZ - z)); int chunkDist = Math.max(Math.abs(c.locX-x), Math.abs(c.locZ-z));
if (chunkDist > Bukkit.getViewDistance()) continue; if(chunkDist > Bukkit.getViewDistance()) continue;
sendPacket(c, p); sendPacket(c, p);
} }
} }
} }
private void sendPacket(Chunk c, Player... players) private void sendPacket(Chunk c, Player...players)
{ {
List<BlockVector> list = _chunks.get(c); List<BlockVector> list = _chunks.get(c);
if (list == null) return; if(list == null) return;
if (list.size() >= 64) if(list.size() >= 64)
{ {
for (Player p : players) for(Player p : players)
{ {
int protocol = ((CraftPlayer) p).getHandle().getProtocol(); UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(c, true, 65535));
UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(protocol, c, true, 65535));
} }
} else }
else
{ {
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(); PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
packet.a = new ChunkCoordIntPair(c.locX, c.locZ); packet.a = new ChunkCoordIntPair(c.locX, c.locZ);
packet.b = new MultiBlockChangeInfo[list.size()]; packet.b = new MultiBlockChangeInfo[list.size()];
for (int i = 0; i < list.size(); i++) for(int i = 0; i < list.size(); i++)
{ {
BlockVector bv = list.get(i); BlockVector bv = list.get(i);
short xyz = (short) ((bv.getBlockX() & 0xF) << 12 | (bv.getBlockZ() & 0xF) << 8 | bv.getBlockY()); short xyz = (short)((bv.getBlockX() & 0xF) << 12 | (bv.getBlockZ() & 0xF) << 8 | bv.getBlockY());
packet.b[i] = packet.new MultiBlockChangeInfo(xyz, c); packet.b[i] = packet.new MultiBlockChangeInfo(xyz, c);
} }
for (Player p : players) for(Player p : players)
{ {
UtilPlayer.sendPacket(p, packet); UtilPlayer.sendPacket(p, packet);
} }
} }
Packet<?>[] tileEntities = new Packet[c.tileEntities.size()]; Packet<?>[] tileEntities = new Packet[c.tileEntities.size()];
int i = 0; int i = 0;
for (TileEntity te : c.tileEntities.values()) for(TileEntity te : c.tileEntities.values())
{ {
tileEntities[i++] = te.getUpdatePacket(); tileEntities[i++] = te.getUpdatePacket();
} }
for (Player p : players) for(Player p : players)
{ {
UtilPlayer.sendPacket(p, tileEntities); UtilPlayer.sendPacket(p, tileEntities);
((WorldServer) c.world).getTracker().untrackPlayer(((CraftPlayer) p).getHandle()); ((WorldServer)c.world).getTracker().untrackPlayer(((CraftPlayer)p).getHandle());
} }
Bukkit.getScheduler().runTaskLater(UtilServer.getPlugin(), () -> Bukkit.getScheduler().runTaskLater(UtilServer.getPlugin(), () ->
{ {
for (Player p : players) for(Player p : players)
{ {
((WorldServer) c.world).getTracker().a(((CraftPlayer) p).getHandle(), c); ((WorldServer)c.world).getTracker().a(((CraftPlayer)p).getHandle(), c);
} }
}, 5); }, 5);
} }
} }

View File

@ -4,8 +4,7 @@ public enum LineFormat
{ {
LORE(220), LORE(220),
PUNISHMENT_UI(48), PUNISHMENT_UI(48),
CHAT(319), CHAT(319);
SCOREBOARD(16);
private int _length; private int _length;

View File

@ -1,10 +1,7 @@
package mineplex.core.common.util; package mineplex.core.common.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import net.minecraft.server.v1_8_R3.EnumParticle; import net.minecraft.server.v1_8_R3.EnumParticle;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles; import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
@ -175,16 +172,6 @@ public class UtilParticle
WATER_WAKE(EnumParticle.WATER_WAKE, "wake"); WATER_WAKE(EnumParticle.WATER_WAKE, "wake");
private static final Map<String, ParticleType> byName = new ConcurrentHashMap<>();
static
{
for (ParticleType type : values())
{
byName.put(type.particleName, type);
}
}
public EnumParticle particle; public EnumParticle particle;
public String particleName; public String particleName;
private boolean _friendlyData; private boolean _friendlyData;
@ -261,7 +248,15 @@ public class UtilParticle
details[i] = Integer.parseInt(parts[i + 1]); details[i] = Integer.parseInt(parts[i + 1]);
} }
ParticleType particleType = ParticleType.byName.getOrDefault(parts[0], ParticleType.CRIT); ParticleType particleType = ParticleType.CRIT;
for (ParticleType type : ParticleType.values())
{
if (type.particleName.equalsIgnoreCase(parts[0]))
{
particleType = type;
}
}
return new PacketPlayOutWorldParticles(particleType.particle, displayFar, return new PacketPlayOutWorldParticles(particleType.particle, displayFar,
(float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed,

View File

@ -554,7 +554,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
if (pDisguise.getSleepingDirection() != null) if (pDisguise.getSleepingDirection() != null)
{ {
for (Packet packet : getBedPackets(protocol, pDisguise)) for (Packet packet : getBedPackets(pDisguise))
{ {
handlePacket(packet, packetVerifier); handlePacket(packet, packetVerifier);
} }
@ -821,15 +821,14 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
{ {
List<Packet> packets = new ArrayList<>(); List<Packet> packets = new ArrayList<>();
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff');
final int protocol = nmsPlayer.getProtocol();
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(protocol, _bedChunk, true, '\uffff');
chunk.a = BED_POS_NORTH[0] >> 4; chunk.a = BED_POS_NORTH[0] >> 4;
chunk.b = BED_POS_NORTH[2] >> 4; chunk.b = BED_POS_NORTH[2] >> 4;
packets.add(chunk); packets.add(chunk);
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
_spawnPacketMap.entrySet().stream() _spawnPacketMap.entrySet().stream()
.filter(entry -> entry.getValue().size() > 0 && entry.getValue().getFirst() instanceof DisguisePlayer && ((DisguisePlayer) entry.getValue().getFirst()).getSleepingDirection() != null) .filter(entry -> entry.getValue().size() > 0 && entry.getValue().getFirst() instanceof DisguisePlayer && ((DisguisePlayer) entry.getValue().getFirst()).getSleepingDirection() != null)
.filter(entry -> this.containsSpawnDisguise(player, entry.getValue().getFirst())) .filter(entry -> this.containsSpawnDisguise(player, entry.getValue().getFirst()))
@ -839,7 +838,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
if (tracker != null && tracker.trackedPlayers.contains(nmsPlayer)) if (tracker != null && tracker.trackedPlayers.contains(nmsPlayer))
{ {
packets.addAll(getBedPackets(protocol, (DisguisePlayer) entry.getValue().getFirst())); packets.addAll(getBedPackets((DisguisePlayer) entry.getValue().getFirst()));
} }
}); });
@ -854,7 +853,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
* *
* fixme can we make this better at all?!?!?! * fixme can we make this better at all?!?!?!
*/ */
private List<Packet> getBedPackets(int protocol, DisguisePlayer playerDisguise) private List<Packet> getBedPackets(DisguisePlayer playerDisguise)
{ {
int[] coords = getCoordsFor(playerDisguise); int[] coords = getCoordsFor(playerDisguise);
@ -874,7 +873,8 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
double d1 = posY + (targetY - posY) / (double) partitions; double d1 = posY + (targetY - posY) / (double) partitions;
double d2 = posZ + (targetZ - posZ) / (double) partitions; double d2 = posZ + (targetZ - posZ) / (double) partitions;
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(protocol, _bedChunk, true, '\uffff');
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff');
chunk.a = (int) Math.floor(d0) >> 4; chunk.a = (int) Math.floor(d0) >> 4;
chunk.b = (int) Math.floor(d2) >> 4; chunk.b = (int) Math.floor(d2) >> 4;
packets.add(chunk); packets.add(chunk);

View File

@ -1,15 +1,12 @@
package mineplex.hub; package mineplex.hub;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText;
public class HubClient public class HubClient
{ {
private static final int DISPLAY_LENGTH = 16; private static final int DISPLAY_LENGTH = 16;
private String _display; private String ScoreboardString;
private int _index; private int ScoreboardIndex ;
public HubClient(String name) public HubClient(String name)
{ {
@ -18,29 +15,26 @@ public class HubClient
public void setName(String name) public void setName(String name)
{ {
//_display = " Welcome " + name + ", to the Mineplex Network!"; ScoreboardString = " Welcome " + name + ", to the Mineplex Network!";
//_index = 0; ScoreboardIndex = 0;
_display = UtilText.center(C.cGoldB + "MINE" + C.cYellowB + "PLEX", LineFormat.SCOREBOARD);
} }
public String GetScoreboardText() public String GetScoreboardText()
{ {
/* if (_display.length() <= DISPLAY_LENGTH) if (ScoreboardString.length() <= DISPLAY_LENGTH)
{ {
return _display; return ScoreboardString;
} }
String display = _display.substring(_index, Math.min(_index + DISPLAY_LENGTH, _display.length())); String display = ScoreboardString.substring(ScoreboardIndex, Math.min(ScoreboardIndex + DISPLAY_LENGTH, ScoreboardString.length()));
if (display.length() < DISPLAY_LENGTH) if (display.length() < DISPLAY_LENGTH)
{ {
int add = DISPLAY_LENGTH - display.length(); int add = DISPLAY_LENGTH - display.length();
display += _display.substring(0, add); display += ScoreboardString.substring(0, add);
} }
_index = (_index + 1) % _display.length(); ScoreboardIndex = (ScoreboardIndex + 1) % ScoreboardString.length();
return display; */ return display;
return _display;
} }
} }

View File

@ -47,9 +47,7 @@ public class HubScoreboard extends ScoreboardManager
} }
} }
scoreboard scoreboard.register(HubScoreboardLine.SERVER_TITLE)
.register(HubScoreboardLine.START_EMPTY_SPACER)
.register(HubScoreboardLine.SERVER_TITLE)
.register(HubScoreboardLine.SERVER_NAME) .register(HubScoreboardLine.SERVER_NAME)
.register(HubScoreboardLine.SERVER_EMPTY_SPACER) .register(HubScoreboardLine.SERVER_EMPTY_SPACER)
.register(HubScoreboardLine.GEM_TITLE) .register(HubScoreboardLine.GEM_TITLE)

View File

@ -4,7 +4,6 @@ import mineplex.core.scoreboard.ScoreboardLine;
public enum HubScoreboardLine implements ScoreboardLine public enum HubScoreboardLine implements ScoreboardLine
{ {
START_EMPTY_SPACER,
SERVER_TITLE, SERVER_TITLE,
SERVER_NAME, SERVER_NAME,
SERVER_EMPTY_SPACER, SERVER_EMPTY_SPACER,

View File

@ -15,7 +15,6 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.MapUtil;
@ -154,8 +153,7 @@ public abstract class Crumbleable
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
{ {
int protocol = ((CraftPlayer) player).getHandle().getProtocol(); UtilPlayer.sendPacket(player, new PacketPlayOutMapChunk(chunk, false, mask));
UtilPlayer.sendPacket(player, new PacketPlayOutMapChunk(protocol, chunk, false, mask));
} }
_lastChunk = System.currentTimeMillis(); _lastChunk = System.currentTimeMillis();