HG Lag Fixes!

This commit is contained in:
Chiss 2013-11-23 23:58:51 +11:00
parent f299b4f650
commit 2a41979277

View File

@ -8,11 +8,13 @@ import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
@ -32,7 +34,9 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@ -66,6 +70,7 @@ import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
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.kit.Kit;
@ -90,8 +95,6 @@ public class HungerGames extends SoloGame
private Location _spreadSafe = null;
private HashMap<Player, Long> _redOutTime = new HashMap<Player, Long>();
private ArrayList<BlockChange> _redQueue = new ArrayList<BlockChange>();
private HashMap<Integer, HashMap<Integer, HashSet<Integer>>> _redMap = new HashMap<Integer, HashMap<Integer, HashSet<Integer>>>();
//Supply Drop
@ -131,7 +134,7 @@ public class HungerGames extends SoloGame
});
Manager.GetAntiStack().SetEnabled(false);
this.WorldTimeSet = 0;
this.SpawnDistanceRequirement = 48;
@ -139,7 +142,6 @@ public class HungerGames extends SoloGame
this.DamageSelf = true;
this.DamageTeamSelf = true;
//this.DeathOut = false; //XXX
this.DeathDropItems = true;
this.ItemDrop = true;
@ -428,13 +430,13 @@ public class HungerGames extends SoloGame
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 < 10; i++) _superChestLoot.add(new ItemStack(Material.IRON_HELMET));
for (int i = 0; i < 8; i++) _superChestLoot.add(new ItemStack(Material.IRON_CHESTPLATE));
for (int i = 0; i < 9; i++) _superChestLoot.add(new ItemStack(Material.IRON_LEGGINGS));
for (int i = 0; i < 10; i++) _superChestLoot.add(new ItemStack(Material.IRON_BOOTS));
for (int i = 0; i < 30; i++) _superChestLoot.add(new ItemStack(Material.IRON_HELMET));
for (int i = 0; i < 24; i++) _superChestLoot.add(new ItemStack(Material.IRON_CHESTPLATE));
for (int i = 0; i < 27; i++) _superChestLoot.add(new ItemStack(Material.IRON_LEGGINGS));
for (int i = 0; i < 30; i++) _superChestLoot.add(new ItemStack(Material.IRON_BOOTS));
for (int i = 0; i < 2; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_SWORD));
for (int i = 0; i < 4; i++) _baseChestLoot.add(new ItemStack(Material.DIAMOND_AXE));
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));
}
@ -520,6 +522,11 @@ public class HungerGames extends SoloGame
_redLocations.add(block.getLocation());
}
}
public int RedMax()
{
return _maxSpreadRate;// + (24 - GetPlayers(true).size())*2;
}
@EventHandler
public void RedUpdate(UpdateEvent event)
@ -529,13 +536,13 @@ public class HungerGames extends SoloGame
if (!IsLive())
return;
long time = System.currentTimeMillis();
if (_redLocations.isEmpty())
return;
int max = Math.max(5, Math.min(_maxSpreadRate, _redLocations.size()/100));
int max = Math.max(5, Math.min(RedMax(), _redLocations.size()/100));
for (int i=0 ; i<max ; i++)
{
@ -699,74 +706,70 @@ public class HungerGames extends SoloGame
_redMap.get(loc.getBlockX()).get(loc.getBlockY()).add(loc.getBlockZ());
//Queue Disabled
//_redQueue.add(new BlockChange(loc, id, data));
//Non-Queue
for (Player player : UtilServer.getPlayers())
{
if (player.getLocation().getChunk().getX() - loc.getChunk().getX() > UtilServer.getServer().getViewDistance())
if (Math.abs(player.getLocation().getChunk().getX() - loc.getChunk().getX()) > UtilServer.getServer().getViewDistance())
continue;
if (player.getLocation().getChunk().getZ() - loc.getChunk().getZ() > UtilServer.getServer().getViewDistance())
if (Math.abs(player.getLocation().getChunk().getZ() - loc.getChunk().getZ()) > UtilServer.getServer().getViewDistance())
continue;
if (_fixChoice.containsKey(player))
{
int req = _fixChoice.get(player);
int done = 0;
if (_fixSkip.containsKey(player))
done = _fixSkip.get(player);
done = (done + 1)%req;
_fixSkip.put(player, done);
if (done != 0)
{
if (!_fixChunk.containsKey(player))
_fixChunk.put(player, new ArrayList<Chunk>());
if (!_fixChunk.get(player).contains(loc.getChunk()))
_fixChunk.get(player).add(loc.getChunk());
continue;
}
}
player.sendBlockChange(loc, id, data);
}
}
@EventHandler
public void RedChangeBlockClient(UpdateEvent event)
public void RedChunkUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
if (event.getType() != UpdateType.FAST)
return;
if (_redQueue.isEmpty())
return;
/** TYPE A **/
for (BlockChange change : _redQueue)
for (Player player : _fixChunk.keySet())
{
for (Player player : UtilServer.getPlayers())
Iterator<Chunk> chunkIterator = _fixChunk.get(player).iterator();
while (chunkIterator.hasNext())
{
if (player.getLocation().getChunk().getX() - change.Location.getChunk().getX() > UtilServer.getServer().getViewDistance())
continue;
if (player.getLocation().getChunk().getZ() - change.Location.getChunk().getZ() > UtilServer.getServer().getViewDistance())
continue;
player.sendBlockChange(change.Location, change.Id, change.Data);
Chunk chunk = chunkIterator.next();
if (Math.abs(player.getLocation().getChunk().getX() - chunk.getX()) > UtilServer.getServer().getViewDistance() ||
Math.abs(player.getLocation().getChunk().getZ() - chunk.getZ()) > UtilServer.getServer().getViewDistance())
{
chunkIterator.remove();
}
}
if (_fixChunk.get(player).isEmpty())
continue;
Chunk chunk = _fixChunk.get(player).remove(0);
MapUtil.SendChunkForPlayer(chunk.getX(), chunk.getZ(), player);
}
_redQueue.clear();
/** TYPE B **/
/*
HashSet<Chunk> chunks = new HashSet<Chunk>();
for (BlockChange change : _redQueue)
{
chunks.add(change.Location.getChunk());
}
for (Chunk chunk : chunks)
{
for (Player player : UtilServer.getPlayers())
{
if (player.getLocation().getChunk().getX() - chunk.getX() > UtilServer.getServer().getViewDistance())
continue;
if (player.getLocation().getChunk().getZ() - chunk.getZ() > UtilServer.getServer().getViewDistance())
continue;
MapUtil.SendChunkForPlayer(chunk.getX(), chunk.getZ(), player);
}
}
_redQueue.clear();
*/
}
public boolean IsRed(Block block)
@ -1190,4 +1193,87 @@ public class HungerGames extends SoloGame
{
event.blockList().clear();
}
private long _fixTimer = 0;
private HashMap<Player, Integer> _fixChoice = 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
public void FixInform(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (this.GetState() != GameState.Recruit)
return;
if (!UtilTime.elapsed(_fixTimer, 15000))
return;
_fixTimer = System.currentTimeMillis();
Announce(C.cGold + C.Bold + "Are you getting frame lag?");
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 high " + C.cYellow + "Highly reduce freeze visuals");
UtilPlayer.message(player, "/fix max " + C.cYellow + "Extremely reduce freeze visuals");
}
}
@EventHandler
public void FixCommand(PlayerCommandPreprocessEvent event)
{
String[] tokens = event.getMessage().split(" ");
if (tokens.length < 2)
return;
if (!tokens[0].equalsIgnoreCase("/fix"))
return;
event.setCancelled(true);
if (tokens[1].equalsIgnoreCase("off"))
{
_fixChoice.remove(event.getPlayer());
UtilPlayer.message(event.getPlayer(), C.cPurple + C.Bold + "Turned off freeze visual fix!");
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PLING, 2f, 2f);
}
else if (tokens[1].equalsIgnoreCase("low"))
{
_fixChoice.put(event.getPlayer(), 2);
UtilPlayer.message(event.getPlayer(), C.cPurple + C.Bold + "Freeze visuals slightly reduced!");
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PLING, 2f, 2f);
}
else if (tokens[1].equalsIgnoreCase("high"))
{
_fixChoice.put(event.getPlayer(), 4);
UtilPlayer.message(event.getPlayer(), C.cPurple + C.Bold + "Freeze visuals highly reduced!");
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PLING, 2f, 2f);
}
else if (tokens[1].equalsIgnoreCase("max"))
{
_fixChoice.put(event.getPlayer(), 9);
UtilPlayer.message(event.getPlayer(), C.cPurple + C.Bold + "Freeze visuals extremely reduced!");
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.NOTE_PLING, 2f, 2f);
}
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 high " + C.cYellow + "Highly reduce freeze visuals");
UtilPlayer.message(event.getPlayer(), "/fix max " + C.cYellow + "Extremely reduce freeze visuals");
}
}
@EventHandler
public void FixClean(PlayerQuitEvent event)
{
_fixChoice.remove(event.getPlayer());
_fixSkip.remove(event.getPlayer());
_fixChunk.remove(event.getPlayer());
}
}