Skip to content

Commit

Permalink
Changes to CommandKill
Browse files Browse the repository at this point in the history
moved the function "CommandKillPlayer" for killing a specific player to CommandKill under "killSpecificUser"
  • Loading branch information
Lightkeks committed Aug 25, 2024
1 parent c44cb01 commit eaaa961
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,74 @@
package io.github.davidmc971.modularmsmf.basics.commands;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;

import io.github.davidmc971.modularmsmf.api.IModularMSMFCommand;
import io.github.davidmc971.modularmsmf.basics.ModularMSMFBasics;
import io.github.davidmc971.modularmsmf.basics.PermissionManager;
import io.github.davidmc971.modularmsmf.basics.listeners.BasicEvents;
import io.github.davidmc971.modularmsmf.basics.util.ChatUtil;
import io.github.davidmc971.modularmsmf.basics.util.CommandUtil;
import io.github.davidmc971.modularmsmf.basics.util.KillType;
import io.github.davidmc971.modularmsmf.basics.util.ChatUtil.ChatFormat;
import io.github.davidmc971.modularmsmf.basics.util.Util;

public class CommandKill implements IModularMSMFCommand {
public class CommandKill implements IModularMSMFCommand, Listener {

private BasicEvents basicEvents;

public CommandKill(){
basicEvents = ModularMSMFBasics.Instance().getBasicEvents();
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {

if(!PermissionManager.checkPermission(sender, "kill")){
if (!PermissionManager.checkPermission(sender, "kill")) {
ChatUtil.sendMsgNoPerm(sender);
return true;
}
switch(args.length){
switch (args.length) {
case 0:
// This will open a GUI where you can select specific types of kills or users.
return killOpenGUI(sender, command, label, args);
case 1:
case 2:
// This will only kill the specified user
return killSpecificUser(sender, command, label, args);
default:
Util.sendMessageWithConfiguredLanguage(sender, ChatFormat.ERROR, "general.toomanyargs");
return true;
}
}

private boolean killOpenGUI(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {

if (!CommandUtil.isSenderEligible(sender, command, label)) {
return true;
}
return true;
}

private boolean killSpecificUser(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (args[0].toLowerCase().equals(player.getName().toLowerCase())) {
basicEvents.registerKilledPlayer(player, KillType.KILL);
Util.broadcastWithConfiguredLanguageEach(ChatFormat.DEATH, "events.killed",
"_player", player.getName());
player.setHealth(0);
return true;
}
}
Util.sendMessageWithConfiguredLanguage(sender, ChatFormat.ERROR, "player.nonexistant");
return true;

return true;
}

@Override
Expand All @@ -41,5 +85,5 @@ public String[] Aliases() {
public boolean Enabled() {
return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
package io.github.davidmc971.modularmsmf.basics.commands;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
// import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import io.github.davidmc971.modularmsmf.basics.PermissionManager;
import io.github.davidmc971.modularmsmf.basics.listeners.BasicEvents;
import io.github.davidmc971.modularmsmf.api.IModularMSMFCommand;
import io.github.davidmc971.modularmsmf.basics.ModularMSMFBasics;
import io.github.davidmc971.modularmsmf.basics.util.KillType;
import io.github.davidmc971.modularmsmf.basics.util.Util;
import io.github.davidmc971.modularmsmf.basics.util.ChatUtil.ChatFormat;
import io.github.davidmc971.modularmsmf.basics.util.ChatUtil;
Expand All @@ -32,12 +16,6 @@

public class CommandKillPlayer implements IModularMSMFCommand/* , Listener, InventoryHolder */ {

private BasicEvents basicEvents;

public CommandKillPlayer() {
basicEvents = ModularMSMFBasics.Instance().getBasicEvents();
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!PermissionManager.checkPermission(sender, "kill")) {
Expand All @@ -46,24 +24,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
if (args.length == 0) {
return killHelp(sender, command, label, args); // will be changed with a usable GUI
//return killGUI(sender, command, label, args); //opening a GUI to choose options (like down below)
}
if (args.length == 1) {
for (Player player : Bukkit.getOnlinePlayers()) {
// if (args[0].toLowerCase().equals(sender.getName().toLowerCase())) {
// return killMeSub(sender, command, label, args);
// }
if (args[0].toLowerCase().equals(player.getName().toLowerCase())) {
basicEvents.registerKilledPlayer(player, KillType.KILL);
Util.broadcastWithConfiguredLanguageEach(ChatFormat.DEATH, "events.killed",
"_player", player.getName());
player.setHealth(0);
return true;
}
}
Util.sendMessageWithConfiguredLanguage(sender, ChatFormat.ERROR, "player.nonexistant");
return true;
}

if (args.length <= 2) {
Util.sendMessageWithConfiguredLanguage(sender, ChatFormat.ERROR, "arguments.toomany");
return true;
Expand All @@ -79,67 +41,6 @@ private boolean killHelp(CommandSender sender, Command command, String label, St
return true;
}

// private boolean killMeSub(CommandSender sender, Command command, String label, String[] args) {
// if (sender instanceof ConsoleCommandSender || !PermissionManager.checkPermission(sender, "kill_me")) {
// ChatUtil.sendMsgNoPerm(sender);
// return true;
// }
// basicEvents.registerKilledPlayer(((Player) sender), KillType.SUICIDE);
// Util.broadcastWithConfiguredLanguageEach(ChatFormat.DEATH, "events.suicide", "_player",
// sender.getName());
// ((Player) sender).setHealth(0);
// return true;
// }

/* private boolean killGUI(CommandSender sender, Command command, String label, String[] args){
final Inventory inv;
public Kill_GUI(){
//Create a new ownerless inventory (not a real inv)
inv = Bukkit.createInventory(null, 9, "Kill GUI");
//Put items into inv
initializeItems();
}
public void initializeItems(){
inv.addItem(createGuiItem(Material.PLAYER_HEAD, "Option to kill yourself", "§4KILL YOURSELF"));
inv.addItem(createGuiItem(Material.TNT, "Cast a spell to kill all at once", "§4KILL ALL USERS AT ONCE"));
}
protected ItemStack createGuiItem(final Material material, final String name, final String... lore){
final ItemStack item = new ItemStack(material, 1);
final ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(Arrays.asList(lore));
return item;
}
@EventHandler
public void onInventoryClick(final InventoryClickEvent e){
if (!e.getInventory().equals(inv)) return;
e.setCancelled(true);
final ItemStack clickedItem = e.getCurrentItem();
if(clickedItem == null || clickedItem.getType().isAir()) return;
final Player p = (Player) e.getWhoClicked();
p.sendMessage("You clicked at slot "+e.getRawSlot());
}
@EventHandler
public void onInventoryClick(final InventoryDragEvent e){
if(e.getInventory().equals(inv)){
e.setCancelled(true);
}
}
return true;
} */

@Override
public String Label() {
return "kill";
Expand All @@ -154,10 +55,4 @@ public String[] Aliases() {
public boolean Enabled() {
return true;
}

/* @Override
public @NotNull Inventory getInventory() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInventory'");
} */
}

0 comments on commit eaaa961

Please sign in to comment.