ToggleDeathCoordinates 1.0 Release
This commit is contained in:
1 parent
60b871bedb
commit
c7a75b7804
10 files changed
+337
-134
No files matched your search
+3
-1
@@ -1,5 +1,7 @@
|
||||
# User-specific stuff
|
||||
.idea/
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
<div align="center">
|
||||
<h1>CoordinatesOnDeath</h1>
|
||||
# ToggleDeathCoords-OG
|
||||
|
||||
<img src="https://img.shields.io/github/v/tag/can-aslan/CoordinatesOnDeath?color=l&label=version">
|
||||
<img src="https://img.shields.io/github/issues/can-aslan/CoordinatesOnDeath?label=known%20issues">
|
||||
<img src="https://img.shields.io/github/commit-activity/w/can-aslan/CoordinatesOnDeath">
|
||||
<img src="https://img.shields.io/github/license/can-aslan/CoordinatesOnDeath">
|
||||
|
||||
### Displays the death coordinates of players to them upon death.
|
||||
</div>
|
||||
A spigot plugin to display death coordinates with a per-player permissions-based toggle. Built for [TrueOG](https://true-og.net/).
|
||||
|
||||
Gradle Version: 8.1.1
|
||||
|
||||
Java Version: 17
|
||||
|
||||
Minecraft API: 1.18.2
|
||||
|
||||
ToggleDeathCoords-OG is a fork of [CoordinatesOnDeath](https://github.com/can-aslan/CoordinatesOnDeath) by [Yağız Can Aslan](https://github.com/can-aslan) released under the terms of the [MIT License](https://github.com/NotAlexNoyle/ToggleDeathCoordinates-OG/blob/master/LICENSE.md).
|
||||
|
||||
## Features
|
||||
+ Prints the player name and death location (x-y-z coordinates) of the player to the console.
|
||||
+ Sends the player death location (x-y-z coordinates) to the player who died as a message.
|
||||
+ Automatic update checks upon server start.
|
||||
|
||||
### Message Upon Player Death Example:
|
||||

|
||||
|
||||
### Up-To-Date Plugin Example:
|
||||

|
||||
|
||||
### Outdated Plugin Example:
|
||||

|
||||
|
||||
# Download: https://www.curseforge.com/minecraft/bukkit-plugins/coordinatesondeath
|
||||
- Prints the player name and death location (x-y-z coordinates) of the player to the console.
|
||||
- Sends the player death location (x-y-z coordinates) to the player who died as a message.
|
||||
- Allows individual players to toggle showing death coordinates based on rank and permissions.
|
||||
@@ -4,12 +4,12 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>CoordinatesOnDeath</groupId>
|
||||
<artifactId>CoordinatesOnDeath</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<groupId>net.trueog</groupId>
|
||||
<artifactId>ToggleDeathCoordinates</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>CoordinatesOnDeath</name>
|
||||
<name>ToggleDeathCoordinates</name>
|
||||
|
||||
<description>Displays the coordinates of the death location of players upon player death.</description>
|
||||
<properties>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package coordinatesondeath.coordinatesondeath;
|
||||
|
||||
import coordinatesondeath.coordinatesondeath.handlers.DeathHandler;
|
||||
import coordinatesondeath.coordinatesondeath.updatecheck.UpdateChecker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class CoordinatesOnDeath extends JavaPlugin {
|
||||
final String PREFIX = "[CoordinatesOnDeath] ";
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + PREFIX + "CoordinatesOnDeath enabled.");
|
||||
|
||||
// Update checker logic
|
||||
new UpdateChecker(this).getVersion(version -> {
|
||||
if (this.getDescription().getVersion().equals(version)) Bukkit.getConsoleSender().sendMessage(
|
||||
ChatColor.GREEN
|
||||
+ "\n-------------------------------------------------------"
|
||||
+ "\n" + PREFIX + "You are running the latest version of CoordinatesOnDeath (" + this.getDescription().getVersion() + ")."
|
||||
+ "\n-------------------------------------------------------");
|
||||
else Bukkit.getConsoleSender().sendMessage(
|
||||
ChatColor.YELLOW
|
||||
+ "\n-------------------------------------------------------"
|
||||
+ "\n" + PREFIX + "WARNING: You are running an outdated version of CoordinatesOnDeath (" + this.getDescription().getVersion() + ")! Newest version: " + version + "."
|
||||
+ "\n" + PREFIX + "Download the latest version from: https://www.curseforge.com/minecraft/bukkit-plugins/coordinatesondeath"
|
||||
+ "\n-------------------------------------------------------");
|
||||
});
|
||||
|
||||
// Plugin logic
|
||||
new DeathHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Bukkit.getLogger().info(ChatColor.RED + PREFIX + "CoordinatesOnDeath disabled.");
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package coordinatesondeath.coordinatesondeath.handlers;
|
||||
|
||||
import coordinatesondeath.coordinatesondeath.CoordinatesOnDeath;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
public class DeathHandler implements Listener {
|
||||
final String PREFIX = ChatColor.AQUA + "[" + ChatColor.GREEN + "CoordinatesOnDeath" + ChatColor.AQUA + "] " + ChatColor.GOLD;
|
||||
public DeathHandler(CoordinatesOnDeath plugin) {
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
Location eyeLocation = player.getEyeLocation();
|
||||
String name = player.getDisplayName();
|
||||
|
||||
String deathMsg = (
|
||||
" died at X = " + eyeLocation.getBlockX()
|
||||
+ ", Y = " + eyeLocation.getBlockY()
|
||||
+ ", Z = " + eyeLocation.getBlockZ() + ".");
|
||||
|
||||
Bukkit.getLogger().info(PREFIX + name + deathMsg);
|
||||
event.getEntity().sendMessage(PREFIX + "You" + deathMsg);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package coordinatesondeath.coordinatesondeath.updatecheck;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class UpdateChecker {
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public UpdateChecker(JavaPlugin pl) {
|
||||
plugin = pl;
|
||||
}
|
||||
|
||||
public void getVersion(final Consumer<String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=102587").openStream(); Scanner scan = new Scanner(inputStream)) {
|
||||
if (scan.hasNext()) {
|
||||
consumer.accept(scan.next());
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
plugin.getLogger().info("ERROR: Cannot check for updates: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
// Author: NotAlexNoyle (admin@true-og.net)
|
||||
|
||||
// Declare container package that this class resides in.
|
||||
package toggleDeathCoordinates;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
// Import required libraries.
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Extends bukkit class to run commands.
|
||||
public class CommandManager implements CommandExecutor {
|
||||
|
||||
// Keep inheritance of command manager private so nothing else can hook into it and run an unrelated command.
|
||||
private static CommandManager instance;
|
||||
|
||||
String chatTag = ChatColor.translateAlternateColorCodes('&', "&8[&aNoClip &4OG&6&8] ");
|
||||
|
||||
// Share this instance of the Command Manager with other classes.
|
||||
public static CommandManager getInstance() {
|
||||
|
||||
// Pass the instance of this class as an object.
|
||||
return instance;
|
||||
|
||||
}
|
||||
|
||||
// Command execution event handler extending bukkit's CommandManager
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
// Takes over command execution if plugin is invoked.
|
||||
if (cmd.getName().equalsIgnoreCase("tdc")) {
|
||||
|
||||
// Checks to make sure the command is being run in-game and not in the console.
|
||||
if (sender instanceof Player) {
|
||||
|
||||
// Convert sender to player once it has been determined that they are one.
|
||||
Player player = (Player) sender;
|
||||
|
||||
// Make sure the player has permission first.
|
||||
if (player.hasPermission("toggledeathcoordinates.use")) {
|
||||
|
||||
// Run the function to toggle death coordinates, since all qualifications have been met.
|
||||
doDeathCoordinateToggle(player);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
// Advertise OG Master to players who don't have it.
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', ToggleDeathCoordinates.getPrefix() + "&cERROR: &6Only" + " &4&lOG Master &6and above can toggle death coordinates being shown in chat with &e/tdc&6. You can upgrade with &B&l/buy&6."));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// Do nothing if run from console.
|
||||
else {
|
||||
|
||||
// Send error message to console.
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', ToggleDeathCoordinates.getPrefix() + "ERROR: The console cannot execute that command!"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Healthy exit status.
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// Declare a function to hold the logic for toggling death coordinates.
|
||||
public void doDeathCoordinateToggle(Player player) {
|
||||
|
||||
// Get the player file from the main class.
|
||||
File playerFile = ToggleDeathCoordinates.getDisabledPlayers();
|
||||
|
||||
// Convert the file to a YAML object for manipulation.
|
||||
YamlConfiguration playerCache = YamlConfiguration.loadConfiguration(playerFile);
|
||||
|
||||
// Get the current state of the player's death coordinates from the YAML.
|
||||
boolean toggleState = playerCache.getBoolean((player).getUniqueId().toString());
|
||||
|
||||
// Flip the true/false value to the opposite of what it currently is.
|
||||
playerCache.set((player).getUniqueId().toString(), ! toggleState);
|
||||
|
||||
// Attempt to run code that throws an error.
|
||||
try {
|
||||
|
||||
// Save the YAML modifications to a file.
|
||||
playerCache.save(ToggleDeathCoordinates.getDisabledPlayers());
|
||||
|
||||
}
|
||||
// Catch a file read/write error if one is thrown.
|
||||
catch (IOException e) {
|
||||
|
||||
// Send an error message to the player who tried to toggle their death coordinates.
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', ToggleDeathCoordinates.getPrefix() + "&cERROR: ToggleDeathCoordinates encountered a problem. Please report this issue to staff."));
|
||||
|
||||
}
|
||||
|
||||
// If the player's death coordinates are toggled off, do this...
|
||||
if(! toggleState) {
|
||||
|
||||
// Send the player a message affirming that their death coordinates have been toggled OFF.
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', ToggleDeathCoordinates.getPrefix() + "&6Death Coordinates turned &cOFF&6."));
|
||||
|
||||
}
|
||||
// If the player's death coordinates are toggled on, do this...
|
||||
else {
|
||||
|
||||
// Send the player a message affirming that their death coordinates have been toggled ON.
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', ToggleDeathCoordinates.getPrefix() + "&aDeath Coordinates turned &2ON&a."));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
// Author: NotAlexNoyle (admin@true-og.net)
|
||||
|
||||
// Declare container package that this class resides in.
|
||||
package toggleDeathCoordinates;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
// Import required libraries.
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
// Declare listener class.
|
||||
public class Listeners implements Listener {
|
||||
|
||||
// Declare class constructor.
|
||||
public Listeners(ToggleDeathCoordinates plugin) {
|
||||
|
||||
// Receive instance of primary class.
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
}
|
||||
|
||||
// Listen for a death event in-game.
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
|
||||
// Get player from event.
|
||||
Player player = event.getEntity();
|
||||
|
||||
// Get player's death location.
|
||||
Location eyeLocation = player.getEyeLocation();
|
||||
|
||||
// Declare death message with formatting and coordinates.
|
||||
String deathMsg = (" died at X = " + eyeLocation.getBlockX() + ", Y = " + eyeLocation.getBlockY() + ", Z = " + eyeLocation.getBlockZ() + ".");
|
||||
|
||||
// Log player's death coordinates in console.
|
||||
Bukkit.getLogger().info(ToggleDeathCoordinates.getPrefix() + player.getDisplayName() + deathMsg);
|
||||
|
||||
// If death coordinates are enabled for the given player, do this...
|
||||
if(deathCoordinatesAreEnabled(player)) {
|
||||
|
||||
// Send the player their death coordinates in chat.
|
||||
player.sendMessage(ToggleDeathCoordinates.getPrefix() + "You" + deathMsg);
|
||||
|
||||
}
|
||||
|
||||
// If the player does not have permission (ie. is not OG Master), do this.
|
||||
if (! player.hasPermission("toggledeathcoordinates.use")) {
|
||||
|
||||
// Advertise OG Master to players who don't have it.
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', ToggleDeathCoordinates.getPrefix() + " &4&lOG Master &6and above can toggle death coordinates being shown in chat with &e/tdc&6. You can upgrade with &B&l/buy&6."));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Declare a function to tell whether or not death coordinates are on for a given player.
|
||||
public boolean deathCoordinatesAreEnabled(Player player) {
|
||||
|
||||
// Get the player file from the main class.
|
||||
File playerFile = ToggleDeathCoordinates.getDisabledPlayers();
|
||||
|
||||
// Convert the file to a YAML object for manipulation.
|
||||
YamlConfiguration playerCache = YamlConfiguration.loadConfiguration(playerFile);
|
||||
|
||||
// Get the current state of the player's death coordinates from the YAML.
|
||||
boolean playersDeathCoordinatesAreEnabled = playerCache.getBoolean((player).getUniqueId().toString());
|
||||
|
||||
// If player's death coordinates are now set to false, do this...
|
||||
if(playersDeathCoordinatesAreEnabled) {
|
||||
|
||||
// Pass the false value back to the Listener.
|
||||
return false;
|
||||
|
||||
}
|
||||
// If player's death coordinates are now set to true, do this...
|
||||
else {
|
||||
|
||||
// Pass the true value back to the Listener.
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
// Author: NotAlexNoyle (admin@true-og.net)
|
||||
|
||||
// Declare container package that this class resides in.
|
||||
package toggleDeathCoordinates;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
// Import required libraries.
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
// Declare primary class for plugin.
|
||||
public final class ToggleDeathCoordinates extends JavaPlugin {
|
||||
|
||||
// Declare prefix for chat messages.
|
||||
final static String prefix = ChatColor.GRAY + "[" + ChatColor.GREEN + "ToggleDeathCoordinates" + ChatColor.DARK_RED + "-OG" + ChatColor.GRAY + "] " + ChatColor.GOLD;
|
||||
|
||||
// Declare a container for the player cache in YAML form.
|
||||
private static File disabledPlayers;
|
||||
|
||||
// Share chat prefix with other classes.
|
||||
public static String getPrefix() {
|
||||
|
||||
// Pass constant String.
|
||||
return prefix;
|
||||
|
||||
}
|
||||
|
||||
// Tell bukkit to load the plugin.
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
File existingPlayerCache = null;
|
||||
try {
|
||||
|
||||
existingPlayerCache = new File(this.getDataFolder(), "PlayerCache.yml");
|
||||
|
||||
if (! existingPlayerCache.exists()) {
|
||||
|
||||
existingPlayerCache.createNewFile();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException error) {
|
||||
|
||||
this.getLogger().severe("Something went wrong when creating the player cache file!");
|
||||
|
||||
}
|
||||
|
||||
// Pass file to other classes.
|
||||
disabledPlayers = existingPlayerCache;
|
||||
// Set YAML cache to contents of file.
|
||||
YamlConfiguration.loadConfiguration(existingPlayerCache);
|
||||
|
||||
// Load listener class and pass this class to it.
|
||||
new Listeners(this);
|
||||
|
||||
// Run command when plugin event is triggered.
|
||||
this.getCommand("tdc").setExecutor(new CommandManager());
|
||||
|
||||
// Show a startup message in the console.
|
||||
Bukkit.getConsoleSender().sendMessage("ToggleDeathCoordinates enabled.");
|
||||
|
||||
}
|
||||
|
||||
// Tell bukkit what to do when shutting the server down.
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
// Display shutdown message in console.
|
||||
Bukkit.getLogger().info("ToggleDeathCoordinates disabled.");
|
||||
|
||||
}
|
||||
|
||||
// Declare a function to share the player cache file with other class.
|
||||
public static File getDisabledPlayers() {
|
||||
|
||||
// Pass the player cache file.
|
||||
return disabledPlayers;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,15 @@
|
||||
name: CoordinatesOnDeath
|
||||
version: 'v0.1.1-beta'
|
||||
main: coordinatesondeath.coordinatesondeath.CoordinatesOnDeath
|
||||
name: ToggleDeathCoordinates
|
||||
version: '1.0'
|
||||
main: toggleDeathCoordinates.ToggleDeathCoordinates
|
||||
api-version: 1.18
|
||||
description: Displays the death coordinates of players to them upon death.
|
||||
|
||||
commands:
|
||||
tdc:
|
||||
description: Turn the display of your death coordinates in chat on or off.
|
||||
aliases: [toggledeathcoordinates]
|
||||
|
||||
permissions:
|
||||
tdc.use:
|
||||
description: Permission to toggle your death coordinates.
|
||||
default: op
|
||||
Reference in new issue
Block a user