Merge branch 'ResourcePack' into Wizards

This commit is contained in:
libraryaddict 2015-04-22 03:46:25 +12:00
commit b29893ff60
7 changed files with 308 additions and 2 deletions

View File

@ -0,0 +1,41 @@
package mineplex.core.resourcepack;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.resourcepack.redis.RedisUnloadResPack;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
import mineplex.serverdata.commands.ServerCommandManager;
public class ResPackManager implements CommandCallback
{
private ResUnloadCheck _packUnloadCheck;
public ResPackManager(ResUnloadCheck packUnloadCheck)
{
_packUnloadCheck = packUnloadCheck;
ServerCommandManager.getInstance().registerCommandType("RedisUnloadResPack", RedisUnloadResPack.class, this);
}
@Override
public void run(ServerCommand command)
{
if (command instanceof RedisUnloadResPack)
{
RedisUnloadResPack redisCommand = (RedisUnloadResPack) command;
Player player = Bukkit.getPlayerExact(redisCommand.getPlayer());
if (player != null)
{
if (_packUnloadCheck.canSendUnload(player))
{
player.setResourcePack("http://www.chivebox.com/file/c/empty.zip");
}
}
}
}
}

View File

@ -0,0 +1,9 @@
package mineplex.core.resourcepack;
import org.bukkit.entity.Player;
public interface ResUnloadCheck
{
public boolean canSendUnload(Player player);
}

View File

@ -0,0 +1,19 @@
package mineplex.core.resourcepack.redis;
import mineplex.serverdata.commands.ServerCommand;
public class RedisUnloadResPack extends ServerCommand
{
private String _player;
public RedisUnloadResPack(String player)
{
_player = player;
}
public String getPlayer()
{
return _player;
}
}

View File

@ -36,6 +36,8 @@ import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
import mineplex.core.resourcepack.ResUnloadCheck;
import mineplex.core.resourcepack.ResPackManager;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.spawn.Spawn;
import mineplex.core.stats.StatsManager;
@ -127,6 +129,13 @@ public class Hub extends JavaPlugin implements IRelation
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
new CustomTagFix(this, packetHandler);
new TablistFix(this);
new ResPackManager(new ResUnloadCheck()
{
public boolean canSendUnload(Player player)
{
return true;
}
});
//new Replay(this, packetHandler);
new PersonalServerManager(this, clientManager);

View File

