From 52f0941fb95e7496bf5db85e63c0c2331cc9b2a4 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 17 Mar 2015 23:59:24 +1300 Subject: [PATCH 1/2] Add resourcepack options --- .../core/resourcepack/ResPackManager.java | 41 ++++ .../core/resourcepack/ResUnloadCheck.java | 9 + .../redis/RedisUnloadResPack.java | 19 ++ .../Mineplex.Hub/src/mineplex/hub/Hub.java | 9 + .../nautilus/game/arcade/ArcadeManager.java | 220 +++++++++++++++++- .../src/nautilus/game/arcade/game/Game.java | 2 + 6 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResPackManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResUnloadCheck.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/resourcepack/redis/RedisUnloadResPack.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResPackManager.java b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResPackManager.java new file mode 100644 index 000000000..2e5d8490b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResPackManager.java @@ -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"); + } + } + } + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResUnloadCheck.java b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResUnloadCheck.java new file mode 100644 index 000000000..c25175c58 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResUnloadCheck.java @@ -0,0 +1,9 @@ +package mineplex.core.resourcepack; + +import org.bukkit.entity.Player; + +public interface ResUnloadCheck +{ + + public boolean canSendUnload(Player player); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/redis/RedisUnloadResPack.java b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/redis/RedisUnloadResPack.java new file mode 100644 index 000000000..88876b510 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/redis/RedisUnloadResPack.java @@ -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; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index a6adf0e0a..865b402a2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -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); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 867c8dce7..b3b0ebb14 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -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 _resourcePackUsers = new NautHashMap(); + private NautHashMap _resourcePackNoResponse = new NautHashMap(); // Observers private HashSet _specList = new HashSet(); @@ -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> itel = _resourcePackNoResponse.entrySet().iterator(); + + while (itel.hasNext()) + { + Entry 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); + } + } + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 4f5a985e6..8b6ac7d57 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -312,6 +312,8 @@ public abstract class Game implements Listener new TeamKillsStatTracker(this) ); } + + Manager.setResourcePack(gameType.getResourcePackUrl(), gameType.isEnforceResourcePack()); System.out.println("Loading " + GetName() + "..."); } From 261b18fcf087ba05d783da6bba3ee50da655bddb Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 17 Mar 2015 23:59:59 +1300 Subject: [PATCH 2/2] Add GameType options --- .../src/nautilus/game/arcade/GameType.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 3e67b2fb8..28a6a668b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -60,6 +60,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; } @@ -79,6 +81,16 @@ public enum GameType _gameId = gameId; } + public boolean isEnforceResourcePack() + { + return _enforceResourcePack; + } + + public String getResourcePackUrl() + { + return _resourcePack; + } + public String GetName() { return _name;