mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-01-10 10:27:44 +01:00
Added new commands
Added new add-to-all commands. Added ability to add offline players.
This commit is contained in:
parent
fd9be88ffa
commit
b429acdf0d
@ -1,5 +1,6 @@
|
||||
package com.jamesdpeters.minecraft.chests.commands;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Messages;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Permissions;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
||||
@ -7,12 +8,14 @@ import com.jamesdpeters.minecraft.chests.storage.autocraft.AutoCraftingStorage;
|
||||
import com.jamesdpeters.minecraft.chests.serialize.Config;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -188,7 +191,7 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
case RENAME:
|
||||
return Config.getAutoCraft().getStorageList(player, args[1]);
|
||||
case MEMBER:
|
||||
return Arrays.asList("add","remove","list");
|
||||
return Stream.of("add","remove","list","add-to-all","remove-from-all").filter(s -> s.contains(args[1])).collect(Collectors.toList());
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
}
|
||||
@ -196,6 +199,8 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
try {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())) {
|
||||
case MEMBER:
|
||||
if(args[1].equals("add-to-all")) return Utils.filterList(Utils.getAllPlayers(), args[2]);
|
||||
if(args[1].equals("remove-from-all")) return Utils.filterList(Utils.getAllPlayers(), args[2]);
|
||||
return Config.getAutoCraft().getStorageList(player, args[2]);
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
@ -204,10 +209,11 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
try {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())) {
|
||||
case MEMBER:
|
||||
return Utils.getOnlinePlayers();
|
||||
return Utils.filterList(Utils.getAllPlayers(), args[3]);
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
}
|
||||
return Collections.singletonList("");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -217,17 +223,21 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
if(args.length > 3){
|
||||
if(sender.hasPermission(Permissions.MEMBER)){
|
||||
if(args[1].equals("add")) {
|
||||
Player toAdd = Bukkit.getPlayer(args[3]);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[3]);
|
||||
AutoCraftingStorage storage = Config.getAutoCraft().getStorage(player.getUniqueId(), args[2]);
|
||||
if (storage != null && storage.addMember(toAdd))
|
||||
storage.getStorageType().getMessages().addedMember(player, storage, args[3]);
|
||||
else Config.getAutoCraft().getMessages().unableToAddMember(player,args[3]);
|
||||
else Config.getAutoCraft().getMessages().unableToAddMember(player, args[3]);
|
||||
});
|
||||
} else if(args[1].equals("remove")){
|
||||
Player toAdd = Bukkit.getPlayer(args[3]);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[3]);
|
||||
AutoCraftingStorage storage = Config.getAutoCraft().getStorage(player.getUniqueId(), args[2]);
|
||||
if(storage != null && storage.removeMember(toAdd))
|
||||
if (storage != null && storage.removeMember(toAdd))
|
||||
storage.getStorageType().getMessages().removedMember(player, storage, args[3]);
|
||||
else Config.getAutoCraft().getMessages().unableToRemoveMember(player, args[3]);
|
||||
});
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.MEMBER.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+ OPTIONS.MEMBER.description);
|
||||
@ -244,6 +254,20 @@ public class AutoCraftCommand extends ServerCommand {
|
||||
storage.getStorageType().getMessages().listMembers(player, storage);
|
||||
return true;
|
||||
}
|
||||
} else if(args[1].equals("add-to-all")){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[2]);
|
||||
Config.getAutoCraft().getStorageMap(player.getUniqueId()).forEach((s, storage) -> storage.addMember(toAdd));
|
||||
Config.getAutoCraft().getMessages().addMemberToAll(player, toAdd);
|
||||
});
|
||||
return true;
|
||||
} else if(args[1].equals("remove-from-all")) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[2]);
|
||||
Config.getAutoCraft().getStorageMap(player.getUniqueId()).forEach((s, storage) -> storage.removeMember(toAdd));
|
||||
Config.getAutoCraft().getMessages().removeMemberFromAll(player, toAdd);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.jamesdpeters.minecraft.chests.commands;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
|
||||
import com.jamesdpeters.minecraft.chests.inventories.ChestLinkMenu;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Messages;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Permissions;
|
||||
@ -9,12 +10,14 @@ import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
|
||||
import com.jamesdpeters.minecraft.chests.sort.SortMethod;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -210,7 +213,7 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
case RENAME:
|
||||
return Config.getChestLink().getStorageList(player, args[1]);
|
||||
case MEMBER:
|
||||
return Arrays.asList("add","remove","list");
|
||||
return Stream.of("add","remove","list","add-to-all","remove-from-all").filter(s -> s.contains(args[1])).collect(Collectors.toList());
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
}
|
||||
@ -218,6 +221,8 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
try {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())) {
|
||||
case MEMBER:
|
||||
if(args[1].equals("add-to-all")) return Utils.filterList(Utils.getAllPlayers(), args[2]);
|
||||
if(args[1].equals("remove-from-all")) return Utils.filterList(Utils.getAllPlayers(), args[2]);
|
||||
return Config.getChestLink().getStorageList(player, args[2]);
|
||||
case SORT:
|
||||
return SortMethod.valuesList;
|
||||
@ -228,10 +233,11 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
try {
|
||||
switch (OPTIONS.valueOf(args[0].toUpperCase())) {
|
||||
case MEMBER:
|
||||
return Utils.getOnlinePlayers();
|
||||
return Utils.filterList(Utils.getAllPlayers(), args[3]);
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
}
|
||||
return Collections.singletonList("");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -241,17 +247,23 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
if(args.length > 3){
|
||||
if(sender.hasPermission(Permissions.MEMBER)){
|
||||
if(args[1].equals("add")) {
|
||||
Player toAdd = Bukkit.getPlayer(args[3]);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[3]);
|
||||
ChestLinkStorage storage = Config.getChestLink().getStorage(player.getUniqueId(), args[2]);
|
||||
if (storage != null && storage.addMember(toAdd))
|
||||
storage.getStorageType().getMessages().addedMember(player, storage, args[3]);
|
||||
else Config.getChestLink().getMessages().unableToAddMember(player,args[3]);
|
||||
});
|
||||
return true;
|
||||
} else if(args[1].equals("remove")){
|
||||
Player toAdd = Bukkit.getPlayer(args[3]);
|
||||
ChestLinkStorage storage = Config.getChestLink().getStorage(player.getUniqueId(),args[2]);
|
||||
if(storage != null && storage.removeMember(toAdd))
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[3]);
|
||||
ChestLinkStorage storage = Config.getChestLink().getStorage(player.getUniqueId(), args[2]);
|
||||
if (storage != null && storage.removeMember(toAdd))
|
||||
storage.getStorageType().getMessages().removedMember(player, storage, args[3]);
|
||||
else Config.getChestLink().getMessages().unableToRemoveMember(player, args[3]);
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.MEMBER.commandHelp);
|
||||
player.sendMessage(ChatColor.RED+OPTIONS.MEMBER.description);
|
||||
@ -268,6 +280,20 @@ public class ChestLinkCommand extends ServerCommand {
|
||||
storage.getStorageType().getMessages().listMembers(player, storage);
|
||||
return true;
|
||||
}
|
||||
} else if(args[1].equals("add-to-all")){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[2]);
|
||||
Config.getChestLink().getStorageMap(player.getUniqueId()).forEach((s, storage) -> storage.addMember(toAdd));
|
||||
Config.getChestLink().getMessages().addMemberToAll(player, toAdd);
|
||||
});
|
||||
return true;
|
||||
} else if(args[1].equals("remove-from-all")){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(ChestsPlusPlus.PLUGIN, () -> {
|
||||
OfflinePlayer toAdd = Bukkit.getOfflinePlayer(args[2]);
|
||||
Config.getChestLink().getStorageMap(player.getUniqueId()).forEach((s, storage) -> storage.removeMember(toAdd));
|
||||
Config.getChestLink().getMessages().removeMemberFromAll(player, toAdd);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -102,6 +102,10 @@ public class Utils {
|
||||
return getPlayersAsNameList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static List<String> getAllPlayers(){
|
||||
return getPlayersAsNameList(Arrays.asList(Bukkit.getOfflinePlayers()));
|
||||
}
|
||||
|
||||
public static List<String> getPlayersAsNameList(Collection<? extends OfflinePlayer> players){
|
||||
List<String> arr = new ArrayList<>();
|
||||
for(OfflinePlayer player : players){
|
||||
@ -160,4 +164,8 @@ public class Utils {
|
||||
if(val != null && val == 1) entity.remove();
|
||||
});
|
||||
}
|
||||
|
||||
public static List<String> filterList(List<String> list, String phrase){
|
||||
return list.stream().filter(s -> s.contains(phrase)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.jamesdpeters.minecraft.chests.storage.abstracts;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class StorageMessages {
|
||||
@ -35,6 +36,10 @@ public abstract class StorageMessages {
|
||||
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Current Members: "+ Utils.prettyPrintPlayers(ChatColor.GREEN,storage.getMembers()));
|
||||
}
|
||||
|
||||
public void addMemberToAll(Player target, OfflinePlayer added){
|
||||
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Succesfully added "+ChatColor.WHITE+added.getName()+ChatColor.GREEN+" to all "+getStorageName()+" groups ");
|
||||
}
|
||||
|
||||
public void unableToAddMember(Player target, String toAdd){
|
||||
target.sendMessage(ChatColor.RED+""+ChatColor.BOLD+TAG+" Unable to add player "+toAdd+" to "+getStorageName()+"!");
|
||||
}
|
||||
@ -44,6 +49,10 @@ public abstract class StorageMessages {
|
||||
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Current Members: "+ Utils.prettyPrintPlayers(ChatColor.GREEN,storage.getMembers()));
|
||||
}
|
||||
|
||||
public void removeMemberFromAll(Player target, OfflinePlayer added){
|
||||
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+TAG+" Succesfully removed "+ChatColor.WHITE+added.getName()+ChatColor.GREEN+" from all "+getStorageName()+" groups ");
|
||||
}
|
||||
|
||||
public void unableToRemoveMember(Player target, String toAdd){
|
||||
target.sendMessage(ChatColor.RED+""+ChatColor.BOLD+TAG+" Unable to remove player "+toAdd+" from "+getStorageName()+"! Were they already removed?");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user