From 96efab0eb78d0505af468da7b15785e9b60a533f Mon Sep 17 00:00:00 2001 From: Jeremy Noesen Date: Thu, 7 Jan 2021 14:21:57 -0600 Subject: [PATCH 1/5] added gradle to project --- .gitignore | 7 ++++- build.gradle | 19 +++++++++++++ .../jeremynoesen/couriernew/CommandExec.java | 0 .../java}/jeremynoesen/couriernew/Config.java | 0 .../jeremynoesen/couriernew/CourierNew.java | 0 .../jeremynoesen/couriernew/Message.java | 0 .../couriernew/courier/Courier.java | 28 +++---------------- .../couriernew/courier/CourierOptions.java | 0 .../couriernew/letter/LetterChecker.java | 0 .../couriernew/letter/LetterCreation.java | 0 .../couriernew/letter/LetterSender.java | 0 .../couriernew/letter/Outgoing.java | 0 {resources => src/main/resources}/config.yml | 0 .../main/resources}/messages.yml | 0 .../main/resources}/outgoing.yml | 0 {resources => src/main/resources}/plugin.yml | 4 +-- 16 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 build.gradle rename src/{ => main/java}/jeremynoesen/couriernew/CommandExec.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/Config.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/CourierNew.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/Message.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/courier/Courier.java (83%) rename src/{ => main/java}/jeremynoesen/couriernew/courier/CourierOptions.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/letter/LetterChecker.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/letter/LetterCreation.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/letter/LetterSender.java (100%) rename src/{ => main/java}/jeremynoesen/couriernew/letter/Outgoing.java (100%) rename {resources => src/main/resources}/config.yml (100%) rename {resources => src/main/resources}/messages.yml (100%) rename {resources => src/main/resources}/outgoing.yml (100%) rename {resources => src/main/resources}/plugin.yml (93%) diff --git a/.gitignore b/.gitignore index 7901350..67de262 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,9 @@ out/ *.zip *.tar.gz *.rar -hs_err_pid* \ No newline at end of file +hs_err_pid* +gradlew.bat +gradlew +gradle +.gradle +build \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..4dbae13 --- /dev/null +++ b/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group 'jeremynoesen.couriernew' +version '1.3.2' +compileJava.options.encoding = 'UTF-8' + +repositories { + mavenCentral() + jcenter() + mavenLocal() + maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' } + maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' } +} + +dependencies { + compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT' +} \ No newline at end of file diff --git a/src/jeremynoesen/couriernew/CommandExec.java b/src/main/java/jeremynoesen/couriernew/CommandExec.java similarity index 100% rename from src/jeremynoesen/couriernew/CommandExec.java rename to src/main/java/jeremynoesen/couriernew/CommandExec.java diff --git a/src/jeremynoesen/couriernew/Config.java b/src/main/java/jeremynoesen/couriernew/Config.java similarity index 100% rename from src/jeremynoesen/couriernew/Config.java rename to src/main/java/jeremynoesen/couriernew/Config.java diff --git a/src/jeremynoesen/couriernew/CourierNew.java b/src/main/java/jeremynoesen/couriernew/CourierNew.java similarity index 100% rename from src/jeremynoesen/couriernew/CourierNew.java rename to src/main/java/jeremynoesen/couriernew/CourierNew.java diff --git a/src/jeremynoesen/couriernew/Message.java b/src/main/java/jeremynoesen/couriernew/Message.java similarity index 100% rename from src/jeremynoesen/couriernew/Message.java rename to src/main/java/jeremynoesen/couriernew/Message.java diff --git a/src/jeremynoesen/couriernew/courier/Courier.java b/src/main/java/jeremynoesen/couriernew/courier/Courier.java similarity index 83% rename from src/jeremynoesen/couriernew/courier/Courier.java rename to src/main/java/jeremynoesen/couriernew/courier/Courier.java index 1c3af4c..dbfa052 100644 --- a/src/jeremynoesen/couriernew/courier/Courier.java +++ b/src/main/java/jeremynoesen/couriernew/courier/Courier.java @@ -1,18 +1,15 @@ package jeremynoesen.couriernew.courier; -import com.earth2me.essentials.Essentials; -import de.myzelyam.supervanish.SuperVanish; import jeremynoesen.couriernew.CourierNew; import jeremynoesen.couriernew.Message; import jeremynoesen.couriernew.letter.Outgoing; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.metadata.MetadataValue; import org.bukkit.scheduler.BukkitRunnable; -import org.kitteh.vanish.VanishPlugin; import java.util.HashMap; @@ -167,26 +164,9 @@ public Entity getCourier() { public static boolean canSpawn(Player recipient) { if (!recipient.isOnline()) return false; - - if (Bukkit.getPluginManager().isPluginEnabled("VanishNoPacket")) { - if (((VanishPlugin) Bukkit.getPluginManager().getPlugin("VanishNoPacket")).getManager().isVanished - (recipient)) { - recipient.sendMessage(Message.ERROR_VANISHED); - return false; - } - } - - if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) { - if (((Essentials) Bukkit.getPluginManager().getPlugin("Essentials")) - .getVanishedPlayers().contains(recipient.getName())) { - recipient.sendMessage(Message.ERROR_VANISHED); - return false; - } - } - - if (Bukkit.getPluginManager().isPluginEnabled("SuperVanish")) { - if (((SuperVanish) Bukkit.getPluginManager().getPlugin("SuperVanish")) - .getVanishStateMgr().isVanished(recipient.getUniqueId())) { + + for (MetadataValue meta : recipient.getMetadata("vanished")) { + if (meta.asBoolean()) { recipient.sendMessage(Message.ERROR_VANISHED); return false; } diff --git a/src/jeremynoesen/couriernew/courier/CourierOptions.java b/src/main/java/jeremynoesen/couriernew/courier/CourierOptions.java similarity index 100% rename from src/jeremynoesen/couriernew/courier/CourierOptions.java rename to src/main/java/jeremynoesen/couriernew/courier/CourierOptions.java diff --git a/src/jeremynoesen/couriernew/letter/LetterChecker.java b/src/main/java/jeremynoesen/couriernew/letter/LetterChecker.java similarity index 100% rename from src/jeremynoesen/couriernew/letter/LetterChecker.java rename to src/main/java/jeremynoesen/couriernew/letter/LetterChecker.java diff --git a/src/jeremynoesen/couriernew/letter/LetterCreation.java b/src/main/java/jeremynoesen/couriernew/letter/LetterCreation.java similarity index 100% rename from src/jeremynoesen/couriernew/letter/LetterCreation.java rename to src/main/java/jeremynoesen/couriernew/letter/LetterCreation.java diff --git a/src/jeremynoesen/couriernew/letter/LetterSender.java b/src/main/java/jeremynoesen/couriernew/letter/LetterSender.java similarity index 100% rename from src/jeremynoesen/couriernew/letter/LetterSender.java rename to src/main/java/jeremynoesen/couriernew/letter/LetterSender.java diff --git a/src/jeremynoesen/couriernew/letter/Outgoing.java b/src/main/java/jeremynoesen/couriernew/letter/Outgoing.java similarity index 100% rename from src/jeremynoesen/couriernew/letter/Outgoing.java rename to src/main/java/jeremynoesen/couriernew/letter/Outgoing.java diff --git a/resources/config.yml b/src/main/resources/config.yml similarity index 100% rename from resources/config.yml rename to src/main/resources/config.yml diff --git a/resources/messages.yml b/src/main/resources/messages.yml similarity index 100% rename from resources/messages.yml rename to src/main/resources/messages.yml diff --git a/resources/outgoing.yml b/src/main/resources/outgoing.yml similarity index 100% rename from resources/outgoing.yml rename to src/main/resources/outgoing.yml diff --git a/resources/plugin.yml b/src/main/resources/plugin.yml similarity index 93% rename from resources/plugin.yml rename to src/main/resources/plugin.yml index d9abc7f..a498e9c 100644 --- a/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: CourierNew -version: 1.3.1 -description: A new form of Courier +version: 1.3.2 +description: A unique mail system author: Jeremaster101 main: jeremynoesen.couriernew.CourierNew softdepend: [VanishNoPacket, Essentials, SuperVanish] From ab76d67288f247ee09e123b1641deb7db5e736ea Mon Sep 17 00:00:00 2001 From: Jeremy Noesen Date: Thu, 7 Jan 2021 14:29:23 -0600 Subject: [PATCH 2/5] clean up command class --- .../jeremynoesen/couriernew/CommandExec.java | 167 ++++++++---------- 1 file changed, 73 insertions(+), 94 deletions(-) diff --git a/src/main/java/jeremynoesen/couriernew/CommandExec.java b/src/main/java/jeremynoesen/couriernew/CommandExec.java index d884bc5..79d6a67 100644 --- a/src/main/java/jeremynoesen/couriernew/CommandExec.java +++ b/src/main/java/jeremynoesen/couriernew/CommandExec.java @@ -1,8 +1,5 @@ package jeremynoesen.couriernew; -import jeremynoesen.couriernew.Config; -import jeremynoesen.couriernew.CourierNew; -import jeremynoesen.couriernew.Message; import jeremynoesen.couriernew.courier.Courier; import jeremynoesen.couriernew.courier.CourierOptions; import jeremynoesen.couriernew.letter.LetterChecker; @@ -37,109 +34,91 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (!worlds.contains(player.getWorld()) && !modes.contains(player.getGameMode())) { - if (label.equalsIgnoreCase("letter")) { + switch (label.toLowerCase()) { - if (player.hasPermission("couriernew.letter")) { - if (args.length >= 1) { - StringBuilder sb = new StringBuilder(); - for (String arg : args) { - sb.append(arg).append(" "); - } - if (LetterChecker.isHoldingOwnLetter(player) && - !LetterChecker.wasSent(player.getInventory().getItemInMainHand())) - LetterCreation.editBook(player, sb.toString()); - else LetterCreation.writeBook(player, sb.toString()); - //lc.writeMap(player, sb.toString()); + case "letter": + if (player.hasPermission("couriernew.letter")) { + if (args.length >= 1) { + StringBuilder sb = new StringBuilder(); + for (String arg : args) { + sb.append(arg).append(" "); + } + if (LetterChecker.isHoldingOwnLetter(player) && + !LetterChecker.wasSent(player.getInventory().getItemInMainHand())) + LetterCreation.editBook(player, sb.toString()); + else LetterCreation.writeBook(player, sb.toString()); + //lc.writeMap(player, sb.toString()); + } else + player.sendMessage(Message.ERROR_NO_MSG); } else - player.sendMessage(Message.ERROR_NO_MSG); - } else - player.sendMessage(Message.ERROR_NO_PERMS); - - } - - - if (label.equalsIgnoreCase("cnreload")) { - - if (player.hasPermission("couriernew.reload")) { - Config.getMainConfig().reloadConfig(); - Config.getOutgoingConfig().reloadConfig(); - Config.getMessageConfig().reloadConfig(); - Courier.getCouriers().keySet().forEach(Entity::remove); - Courier.getCouriers().clear(); - player.sendMessage(Message.SUCCESS_RELOADED); - } else - player.sendMessage(Message.ERROR_NO_PERMS); - - } - - - if (label.equalsIgnoreCase("post")) { + player.sendMessage(Message.ERROR_NO_PERMS); + break; - if (args.length == 1) { - if (player.hasPermission("couriernew.post.one") || player.hasPermission("couriernew" + - ".post.multiple") || - player.hasPermission("couriernew.post.allonline") || player.hasPermission("couriernew" + - ".post.all")) { - LetterSender.send(player, args[0]); + case "cnreload": + if (player.hasPermission("couriernew.reload")) { + Config.getMainConfig().reloadConfig(); + Config.getOutgoingConfig().reloadConfig(); + Config.getMessageConfig().reloadConfig(); + Courier.getCouriers().keySet().forEach(Entity::remove); + Courier.getCouriers().clear(); + player.sendMessage(Message.SUCCESS_RELOADED); } else player.sendMessage(Message.ERROR_NO_PERMS); - } else - player.sendMessage(Message.ERROR_TOO_MANY_ARGS); - - } - - - if (label.equalsIgnoreCase("cnhelp")) { - - if (player.hasPermission("couriernew.help")) { - player.sendMessage(Message.HELP); - } else - player.sendMessage(Message.ERROR_NO_PERMS); + break; - } - - - if (label.equalsIgnoreCase("shred")) { - - if (player.hasPermission("couriernew.shred")) { - LetterCreation.delete(player); - } else - player.sendMessage(Message.ERROR_NO_PERMS); + case "post": + if (args.length == 1) { + if (player.hasPermission("couriernew.post.one") || player.hasPermission("couriernew" + + ".post.multiple") || + player.hasPermission("couriernew.post.allonline") || player.hasPermission("couriernew" + + ".post.all")) { + LetterSender.send(player, args[0]); + } else + player.sendMessage(Message.ERROR_NO_PERMS); + } else + player.sendMessage(Message.ERROR_TOO_MANY_ARGS); + break; - } - - - if (label.equalsIgnoreCase("shredall")) { + case "cnhelp": + if (player.hasPermission("couriernew.help")) { + player.sendMessage(Message.HELP); + } else + player.sendMessage(Message.ERROR_NO_PERMS); + break; - if (player.hasPermission("couriernew.shredall")) { - LetterCreation.deleteAll(player); - } else - player.sendMessage(Message.ERROR_NO_PERMS); + case "shred": + if (player.hasPermission("couriernew.shred")) { + LetterCreation.delete(player); + } else + player.sendMessage(Message.ERROR_NO_PERMS); + break; - } - - - if (label.equalsIgnoreCase("unread")) { + case "shredall": + if (player.hasPermission("couriernew.shredall")) { + LetterCreation.deleteAll(player); + } else + player.sendMessage(Message.ERROR_NO_PERMS); + break; - if (player.hasPermission("couriernew.unread")) { - - if (Outgoing.getOutgoing().containsKey(player) && Outgoing.getOutgoing().get(player).size() > 0) { - player.sendMessage(Message.SUCCESS_EXTRA_DELIVERIES); - new BukkitRunnable() { - @Override - public void run() { - if (player.isOnline()) { - LetterSender.spawnCourier(player); + case "unread": + if (player.hasPermission("couriernew.unread")) { + if (Outgoing.getOutgoing().containsKey(player) && Outgoing.getOutgoing().get(player).size() > 0) { + player.sendMessage(Message.SUCCESS_EXTRA_DELIVERIES); + new BukkitRunnable() { + @Override + public void run() { + if (player.isOnline()) { + LetterSender.spawnCourier(player); + } } - } - }.runTaskLater(CourierNew.getInstance(), CourierOptions.RECEIVE_DELAY); - } else { - player.sendMessage(Message.ERROR_NO_MAIL); - } - } else - player.sendMessage(Message.ERROR_NO_PERMS); + }.runTaskLater(CourierNew.getInstance(), CourierOptions.RECEIVE_DELAY); + } else { + player.sendMessage(Message.ERROR_NO_MAIL); + } + } else + player.sendMessage(Message.ERROR_NO_PERMS); + break; } - } else { player.sendMessage(Message.ERROR_WORLD); } From f3fcf04cfd7ea89fe2b41d22f8e03a4194da1b54 Mon Sep 17 00:00:00 2001 From: Jeremy Noesen Date: Thu, 7 Jan 2021 14:30:52 -0600 Subject: [PATCH 3/5] remove unnecessary softdepends --- src/main/resources/plugin.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a498e9c..6da204c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,6 @@ version: 1.3.2 description: A unique mail system author: Jeremaster101 main: jeremynoesen.couriernew.CourierNew -softdepend: [VanishNoPacket, Essentials, SuperVanish] api-version: 1.13 commands: letter: From 3de1cac2f9d042e2f6685702419ddb13cf772933 Mon Sep 17 00:00:00 2001 From: Jeremy Noesen Date: Thu, 7 Jan 2021 14:33:31 -0600 Subject: [PATCH 4/5] fix reload command --- src/main/java/jeremynoesen/couriernew/CommandExec.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/jeremynoesen/couriernew/CommandExec.java b/src/main/java/jeremynoesen/couriernew/CommandExec.java index 79d6a67..b651061 100644 --- a/src/main/java/jeremynoesen/couriernew/CommandExec.java +++ b/src/main/java/jeremynoesen/couriernew/CommandExec.java @@ -56,11 +56,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St case "cnreload": if (player.hasPermission("couriernew.reload")) { + Outgoing.saveAll(); + Courier.getCouriers().keySet().forEach(Entity::remove); + Courier.getCouriers().clear(); Config.getMainConfig().reloadConfig(); Config.getOutgoingConfig().reloadConfig(); Config.getMessageConfig().reloadConfig(); - Courier.getCouriers().keySet().forEach(Entity::remove); - Courier.getCouriers().clear(); + CourierOptions.load(); + Outgoing.loadAll(); + Message.reloadMessages(); player.sendMessage(Message.SUCCESS_RELOADED); } else player.sendMessage(Message.ERROR_NO_PERMS); From 55e13ea6c1a81e29d96c159448e2ccdeb965224d Mon Sep 17 00:00:00 2001 From: Jeremy Noesen Date: Thu, 7 Jan 2021 14:39:39 -0600 Subject: [PATCH 5/5] update readme with building --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb4998c..43b4264 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ CourierNew is a built-from-scratch partial remake of an abandoned Bukkit plugin - `couriernew.reload` - Allows for reloading of configs ## Requirements -- Spigot 1.13 - 1.16 +- Spigot 1.13.0 - 1.16.4 - Java 8 ## Installation @@ -65,6 +65,9 @@ The third configuration file is actually used to store outgoing mail. Don't modi ## Demonstration ![Demonstration](demo.gif) +## Building +If you wish to build from source, a `build.gradle` is included to create the jar, as well as get dependencies if you import the project into your IDE. + ## Troubleshooting Courier not spawning? - In the WorldGuard config, set `block-plugin-spawning` to false.