commit b3f1894360c8e4f45ba1cc5d813290ceb9bae091 Author: ElnuDev Date: Sat Nov 27 16:23:50 2021 -0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f779353 --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +.idea/modules.xml +.idea/*.iml +.idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +# JetBrains templates +**___jb_tmp___ + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/artifacts/DeathCoordinates_jar.xml b/.idea/artifacts/DeathCoordinates_jar.xml new file mode 100644 index 0000000..77db1b7 --- /dev/null +++ b/.idea/artifacts/DeathCoordinates_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/DeathCoordinates_jar + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/com/elnu/DeathCoordinates.java b/src/com/elnu/DeathCoordinates.java new file mode 100644 index 0000000..428d115 --- /dev/null +++ b/src/com/elnu/DeathCoordinates.java @@ -0,0 +1,51 @@ +package com.elnu; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + +public class DeathCoordinates extends JavaPlugin { + DeathListener deathListener; + + @Override + public void onEnable() { + deathListener = new DeathListener(); + Bukkit.getPluginManager().registerEvents(deathListener, this); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (cmd.getName().equalsIgnoreCase("announcedeath")) { + var senderName = sender.getName(); + try { + var playerDeathInfoMap = deathListener.getPlayerDeathInfoMap(); + var deathInfo = playerDeathInfoMap.get(senderName); + var location = deathInfo.getLocation(); + var time = deathInfo.getTime(); + var now = LocalDateTime.now(); + var minutesSinceDeath = time.until(now, ChronoUnit.MINUTES); + var secondsSinceDeath = time.until(now, ChronoUnit.SECONDS); + playerDeathInfoMap.remove(senderName); + Bukkit.getServer().broadcastMessage(ChatColor.RED + String.format( + "%s is announcing that they died at (%d, %d, %d) in %s, %d minutes and %d seconds ago.", + senderName, + location.getBlockX(), + location.getBlockY(), + location.getBlockZ(), + location.getWorld().getEnvironment(), + minutesSinceDeath, + secondsSinceDeath + )); + } catch(NullPointerException e) { + sender.sendMessage(ChatColor.YELLOW + "No death coordinates to announce."); + } + return true; + } + return false; + } +} diff --git a/src/com/elnu/DeathInfo.java b/src/com/elnu/DeathInfo.java new file mode 100644 index 0000000..36693b2 --- /dev/null +++ b/src/com/elnu/DeathInfo.java @@ -0,0 +1,23 @@ +package com.elnu; + +import org.bukkit.Location; + +import java.time.LocalDateTime; + +public class DeathInfo { + Location location; + LocalDateTime time; + + public DeathInfo(Location location) { + this.location = location; + time = LocalDateTime.now(); + } + + public Location getLocation() { + return location; + } + + public LocalDateTime getTime() { + return time; + } +} diff --git a/src/com/elnu/DeathListener.java b/src/com/elnu/DeathListener.java new file mode 100644 index 0000000..0709499 --- /dev/null +++ b/src/com/elnu/DeathListener.java @@ -0,0 +1,34 @@ +package com.elnu; + +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; + +import java.util.HashMap; + +public class DeathListener implements Listener { + HashMap playerDeathInfoMap; + + public DeathListener() { + playerDeathInfoMap = new HashMap(); + } + + public HashMap getPlayerDeathInfoMap() { + return playerDeathInfoMap; + } + + @EventHandler + public void onDeath(PlayerDeathEvent event) { + var location = event.getEntity().getLocation(); + var player = event.getEntity(); + player.sendMessage(ChatColor.RED + String.format( + "Oof! You died at (%d, %d, %d) in %s.", + location.getBlockX(), + location.getBlockY(), + location.getBlockZ(), + location.getWorld().getEnvironment() + )); + playerDeathInfoMap.put(player.getName(), new DeathInfo(location)); + } +} diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..052bf0b --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,8 @@ +name: DeathCoordinates +main: com.elnu.DeathCoordinates +version: 1.0 +author: ElnuDraws +commands: + announcedeath: + description: Announce last death coordinates. + usage: /announcedeath \ No newline at end of file