Skip to content

Commit

Permalink
Finished beta stage of mailboxes database
Browse files Browse the repository at this point in the history
Functional but not finished
  • Loading branch information
leothawne committed Dec 17, 2023
1 parent 90597d0 commit c77d240
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 45 deletions.
Binary file added mailboxes.db
Binary file not shown.
14 changes: 4 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.leothawne</groupId>
<artifactId>LTItemMail</artifactId>
<version>0.2.5</version>
<version>0.2.6</version>
<name>LT Item Mail</name>
<description>A way of sending items to another players without needing to teleport to them.</description>
<build>
Expand All @@ -12,8 +12,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.17</source>
<target>1.17</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<version>1.17-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
Expand All @@ -87,11 +87,5 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public static final void sendSpecial(final Player receiver, final LinkedList<Ite
final String[] mailboxOpening = LTItemMail.getInstance().getLanguage().getString("mailbox-opening-seconds").split("%");
LTItemMail.getInstance().getPlayerBusy().put(receiver.getUniqueId(), true);
if(LTItemMail.getInstance().getConfiguration().getBoolean("use-title") == true) {
receiver.sendTitle(ChatColor.LIGHT_PURPLE + "" + mailboxFrom, ChatColor.AQUA + "" + mailboxOpening[0] + "" + ChatColor.GREEN + "" + LTItemMail.getInstance().getConfiguration().getInt("mail-time") + "" + ChatColor.AQUA + "" + mailboxOpening[1] + " " + ChatColor.DARK_RED + "" + LTItemMail.getInstance().getLanguage().getString("mailbox-lose"), 20 * 1, 20 * LTItemMail.getInstance().getConfiguration().getInt("mail-time"), 20 * 1);
receiver.sendTitle(ChatColor.LIGHT_PURPLE + "" + mailboxFrom, ChatColor.AQUA + "" + mailboxOpening[0] + "" + ChatColor.GREEN + "" + LTItemMail.getInstance().getConfiguration().getInt("mail-time") + "" + ChatColor.AQUA + "" + mailboxOpening[1], 20 * 1, 20 * LTItemMail.getInstance().getConfiguration().getInt("mail-time"), 20 * 1);
} else {
receiver.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.AQUA + "" + mailboxFrom);
receiver.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.AQUA + "" + mailboxOpening[0] + "" + ChatColor.GREEN + "" + LTItemMail.getInstance().getConfiguration().getInt("mail-time") + "" + ChatColor.AQUA + "" + mailboxOpening[1] + " " + ChatColor.DARK_RED + "" + LTItemMail.getInstance().getLanguage().getString("mailbox-lose"));
receiver.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.AQUA + "" + mailboxOpening[0] + "" + ChatColor.GREEN + "" + LTItemMail.getInstance().getConfiguration().getInt("mail-time") + "" + ChatColor.AQUA + "" + mailboxOpening[1]);
}
new BukkitRunnable() {
@Override
public final void run() {
receiver.openInventory(MailboxInventory.getMailboxInventory(MailboxType.IN, null, items));
receiver.openInventory(MailboxInventory.getMailboxInventory(MailboxType.IN, null, null, items));
}
}.runTaskLater(LTItemMail.getInstance(), 20 * LTItemMail.getInstance().getConfiguration().getInt("mail-time") + 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class MetricsAPI {
* @param serviceId The id of the service. It can be found at <a
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
@SuppressWarnings("deprecation")
public MetricsAPI(JavaPlugin plugin, int serviceId) {
this.plugin = plugin;
// Get the config file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package io.github.leothawne.LTItemMail.command;

import java.util.HashMap;
import java.util.LinkedList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import io.github.leothawne.LTItemMail.LTItemMail;
import io.github.leothawne.LTItemMail.api.HTTP;
import io.github.leothawne.LTItemMail.inventory.MailboxInventory;
import io.github.leothawne.LTItemMail.module.DataModule;
import io.github.leothawne.LTItemMail.module.DatabaseModule;
import io.github.leothawne.LTItemMail.type.MailboxType;

public final class ItemMailAdminCommand implements CommandExecutor {
public ItemMailAdminCommand() {}
Expand All @@ -19,6 +29,8 @@ public final boolean onCommand(final CommandSender sender, final Command cmd, fi
sender.sendMessage(ChatColor.AQUA + "=+=+=+= [LT Item Mail :: Admin] =+=+=+=");
sender.sendMessage(ChatColor.GREEN + "/itemmailadmin " + ChatColor.AQUA + "- Commands for administrators.");
sender.sendMessage(ChatColor.GREEN + "/itemmailadmin update " + ChatColor.AQUA + "- Check for new updates.");
sender.sendMessage(ChatColor.GREEN + "/itemmailadmin list <player> " + ChatColor.AQUA + "- List opened mailboxes of a specific player.");
sender.sendMessage(ChatColor.GREEN + "/itemmailadmin recover <mailbox id> " + ChatColor.AQUA + "- Recover lost items (if there is any).");
sender.sendMessage(ChatColor.YELLOW + "You can also use "+ ChatColor.GREEN + "/itemmailadmin "+ ChatColor.YELLOW + "as "+ ChatColor.GREEN + "/imad"+ ChatColor.YELLOW + ".");
} else if(args[0].equalsIgnoreCase("update")) {
if(args.length == 1) {
Expand Down Expand Up @@ -46,6 +58,29 @@ public final void run() {
}
}.runTaskAsynchronously(LTItemMail.getInstance());
} else sender.sendMessage(ChatColor.AQUA + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + " :: Admin] " + ChatColor.YELLOW + "Too many arguments!");
} else if(args[0].equalsIgnoreCase("list") && sender instanceof Player) {
final Player player = (Player) sender;
if(args.length == 2) {
@SuppressWarnings("deprecation")
final OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(args[1]);
final HashMap<Integer, String> mailboxes = DatabaseModule.Function.getOpenedMailboxesList(offPlayer.getUniqueId());
if(mailboxes.size() > 0) {
player.sendMessage(offPlayer.getName() + "'s opened mailboxes:");
for(final Integer mailboxID : mailboxes.keySet()) player.sendMessage("Mailbox #" + mailboxID + " : " + mailboxes.get(mailboxID));
} else player.sendMessage("No opened mailboxes for player " + offPlayer.getName() + ".");
}
} else if(args[0].equalsIgnoreCase("recover") && sender instanceof Player) {
final Player player = (Player) sender;
if(args.length == 2) try {
final Integer mailboxID = Integer.valueOf(args[1]);
final LinkedList<ItemStack> items = DatabaseModule.Function.getLostMailbox(mailboxID);
if(items.size() > 0) {
LTItemMail.getInstance().getPlayerBusy().put(player.getUniqueId(), true);
player.openInventory(MailboxInventory.getMailboxInventory(MailboxType.IN, mailboxID, null, items));
} else player.sendMessage("There is no lost items on this mailbox.");
} catch (final NumberFormatException e) {
player.sendMessage("Mailbox ID must be a number!");
}
} else sender.sendMessage(ChatColor.AQUA + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + " :: Admin] " + ChatColor.YELLOW + "Invalid command! Type " + ChatColor.GREEN + "/itemmailadmin " + ChatColor.YELLOW + "to see all available commands.");
} else {
sender.sendMessage(ChatColor.AQUA + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + " :: Admin] " + ChatColor.YELLOW + "" + LTItemMail.getInstance().getLanguage().getString("no-permission"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package io.github.leothawne.LTItemMail.command;

import java.util.HashMap;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import io.github.leothawne.LTItemMail.LTItemMail;
import io.github.leothawne.LTItemMail.inventory.MailboxInventory;
import io.github.leothawne.LTItemMail.module.DataModule;
import io.github.leothawne.LTItemMail.module.DatabaseModule;
import io.github.leothawne.LTItemMail.type.MailboxType;

public final class ItemMailCommand implements CommandExecutor {
public ItemMailCommand() {}
Expand All @@ -27,10 +33,25 @@ public final boolean onCommand(final CommandSender sender, final Command cmd, fi
if(args.length == 1) {
DataModule.version(LTItemMail.getInstance().getDescription().getVersion(), sender);
} else sender.sendMessage(ChatColor.AQUA + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "Too many arguments!");
} else if(args[0].equalsIgnoreCase("open")) {

} else if(args[0].equalsIgnoreCase("list")) {

} else if(args[0].equalsIgnoreCase("open") && sender instanceof Player) {
final Player player = (Player) sender;
if(args.length == 2) try {
final Integer mailboxID = Integer.valueOf(args[1]);
if(DatabaseModule.Function.isMaiboxOwner(player.getUniqueId(), mailboxID) && !DatabaseModule.Function.isMailboxOpened(mailboxID)) {
player.sendMessage(ChatColor.DARK_RED + "" + LTItemMail.getInstance().getLanguage().getString("mailbox-lose"));
LTItemMail.getInstance().getPlayerBusy().put(player.getUniqueId(), true);
player.openInventory(MailboxInventory.getMailboxInventory(MailboxType.IN, mailboxID, null, DatabaseModule.Function.getMailbox(mailboxID)));
DatabaseModule.Function.setMailboxOpened(mailboxID);
}
} catch (final NumberFormatException e) {
player.sendMessage("Mailbox ID must be a number!");
}
} else if(args[0].equalsIgnoreCase("list") && sender instanceof Player) {
final Player player = (Player) sender;
final HashMap<Integer, String> mailboxes = DatabaseModule.Function.getMailboxesList(player.getUniqueId());
if(mailboxes.size() > 0) {
for(final Integer mailboxID : mailboxes.keySet()) player.sendMessage("Mailbox #" + mailboxID + " : " + mailboxes.get(mailboxID));
} else player.sendMessage("No new mailboxes.");
} else sender.sendMessage(ChatColor.AQUA + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "Invalid command! Type " + ChatColor.GREEN + "/itemmail " + ChatColor.YELLOW + "to see all available commands.");
} else {
sender.sendMessage(ChatColor.AQUA + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "" + LTItemMail.getInstance().getLanguage().getString("no-permission"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public final boolean onCommand(final CommandSender sender, final Command cmd, fi
if(player1.getUniqueId().equals(player.getUniqueId())) {
if(args.length == 2 && args[1].equalsIgnoreCase("--bypass") && player.hasPermission("LTItemMail.admin")) {
player.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "Okay...");
player.openInventory(MailboxInventory.getMailboxInventory(MailboxType.OUT, player1, null));
player.openInventory(MailboxInventory.getMailboxInventory(MailboxType.OUT, null, player1, null));
} else player.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "" + LTItemMail.getInstance().getLanguage().getString("player-self"));
} else {
player.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "" + LTItemMail.getInstance().getLanguage().getString("mailbox-opening"));
player.openInventory(MailboxInventory.getMailboxInventory(MailboxType.OUT, player1, null));
player.openInventory(MailboxInventory.getMailboxInventory(MailboxType.OUT, null, player1, null));
}
} else player.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "" + LTItemMail.getInstance().getLanguage().getString("recipient-offline"));
} else player.sendMessage(ChatColor.DARK_GREEN + "[" + LTItemMail.getInstance().getConfiguration().getString("plugin-tag") + "] " + ChatColor.YELLOW + "" + LTItemMail.getInstance().getLanguage().getString("player-tma"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.github.leothawne.LTItemMail.command.tabCompleter;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

import com.google.common.collect.ImmutableList;

Expand All @@ -15,11 +18,18 @@ public final class ItemMailAdminCommandTabCompleter implements TabCompleter {
@Override
public final List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args){
final List<String> ReturnNothing = new ArrayList<>();
if(sender.hasPermission("LTItemMail.use") && sender.hasPermission("LTItemMail.admin")) {
if(sender.hasPermission("LTItemMail.admin")) {
if(args.length == 1) {
final ImmutableList<String> MailAdmin = ImmutableList.of("update");
final ImmutableList<String> MailAdmin = ImmutableList.of("update", "list", "recover");
return TabCompleterAPI.partial(args[0], MailAdmin);
}
if(args.length == 2) {
if(args[0].equals("list")) {
final LinkedList<String> completes = new LinkedList<>();
for(final Player p: Bukkit.getOnlinePlayers()) completes.add(p.getName());
return TabCompleterAPI.partial(args[1], completes);
}
}
}
return ReturnNothing;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
package io.github.leothawne.LTItemMail.command.tabCompleter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

import com.google.common.collect.ImmutableList;

import io.github.leothawne.LTItemMail.api.TabCompleterAPI;
import io.github.leothawne.LTItemMail.module.DatabaseModule;

public final class ItemMailCommandTabCompleter implements TabCompleter {
@Override
public final List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args){
final List<String> ReturnNothing = new ArrayList<>();
if(sender.hasPermission("LTItemMail.use")) {
if(args.length == 1) {
final ImmutableList<String> Mail = ImmutableList.of("version");
return TabCompleterAPI.partial(args[0], Mail);
final ImmutableList<String> completes = ImmutableList.of("version", "list", "open");
return TabCompleterAPI.partial(args[0], completes);
}
if(args.length == 2) {
if(args[0].equals("open")) if(sender instanceof Player) {
final Player player = (Player) sender;
final HashMap<Integer, String> mailboxes = DatabaseModule.Function.getMailboxesList(player.getUniqueId());
final LinkedList<String> completes = new LinkedList<>();
for(final Integer i : mailboxes.keySet()) completes.add(String.valueOf(i));
return TabCompleterAPI.partial(args[1], completes);
}
}
}
return ReturnNothing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
import io.github.leothawne.LTItemMail.type.MailboxType;

public final class MailboxInventory {
public static final String getMailboxName(final MailboxType type) {
if(type.equals(MailboxType.IN)) return "> Mailbox <";
if(type.equals(MailboxType.OUT)) return "< Mailbox >";
public static final String getMailboxName(final MailboxType type, final Integer mailboxID) {
if(mailboxID != null) {
if(type.equals(MailboxType.IN)) if(mailboxID == 0) {
return "Mailbox#";
} else return "Mailbox#" + String.valueOf(mailboxID);
} else {
if(type.equals(MailboxType.IN)) return "> Mailbox <";
if(type.equals(MailboxType.OUT)) return "< Mailbox >";
}
return null;
}
public static final Inventory getMailboxInventory(final MailboxType type, Player player, final LinkedList<ItemStack> contents) {
public static final Inventory getMailboxInventory(final MailboxType type, final Integer mailboxID, Player player, final LinkedList<ItemStack> contents) {
if(type.equals(MailboxType.IN)) {
final Inventory inventory = Bukkit.createInventory(null, 54, getMailboxName(type));
final Inventory inventory = Bukkit.createInventory(null, 27, getMailboxName(type, mailboxID));
for(int i = 0; i < (contents.size() - 1); i++) inventory.setItem(i, contents.get(i));
return inventory;
} else if(type.equals(MailboxType.OUT)) {
final Inventory inventory = Bukkit.createInventory(player, 54, getMailboxName(type));
final Inventory inventory = Bukkit.createInventory(player, 27, getMailboxName(type, mailboxID));
return inventory;
}
return null;
Expand Down
Loading

0 comments on commit c77d240

Please sign in to comment.