Skip to content

Commit

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

import com.rathserver.event.invisible.command.InvToolCommand;
import com.rathserver.event.invisible.command.*;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -47,6 +47,8 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(new InvisibleListener(this), this);

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

@Override
Expand All @@ -57,12 +59,12 @@ public void onDisable() {
}
}

void hidePlayers(Player player) {
public void hidePlayers(Player player) {
getServer().getOnlinePlayers().forEach(target -> player.hidePlayer(this, target));
player.setMetadata(METADATA_KEY, new FixedMetadataValue(this, true));
}

void showPlayers(Player player) {
public void showPlayers(Player player) {
getServer().getOnlinePlayers().forEach(target -> player.showPlayer(this, target));
player.removeMetadata(METADATA_KEY, this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.rathserver.event.invisible.command;

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

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

public InvAllCommand(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;
this.plugin.hidePlayers(player);
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.6F, 0.5F);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.rathserver.event.invisible.command;

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

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

public ShowAllCommand(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;
this.plugin.showPlayers(player);
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.6F, 0.5F);
return true;
}
}
8 changes: 8 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ api-version: 1.13
commands:
invtool:
permission: invisible.command.invtool
invall:
permission: invisible.command.invall
showall:
permission: invisible.command.showall

permissions:
invisible.command.invtool:
default: true
invisible.command.invall:
default: true
invisible.command.showall:
default: true

0 comments on commit 6087dba

Please sign in to comment.