Some changes *_*

This commit is contained in:
Shaun Bennett 2014-12-04 17:29:47 -06:00
parent cded2c7d8f
commit 0bb2d1db5b
13 changed files with 145 additions and 42 deletions

View File

@ -10,5 +10,4 @@
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
</project>

View File

@ -18,6 +18,6 @@
<orderEntry type="module" module-name="Mineplex.Database" />
<orderEntry type="library" name="jooq" level="project" />
<orderEntry type="library" name="commons-dbcp2" level="project" />
<orderEntry type="module" module-name="Classpath.Dummy" />
</component>
</module>
</module>

View File

@ -98,4 +98,14 @@ public abstract class MiniPlugin implements Listener
{
_plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, runnable);
}
protected void runSync(Runnable runnable)
{
_plugin.getServer().getScheduler().runTask(_plugin, runnable);
}
protected void runSyncLater(Runnable runnable, long delay)
{
_plugin.getServer().getScheduler().runTaskLater(_plugin, runnable, delay);
}
}

View File

@ -193,7 +193,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true;
// new MailManager(_plugin, _clientManager, _donationManager);
new MailManager(_plugin, _clientManager, _donationManager);
_ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, ChatColor.GREEN + "Rule Book", new String[] { });
BookMeta meta = (BookMeta)_ruleBook.getItemMeta();

View File

@ -1,19 +1,21 @@
package mineplex.hub.mail;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.Callback;
import mineplex.core.donation.DonationManager;
import mineplex.hub.mail.command.MailCommand;
import mineplex.hub.mail.gui.MailShop;
/**
* Created by shaun on 14-11-20.
*/
public class MailManager extends MiniClientPlugin<PlayerMailData>
{
private MailRepository _repository;
@ -57,4 +59,54 @@ public class MailManager extends MiniClientPlugin<PlayerMailData>
{
addCommand(new MailCommand(this));
}
public void archive(final MailMessage message, final Callback<Boolean> callback)
{
if (message.isArchived())
return;
runAsync(new Runnable()
{
@Override
public void run()
{
final boolean completed = _repository.archive(message);
runSync(new Runnable()
{
@Override
public void run()
{
callback.run(completed);
}
});
}
});
}
@EventHandler
public void showNotification(PlayerJoinEvent event)
{
final Player player = event.getPlayer();
runSyncLater(new Runnable()
{
@Override
public void run()
{
if (player.isOnline())
{
PlayerMailData mailData = Get(player);
if (mailData != null)
{
List<MailMessage> unreadMessages = mailData.getUnreadMessages();
if (unreadMessages.size() > 0)
{
JsonMessage message = new JsonMessage("You have unread notifications. Click here to read them!");
message.color("red");
}
}
}
}
}, 20 * 8);
}
}

View File

@ -2,9 +2,6 @@ package mineplex.hub.mail;
import java.sql.Timestamp;
/**
* Created by shaun on 14-11-20.
*/
public class MailMessage
{
private int _messageId;

View File

@ -1,10 +1,13 @@
package mineplex.hub.mail;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.database.RepositoryBase;
import mineplex.database.Tables;
import mineplex.database.tables.records.MailRecord;
@ -12,9 +15,6 @@ import org.jooq.DSLContext;
import org.jooq.Result;
import org.jooq.impl.DSL;
/**
* Created by shaun on 14-11-20.
*/
public class MailRepository extends RepositoryBase
{
public MailRepository(JavaPlugin plugin)
@ -34,6 +34,14 @@ public class MailRepository extends RepositoryBase
}
public PlayerMailData loadMailData(ResultSet resultSet) throws SQLException
{
PlayerMailData data = new PlayerMailData();
return data;
}
public PlayerMailData loadMailData(UUID uuid)
{
PlayerMailData data = new PlayerMailData();
@ -57,4 +65,13 @@ public class MailRepository extends RepositoryBase
{
return new MailMessage(record.getId(), record.getSender(), record.getMessage(), (record.getArchived() & 0x01) != 0, (record.getDeleted() & 0x01) != 0, record.getTimeSent());
}
public boolean archive(MailMessage mailMessage)
{
DSLContext context = DSL.using(getConnection());
int recordsUpdated = context.update(Tables.mail).set(Tables.mail.archived, (byte) 1).where(Tables.mail.id.eq(mailMessage.getMessageId())).execute();
return recordsUpdated == 1;
}
}

View File

@ -5,9 +5,6 @@ import java.util.List;
import mineplex.database.tables.records.MailRecord;
/**
* Created by shaun on 14-11-20.
*/
public class PlayerMailData
{
private List<MailMessage> _messages;

View File

@ -8,9 +8,6 @@ import mineplex.hub.mail.MailManager;
import mineplex.hub.mail.MailMessage;
import mineplex.hub.mail.PlayerMailData;
/**
* Created by shaun on 14-11-20.
*/
public class MailCommand extends CommandBase<MailManager>
{
public MailCommand(MailManager plugin)
@ -28,7 +25,6 @@ public class MailCommand extends CommandBase<MailManager>
caller.sendMessage(message.getMessage());
}
Plugin.openShop(caller);
}
}

