Merge branches 'develop' and 'feature/player-data' of ssh://184.154.0.242:25565/min/mineplex into feature/player-data

# Conflicts:
#	Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java
This commit is contained in:
William Burns 2015-12-17 21:44:31 +00:00
commit 2ac28c4fd5
6 changed files with 249 additions and 250 deletions

View File

@ -1,41 +0,0 @@
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://file.mineplex.com/ResReset.zip");
}
}
}
}
}

View File

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

View File

@ -0,0 +1,238 @@
package mineplex.core.resourcepack;
import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.base.Objects;
import mineplex.core.MiniPlugin;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.portal.Portal;
import mineplex.core.resourcepack.redis.RedisUnloadResPack;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
import mineplex.serverdata.commands.ServerCommandManager;
public class ResourcePackManager extends MiniPlugin implements CommandCallback
{
private String _resourcePackUrl;
private boolean _resourcePackRequired;
private NautHashMap<String, Boolean> _resourcePackUsers = new NautHashMap<String, Boolean>();
private NautHashMap<String, Long> _resourcePackNoResponse = new NautHashMap<String, Long>();
private Portal _portal;
public ResourcePackManager(JavaPlugin plugin, Portal portal)
{
super("Resource Pack Manager", plugin);
_portal = portal;
ServerCommandManager.getInstance().registerCommandType("RedisUnloadResPack", RedisUnloadResPack.class, this);
}
@EventHandler
public void ResourcePackJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
if (_resourcePackUrl == null)
{
return;
}
if (_resourcePackRequired)
{
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
}
_resourcePackUsers.put(player.getName(), false);
player.setResourcePack(_resourcePackUrl);
}
@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(), 20000))
{
continue;
}
Player player = Bukkit.getPlayerExact(entry.getKey());
if (player == null)
{
itel.remove();
continue;
}
// Send it again, enforce it!
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
player.setResourcePack(_resourcePackUrl);
}
}
@EventHandler
public void onResourcePackStatus(PlayerResourcePackStatusEvent event)
{
if (_resourcePackUrl == null)
{
return;
}
Player player = event.getPlayer();
if (_resourcePackRequired)
{
if (event.getStatus() == Status.ACCEPTED)
{
_resourcePackNoResponse.remove(player.getName());
}
else if (event.getStatus() == Status.DECLINED)
{
_resourcePackNoResponse.remove(player.getName());
UtilPlayer.message(player, " ");
JsonMessage message = new JsonMessage("").color("gold").bold()
.extra("You need to accept the resource pack!\n" + "Click me for instructions on how to fix this!")
.click(ClickEvent.OPEN_URL,
"http://mineplex.com/forums/m/11929946/viewthread/21554536-wizards-resource-pack-help");
message.sendToPlayer(player);
UtilPlayer.message(player, " ");
returnHubNoResPack(player);
}
else if (event.getStatus() == Status.FAILED_DOWNLOAD)
{
_resourcePackNoResponse.remove(player.getName());
returnHubNoResPack(player, "Failed to download resource pack!");
return;
}
}
if (event.getStatus() == Status.ACCEPTED || event.getStatus() == Status.SUCCESSFULLY_LOADED)
{
_resourcePackUsers.put(player.getName(), true);
}
else
{
_resourcePackUsers.remove(player.getName());
}
}
@EventHandler
public void ResourcePackQuit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
if (!_resourcePackUsers.containsKey(player.getName()) || !_resourcePackUsers.get(player.getName()))
{
return;
}
new RedisUnloadResPack(player.getName()).publish();
_resourcePackUsers.remove(player.getName());
}
private void returnHubNoResPack(Player player)
{
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
_portal.sendPlayerToServer(player, "Lobby");
}
private void returnHubNoResPack(Player player, String message)
{
UtilPlayer.message(player, " ");
UtilPlayer.message(player, C.cGold + C.Bold + message);
UtilPlayer.message(player, " ");
returnHubNoResPack(player);
}
public void setResourcePack(String resourcePack, boolean forceResourcePack)
{
if (Objects.equal(resourcePack, _resourcePackUrl) && forceResourcePack == _resourcePackRequired)
{
return;
}
_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://file.mineplex.com/ResReset.zip");
}
}
else
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (_resourcePackRequired)
{
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
}
_resourcePackUsers.put(player.getName(), false);
player.setResourcePack(_resourcePackUrl);
}
}
}
@Override
public void run(ServerCommand command)
{
if (command instanceof RedisUnloadResPack)
{
RedisUnloadResPack redisCommand = (RedisUnloadResPack) command;
Player player = Bukkit.getPlayerExact(redisCommand.getPlayer());
if (player == null)
{
return;
}
if (_resourcePackUsers.containsKey(player.getName()))
{
return;
}
player.setResourcePack("http://file.mineplex.com/ResReset.zip");
}
}
}

View File

@ -43,8 +43,7 @@ import mineplex.core.profileCache.ProfileCacheManager;
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.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
@ -149,13 +148,7 @@ public class Hub extends JavaPlugin implements IRelation
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
new CustomTagFix(this, packetHandler);
new PacketsInteractionFix(this, packetHandler);
new ResPackManager(new ResUnloadCheck()
{
public boolean canSendUnload(Player player)
{
return true;
}
});
new ResourcePackManager(this, portal);
new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager, giveawayManager);
//new Replay(this, packetHandler);

View File

