PC-426: Update UX for non-premium players:

Removes the in game advertisement display when selecting servers.
Removes all chat throttling.
Adds a message sent on join to the player, promoting the newest sale or promotion.
This commit is contained in:
TadahTech 2016-07-15 00:01:24 -05:00 committed by cnr
parent c32e647d9e
commit 136eb078ef
8 changed files with 280 additions and 1 deletions

View File

@ -56,6 +56,7 @@ import mineplex.core.valentines.ValentinesGiftManager;
import mineplex.core.youtube.YoutubeManager; import mineplex.core.youtube.YoutubeManager;
import mineplex.hub.commands.*; import mineplex.hub.commands.*;
import mineplex.hub.modules.*; import mineplex.hub.modules.*;
import mineplex.hub.modules.nonpremium.NonPremiumManager;
import mineplex.hub.profile.gui.GUIProfile; import mineplex.hub.profile.gui.GUIProfile;
import mineplex.hub.tutorial.TutorialManager; import mineplex.hub.tutorial.TutorialManager;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
@ -243,6 +244,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
_valentinesManager = new ValentinesManager(plugin, clientManager, donationManager); _valentinesManager = new ValentinesManager(plugin, clientManager, donationManager);
new NonPremiumManager(plugin, clientManager);
try try
{ {

View File

@ -0,0 +1,84 @@
package mineplex.hub.modules.nonpremium;
import mineplex.core.progression.util.SQLStatement;
import mineplex.serverdata.database.DBPool;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
*/
public class MessageRepository
{
private static final String SCHEMA = "CREATE TABLE IF NOT EXISTS nonPremiumJoinMessage (message VARCHAR(256));";
private static final String QUERY = "SELECT `message` FROM `nonPremiumJoinMessage`;";
private static final String UPDATE = "UPDATE `nonPremiumJoinMessage` SET `message` = ?;";
private static final String INSERT = "INSERT INTO `nonPremiumJoinMessage` VALUES(?);";
private final JavaPlugin _plugin;
private String _message;
public MessageRepository(JavaPlugin plugin)
{
_plugin = plugin;
}
/**
* Update the message globally.
*
* @param message The new string literal message
*/
public void updateMessage(String message)
{
_message = message;
async(() -> {
try (Connection connection = DBPool.getAccount().getConnection())
{
ResultSet resultSet = new SQLStatement(QUERY).prepare(connection).executeQuery();
if (!resultSet.next())
{
new SQLStatement(INSERT).set(1, message).prepare(connection).executeUpdate();
} else
{
new SQLStatement(UPDATE).set(1, message).prepare(connection).executeUpdate();
}
} catch (SQLException e)
{
e.printStackTrace();
}
});
}
private void async(Runnable runnable)
{
Bukkit.getScheduler().runTaskAsynchronously(_plugin, runnable);
}
public String getMessage()
{
if (_message == null)
{
try (Connection connection = DBPool.getAccount().getConnection())
{
ResultSet resultSet = new SQLStatement(QUERY).prepare(connection).executeQuery();
if (resultSet == null || !resultSet.next())
{
return null;
}
_message = resultSet.getString(1);
} catch (SQLException e)
{
e.printStackTrace();
}
}
return _message;
}
}

View File

@ -0,0 +1,47 @@
package mineplex.hub.modules.nonpremium;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/**
*
*/
public class NPUMCommand extends CommandBase<NonPremiumManager>
{
public NPUMCommand(NonPremiumManager plugin)
{
super(plugin, Rank.ADMIN, "updatemessage");
}
@Override
public void Execute(Player caller, String[] args)
{
if(!Plugin.getClientManager().Get(caller).GetRank().has(Rank.ADMIN)) {
caller.sendMessage(C.cRed + "No.");
return;
}
if(args.length == 0) {
caller.sendMessage(F.main("NPUM", "Invalid Command Arguments. Usage: /updatemessage \"Message here\". Use '&' for color codes. Spaces are allowed."));
return;
}
StringBuilder message = new StringBuilder();
for(int i = 0; i < args.length; i++) {
message.append(args[i]);
if((i + 1) != args.length) {
message.append(" ");
}
}
Plugin.setMessage(message.toString(), true);
caller.sendMessage(F.main("NPUM", "Non-Premium User message updated. New message: "));
caller.sendMessage(ChatColor.translateAlternateColorCodes('&', message.toString()));
}
}

View File

@ -0,0 +1,84 @@
package mineplex.hub.modules.nonpremium;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.serverdata.commands.ServerCommandManager;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
/**
*
*/
public class NonPremiumManager extends MiniPlugin
{
private static final String LINE = C.cDGreenB + C.Strike + "=============================================";
private String _message;
private MessageRepository _messageRepository;
private CoreClientManager _clientManager;
public NonPremiumManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("NonPremiumPlayerManager", plugin);
addCommand(new NPUMCommand(this));
_clientManager = clientManager;
_messageRepository = new MessageRepository(plugin);
_message = _messageRepository.getMessage();
UpdateMessageHandler handler = new UpdateMessageHandler(this);
ServerCommandManager.getInstance().registerCommandType(UpdateMessageCommand.class, handler);
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
Rank rank = _clientManager.Get(player).GetRank();
if (_message == null)
{
return;
}
if (rank != Rank.ALL)
{
return;
}
getPlugin().getServer().getScheduler().runTaskLater(getPlugin(), () -> {
player.sendMessage(" ");
player.sendMessage(LINE);
player.sendMessage(" ");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', _message));
player.sendMessage(" ");
player.sendMessage(LINE);
player.sendMessage(" ");
player.sendMessage(" ");
}, 5L);
}
public void setMessage(String message, boolean updateDB)
{
_message = message;
if (!updateDB)
{
return;
}
_messageRepository.updateMessage(message);
ServerCommandManager.getInstance().publishCommand(new UpdateMessageCommand(message, getServer()));
}
public CoreClientManager getClientManager()
{
return _clientManager;
}
public String getServer() {
return getPlugin().getConfig().getString("serverstatus.name");
}
}

View File

@ -0,0 +1,28 @@
package mineplex.hub.modules.nonpremium;
import mineplex.serverdata.commands.ServerCommand;
/**
*
*/
public class UpdateMessageCommand extends ServerCommand
{
private String _message;
private String _from;
public UpdateMessageCommand(String message, String from) {
_message = message;
_from = from;
}
public String getMessage()
{
return _message;
}
public String getFrom()
{
return _from;
}
}

View File

@ -0,0 +1,29 @@
package mineplex.hub.modules.nonpremium;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
/**
*
*/
public class UpdateMessageHandler implements CommandCallback
{
private final NonPremiumManager _manager;
public UpdateMessageHandler(NonPremiumManager manager) {
_manager = manager;
}
@Override
public void run(ServerCommand command)
{
if(!(command instanceof UpdateMessageCommand)) {
return;
}
if(_manager.getServer().equalsIgnoreCase(((UpdateMessageCommand) command).getFrom())) {
return;
}
_manager.setMessage(((UpdateMessageCommand) command).getMessage(), false);
}
}

View File

@ -67,7 +67,7 @@ import mineplex.serverdata.data.ServerGroup;
public class ServerManager extends MiniDbClientPlugin<SimpleClanToken> implements BrawlShopProvider public class ServerManager extends MiniDbClientPlugin<SimpleClanToken> implements BrawlShopProvider
{ {
private static final Long FREE_PORTAL_TIMER = 20000L; private static final Long FREE_PORTAL_TIMER = -1L;
private static final Long BETA_PORTAL_TIMER = 120000L; private static final Long BETA_PORTAL_TIMER = 120000L;
private static final Random random = new Random(); private static final Random random = new Random();

View File

@ -92,6 +92,10 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
private void showClock(long milliseconds, boolean beta) private void showClock(long milliseconds, boolean beta)
{ {
if (!beta)
{
return;
}
int seconds = (int) (milliseconds / 1000); int seconds = (int) (milliseconds / 1000);
String timeLeft = UtilTime.convertString(milliseconds, 0, UtilTime.TimeUnit.FIT); String timeLeft = UtilTime.convertString(milliseconds, 0, UtilTime.TimeUnit.FIT);