Proper optimization?

This commit is contained in:
Olof Larsson 2012-05-29 17:10:36 +02:00
parent 84a3bf5e5a
commit 25c644db1b
2 changed files with 20 additions and 2 deletions

View File

@ -2,10 +2,10 @@ package com.massivecraft.mcore3.persist;
import java.util.Collection; import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.mcore3.util.PlayerUtil;
import com.massivecraft.mcore3.util.Txt; import com.massivecraft.mcore3.util.Txt;
@ -13,7 +13,7 @@ public abstract class PlayerEntity<T extends PlayerEntity<T>> extends Entity<T>
{ {
public Player getPlayer() public Player getPlayer()
{ {
return Bukkit.getPlayerExact(this.getId()); return PlayerUtil.getPlayerExact(this.getId());
} }
public boolean isOnline() public boolean isOnline()

View File

@ -1,6 +1,7 @@
package com.massivecraft.mcore3.util; package com.massivecraft.mcore3.util;
import java.io.File; import java.io.File;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -8,6 +9,7 @@ import net.minecraft.server.EntityPlayer;
import net.minecraft.server.Packet8UpdateHealth; import net.minecraft.server.Packet8UpdateHealth;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,4 +37,20 @@ public class PlayerUtil
EntityPlayer eplayer = cplayer.getHandle(); EntityPlayer eplayer = cplayer.getHandle();
eplayer.netServerHandler.sendPacket(new Packet8UpdateHealth(eplayer.getHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().c())); eplayer.netServerHandler.sendPacket(new Packet8UpdateHealth(eplayer.getHealth(), eplayer.getFoodData().a(), eplayer.getFoodData().c()));
} }
@SuppressWarnings("unchecked")
public static Player getPlayerExact(String exactPlayerName)
{
CraftServer craftServer = (CraftServer) Bukkit.getServer();
List<EntityPlayer> entityPlayers = craftServer.getHandle().players;
for (EntityPlayer entityPlayer : entityPlayers)
{
Player player = entityPlayer.netServerHandler.getPlayer();
if (player.getName().equals(exactPlayerName))
{
return player;
}
}
return null;
}
} }