Skip to content

Commit

Permalink
v0.0.9 - Info command for everyone to use by default
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroGamers committed Jun 7, 2019
1 parent 6b08553 commit 9f67c25
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>dk.fido2603</groupId>
<artifactId>semihardcore</artifactId>
<version>0.0.8</version>
<version>0.0.9</version>
<name>Semi-Hardcore</name>
<repositories>
<!-- Spigot Repo for Spigot and Bukkit -->
Expand Down
114 changes: 94 additions & 20 deletions src/main/java/dk/fido2603/semihardcore/Commands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dk.fido2603.semihardcore;

import java.util.UUID;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -20,7 +22,7 @@ public void commandReload(Player player)
if (player == null)
{
this.plugin.reloadSettings();
this.plugin.log(this.plugin.getDescription().getFullName() + ": Reloaded configuration.");
this.plugin.log("Reloaded configuration.");
}
else if (player.isOp() || (SemiHardcore.getPermissionsManager().hasPermission(player, "semihardcore.reload")))
{
Expand All @@ -34,7 +36,7 @@ public void commandSave(Player player)
if (player == null)
{
SemiHardcore.getPlayerManager().save();
this.plugin.log(this.plugin.getDescription().getFullName() + ": Saved configuration(s).");
this.plugin.log("Saved configuration(s).");
}
else if (player.isOp() || (SemiHardcore.getPermissionsManager().hasPermission(player, "semihardcore.save")))
{
Expand All @@ -50,39 +52,107 @@ public void commandUnban(Player player, String[] args) {
}
}

private boolean commandHelp(CommandSender sender)
public void commandInfo(Player player, String[] args) {
if (player == null || player.isOp() || SemiHardcore.getPermissionsManager().hasPermission(player, "semihardcore.info")) {
String playerName = args[1];
UUID playerUUID = SemiHardcore.getPlayerManager().getUUID(playerName);

if (player == null) {
this.plugin.log("---------------- " + plugin.getDescription().getFullName() + " ----------------");
this.plugin.log("Playerinfo for " + playerName);
this.plugin.log("");

if (playerUUID == null) {
this.plugin.log("The given player could not be found in the list of dead players!");
return;
}

this.plugin.log("Banned: " + SemiHardcore.getPlayerManager().isBanned(playerUUID));
this.plugin.log("Deaths: " + SemiHardcore.getPlayerManager().getDeaths(playerUUID));
this.plugin.log("Time of last death: " + SemiHardcore.getPlayerManager().getDeathTime(playerUUID));
this.plugin.log("Time since last death: " + SemiHardcore.getPlayerManager().getTimeSinceDeathTime(playerUUID));

return;
}

player.sendMessage(ChatColor.YELLOW + "---------------- " + plugin.getDescription().getFullName() + " ----------------");
player.sendMessage(ChatColor.AQUA + "Playerinfo for " + ChatColor.WHITE + playerName);
player.sendMessage(ChatColor.AQUA + "");

if (playerUUID == null) {
player.sendMessage(ChatColor.RED + "The given player could not be found in the list of dead players!");
return;
}

player.sendMessage(ChatColor.AQUA + "Banned: " + ChatColor.WHITE + SemiHardcore.getPlayerManager().isBanned(playerUUID));
player.sendMessage(ChatColor.AQUA + "Deaths: " + ChatColor.WHITE + SemiHardcore.getPlayerManager().getDeaths(playerUUID));
player.sendMessage(ChatColor.AQUA + "Time of last death: " + ChatColor.WHITE + SemiHardcore.getPlayerManager().getDeathTime(playerUUID));
player.sendMessage(ChatColor.AQUA + "Time since last death: " + ChatColor.WHITE + SemiHardcore.getPlayerManager().getTimeSinceDeathTime(playerUUID));

return;
}
}

private boolean commandHelp(Player player)
{
sender.sendMessage(ChatColor.YELLOW + "---------------- " + plugin.getDescription().getFullName() + " ----------------");
sender.sendMessage(ChatColor.AQUA + "Made by Fido2603");
sender.sendMessage(ChatColor.AQUA + "");
if (player == null) {
this.plugin.log("---------------- " + plugin.getDescription().getFullName() + " ----------------");
this.plugin.log("Made by Fido2603");
this.plugin.log("");
if (plugin.isUHCDay) {
this.plugin.log("It is currently UHC Day! No natural regeneration!");
this.plugin.log("");
}
this.plugin.log("Use /semihardcore help, to get a list of available commands.");

return true;
}
player.sendMessage(ChatColor.YELLOW + "---------------- " + plugin.getDescription().getFullName() + " ----------------");
player.sendMessage(ChatColor.AQUA + "Made by Fido2603");
player.sendMessage(ChatColor.AQUA + "");
if (plugin.isUHCDay) {
sender.sendMessage(ChatColor.AQUA + "It is currently UHC Day! No natural regeneration!");
sender.sendMessage(ChatColor.AQUA + "");
player.sendMessage(ChatColor.AQUA + "It is currently UHC Day! No natural regeneration!");
player.sendMessage(ChatColor.AQUA + "");
}
sender.sendMessage(ChatColor.AQUA + "Use " + ChatColor.WHITE + "/semihardcore help" + ChatColor.AQUA + ", to get a list of available commands.");
player.sendMessage(ChatColor.AQUA + "Use " + ChatColor.WHITE + "/semihardcore help" + ChatColor.AQUA + ", to get a list of available commands.");

return true;
}

private boolean commandList(CommandSender sender)
private boolean commandList(Player player)
{
sender.sendMessage(ChatColor.YELLOW + "---------------- " + this.plugin.getDescription().getFullName() + " ----------------");
sender.sendMessage(ChatColor.AQUA + "/semihardcore" + ChatColor.WHITE + " - Info about the plugin");
if ((sender.isOp()) || (sender.hasPermission("semihardcore.help")))
if (player == null) {
this.plugin.log("---------------- " + this.plugin.getDescription().getFullName() + " ----------------");
this.plugin.log("/semihardcore - Info about the plugin");
this.plugin.log("/semihardcore help - Shows this message");
this.plugin.log("/semihardcore unban <player> - Unbans a player from the server, if the cause of the ban is death");
this.plugin.log("/semihardcore info <player> - Gets info about a player");
this.plugin.log("/semihardcore reload - Reloads configs from disk");
this.plugin.log("/semihardcore save - Saves modified configs to disk");

return true;
}

player.sendMessage(ChatColor.YELLOW + "---------------- " + this.plugin.getDescription().getFullName() + " ----------------");
player.sendMessage(ChatColor.AQUA + "/semihardcore" + ChatColor.WHITE + " - Info about the plugin");
if ((player.isOp()) || (player.hasPermission("semihardcore.help")))
{
sender.sendMessage(ChatColor.AQUA + "/semihardcore help" + ChatColor.WHITE + " - Shows this message");
player.sendMessage(ChatColor.AQUA + "/semihardcore help" + ChatColor.WHITE + " - Shows this message");
}
if ((sender.isOp()) || (sender.hasPermission("semihardcore.unban")))
if ((player.isOp()) || (player.hasPermission("semihardcore.unban")))
{
sender.sendMessage(ChatColor.AQUA + "/semihardcore unban <player>" + ChatColor.WHITE + " - Unbans a player from the server, if the cause of the ban is death");
player.sendMessage(ChatColor.AQUA + "/semihardcore unban <player>" + ChatColor.WHITE + " - Unbans a player from the server, if the cause of the ban is death");
}
if ((sender.isOp()) || (sender.hasPermission("semihardcore.reload")))
if ((player.isOp()) || (player.hasPermission("semihardcore.info"))) {
player.sendMessage(ChatColor.AQUA + "/semihardcore info <player>" + ChatColor.WHITE + " - Gets info about a player");
}
if ((player.isOp()) || (player.hasPermission("semihardcore.reload")))
{
sender.sendMessage(ChatColor.AQUA + "/semihardcore reload" + ChatColor.WHITE + " - Reloads configs from disk");
player.sendMessage(ChatColor.AQUA + "/semihardcore reload" + ChatColor.WHITE + " - Reloads configs from disk");
}
if ((sender.isOp()) || (sender.hasPermission("semihardcore.save")))
if ((player.isOp()) || (player.hasPermission("semihardcore.save")))
{
sender.sendMessage(ChatColor.AQUA + "/semihardcore save" + ChatColor.WHITE + " - Saves modified configs to disk");
player.sendMessage(ChatColor.AQUA + "/semihardcore save" + ChatColor.WHITE + " - Saves modified configs to disk");
}

return true;
Expand Down Expand Up @@ -124,6 +194,10 @@ else if (args.length == 2)
{
commandUnban(player, args);
}
if (args[0].equalsIgnoreCase("info"))
{
commandInfo(player, args);
}
return true;
}
return false;
Expand Down
53 changes: 38 additions & 15 deletions src/main/java/dk/fido2603/semihardcore/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,7 @@ public void unbanPlayer(UUID playerId) {
}

public void unbanPlayer(Player player, String bannedPlayer) {
Map<String, Object> deadPlayers = this.semihardcoreConfig.getValues(true);
UUID unbanPlayerId = null;
for (Map.Entry<String, Object> entry : deadPlayers.entrySet()) {
if (entry.getValue() instanceof String) {
this.plugin.logDebug("Entry key: " + entry.getKey());
this.plugin.logDebug("Entry value: " + entry.getValue());
if (entry.getKey().contains(".Name") && entry.getValue().toString().equalsIgnoreCase(bannedPlayer)) {
unbanPlayerId = UUID.fromString(entry.getKey().replace(".Name", ""));
break;
}
}
}
UUID unbanPlayerId = getUUID(bannedPlayer);

if (unbanPlayerId == null) {
if (player == null) {
Expand All @@ -118,7 +107,7 @@ public void unbanPlayer(Player player, String bannedPlayer) {
return;
}

if (!SemiHardcore.getPlayerManager().isBanned(unbanPlayerId)) {
if (!isBanned(unbanPlayerId)) {
if (player == null) {
this.plugin.log(this.plugin.getDescription().getFullName() + ": Error unbanning player: Player is not banned!");
}
Expand All @@ -128,7 +117,8 @@ public void unbanPlayer(Player player, String bannedPlayer) {
return;
}

SemiHardcore.getPlayerManager().unbanPlayer(unbanPlayerId);
unbanPlayer(unbanPlayerId);

if (player == null) {
this.plugin.log(this.plugin.getDescription().getFullName() + ": Unbanned " + bannedPlayer + "!");
}
Expand All @@ -141,6 +131,18 @@ public boolean isDead(UUID playerId) {
return this.semihardcoreConfig.getBoolean(playerId.toString() + ".IsDead");
}

public String getDeathTime(UUID playerId) {
return this.semihardcoreConfig.getString(playerId.toString() + ".LastDeath");
}

public String getTimeSinceDeathTime(UUID playerId) {
return TimeConverter.parseMillisToUFString(timeDiff(playerId));
}

public String getDeaths(UUID playerId) {
return this.semihardcoreConfig.getString(playerId.toString() + ".Deaths");
}

public boolean isBanned(UUID playerId) {
return this.semihardcoreConfig.getBoolean(playerId.toString() + ".IsDead");
}
Expand All @@ -160,7 +162,7 @@ private long timeDiff(UUID playerId) {
Date deathTime = new Date();
Date currentTime = new Date();

String deathTimeStr = this.semihardcoreConfig.getString(playerId.toString() + ".LastDeath");
String deathTimeStr = getDeathTime(playerId);

try
{
Expand Down Expand Up @@ -215,4 +217,25 @@ public void run() {

return true;
}

public UUID getUUID(String playerName) {
Map<String, Object> deadPlayers = this.semihardcoreConfig.getValues(true);
UUID playerId = null;
for (Map.Entry<String, Object> entry : deadPlayers.entrySet()) {
if (entry.getValue() instanceof String) {
this.plugin.logDebug("Entry key: " + entry.getKey());
this.plugin.logDebug("Entry value: " + entry.getValue());
if (entry.getKey().contains(".Name") && entry.getValue().toString().equalsIgnoreCase(playerName)) {
playerId = UUID.fromString(entry.getKey().replace(".Name", ""));
break;
}
}
}

if (playerId == null) {
this.plugin.logDebug("Error finding player: Player doesn't exist in dead-players.yml!");
}

return playerId;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ permissions:
semihardcore.exempt: true
semihardcore.unban: true
semihardcore.help: true
semihardcore.info: true
semihardcore.reload:
description: Player can reload the Semi-Hardcore configs
default: false
Expand All @@ -37,3 +38,6 @@ permissions:
semihardcore.help:
description: Player can get help about commands
default: true
semihardcore.info:
description: Player can get info about another players death(s)
default: true

0 comments on commit 9f67c25

Please sign in to comment.