mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2024-11-14 22:56:27 +01:00
AutoCraft Permission & Messages
Added new messages for AutoCrafting stations when being added or removed. Added commands to remove and list autocrafting stations as well as add/remove members for them. Changed addMember method so you cannot add a member already present.
This commit is contained in:
parent
43b91b039f
commit
1d1d0f8d12
@ -39,7 +39,9 @@ import org.bukkit.plugin.java.annotation.plugin.author.Author;
|
||||
@Permission(name = Permissions.OPEN_ANY, desc = "Gives permission to open all chests, for admin use.", defaultValue = PermissionDefault.FALSE)
|
||||
@Permission(name = Permissions.MEMBER, desc = "Gives permission to add/remove a member to/from their chestlink.", defaultValue = PermissionDefault.TRUE)
|
||||
@Permission(name = Permissions.SORT, desc = "Set the sorting option for the given ChestLink.", defaultValue = PermissionDefault.TRUE)
|
||||
@Permission(name = Permissions.AUTOCRAFT, desc = "Gives permission to add AutoCrafting stations.", defaultValue = PermissionDefault.TRUE)
|
||||
@Permission(name = Permissions.AUTOCRAFT_OPEN, desc = "Gives permission to open AutoCrafting stations.", defaultValue = PermissionDefault.TRUE)
|
||||
@Permission(name = Permissions.AUTOCRAFT_ADD, desc = "Gives permission to add AutoCrafting stations.", defaultValue = PermissionDefault.TRUE)
|
||||
@Permission(name = Permissions.AUTOCRAFT_REMOVE, desc = "Gives permission to remove AutoCrafting stations.", defaultValue = PermissionDefault.TRUE)
|
||||
public class ChestsPlusPlus extends JavaPlugin {
|
||||
|
||||
public static JavaPlugin PLUGIN;
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -189,16 +190,37 @@ public class RemoteChestCommand extends ServerCommand {
|
||||
}
|
||||
}
|
||||
case AUTOCRAFT: {
|
||||
if(args.length > 2){
|
||||
if(args[1].equals("add")){
|
||||
Block targetBlock = player.getTargetBlockExact(5);
|
||||
if (targetBlock != null) Utils.createAutoCraftChest(player, targetBlock, args[2]);
|
||||
else Messages.MUST_LOOK_AT_CHEST(player);
|
||||
if(args.length > 2) {
|
||||
if (args[1].equals("add")) {
|
||||
if (player.hasPermission(Permissions.AUTOCRAFT_ADD)) {
|
||||
Block targetBlock = player.getTargetBlockExact(5);
|
||||
if (targetBlock != null) Utils.createAutoCraftChest(player, targetBlock, args[2]);
|
||||
else Messages.MUST_LOOK_AT_CHEST(player);
|
||||
} else {
|
||||
Messages.NO_PERMISSION(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equals("remove")) {
|
||||
if (sender.hasPermission(Permissions.AUTOCRAFT_REMOVE)) {
|
||||
Config.removeAutoCraft(player, args[2]);
|
||||
return true;
|
||||
} else {
|
||||
Messages.NO_PERMISSION(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Crafting.craft(player);
|
||||
if(args.length > 1){
|
||||
if(args[1].equals("list")){
|
||||
Messages.LIST_AUTOCRAFT(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
memberAutoCraftCommand(args,sender);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ public class ChestLinkListener implements Listener {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
Messages.CHEST_ADDED(event.getPlayer(), signChangeEvent.getLine(1), chestLinkInfo.getPlayer().getName());
|
||||
signChange(sign,signChangeEvent,chestLinkInfo.getPlayer(),event.getPlayer());
|
||||
} else {
|
||||
Messages.SIGN_FRONT_OF_CHEST(event.getPlayer());
|
||||
@ -63,6 +64,7 @@ public class ChestLinkListener implements Listener {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
Messages.AUTOCRAFT_ADDED(event.getPlayer(), signChangeEvent.getLine(1), autoCraftInfo.getPlayer().getName());
|
||||
signChange(sign,signChangeEvent,autoCraftInfo.getPlayer(),event.getPlayer());
|
||||
} else {
|
||||
Messages.SIGN_FRONT_OF_CHEST(event.getPlayer());
|
||||
@ -80,7 +82,6 @@ public class ChestLinkListener implements Listener {
|
||||
}
|
||||
|
||||
private void signChange(Sign sign, SignChangeEvent signChangeEvent, OfflinePlayer addedPlayer, Player player){
|
||||
Messages.CHEST_ADDED(player, signChangeEvent.getLine(1), addedPlayer.getName());
|
||||
setLine(sign, signChangeEvent, 0, ChatColor.RED + ChatColor.stripColor(signChangeEvent.getLine(0)));
|
||||
setLine(sign, signChangeEvent, 1, ChatColor.GREEN + ChatColor.stripColor(signChangeEvent.getLine(1)));
|
||||
setLine(sign, signChangeEvent, 2, ChatColor.BOLD + ChatColor.stripColor(addedPlayer.getName()));
|
||||
@ -113,7 +114,7 @@ public class ChestLinkListener implements Listener {
|
||||
AutoCraftInfo info = Utils.getAutoCraftInfo(sign,sign.getLines());
|
||||
if (info != null) {
|
||||
Config.removeAutoCraft(info.getPlayer(), info.getGroup(), block.getLocation());
|
||||
Messages.CHEST_REMOVED(event.getPlayer(),info.getGroup(),info.getPlayer().getName());
|
||||
Messages.AUTOCRAFT_REMOVED(event.getPlayer(),info.getGroup(),info.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -139,7 +140,7 @@ public class ChestLinkListener implements Listener {
|
||||
if(event.getBlock().getType() == Material.CRAFTING_TABLE){
|
||||
AutoCraftingStorage storage = Config.removeAutoCraft(event.getBlock().getLocation());
|
||||
if(storage != null){
|
||||
Messages.CHEST_REMOVED(event.getPlayer(),storage.getIdentifier(),storage.getOwner().getName());
|
||||
Messages.AUTOCRAFT_REMOVED(event.getPlayer(),storage.getIdentifier(),storage.getOwner().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class InventoryListener implements Listener {
|
||||
|
||||
if(craftingStorage != null){
|
||||
event.setCancelled(true);
|
||||
if(event.getPlayer().hasPermission(Permissions.AUTOCRAFT) && craftingStorage.hasPermission((Player) event.getPlayer())) {
|
||||
if(event.getPlayer().hasPermission(Permissions.AUTOCRAFT_OPEN) && craftingStorage.hasPermission((Player) event.getPlayer())) {
|
||||
Utils.openInventory((Player) event.getPlayer(), craftingStorage.getInventory());
|
||||
craftingStorage.getVirtualCraftingHolder().startAnimation();
|
||||
}
|
||||
|
@ -19,6 +19,14 @@ public class Messages {
|
||||
target.sendMessage(ChatColor.GREEN+TAG+" Succesfully added a chest to group: "+ChatColor.WHITE+group+ChatColor.RED+" for "+ChatColor.WHITE+player);
|
||||
}
|
||||
|
||||
public static void AUTOCRAFT_REMOVED(Player target, String group, String player){
|
||||
target.sendMessage(ChatColor.RED+TAG+" Succesfully removed an AutoCraft station from group: "+ChatColor.WHITE+group+ChatColor.RED+" for "+ChatColor.WHITE+player);
|
||||
}
|
||||
|
||||
public static void AUTOCRAFT_ADDED(Player target, String group, String player){
|
||||
target.sendMessage(ChatColor.GREEN+TAG+" Succesfully added an AutoCraft station to group: "+ChatColor.WHITE+group+ChatColor.RED+" for "+ChatColor.WHITE+player);
|
||||
}
|
||||
|
||||
public static void CHEST_HAD_OVERFLOW(Player target){
|
||||
target.sendMessage(ChatColor.GOLD+TAG+" Chest item's wouldn't all fit into ChestLink!");
|
||||
}
|
||||
@ -108,6 +116,15 @@ public class Messages {
|
||||
}
|
||||
}
|
||||
|
||||
public static void LIST_AUTOCRAFT(Player target){
|
||||
target.sendMessage(ChatColor.GREEN+""+ChatColor.BOLD+"List of your AutoCraft Stations:");
|
||||
for(AutoCraftingStorage storage : Config.getAutoCraftTableMap(target.getUniqueId()).values()){
|
||||
if(storage != null){
|
||||
target.sendMessage(ChatColor.GREEN+storage.getIdentifier()+ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void INVALID_CHESTID(Player target){
|
||||
target.sendMessage(ChatColor.RED+"Invalid ChestLink ID! Must not contain a colon ':' unless you are referencing another players group that you are a member off");
|
||||
target.sendMessage(ChatColor.RED+"/chestlink add <owner>:<group>");
|
||||
|
@ -9,5 +9,7 @@ public class Permissions {
|
||||
public static final String OPEN_ANY = "chestlink.openall";
|
||||
public static final String MEMBER = "chestlink.member";
|
||||
public static final String SORT = "chestlink.sort";
|
||||
public static final String AUTOCRAFT = "chestlink.autocraft";
|
||||
public static final String AUTOCRAFT_OPEN = "chestlink.autocraft.open";
|
||||
public static final String AUTOCRAFT_ADD = "chestlink.autocraft.add";
|
||||
public static final String AUTOCRAFT_REMOVE = "chestlink.autocraft.remove";
|
||||
}
|
||||
|
@ -143,11 +143,13 @@ public class AutoCraftingStorage implements ConfigurationSerializable {
|
||||
virtualCraftingHolder.updateGUI();
|
||||
}
|
||||
|
||||
public boolean addMember(Player player){
|
||||
public boolean addMember(OfflinePlayer player){
|
||||
if(player != null){
|
||||
if(members == null) members = new ArrayList<>();
|
||||
if(bukkitMembers == null) bukkitMembers = new ArrayList<>();
|
||||
members.add(player.getUniqueId().toString());
|
||||
String uuid = player.getUniqueId().toString();
|
||||
if(members.contains(uuid)) return false;
|
||||
members.add(uuid);
|
||||
bukkitMembers.add(player);
|
||||
return true;
|
||||
}
|
||||
|
@ -203,7 +203,9 @@ public class InventoryStorage implements ConfigurationSerializable {
|
||||
if(player != null){
|
||||
if(members == null) members = new ArrayList<>();
|
||||
if(bukkitMembers == null) bukkitMembers = new ArrayList<>();
|
||||
members.add(player.getUniqueId().toString());
|
||||
String uuid = player.getUniqueId().toString();
|
||||
if(members.contains(uuid)) return false;
|
||||
members.add(uuid);
|
||||
bukkitMembers.add(player);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user