Skip to content

Commit

Permalink
Add invtool command (Close #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-nekoneko committed Jun 17, 2020
1 parent b7179f3 commit a25edff
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@
* SOFTWARE.
*/

import org.bukkit.ChatColor;
import org.bukkit.Material;
import com.rathserver.event.invisible.command.InvToolCommand;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Optional;

public class InvisiblePlugin extends JavaPlugin {

static final String METADATA_KEY = "invisible";
public static final String METADATA_KEY = "invisible";

private InvisibleTask task;

private ItemStack activeInvisibleItem;
private ItemStack deActiveInvisibleItem;

@Override
public void onEnable() {
Items.initialize(this);
Expand All @@ -49,6 +45,8 @@ public void onEnable() {
this.task.runTaskTimer(this, 0L, 60L);

this.getServer().getPluginManager().registerEvents(new InvisibleListener(this), this);

Optional.ofNullable(this.getCommand("invtool")).ifPresent(command -> command.setExecutor(new InvToolCommand(this)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.rathserver.event.invisible.command;

import com.rathserver.event.invisible.InvisiblePlugin;
import com.rathserver.event.invisible.Items;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;

/**
* Created by Nekoneko on 2020/06/17.
*/
public class InvToolCommand implements CommandExecutor {
private final InvisiblePlugin plugin;

public InvToolCommand(InvisiblePlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
return false;
}

Player player = (Player) sender;
PlayerInventory inventory = player.getInventory();
if (player.hasMetadata(InvisiblePlugin.METADATA_KEY)) {
inventory.addItem(Items.getInvisibleDeActiveItem().clone());
} else {
inventory.addItem(Items.getInvisibleActiveItem().clone());
}
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.6F, 0.5F);
return true;
}
}
7 changes: 7 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ version: ${project.version}
main: com.rathserver.event.invisible.InvisiblePlugin
author: Nekoneko@NekonekoNetwork
api-version: 1.13
commands:
invtool:
permission: invisible.command.invtool

permissions:
invisible.command.invtool:
default: true

0 comments on commit a25edff

Please sign in to comment.