@ -3,12 +3,15 @@ package nautilus.game.arcade;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Entity;
@ -30,6 +33,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.util.Vector;
import com.google.common.base.Objects;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
@ -39,11 +44,12 @@ import mineplex.core.chat.Chat;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.creature.Creature;
import mineplex.core.disguise.DisguiseManager;
@ -55,12 +61,19 @@ import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.movement.Movement;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.packethandler.PacketPlayResourcePackStatus;
import mineplex.core.packethandler.PacketPlayResourcePackStatus.EnumResourcePackStatus;
import mineplex.core.party.PartyManager;
import mineplex.core.pet.PetManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.resourcepack.ResUnloadCheck;
import mineplex.core.resourcepack.ResPackManager;
import mineplex.core.resourcepack.redis.RedisUnloadResPack;
import mineplex.core.reward.RewardRarity;
import mineplex.core.reward.rewards.PetReward;
import mineplex.core.stats.StatsManager;
@ -68,7 +81,6 @@ import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
@ -169,6 +181,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private PacketHandler _packetHandler;
private IPacketHandler _resourcePacketHandler;
private String _resourcePackUrl;
private boolean _resourcePackRequired;
private NautHashMap<String, EnumResourcePackStatus> _resourcePackUsers = new NautHashMap<String, EnumResourcePackStatus>();
private NautHashMap<String, Long> _resourcePackNoResponse = new NautHashMap<String, Long>();
// Observers
private HashSet<Player> _specList = new HashSet<Player>();
@ -301,6 +318,78 @@ public class ArcadeManager extends MiniPlugin implements IRelation
}
}, 80L);
}
_resourcePacketHandler = new IPacketHandler()
{
@Override
public void handle(PacketInfo packetInfo)
{
if (_resourcePackUrl != null && packetInfo.getPacket() instanceof PacketPlayResourcePackStatus)
{
final Player player = packetInfo.getPlayer();
final EnumResourcePackStatus response = ((PacketPlayResourcePackStatus) packetInfo.getPacket())
.getResourcePackStatus();
Bukkit.getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
{
@Override
public void run()
{
if (_resourcePackRequired)
{
if (response == EnumResourcePackStatus.ACCEPTED)
{
_resourcePackNoResponse.remove(player.getName());
}
else if (response == EnumResourcePackStatus.DECLINED)
{
_resourcePackNoResponse.remove(player.getName());
returnHubNoResPack(player);
}
else if (response == EnumResourcePackStatus.FAILED_DOWNLOAD)
{
System.out.println(player.getName() + " failed to download resource pack, trying again..");
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
player.setResourcePack(_resourcePackUrl);
return;
}
}
if (response == EnumResourcePackStatus.ACCEPTED || response == EnumResourcePackStatus.LOADED)
{
_resourcePackUsers.put(player.getName(), response);
}
else
{
_resourcePackUsers.remove(player.getName());
}
}
});
}
}
};
new ResPackManager(new ResUnloadCheck()
{
public boolean canSendUnload(Player player)
{
if (_resourcePackUsers.containsKey(player.getName()))
{
return false;
}
return true;
}
});
getPacketHandler().addPacketHandler(_resourcePacketHandler);
}
@Override
@ -1225,4 +1314,129 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return UtilPlayer.isSpectator((Player)player);
return false;
}
@EventHandler
public void onSecond(UpdateEvent event)
{
Iterator<Entry<String, Long>> itel = _resourcePackNoResponse.entrySet().iterator();
while (itel.hasNext())
{
Entry<String, Long> entry = itel.next();
if (UtilTime.elapsed(entry.getValue(), 10000))
{
Player player = Bukkit.getPlayerExact(entry.getKey());
if (player != null)
{
// Send it again, enforce it!
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
player.setResourcePack(_resourcePackUrl);
}
else
{
itel.remove();
}
}
}
}
@EventHandler
public void ResourcePackQuit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
EnumResourcePackStatus status = _resourcePackUsers.get(player.getName());
if (status == EnumResourcePackStatus.ACCEPTED || status == EnumResourcePackStatus.LOADED)
{
new RedisUnloadResPack(player.getName()).publish();
_resourcePackUsers.remove(player.getName());
}
}
@EventHandler
public void outdatedVersion(GameStateChangeEvent event)
{
if (!_resourcePackRequired)
return;
for (Player player : UtilServer.getPlayers())
{
if (!UtilPlayer.is1_8(player))
returnHubNoResPack(player);
}
}
private void returnHubNoResPack(Player player)
{
UtilPlayer.message(player, " ");
UtilPlayer.message(player, C.cGold + C.Bold + "You need to be using 1.8 to play " + GetGame().GetName() + "!");
UtilPlayer.message(player, " ");
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
GetPortal().sendPlayerToServer(player, "Lobby");
}
@EventHandler
public void ResourcePackJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
if (!UtilPlayer.is1_8(player) && _resourcePackRequired)
{
returnHubNoResPack(player);
return;
}
if (_resourcePackUrl != null)
{
if (_resourcePackRequired)
{
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
}
_resourcePackUsers.put(player.getName(), null);
player.setResourcePack(_resourcePackUrl);
}
}
public void setResourcePack(String resourcePack, boolean forceResourcePack)
{
if (!Objects.equal(resourcePack, _resourcePackUrl) || forceResourcePack != _resourcePackRequired)
{
_resourcePackNoResponse.clear();
_resourcePackUsers.clear();
_resourcePackUrl = resourcePack == null || resourcePack.isEmpty() ? null : resourcePack;
_resourcePackRequired = forceResourcePack;
if (_resourcePackUrl == null || _resourcePackUrl.isEmpty())
{
_resourcePackRequired = false;
for (Player player : Bukkit.getOnlinePlayers())
{
player.setResourcePack("http://www.chivebox.com/file/c/empty.zip");
}
}
else
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (_resourcePackRequired)
{
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
}
_resourcePackUsers.put(player.getName(), null);
player.setResourcePack(_resourcePackUrl);
}
}
}
}
}

View File

@ -62,6 +62,8 @@ public enum GameType
Material _mat;
byte _data;
GameCategory _gameCategory;
boolean _enforceResourcePack;
String _resourcePack;
private int _gameId; // Unique identifying id for this gamemode (used for statistics)
public int getGameId() { return _gameId; }
@ -81,6 +83,16 @@ public enum GameType
_gameId = gameId;
}
public boolean isEnforceResourcePack()
{
return _enforceResourcePack;
}
public String getResourcePackUrl()
{
return _resourcePack;
}
public String GetName()
{
return _name;

View File

@ -316,6 +316,8 @@ public abstract class Game implements Listener
new TeamKillsStatTracker(this)
);
}
Manager.setResourcePack(gameType.getResourcePackUrl(), gameType.isEnforceResourcePack());
System.out.println("Loading " + GetName() + "...");
}