HG lag fix

This commit is contained in:
Chiss 2013-11-24 21:29:49 +11:00
parent fd63a0a0b1
commit c9e1c0a0f4
2 changed files with 85 additions and 20 deletions

View File

@ -0,0 +1,29 @@
package nautilus.game.arcade.game.games.hungergames;
import java.util.ArrayList;
import org.bukkit.Chunk;
import org.bukkit.Location;
public class ChunkChange
{
public Chunk Chunk;
public long Time;
public ArrayList<BlockChange> Changes;
public ChunkChange(Location loc, int id, byte data)
{
Chunk = loc.getChunk();
Changes = new ArrayList<BlockChange>();
AddChange(loc, id, data);
Time = System.currentTimeMillis();
}
public void AddChange(Location loc, int id, byte data)
{
Changes.add(new BlockChange(loc, id, data));
}
}

View File

@ -10,6 +10,7 @@ import java.util.Map.Entry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Effect;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -70,7 +71,6 @@ import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.hungergames.kit.*; import nautilus.game.arcade.game.games.hungergames.kit.*;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
@ -96,7 +96,8 @@ public class HungerGames extends SoloGame
private HashMap<Player, Long> _redOutTime = new HashMap<Player, Long>(); private HashMap<Player, Long> _redOutTime = new HashMap<Player, Long>();
private HashMap<Integer, HashMap<Integer, HashSet<Integer>>> _redMap = new HashMap<Integer, HashMap<Integer, HashSet<Integer>>>(); private HashMap<Integer, HashMap<Integer, HashSet<Integer>>> _redMap = new HashMap<Integer, HashMap<Integer, HashSet<Integer>>>();
private HashMap<Player, ArrayList<ChunkChange>> _redChunks = new HashMap<Player, ArrayList<ChunkChange>>();
//Supply Drop //Supply Drop
private ArrayList<Location> _supplyLocations = new ArrayList<Location>(); private ArrayList<Location> _supplyLocations = new ArrayList<Location>();
private Location _supplyCurrent = null; private Location _supplyCurrent = null;
@ -425,7 +426,7 @@ public class HungerGames extends SoloGame
if (_superChestLoot.isEmpty()) if (_superChestLoot.isEmpty())
{ {
for (int i = 0; i < 3; i++) _baseChestLoot.add(new ItemStack(Material.DIAMOND_HELMET)); for (int i = 0; i < 3; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_HELMET));
for (int i = 0; i < 1; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_CHESTPLATE)); for (int i = 0; i < 1; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_CHESTPLATE));
for (int i = 0; i < 2; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_LEGGINGS)); for (int i = 0; i < 2; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_LEGGINGS));
for (int i = 0; i < 3; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_BOOTS)); for (int i = 0; i < 3; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_BOOTS));
@ -436,7 +437,7 @@ public class HungerGames extends SoloGame
for (int i = 0; i < 30; i++) _superChestLoot.add(new ItemStack(Material.IRON_BOOTS)); for (int i = 0; i < 30; i++) _superChestLoot.add(new ItemStack(Material.IRON_BOOTS));
for (int i = 0; i < 12; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_SWORD)); for (int i = 0; i < 12; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_SWORD));
for (int i = 0; i < 16; i++) _baseChestLoot.add(new ItemStack(Material.DIAMOND_AXE)); for (int i = 0; i < 16; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_AXE));
} }
@ -448,6 +449,9 @@ public class HungerGames extends SoloGame
if (stack.getType().getMaxStackSize() > 1) if (stack.getType().getMaxStackSize() > 1)
amount = Math.max(1, UtilMath.r(stack.getAmount())); amount = Math.max(1, UtilMath.r(stack.getAmount()));
if (stack.getTypeId() == 33)
return ItemStackFactory.Instance.CreateStack(stack.getTypeId(), (byte)0, amount, "Barricade");
return ItemStackFactory.Instance.CreateStack(stack.getTypeId(), amount); return ItemStackFactory.Instance.CreateStack(stack.getTypeId(), amount);
} }
@ -715,6 +719,21 @@ public class HungerGames extends SoloGame
if (Math.abs(player.getLocation().getChunk().getZ() - loc.getChunk().getZ()) > UtilServer.getServer().getViewDistance()) if (Math.abs(player.getLocation().getChunk().getZ() - loc.getChunk().getZ()) > UtilServer.getServer().getViewDistance())
continue; continue;
if (!_redChunks.containsKey(player))
_redChunks.put(player, new ArrayList<ChunkChange>());
boolean added = false;
for (ChunkChange change : _redChunks.get(player))
{
if (change.Chunk.equals(loc.getChunk()))
{
change.AddChange(loc, id, data);
}
}
if (!added)
_redChunks.get(player).add(new ChunkChange(loc, id, data));
/*
if (_fixChoice.containsKey(player)) if (_fixChoice.containsKey(player))
{ {
int req = _fixChoice.get(player); int req = _fixChoice.get(player);
@ -727,7 +746,7 @@ public class HungerGames extends SoloGame
_fixSkip.put(player, done); _fixSkip.put(player, done);
if (done != 0) if (done != 999999)
{ {
if (!_fixChunk.containsKey(player)) if (!_fixChunk.containsKey(player))
_fixChunk.put(player, new ArrayList<Chunk>()); _fixChunk.put(player, new ArrayList<Chunk>());
@ -740,35 +759,43 @@ public class HungerGames extends SoloGame
} }
player.sendBlockChange(loc, id, data); player.sendBlockChange(loc, id, data);
*/
} }
} }
@EventHandler @EventHandler
public void RedChunkUpdate(UpdateEvent event) public void RedChunkUpdate(UpdateEvent event)
{ {
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FASTER)
return; return;
for (Player player : _fixChunk.keySet()) for (Player player : _redChunks.keySet())
{ {
Iterator<Chunk> chunkIterator = _fixChunk.get(player).iterator(); //Remove Far Away
Iterator<ChunkChange> chunkIterator = _redChunks.get(player).iterator();
while (chunkIterator.hasNext()) while (chunkIterator.hasNext())
{ {
Chunk chunk = chunkIterator.next(); ChunkChange change = chunkIterator.next();
if (Math.abs(player.getLocation().getChunk().getX() - chunk.getX()) > UtilServer.getServer().getViewDistance() || if (Math.abs(player.getLocation().getChunk().getX() - change.Chunk.getX()) > UtilServer.getServer().getViewDistance() ||
Math.abs(player.getLocation().getChunk().getZ() - chunk.getZ()) > UtilServer.getServer().getViewDistance()) Math.abs(player.getLocation().getChunk().getZ() - change.Chunk.getZ()) > UtilServer.getServer().getViewDistance())
{ {
chunkIterator.remove(); chunkIterator.remove();
} }
} }
if (_fixChunk.get(player).isEmpty()) if (_redChunks.get(player).isEmpty())
continue; continue;
Chunk chunk = _fixChunk.get(player).remove(0); //Get Best
MapUtil.SendChunkForPlayer(chunk.getX(), chunk.getZ(), player); //XXX Currently, just using a FIFO queue to select
// Add weighting to select the best chunk based on time/distance/count.
ChunkChange change = _redChunks.get(player).remove(0);
//change.Changes contains Location/Id/Data for all pending changes in this chunk
//XXX Simply replace this line with the the Multiblocks packet.
MapUtil.SendChunkForPlayer(change.Chunk.getX(), change.Chunk.getZ(), player);
} }
} }
@ -1132,7 +1159,8 @@ public class HungerGames extends SoloGame
{ {
if (_placedBlocks.remove(event.getBlock().getLocation())) if (_placedBlocks.remove(event.getBlock().getLocation()))
{ {
event.setCancelled(false); event.getBlock().getWorld().playEffect(event.getBlock().getLocation(), Effect.STEP_SOUND, event.getBlock().getType());
event.getBlock().setType(Material.AIR);
} }
} }
@ -1194,10 +1222,11 @@ public class HungerGames extends SoloGame
event.blockList().clear(); event.blockList().clear();
} }
/*
private long _fixTimer = 0; private long _fixTimer = 0;
private HashMap<Player, Integer> _fixChoice = new HashMap<Player, Integer>(); private HashMap<Player, Integer> _fixChoice = new HashMap<Player, Integer>();
private HashMap<Player, Integer> _fixSkip = new HashMap<Player, Integer>(); private HashMap<Player, Integer> _fixSkip = new HashMap<Player, Integer>();
private HashMap<Player, ArrayList<Chunk>> _fixChunk = new HashMap<Player, ArrayList<Chunk>>();
@EventHandler @EventHandler
public void FixInform(UpdateEvent event) public void FixInform(UpdateEvent event)
@ -1216,10 +1245,10 @@ public class HungerGames extends SoloGame
Announce(C.cGold + C.Bold + "Are you getting frame lag?"); Announce(C.cGold + C.Bold + "Are you getting frame lag?");
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
{ {
UtilPlayer.message(player, "/fix off " + C.cYellow + "Turn off lag reduction");
UtilPlayer.message(player, "/fix low " + C.cYellow + "Slightly reduce freeze visuals"); UtilPlayer.message(player, "/fix low " + C.cYellow + "Slightly reduce freeze visuals");
UtilPlayer.message(player, "/fix high " + C.cYellow + "Highly reduce freeze visuals"); UtilPlayer.message(player, "/fix high " + C.cYellow + "Highly reduce freeze visuals");
UtilPlayer.message(player, "/fix max " + C.cYellow + "Extremely reduce freeze visuals"); UtilPlayer.message(player, "/fix max " + C.cYellow + "Extremely reduce freeze visuals");
UtilPlayer.message(player, "/fix off " + C.cYellow + "Turn off lag reduction");
} }
} }
@ -1261,11 +1290,11 @@ public class HungerGames extends SoloGame
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PLING, 2f, 2f); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PLING, 2f, 2f);
} }
else else
{ {
UtilPlayer.message(event.getPlayer(), "/fix off " + C.cYellow + "Turn off lag reduction");
UtilPlayer.message(event.getPlayer(), "/fix low " + C.cYellow + "Slightly reduce freeze visuals"); UtilPlayer.message(event.getPlayer(), "/fix low " + C.cYellow + "Slightly reduce freeze visuals");
UtilPlayer.message(event.getPlayer(), "/fix high " + C.cYellow + "Highly reduce freeze visuals"); UtilPlayer.message(event.getPlayer(), "/fix high " + C.cYellow + "Highly reduce freeze visuals");
UtilPlayer.message(event.getPlayer(), "/fix max " + C.cYellow + "Extremely reduce freeze visuals"); UtilPlayer.message(event.getPlayer(), "/fix max " + C.cYellow + "Extremely reduce freeze visuals");
UtilPlayer.message(event.getPlayer(), "/fix off " + C.cYellow + "Turn off lag reduction");
} }
} }
@ -1276,4 +1305,11 @@ public class HungerGames extends SoloGame
_fixSkip.remove(event.getPlayer()); _fixSkip.remove(event.getPlayer());
_fixChunk.remove(event.getPlayer()); _fixChunk.remove(event.getPlayer());
} }
*/
@EventHandler
public void FixClean(PlayerQuitEvent event)
{
_redChunks.remove(event.getPlayer());
}
} }