@ -49,9 +49,7 @@ import mineplex.core.poll.PollManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.resourcepack.ResPackManager;
import mineplex.core.resourcepack.ResUnloadCheck;
import mineplex.core.resourcepack.redis.RedisUnloadResPack;
import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.reward.RewardData;
import mineplex.core.reward.RewardRarity;
import mineplex.core.reward.rewards.PetReward;
@ -106,7 +104,6 @@ import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.HolidayManager;
import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
import nautilus.game.arcade.player.ArcadePlayer;
import nautilus.game.arcade.shop.ArcadeShop;
import org.bukkit.Bukkit;
@ -193,16 +190,12 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private PartyManager _partyManager;
private PreferencesManager _preferencesManager;
private GiveawayManager _giveawayManager;
private ResourcePackManager _resourcePackManager;
private CustomDataManager _customDataManager;
private TaskManager _taskManager;
private PacketHandler _packetHandler;
private String _resourcePackUrl;
private boolean _resourcePackRequired;
private NautHashMap<String, Boolean> _resourcePackUsers = new NautHashMap<String, Boolean>();
private NautHashMap<String, Long> _resourcePackNoResponse = new NautHashMap<String, Long>();
// Observers
private HashSet<Player> _specList = new HashSet<Player>();
@ -282,6 +275,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_petManager = petManager;
_eventManager = new EventModule(this, getPlugin());
_giveawayManager = giveawayManager;
_resourcePackManager = new ResourcePackManager(plugin, portal);
_customDataManager = customDataManager;
@ -346,19 +340,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
}, 80L);
}
new ResPackManager(new ResUnloadCheck()
{
public boolean canSendUnload(Player player)
{
if (_resourcePackUsers.containsKey(player.getName()))
{
return false;
}
return true;
}
});
loadRequiredRank();
}
@ -371,74 +352,17 @@ public class ArcadeManager extends MiniPlugin implements IRelation
addCommand(new DisguiseCommand(this));
addCommand(new RequiredRankCommand(this));
}
@EventHandler
public void onResourcePackStatus(PlayerResourcePackStatusEvent event)
{
if (_resourcePackUrl == null)
{
return;
}
Player player = event.getPlayer();
if (_resourcePackRequired)
{
if (event.getStatus() == Status.ACCEPTED)
{
_resourcePackNoResponse.remove(player.getName());
}
else if (event.getStatus() == Status.DECLINED)
{
_resourcePackNoResponse.remove(player.getName());
UtilPlayer.message(player, " ");
JsonMessage message = new JsonMessage("")
.color("gold")
.bold()
.extra("You need to accept the resource pack!\n"
+ "Click me for instructions on how to fix this!")
.click(ClickEvent.OPEN_URL,
"http://mineplex.com/forums/m/11929946/viewthread/21554536-wizards-resource-pack-help");
message.sendToPlayer(player);
UtilPlayer.message(player, " ");
returnHubNoResPack(player);
}
else if (event.getStatus() == Status.FAILED_DOWNLOAD)
{
_resourcePackNoResponse.remove(player.getName());
returnHubNoResPack(player, "Failed to download resource pack!");
return;
}
}
if (event.getStatus() == Status.ACCEPTED
|| event.getStatus() == Status.SUCCESSFULLY_LOADED)
{
_resourcePackUsers.put(player.getName(), true);
}
else
{
_resourcePackUsers.remove(player.getName());
}
}
public ArcadePlayer getArcadePlayer(Player player)
{
return new ArcadePlayer(player, getCustomDataManager(), this);
}
public GameServerConfig GetServerConfig()
{
return _serverConfig;
}
public ResourcePackManager getResourcePackManager()
{
return _resourcePackManager;
}
public ArrayList<GameType> GetGameList()
{
return GetServerConfig().GameList;
@ -1448,112 +1372,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
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(), 20000))
{
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();
if (_resourcePackUsers.containsKey(player.getName()) && _resourcePackUsers.get(player.getName()))
{
new RedisUnloadResPack(player.getName()).publish();
_resourcePackUsers.remove(player.getName());
}
}
private void returnHubNoResPack(Player player)
{
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
GetPortal().sendPlayerToServer(player, "Lobby");
}
private void returnHubNoResPack(Player player, String message)
{
UtilPlayer.message(player, " ");
UtilPlayer.message(player, C.cGold + C.Bold + message);
UtilPlayer.message(player, " ");
returnHubNoResPack(player);
}
@EventHandler
public void ResourcePackJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
if (_resourcePackUrl != null)
{
if (_resourcePackRequired)
{
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
}
_resourcePackUsers.put(player.getName(), false);
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://file.mineplex.com/ResReset.zip");
}
}
else
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (_resourcePackRequired)
{
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
}
_resourcePackUsers.put(player.getName(), false);
player.setResourcePack(_resourcePackUrl);
}
}
}
}
public void loadRequiredRank()
{
_requiredRank = null;

View File

@ -383,7 +383,7 @@ public abstract class Game implements Listener
new ExperienceStatTracker(this), new WinStatTracker(this), new LoseStatTracker(this), new DamageDealtStatTracker(
this), new DamageTakenStatTracker(this), new GamesPlayedStatTracker(this));
Manager.setResourcePack(gameType.getResourcePackUrl(), gameType.isEnforceResourcePack());
Manager.getResourcePackManager().setResourcePack(gameType.getResourcePackUrl(), gameType.isEnforceResourcePack());
_useEntityPacketHandler = new IPacketHandler()
{