mirror of
https://github.com/songoda/UltimateModeration.git
synced 2025-02-07 07:01:24 +01:00
Added revive command.
This commit is contained in:
parent
7e38aa2107
commit
5c5a0d40b8
@ -63,6 +63,7 @@ public class UltimateModeration extends JavaPlugin {
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
// Register Listeners
|
||||
Bukkit.getPluginManager().registerEvents(new DeathListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new MoveListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new DropListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new InventoryListener(this), this);
|
||||
|
@ -33,6 +33,7 @@ public class CommandManager implements CommandExecutor {
|
||||
instance.getCommand("ViewEnderChest").setExecutor(this);
|
||||
instance.getCommand("InvSee").setExecutor(this);
|
||||
instance.getCommand("Freeze").setExecutor(this);
|
||||
instance.getCommand("Revive").setExecutor(this);
|
||||
|
||||
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
|
||||
addCommand(new CommandClearChat());
|
||||
@ -42,6 +43,7 @@ public class CommandManager implements CommandExecutor {
|
||||
addCommand(new CommandViewEnderChest());
|
||||
addCommand(new CommandInvSee());
|
||||
addCommand(new CommandFreeze());
|
||||
addCommand(new CommandRevive());
|
||||
|
||||
addCommand(new CommandSettings(commandUltimateModeration));
|
||||
addCommand(new CommandReload(commandUltimateModeration));
|
||||
|
@ -0,0 +1,76 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.listeners.DeathListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandRevive extends AbstractCommand {
|
||||
|
||||
private static List<UUID> frozen = new ArrayList<>();
|
||||
|
||||
public CommandRevive() {
|
||||
super(true, true,"Revive");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
if (args.length != 1)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Player player = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
List<ItemStack> drops = DeathListener.getLastDrop(player);
|
||||
|
||||
if (drops == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.revive.noloot"));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
ItemStack[] dropArr = new ItemStack[drops.size()];
|
||||
dropArr = drops.toArray(dropArr);
|
||||
|
||||
HashMap<Integer, ItemStack> leftOver = player.getInventory().addItem(dropArr);
|
||||
|
||||
for (ItemStack item : leftOver.values()) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item);
|
||||
}
|
||||
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.revive.noloot"));
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.revive.success", player.getName()));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.revive";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/Revive <player>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to revive a player.";
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandFreeze;
|
||||
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.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DeathListener implements Listener {
|
||||
|
||||
private static Map<UUID, List<ItemStack>> playerDrops = new HashMap<>();
|
||||
|
||||
private UltimateModeration instance;
|
||||
|
||||
public DeathListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
playerDrops.put(player.getUniqueId(), event.getDrops());
|
||||
}
|
||||
|
||||
public static List<ItemStack> getLastDrop(Player player) {
|
||||
return playerDrops.get(player.getUniqueId());
|
||||
}
|
||||
}
|
@ -17,4 +17,8 @@ command.freeze.add = "&7You have frozen &6%player%&7 successfully.";
|
||||
command.freeze.remove = "&7You have unfrozen &6%player%&7 successfully.";
|
||||
command.freeze.alertadd = "&7You have been frozen.";
|
||||
command.freeze.alertremove = "&7You have been unfrozen.";
|
||||
command.freeze.nope = "&cYou cannot do that because you are currently frozen...";
|
||||
command.freeze.nope = "&cYou cannot do that because you are currently frozen...";
|
||||
|
||||
command.revive.noloot = "&cNo loot could be found to revive the player with."
|
||||
command.revive.success = "&7You have revived &6%player% &7successfully."
|
||||
command.revive.revived = "&7You have been revived."
|
@ -43,4 +43,8 @@ commands:
|
||||
Freeze:
|
||||
description: Freeze
|
||||
default: false
|
||||
usage: /freeze
|
||||
usage: /freeze
|
||||
Revive:
|
||||
description: Revive
|
||||
default: false
|
||||
usage: /revive
|
Loading…
Reference in New Issue
Block a user