From 0bc20e79ad26669531e52db0261ba55cd22f4ef3 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 2 May 2020 20:25:42 +0200 Subject: [PATCH] Inital commit --- .gitignore | 1 + .vscode/extensions.json | 5 + .vscode/settings.json | 12 + README.md | 43 +++ eclipse-formatter.xml | 315 ++++++++++++++++++ varo/.classpath | 49 +++ varo/.project | 23 ++ .../org.eclipse.core.resources.prefs | 4 + varo/.settings/org.eclipse.jdt.apt.core.prefs | 2 + varo/.settings/org.eclipse.jdt.core.prefs | 9 + varo/pom.xml | 55 +++ .../main/java/de/cliffbreak/varo/Varo.java | 37 ++ .../cliffbreak/varo/commands/TestCommand.java | 32 ++ .../varo/listeners/ChatListener.java | 17 + .../listeners/EntityRegainHealthListener.java | 23 ++ .../listeners/PlayerJoinQuitListener.java | 50 +++ .../cliffbreak/varo/uitls/MessageUtils.java | 92 +++++ varo/src/main/resources/plugin.yml | 10 + 18 files changed, 779 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 eclipse-formatter.xml create mode 100644 varo/.classpath create mode 100644 varo/.project create mode 100644 varo/.settings/org.eclipse.core.resources.prefs create mode 100644 varo/.settings/org.eclipse.jdt.apt.core.prefs create mode 100644 varo/.settings/org.eclipse.jdt.core.prefs create mode 100644 varo/pom.xml create mode 100644 varo/src/main/java/de/cliffbreak/varo/Varo.java create mode 100644 varo/src/main/java/de/cliffbreak/varo/commands/TestCommand.java create mode 100644 varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java create mode 100644 varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java create mode 100644 varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java create mode 100644 varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java create mode 100644 varo/src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..48181e9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "vscjava.vscode-java-pack", + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a02b5c2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "files.autoGuessEncoding": false, + "files.encoding": "utf8", + "java.jdt.ls.vmargs": "-Dfile.encoding=UTF-8", + "java.configuration.updateBuildConfiguration": "automatic", + "cSpell.words": [ + "Gamerules", + "cliffbreak", + "varo" + ], + "java.format.settings.url": "eclipse-formatter.xml", +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..18aa3f7 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# CliffbreakVARO 🗡️ + +This is the main Repository containing all required resources to compile the Java PaperMC Plugin. + +## Getting Started + +The following instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. + +### Prerequisites + +`Java 11` is required to compile this project. + +### Installing + +First clone this repository to your local machine by using + +``` +git clone https://git.cliffbreak.de/Cliffbreak/Varo.git +``` + +## Configure Visual Studio Code +If you haven't a instance of Visual Studio Code up and running download the latest version [here](https://code.visualstudio.com/download). +Install the recommended extensions by opening the Extensions-Tab (Ctrl+Shift+X). +Enter `@recommended` and install all extensions. +After that restart Visual Studio Code to apply all changes. + +## Contributing +First create an issue and assign it to yourself. Or assign an existing issue. +Make sure all issue details (description, labels, milestones) are correct. +Check out in a new branch. Notice our convention: use either feature or fix followed by a slash (`/`) and then a **short** description using camel case. (`fix/addMissingImports` or `feature/addBasicAuth`). +After that you may create a Pull Request to merge your changes into master (If it's work in progress add `WIP:` to the title!). + +## Deployment +In this section you can read details on the deployment cycle. + +## Built With + +* [OpenJDK](https://openjdk.java.net/) - The Java runtime used to compile the plugin +* [PaperMC](https://papermc.io/javadocs) - The framework used to create the plugin + +## Authors + +* **Simon Giesel** - *Initial work* - [Simon Giesel](https://git.cliffbreak.de/SimGie) \ No newline at end of file diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml new file mode 100644 index 0000000..f0bd101 --- /dev/null +++ b/eclipse-formatter.xml @@ -0,0 +1,315 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/varo/.classpath b/varo/.classpath new file mode 100644 index 0000000..9c4312a --- /dev/null +++ b/varo/.classpath @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/varo/.project b/varo/.project new file mode 100644 index 0000000..c924a9d --- /dev/null +++ b/varo/.project @@ -0,0 +1,23 @@ + + + varo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/varo/.settings/org.eclipse.core.resources.prefs b/varo/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..9bc94d4 --- /dev/null +++ b/varo/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding/=UTF-8 \ No newline at end of file diff --git a/varo/.settings/org.eclipse.jdt.apt.core.prefs b/varo/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..d4313d4 --- /dev/null +++ b/varo/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/varo/.settings/org.eclipse.jdt.core.prefs b/varo/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..1b6e1ef --- /dev/null +++ b/varo/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/varo/pom.xml b/varo/pom.xml new file mode 100644 index 0000000..040131e --- /dev/null +++ b/varo/pom.xml @@ -0,0 +1,55 @@ + + + + 4.0.0 + + de.cliffbreak.varo + varo + 1.0 + + varo + + https://cliffbreak.de/ + + jar + + UTF-8 + 1.8 + 1.8 + + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + + + com.destroystokyo.paper + paper-api + 1.15.2-R0.1-SNAPSHOT + provided + + + + ${project.basedir}/src/main/java + + + ${project.basedir}/src/main/resources + + plugin.yml + + + + + \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java new file mode 100644 index 0000000..72ec19b --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -0,0 +1,37 @@ +package de.cliffbreak.varo; + +import org.bukkit.Difficulty; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.plugin.java.JavaPlugin; + +import de.cliffbreak.varo.commands.TestCommand; +import de.cliffbreak.varo.listeners.ChatListener; +import de.cliffbreak.varo.listeners.EntityRegainHealthListener; +import de.cliffbreak.varo.listeners.PlayerJoinQuitListener; + +public class Varo extends JavaPlugin { + @Override + public void onEnable() { + + getLogger().info("CliffbreakVaro is starting..."); + + getServer().getPluginManager().registerEvents(new ChatListener(), this); + getServer().getPluginManager().registerEvents(new PlayerJoinQuitListener(), this); + getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this); + + getCommand("test").setExecutor(new TestCommand()); + + for (World world : getServer().getWorlds()) { + if (world.getEnvironment() == Environment.NORMAL) { + world.setDifficulty(Difficulty.HARD); + // world.setHardcore(true); //TODO: Should other hearts be displayed? + } + } + } + + @Override + public void onDisable() { + getLogger().info("Stopping CliffbreakVaro!"); + } +} diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/TestCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/TestCommand.java new file mode 100644 index 0000000..3986736 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/commands/TestCommand.java @@ -0,0 +1,32 @@ +package de.cliffbreak.varo.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.cliffbreak.varo.uitls.MessageUtils; + +public class TestCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) + return false; + Player p = (Player) sender; + p.sendMessage(MessageUtils.getRichTextComponent("§4" + "Team 01", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§c" + "Team 02", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§6" + "Team 03", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§e" + "Team 04", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§2" + "Team 05", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§a" + "Team 06", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§b" + "Team 07", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§3" + "Team 08", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§1" + "Team 09", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§9" + "Team 10", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§d" + "Team 11", "Test Nachricht")); + p.sendMessage(MessageUtils.getRichTextComponent("§5" + "Team 12", "Test Nachricht")); + return true; + } + +} \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java new file mode 100644 index 0000000..a6eb88e --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/ChatListener.java @@ -0,0 +1,17 @@ +package de.cliffbreak.varo.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import de.cliffbreak.varo.uitls.MessageUtils; + +public class ChatListener implements Listener { + + @EventHandler() + public void onChat(AsyncPlayerChatEvent e) { + e.setCancelled(true); + Bukkit.broadcast(MessageUtils.getRichTextComponent(e.getPlayer().getName(), e.getMessage())); + } +} diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java new file mode 100644 index 0000000..92eada3 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/EntityRegainHealthListener.java @@ -0,0 +1,23 @@ +package de.cliffbreak.varo.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityRegainHealthEvent; + +import de.cliffbreak.varo.uitls.MessageUtils; + +public class EntityRegainHealthListener implements Listener { + + @EventHandler() + public void onEntityRegainHealth(EntityRegainHealthEvent e) { + if (e.getEntity() instanceof Player) { + Player p = (Player) e.getEntity(); + p.sendMessage(MessageUtils.getRichTextComponent("Amount: ", e.getAmount() + "", true)); + p.sendMessage(MessageUtils.getRichTextComponent("Saturation: ", p.getSaturation() + "", true)); + if (e.isFastRegen()) { + e.setAmount(0.13d); + } + } + } +} \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java new file mode 100644 index 0000000..7e91145 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java @@ -0,0 +1,50 @@ +package de.cliffbreak.varo.listeners; + +import com.destroystokyo.paper.event.server.PaperServerListPingEvent; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.server.ServerListPingEvent; + +import de.cliffbreak.varo.uitls.MessageUtils; + +public class PlayerJoinQuitListener implements Listener { + + @EventHandler() + public void onPlayerQuit(PlayerQuitEvent e) { + e.setQuitMessage(null); + Bukkit.broadcast( + MessageUtils.getRichTextComponent(e.getPlayer().getName(), "§f hat den Server verlassen.", true)); + } + + @EventHandler() + public void onPlayerJoin(PlayerJoinEvent e) { + e.setJoinMessage(null); + Bukkit.broadcast( + MessageUtils.getRichTextComponent(e.getPlayer().getName(), "§f hat den Server betreten.", true)); + e.getPlayer().sendMessage("\n§7§l#### §9Cliffbreak.de - §lVaro §r§9Changelog §7§l####\n \n" + + " §cWarning: §r§c Plugin is running in DEBUG mode!\n " + + "\n §7• §r§lADD: §rRedesigned Chat with Timestamp" + + "\n §7• §r§lADD: §rHover over Playername for Details (Team)" + + "\n §7• §r§lADD: §rControl Difficulty and Gamerules by the Plugin" + + "\n §7• §r§lADD: §rCustom Dynamic ServerListEntry" + "\n §7• §r§lADD: §r1.8 Health Regeneration"); + } + + @EventHandler() + public void onServerListPing(ServerListPingEvent event) { + if (event instanceof PaperServerListPingEvent) { + handlePaperServerListPing((PaperServerListPingEvent) event); + } else { + Bukkit.getLogger().info("Error: Plugin is not running on a PaperServer"); + } + } + + private void handlePaperServerListPing(final PaperServerListPingEvent e) { + e.setHidePlayers(true); + // TODO: Add day counter + e.setMotd("§9§l" + "VARO" + "§b§l " + "Tag: -1" + "\n§r§7" + "powered by " + "§4" + "Cliffbreak.de"); + } +} \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java b/varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java new file mode 100644 index 0000000..2962d84 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/MessageUtils.java @@ -0,0 +1,92 @@ +package de.cliffbreak.varo.uitls; + +import java.util.Calendar; + +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; + +public class MessageUtils { + + public static String getTimestampedMessage(String message) { + + return " §8" + getTimestamp() + " §7| " + message; + } + + /** + * Create a TextComponent with a more detailed player name on hover + * + * @param player + * the playername the message should be sent from + * @param message + * the message to send + * @return TextComponent + */ + public static TextComponent getRichTextComponent(String player, String message) { + return getRichTextComponent(player, message, false, true); + } + + /** + * Create a TextComponent with a more detailed player name on hover + * + * @param player + * the playername the message should be sent from + * @param message + * the message to send + * @param isServiceMessage + * is this a service message (f.e. PlayerJoinEvent) + * @return TextComponent + */ + public static TextComponent getRichTextComponent(String player, String message, boolean isServiceMessage) { + return getRichTextComponent(player, message, isServiceMessage, true); + } + + /** + * Create a TextComponent with a more detailed player name on hover and an optional timestamp + * + * @param player + * the playername the message should be sent from + * @param message + * the message to send + * @param isServiceMessage + * is this a service message (f.e. PlayerJoinEvent) + * @param useTimestamp + * should a timestamp be returned? + * @return TextComponent + */ + public static TextComponent getRichTextComponent(String player, String message, boolean isServiceMessage, + boolean useTimestamp) { + TextComponent mainComponent = new TextComponent(" "); + TextComponent timeComponent = new TextComponent("§8" + getTimestamp() + " §7| "); + TextComponent playerComponent = new TextComponent("§b" + player); + TextComponent messageComponent = new TextComponent(" §7>> §r§f" + message); + timeComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ComponentBuilder("§7" + getTimestampSeconds()).create())); + playerComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + new ComponentBuilder("§e" + "Name:" + "§r " + player + "\n§b" + "Team:" + "§r " + "kein Team :(") + .create())); + playerComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + player + " ")); + if (useTimestamp) + mainComponent.addExtra(timeComponent); + mainComponent.addExtra(playerComponent); + if (!isServiceMessage) + mainComponent.addExtra(messageComponent); + else + mainComponent.addExtra(message); + return mainComponent; + } + + private static String getTimestamp() { + Calendar calendar = Calendar.getInstance(); + return String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY)) + ":" + + String.format("%02d", calendar.get(Calendar.MINUTE)); + } + + private static String getTimestampSeconds() { + Calendar calendar = Calendar.getInstance(); + return String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY)) + ":" + + String.format("%02d", calendar.get(Calendar.MINUTE)) + ":" + + String.format("%02d", calendar.get(Calendar.SECOND)); + } +} \ No newline at end of file diff --git a/varo/src/main/resources/plugin.yml b/varo/src/main/resources/plugin.yml new file mode 100644 index 0000000..d7035a1 --- /dev/null +++ b/varo/src/main/resources/plugin.yml @@ -0,0 +1,10 @@ +main: de.cliffbreak.varo.Varo +name: CliffbreakVaro +description: Custom Cliffbreak.de Varo +version: 0.1 +api-version: 1.15 +commands: + test: + description: A command to test certain plugin behaviors. + aliases: [t] + usage: / \ No newline at end of file