This repository has been archived by the owner on Jun 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/me/shakeforprotein/treebotickets/Commands/RestartWhenEmpty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package me.shakeforprotein.treebotickets.Commands; | ||
|
||
import me.shakeforprotein.treebotickets.TreeboTickets; | ||
import net.md_5.bungee.api.ChatMessageType; | ||
import net.md_5.bungee.api.chat.ComponentBuilder; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
|
||
public class RestartWhenEmpty implements CommandExecutor { | ||
|
||
private TreeboTickets pl; | ||
|
||
|
||
public RestartWhenEmpty(TreeboTickets main) { | ||
this.pl = main; | ||
|
||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
Bukkit.getScheduler().runTaskTimer(pl, new Runnable() { | ||
@Override | ||
public void run() { | ||
if(pl.getServer().getOnlinePlayers().isEmpty()){ | ||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "restart"); | ||
} | ||
else{ | ||
for(Player player : pl.getServer().getOnlinePlayers()){ | ||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder(pl.badge + ChatColor.RED + ChatColor.BOLD + "This server needs to restart for maintenance. Expected downtime is 2 minutes").create()); | ||
} | ||
} | ||
} | ||
}, 100L, 100L); | ||
return true; | ||
} | ||
|
||
|
||
|
||
public static boolean isNumeric (String str) | ||
{ | ||
return str.matches("\\d+"); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/me/shakeforprotein/treebotickets/Commands/RestorePlayerInventory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package me.shakeforprotein.treebotickets.Commands; | ||
|
||
import me.shakeforprotein.treebotickets.TreeboTickets; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class RestorePlayerInventory implements CommandExecutor { | ||
|
||
private TreeboTickets pl; | ||
|
||
public RestorePlayerInventory(TreeboTickets main) { | ||
this.pl = main; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
if (sender instanceof Player) { | ||
|
||
if (args.length == 2) { | ||
|
||
if (Bukkit.getPlayer(args[0]) != null && Bukkit.getPlayer(args[0]).isOnline()) { | ||
Player p = Bukkit.getPlayer(args[0]); | ||
File deathFile = new File(pl.getDataFolder() + File.separator + "deaths", File.separator + p.getUniqueId().toString() + "_" + args[1] + ".yml"); | ||
File deathFileUsed = new File(pl.getDataFolder() + File.separator + "deaths", File.separator + "USED_" + p.getUniqueId().toString() + "_" + args[1] + ".yml"); | ||
|
||
if (deathFile.exists()) { | ||
sender.sendMessage(pl.badge + "Death file found"); | ||
FileConfiguration deathYaml = YamlConfiguration.loadConfiguration(deathFile); | ||
if (deathYaml.getString("used").equalsIgnoreCase("false")) { | ||
if (deathYaml.getString("uuid").equalsIgnoreCase(p.getUniqueId().toString())) { | ||
if (p.getWorld().getName().equalsIgnoreCase(deathYaml.getString("world"))) { | ||
int i = 0; | ||
for (String key : deathYaml.getConfigurationSection("inventory").getKeys(false)) { | ||
p.getInventory().addItem(deathYaml.getItemStack("inventory.slot_" + i)); | ||
i++; | ||
} | ||
p.setTotalExperience(deathYaml.getInt("experience")); | ||
deathYaml.set("used", true); | ||
try { | ||
deathYaml.save(deathFile); | ||
deathFile.renameTo(deathFileUsed); | ||
} catch (IOException err) { | ||
pl.makeLog(err); | ||
sender.sendMessage(pl.err + "Failed to update 'used' status on docket " + deathFile.toString()); | ||
} | ||
} else { | ||
sender.sendMessage(pl.err + "Player world mismatch. This inventory is for World:" + deathYaml.getString("world")); | ||
} | ||
} else { | ||
sender.sendMessage(pl.err + "Player UUID mismatch. This inventory does not belong to Player: " + args[0]); | ||
} | ||
} else { | ||
sender.sendMessage(pl.err + "This inventory has already been recovered"); | ||
} | ||
} else { | ||
sender.sendMessage(pl.err + "No matching death file on record."); | ||
} | ||
} else { | ||
sender.sendMessage(pl.err + "Player: " + args[0] + " not found."); | ||
} | ||
} else if (args.length < 2) { | ||
sender.sendMessage(pl.err + "Insufficient arguments. This command requires a <playername> and <secretkey> argument."); | ||
} else { | ||
sender.sendMessage(pl.err + "Too many arguments. This command requires only a <playername> and <secretkey> argument."); | ||
} | ||
} else { | ||
sender.sendMessage(ChatColor.RED + "You do not have access to this command. You require permission node " + ChatColor.GOLD + "tbtickets.admin.restoreinventory"); | ||
} | ||
return true; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/me/shakeforprotein/treebotickets/Commands/ToggleDeathDocket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package me.shakeforprotein.treebotickets.Commands; | ||
|
||
import me.shakeforprotein.treebotickets.TreeboTickets; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
|
||
public class ToggleDeathDocket implements CommandExecutor { | ||
|
||
private TreeboTickets pl; | ||
|
||
public ToggleDeathDocket(TreeboTickets main) { | ||
this.pl = main; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
if (sender instanceof Player) { | ||
Player p = (Player) sender; | ||
if (pl.getConfig().get("deathDocket.toggle." + p.getUniqueId()) == null || pl.getConfig().get("deathDocket.toggle." + p.getUniqueId()).equals("false")) { | ||
pl.getConfig().set("deathDocket.toggle." + p.getUniqueId(), "true"); | ||
} else { | ||
pl.getConfig().set("deathDocket.toggle." + p.getUniqueId(), "false"); | ||
} | ||
} else { | ||
sender.sendMessage(pl.err + "Only players can run this command"); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/main/java/me/shakeforprotein/treebotickets/Listeners/RespawnListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package me.shakeforprotein.treebotickets.Listeners; | ||
|
||
import me.shakeforprotein.treebotickets.TreeboTickets; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.attribute.Attribute; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.PlayerDeathEvent; | ||
import org.bukkit.event.player.PlayerRespawnEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.bukkit.inventory.meta.PotionMeta; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.*; | ||
|
||
|
||
public class RespawnListener implements Listener { | ||
|
||
private TreeboTickets pl; | ||
|
||
private HashMap<String, ItemStack> docketMap = new HashMap<>(); | ||
|
||
public RespawnListener(TreeboTickets main) { | ||
this.pl = main; | ||
} | ||
|
||
@EventHandler | ||
public boolean onPlayerDeath(PlayerDeathEvent e) { | ||
if (!e.getDrops().isEmpty()) { | ||
String key1 = UUID.randomUUID().toString(); | ||
String key2 = UUID.randomUUID().toString(); | ||
String key3 = key1 + "-" + key2; | ||
|
||
File deathFile = new File(pl.getDataFolder() + File.separator + "deaths", File.separator + e.getEntity().getUniqueId().toString() + "_" + key3 + ".yml"); | ||
FileConfiguration deathYaml = YamlConfiguration.loadConfiguration(deathFile); | ||
|
||
|
||
Player p = e.getEntity(); | ||
Location loc = e.getEntity().getLocation(); | ||
int droppedXP = p.getTotalExperience(); | ||
String deathMessage = e.getDeathMessage(); | ||
|
||
List<ItemStack> itemList = e.getDrops(); | ||
|
||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); | ||
Date date = new Date(System.currentTimeMillis()); | ||
|
||
ItemStack docket = new ItemStack(Material.PAPER, 1); | ||
ItemMeta docketMeta = docket.getItemMeta(); | ||
docketMeta.setDisplayName(pl.badge + "Death Docket - " + date); | ||
deathYaml.set("date", date); | ||
|
||
List<String> docketLore = new ArrayList<String>(); | ||
docketLore.add("Player - " + p.getName()); | ||
deathYaml.set("player", p.getName()); | ||
deathYaml.set("uuid", p.getUniqueId().toString()); | ||
docketLore.add("Location - " + loc.getWorld().getName() + " " + loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ()); | ||
deathYaml.set("world", loc.getWorld().getName()); | ||
deathYaml.set("xyz", loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ()); | ||
docketLore.add("XP - " + droppedXP); | ||
deathYaml.set("experience", droppedXP); | ||
docketLore.add("Death Message - " + deathMessage); | ||
deathYaml.set("deathMessage", deathMessage); | ||
docketLore.add("SecretKey - " + key3); | ||
deathYaml.set("secretKey", key3); | ||
int i = 0; | ||
for (ItemStack item : itemList) { | ||
deathYaml.set("inventory.slot_" + i, item); | ||
i++; | ||
docketLore.add(item.getAmount() + " X " + item.getType().name()); | ||
if (item.hasItemMeta() && item.getItemMeta().hasEnchants()) { | ||
for (Enchantment enchantment : item.getItemMeta().getEnchants().keySet()) { | ||
docketLore.add(" - " + enchantment.getKey() + " LvL " + item.getItemMeta().getEnchants().get(enchantment)); | ||
} | ||
} else if (item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) { | ||
docketLore.add(" - " + ((PotionMeta) item.getItemMeta()).getBasePotionData().getType() + " Ext:" + ((PotionMeta) item.getItemMeta()).getBasePotionData().isExtended() + " Upg:" + ((PotionMeta) item.getItemMeta()).getBasePotionData().isUpgraded()); | ||
} else if (item.hasItemMeta() && item.getItemMeta().hasAttributeModifiers()) { | ||
for (Attribute attrib : item.getItemMeta().getAttributeModifiers().keySet()) { | ||
docketLore.add(" - " + attrib.name() + " LvL " + item.getItemMeta().getAttributeModifiers().get(attrib)); | ||
} | ||
} | ||
} | ||
docketMeta.setLore(docketLore); | ||
docket.setItemMeta(docketMeta); | ||
docketMap.put(p.getUniqueId().toString(), docket); | ||
deathYaml.set("used", "false"); | ||
try { | ||
deathYaml.save(deathFile); | ||
} catch (IOException err) { | ||
pl.makeLog(err); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@EventHandler | ||
public void onRespawnEvent(PlayerRespawnEvent e) { | ||
Player p = e.getPlayer(); | ||
if (!pl.getConfig().getBoolean("deathDocket.disable")) { | ||
if (docketMap.containsKey(p.getUniqueId().toString())) { | ||
if (pl.getConfig().get("deathDocket.toggle." + p.getUniqueId()) == null || pl.getConfig().get("deathDocket.toggle." + p.getUniqueId().toString()).equals("false")) { | ||
|
||
p.getInventory().setItemInOffHand(docketMap.get(p.getUniqueId().toString())); | ||
p.sendMessage(pl.badge + "You been issued a death docket. You can disable this feature at any time with /toggledeathdocket, but in doing so, staff will be unable to assist with item recovery"); | ||
} else { | ||
p.sendMessage(pl.badge + "You have Death Dockets disabled. Re-enable with /toggledeathdocket"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters