Add resourcepack options

This commit is contained in:
libraryaddict 2015-03-17 23:59:24 +13:00
parent 733134f709
commit 52f0941fb9
6 changed files with 299 additions and 1 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.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.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.ServerCommand;
public class RedisUnloadResPack extends ServerCommand
{
private String _player;
public RedisUnloadResPack(String player)
{
_player = player;
}
public String getPlayer()
{
return _player;
}
}

View File

@ -34,6 +34,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;
@ -123,6 +125,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

@ -2,13 +2,17 @@ package nautilus.game.arcade;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
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.EntityType;
@ -28,6 +32,8 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;
import com.google.common.base.Objects;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
@ -37,9 +43,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.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;
@ -51,12 +60,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;
@ -64,6 +80,7 @@ import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
@ -163,7 +180,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private ArcadeRepository _arcadeRepository;
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>();
@ -296,6 +317,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
@ -1179,4 +1272,129 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return _partyManager;
}
@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

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