mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-01-20 23:31:38 +01:00
Added group limiter
This commit is contained in:
parent
097174b221
commit
007fb3817f
@ -34,7 +34,10 @@ public class ChestLinkListener implements Listener {
|
|||||||
if (info != null) {
|
if (info != null) {
|
||||||
if(event.getPlayer().hasPermission(Permissions.ADD)) {
|
if(event.getPlayer().hasPermission(Permissions.ADD)) {
|
||||||
if (Utils.isValidSignPosition(event.getBlockAgainst().getLocation())) {
|
if (Utils.isValidSignPosition(event.getBlockAgainst().getLocation())) {
|
||||||
Config.addChest(event.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation(),info.getPlayer());
|
if(!Config.addChest(event.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation(),info.getPlayer())){
|
||||||
|
sign.getBlock().breakNaturally();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Messages.CHEST_ADDED(event.getPlayer(), info.getGroup(), info.getPlayer().getName());
|
Messages.CHEST_ADDED(event.getPlayer(), info.getGroup(), info.getPlayer().getName());
|
||||||
setLine(sign, signChangeEvent, 0, ChatColor.RED + ChatColor.stripColor(signChangeEvent.getLine(0)));
|
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, 1, ChatColor.GREEN + ChatColor.stripColor(signChangeEvent.getLine(1)));
|
||||||
|
@ -3,6 +3,7 @@ package com.jamesdpeters.minecraft.chests.misc;
|
|||||||
import com.jamesdpeters.minecraft.chests.serialize.Config;
|
import com.jamesdpeters.minecraft.chests.serialize.Config;
|
||||||
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
|
import com.jamesdpeters.minecraft.chests.serialize.InventoryStorage;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class Messages {
|
public class Messages {
|
||||||
@ -104,4 +105,8 @@ public class Messages {
|
|||||||
public static void CANNOT_RENAME_GROUP_DOESNT_EXIST(Player target, String oldidentifier){
|
public static void CANNOT_RENAME_GROUP_DOESNT_EXIST(Player target, String oldidentifier){
|
||||||
target.sendMessage(ChatColor.RED+"Error renaming chest! "+ChatColor.WHITE+oldidentifier+ChatColor.RED+" doesn't exist!");
|
target.sendMessage(ChatColor.RED+"Error renaming chest! "+ChatColor.WHITE+oldidentifier+ChatColor.RED+" doesn't exist!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void OWNER_HAS_TOO_MANY_CHESTS(Player target, OfflinePlayer owner){
|
||||||
|
target.sendMessage(ChatColor.RED+"Owner: "+ChatColor.WHITE+owner.getName()+ChatColor.RED+" has reached the limit of groups allowed!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,18 @@ public class Settings {
|
|||||||
|
|
||||||
private static String CHECK_UPDATE = "update-checker";
|
private static String CHECK_UPDATE = "update-checker";
|
||||||
private static String CHECK_UPDATE_PERIOD = "update-checker-period";
|
private static String CHECK_UPDATE_PERIOD = "update-checker-period";
|
||||||
|
private static String LIMIT_CHESTS = "limit-chestlinks";
|
||||||
|
private static String LIMIT_CHESTS_NUMBER = "limit-chestlinks-amount";
|
||||||
|
|
||||||
private static Settings cf;
|
private static Settings cf;
|
||||||
private FileConfiguration configuration;
|
private FileConfiguration configuration;
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
|
|
||||||
|
private static boolean isUpdateCheckEnabled;
|
||||||
|
private static int updateCheckerPeriod;
|
||||||
|
private static boolean limitChests;
|
||||||
|
private static int limitChestsAmount;
|
||||||
|
|
||||||
public static void initConfig(Plugin plugin){
|
public static void initConfig(Plugin plugin){
|
||||||
cf = new Settings();
|
cf = new Settings();
|
||||||
cf.plugin = plugin;
|
cf.plugin = plugin;
|
||||||
@ -20,9 +27,13 @@ public class Settings {
|
|||||||
//DEFAULT VALUES
|
//DEFAULT VALUES
|
||||||
cf.configuration.addDefault(CHECK_UPDATE,true);
|
cf.configuration.addDefault(CHECK_UPDATE,true);
|
||||||
cf.configuration.addDefault(CHECK_UPDATE_PERIOD,60*60);
|
cf.configuration.addDefault(CHECK_UPDATE_PERIOD,60*60);
|
||||||
|
cf.configuration.addDefault(LIMIT_CHESTS,false);
|
||||||
|
cf.configuration.addDefault(LIMIT_CHESTS_NUMBER,0);
|
||||||
|
|
||||||
cf.configuration.options().copyDefaults(true);
|
cf.configuration.options().copyDefaults(true);
|
||||||
cf.plugin.saveConfig();
|
cf.plugin.saveConfig();
|
||||||
|
|
||||||
|
reloadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void save(){
|
private static void save(){
|
||||||
@ -31,13 +42,20 @@ public class Settings {
|
|||||||
|
|
||||||
public static void reloadConfig(){
|
public static void reloadConfig(){
|
||||||
cf.configuration = cf.plugin.getConfig();
|
cf.configuration = cf.plugin.getConfig();
|
||||||
|
|
||||||
|
isUpdateCheckEnabled = cf.configuration.getBoolean(CHECK_UPDATE);
|
||||||
|
updateCheckerPeriod = cf.configuration.getInt(CHECK_UPDATE_PERIOD);
|
||||||
|
limitChests = cf.configuration.getBoolean(LIMIT_CHESTS);
|
||||||
|
limitChestsAmount = cf.configuration.getInt(LIMIT_CHESTS_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GETTERS AND SETTERS
|
* GETTERS AND SETTERS
|
||||||
*/
|
*/
|
||||||
public static boolean isUpdateCheckEnabled() {
|
public static boolean isUpdateCheckEnabled() {
|
||||||
return cf.configuration.getBoolean(CHECK_UPDATE);
|
return isUpdateCheckEnabled;
|
||||||
}
|
}
|
||||||
public static int getUpdateCheckerPeriodTicks() { return 20*cf.configuration.getInt(CHECK_UPDATE_PERIOD);}
|
public static int getUpdateCheckerPeriodTicks() { return 20*updateCheckerPeriod;}
|
||||||
|
public static boolean isLimitChests() { return limitChests; }
|
||||||
|
public static int getLimitChestsAmount() { return limitChestsAmount; }
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.jamesdpeters.minecraft.chests.serialize;
|
|||||||
|
|
||||||
import com.jamesdpeters.minecraft.chests.containers.ChestLinkInfo;
|
import com.jamesdpeters.minecraft.chests.containers.ChestLinkInfo;
|
||||||
import com.jamesdpeters.minecraft.chests.misc.Messages;
|
import com.jamesdpeters.minecraft.chests.misc.Messages;
|
||||||
|
import com.jamesdpeters.minecraft.chests.misc.Settings;
|
||||||
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -83,12 +84,16 @@ public class Config {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addChest(Player player, String identifier, Location chestLocation, OfflinePlayer owner){
|
public static boolean addChest(Player player, String identifier, Location chestLocation, OfflinePlayer owner){
|
||||||
//List of groups this player has.
|
//List of groups this player has.
|
||||||
HashMap<String, InventoryStorage> map = getInventoryStorageMap(owner.getUniqueId());
|
HashMap<String, InventoryStorage> map = getInventoryStorageMap(owner.getUniqueId());
|
||||||
|
|
||||||
//Get Inventory Storage for the given group or create it if it doesnt exist.
|
//Get Inventory Storage for the given group or create it if it doesnt exist.
|
||||||
if(!map.containsKey(identifier)){
|
if(!map.containsKey(identifier)){
|
||||||
|
if(isAtLimit(owner)){
|
||||||
|
Messages.OWNER_HAS_TOO_MANY_CHESTS(player,owner);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
InventoryStorage storage = new InventoryStorage(owner,identifier,chestLocation);
|
InventoryStorage storage = new InventoryStorage(owner,identifier,chestLocation);
|
||||||
map.put(identifier, storage);
|
map.put(identifier, storage);
|
||||||
}
|
}
|
||||||
@ -115,6 +120,7 @@ public class Config {
|
|||||||
inventoryStorage.getLocations().add(chestLocation);
|
inventoryStorage.getLocations().add(chestLocation);
|
||||||
}
|
}
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP,1.0f,1f);
|
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP,1.0f,1f);
|
||||||
|
return true;
|
||||||
//saveASync();
|
//saveASync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,4 +212,10 @@ public class Config {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAtLimit(OfflinePlayer player){
|
||||||
|
if(Settings.isLimitChests()){
|
||||||
|
return getInventoryStorageMap(player.getUniqueId()).size() >= Settings.getLimitChestsAmount();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user