Initial commit

master
Elnu 3 years ago
commit b3f1894360

102
.gitignore vendored

@ -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

3
.idea/.gitignore vendored

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,9 @@
<component name="ArtifactManager">
<artifact type="jar" name="DeathCoordinates:jar">
<output-path>$PROJECT_DIR$/out/artifacts/DeathCoordinates_jar</output-path>
<root id="archive" name="DeathCoordinates.jar">
<element id="module-output" name="DeathCoordinates" />
<element id="file-copy" path="$PROJECT_DIR$/src/plugin.yml" />
</root>
</artifact>
</component>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -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;
}
}

@ -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;
}
}

@ -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<String, DeathInfo> playerDeathInfoMap;
public DeathListener() {
playerDeathInfoMap = new HashMap();
}
public HashMap<String, DeathInfo> 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));
}
}

@ -0,0 +1,8 @@
name: DeathCoordinates
main: com.elnu.DeathCoordinates
version: 1.0
author: ElnuDraws
commands:
announcedeath:
description: Announce last death coordinates.
usage: /announcedeath