View File

@ -10,9 +10,6 @@ import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.mail.MailManager;
import mineplex.hub.mail.gui.page.MailPage;
/**
* Created by shaun on 14-11-20.
*/
public class MailShop extends ShopBase<MailManager>
{
public MailShop(MailManager plugin, CoreClientManager clientManager, DonationManager donationManager)

View File

@ -1,35 +1,50 @@
package mineplex.hub.mail.gui.button;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mineplex.core.common.util.Callback;
import mineplex.core.shop.item.IButton;
import mineplex.hub.mail.MailManager;
import mineplex.hub.mail.MailMessage;
import mineplex.hub.mail.gui.page.MailPage;
/**
* Created by shaun on 14-11-20.
*/
public class MailButton implements IButton
{
private MailManager _manager;
private MailPage _page;
private MailMessage _message;
public MailButton(MailPage page, MailMessage message)
private Player _player;
public MailButton(MailManager manager, Player player, MailPage page, MailMessage message)
{
_manager = manager;
_page = page;
_message = message;
_player = player;
}
@Override
public void ClickedLeft(Player player)
{
_page.Refresh();
}
@Override
public void ClickedRight(Player player)
{
_page.Refresh();
_manager.archive(_message, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (data)
{
_page.Refresh();
_player.playSound(_player.getLocation(), Sound.SPLASH, 1, 0);
}
}
});
}
}

View File

@ -1,7 +1,9 @@
package mineplex.hub.mail.gui.page;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -14,9 +16,6 @@ import mineplex.hub.mail.MailMessage;
import mineplex.hub.mail.gui.MailShop;
import mineplex.hub.mail.gui.button.MailButton;
/**
* Created by shaun on 14-11-20.
*/
public class MailPage extends ShopPageBase<MailManager, MailShop>
{
public MailPage(MailManager plugin, MailShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
@ -38,7 +37,7 @@ public class MailPage extends ShopPageBase<MailManager, MailShop>
ShopItem item = getItem(message);
System.out.println(message.getMessage());
AddButton(i, item, new MailButton(this, message));
AddButton(i, item, new MailButton(Plugin, Player, this, message));
}
}
@ -49,15 +48,40 @@ public class MailPage extends ShopPageBase<MailManager, MailShop>
return shopItem;
}
private String[] parseMessage(MailMessage message)
private String[] parseMessage(MailMessage mailMessage)
{
String[] lines = new String[5];
ArrayList<String> lines = new ArrayList<String>();
lines[0] = "From: " + message.getSender();
lines[1] = "Message: " + message.getMessage();
lines[2] = "Deleted: " + message.isDeleted();
lines[3] = "Archived: " + message.isArchived();
ArrayList<String> message = formatMessage(mailMessage.getMessage());
return lines;
lines.add("From: " + mailMessage.getSender());
lines.add(" ");
lines.addAll(message);
return lines.toArray(new String[lines.size()]);
}
private ArrayList<String> formatMessage(String mailMessage)
{
mailMessage = ChatColor.translateAlternateColorCodes('&', mailMessage); // Color the message
ArrayList<String> parts = new ArrayList<String>();
int breakIndex = 0;
int charCount = 0;
for (int currIndex = 0; currIndex < mailMessage.length(); currIndex++)
{
charCount++;
char c = mailMessage.charAt(currIndex);
if ((charCount >= 50 && c == ' ') || c == '\n')
{
// New Line
parts.add(mailMessage.substring(breakIndex, currIndex));
breakIndex = currIndex;
}
}
return parts;
}
}

View File

@ -15,7 +15,6 @@ import net.minecraft.server.v1_7_R4.ChatSerializer;
import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
import net.minecraft.util.com.google.gson.JsonObject;
import mineplex.core.MiniClientPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;