Merge ShopWorld and ScoreWorld config variable into QuakeWorld

Restrict shop to LobbyArea (as ScoreBoard)
Fix a long time bug locking inventory after shop exit
Fix shop emerald management

Restric Shop usage Add LobbyArea in order to restrict ScoreBoard display
This commit is contained in:
Arnaud G. GIBERT 2021-05-07 19:21:54 +02:00
parent 8272d58c40
commit 2049a96542
8 changed files with 102 additions and 55 deletions

View File

@ -21,8 +21,8 @@ public class ShopCommand implements BasicCommand {
@Override
public boolean onCommand(Player player, String[] args) {
if (Quake.hasPermission(player, getPermission())) {
_plugin._shop.getMainShop(player);
_plugin._imm.show(player);
_plugin._shop.getMainShop(player);
_plugin._imm.show(player);
} else {
player.sendMessage(_plugin._trad.get("NoPermission"));
}

View File

@ -50,7 +50,8 @@ public class PlayerListener implements Listener {
Action action = event.getAction();
ItemStack hand = player.getInventory().getItemInMainHand();
Arena arena = _plugin._am.getArenabyPlayer(player);
if(arena == null) {
if(arena == null) {
Block block = event.getClickedBlock();
if ((action == Action.LEFT_CLICK_BLOCK || action == Action.RIGHT_CLICK_BLOCK) && _plugin._lobby.isinLobbyWall(event.getClickedBlock().getLocation()) && block.getState() instanceof Sign) {
Sign sign = (Sign)block.getState();
@ -65,7 +66,7 @@ public class PlayerListener implements Listener {
event.setCancelled(true);
return;
}
if (event.getItem() != null && event.getItem().getType().equals(_plugin._shopId) && _plugin._shopWorlds.contains(event.getPlayer().getWorld().getName()) && Quake.hasPermission(player, "Quake.Shop")) {
if (event.getItem() != null && event.getItem().getType().equals(_plugin._shopId) && _plugin._QuakeWorlds.contains(event.getPlayer().getWorld().getName()) && Quake.hasPermission(player, "Quake.Shop")) {
_plugin._shop.getMainShop(player);
_plugin._imm.show(player);
event.setCancelled(true);
@ -134,8 +135,8 @@ public class PlayerListener implements Listener {
}
}
public Boolean isScoreWorld(String name) {
if (_plugin._ScoreWorlds.contains(name)) {
public Boolean isQuakeWorld(String name) {
if (_plugin._QuakeWorlds.contains(name)) {
return true;
}
return false;
@ -245,8 +246,10 @@ public class PlayerListener implements Listener {
public void onPlayerTeleport(PlayerTeleportEvent event) {
Player p = event.getPlayer();
if( isScoreWorld(event.getFrom().getWorld().getName()) ^ isScoreWorld(event.getTo().getWorld().getName())) {
if( isQuakeWorld(event.getFrom().getWorld().getName()) ^ isQuakeWorld(event.getTo().getWorld().getName())) {
_plugin._shop.displayShopItem( p, event.getTo().getWorld().getName());
if (_plugin._scores.containsKey(p.getName())) {
_plugin._scores.get(p.getName()).displayScoreB( event.getTo().getWorld().getName());
} else {

View File

@ -58,8 +58,7 @@ extends JavaPlugin {
public FileConfiguration _config;
public Boolean _useVault = false;
public Material _shopId = Material.EMERALD;
public List<String> _shopWorlds = new ArrayList<>();
public List<String> _ScoreWorlds = new ArrayList<>();
public List<String> _QuakeWorlds = new ArrayList<>();
public HashMap<String, ScoreB> _scores = new HashMap();
public Scoreboard _board;
@ -71,8 +70,7 @@ extends JavaPlugin {
_board = Bukkit.getScoreboardManager().getNewScoreboard();
File confFile = new File(getDataFolder(), "config.yml");
_config = YamlConfiguration.loadConfiguration(confFile);
_shopWorlds.add("world");
_ScoreWorlds.add("world");
_QuakeWorlds.add("world");
if(confFile.exists())
loadConfig();
else
@ -120,11 +118,8 @@ extends JavaPlugin {
_debug = _config.getBoolean("debug", false);
_useVault = _config.getBoolean("useVault", true);
_shopId = Material.getMaterial(_config.getString("shop.id", "EMERALD"));
if(_config.contains("shop.world")) {
_shopWorlds = _config.getStringList("shop.world");
}
if(_config.contains("ScoreBoard.world")) {
_ScoreWorlds = _config.getStringList("ScoreBoard.world");
if(_config.contains("QuakeWorld")) {
_QuakeWorlds = _config.getStringList("QuakeWorld");
}
}
@ -133,10 +128,8 @@ extends JavaPlugin {
_config.set("debug", _debug);
_config.set("useVault", _useVault);
_config.set("shop.id", _shopId.name());
if(!_shopWorlds.isEmpty())
_config.set("shop.world", _shopWorlds);
if(!_ScoreWorlds.isEmpty())
_config.set("ScoreBoard.world", _ScoreWorlds);
if(!_QuakeWorlds.isEmpty())
_config.set("QuakeWorld", _QuakeWorlds);
try {
_config.save(new File(getDataFolder(), "config.yml"));
} catch (IOException e) {

View File

@ -68,20 +68,21 @@ public class IconMenuManager implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
if(!(event.getWhoClicked() instanceof Player))
return;
Player p = (Player)event.getWhoClicked();
if(_menus.containsKey(p))
if(_menus.containsKey(p)) {
_menus.get(p).onInventoryClick(event);
}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if(!(event.getPlayer() instanceof Player))
return;
Player p = (Player)event.getPlayer();
if(_menus.containsKey(p))
if(_menus.containsKey(p)) {
_menus.get(p).onInventoryClose(event);
destroy(p);
}
}
}

View File

@ -41,7 +41,7 @@ public class ShopManager {
}
_plugin._imm.create(p, "Quake Manager", 54, new IconMenu.OptionClickEventHandler() {
@Override
public void onOptionClick(IconMenu.OptionClickEvent event) {
if (event.getName() == null) {
@ -511,5 +511,73 @@ public class ShopManager {
}
}
public void displayShopItem(Player player, String target_world) {
String world;
if( target_world != "") {
world = target_world;
} else {
world = player.getWorld().getName();
}
if( isQuakeWorld( world)) {
if( _plugin._lobby.isinLobbyArea(player.getLocation())) {
enableShopItem(player);
} else {
disableShopItem(player);
}
} else {
disableShopItem(player);
}
return;
}
public void enableShopItem(Player player) {
int nb = 0;
for( int i = 0; i < player.getInventory().getSize(); i++) {
ItemStack it = player.getInventory().getItem(i);
if( it != null && it.getItemMeta() != null && it.getItemMeta().getDisplayName() != null && it.getItemMeta().getDisplayName().equalsIgnoreCase(_plugin._shop.getShop().getItemMeta().getDisplayName())) {
if( nb > 0) {
try {
player.getInventory().clear(i);
} catch (Exception var10_10) {
// empty catch block
}
} else {
if( it.getAmount() > 1) {
it.setAmount(1);
}
nb += it.getAmount();
}
}
}
if( nb == 0) {
player.getInventory().addItem(new ItemStack[]{_plugin._shop.getShop()});
}
}
public void disableShopItem(Player player) {
int nb = 0;
for( int i = 0; i < player.getInventory().getSize(); i++) {
ItemStack it = player.getInventory().getItem(i);
if( it != null && it.getItemMeta() != null && it.getItemMeta().getDisplayName() != null && it.getItemMeta().getDisplayName().equalsIgnoreCase(_plugin._shop.getShop().getItemMeta().getDisplayName())) {
try {
player.getInventory().clear(i);
} catch (Exception var10_10) {
// empty catch block
}
}
}
}
public Boolean isQuakeWorld(String name) {
return _plugin._QuakeWorlds.contains(name);
}
}

View File

@ -46,25 +46,10 @@ public class Task implements Runnable {
resetTime(arena);
return;
}
if (_plugin._shopWorlds.contains(p.getWorld().getName()) && !p.getInventory().contains(_plugin._shop.getShop()) && Quake.hasPermission(p, "Quake.Shop")) {
ItemStack[] arritemStack = p.getInventory().getContents();
int n3 = arritemStack.length;
int n4 = 0;
while (n4 < n3) {
ItemStack it = arritemStack[n4];
if (it != null && it.getItemMeta() != null && it.getItemMeta().getDisplayName() != null && it.getItemMeta().getDisplayName().equalsIgnoreCase(_plugin._shop.getShop().getItemMeta().getDisplayName())) {
try {
p.getInventory().remove(it);
} catch (Exception var10_10) {
// empty catch block
}
}
++n4;
}
p.getInventory().addItem(new ItemStack[]{_plugin._shop.getShop()});
}
if (isScoreWorld(p.getWorld().getName())) {
giveScoreBoard(p);
if (isQuakeWorld(p.getWorld().getName())) {
_plugin._shop.displayShopItem( p, "");
giveScoreBoard(p);
}
}
}
@ -77,8 +62,8 @@ public class Task implements Runnable {
}
}
public Boolean isScoreWorld(String name) {
if (_plugin._ScoreWorlds.contains(name)) {
public Boolean isQuakeWorld(String name) {
if (_plugin._QuakeWorlds.contains(name)) {
return true;
}
return false;

View File

@ -101,11 +101,9 @@ public class IconMenu implements Listener {
public void onInventoryClose(InventoryCloseEvent event) {
if(!(event.getPlayer() instanceof Player))
return;
Player p = (Player)event.getPlayer();
if(!_openInventories.contains(p.getUniqueId()))
return;
if(_autodestroy) {
destroy();
}
@ -115,8 +113,7 @@ public class IconMenu implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
if(!(event.getInventory().getHolder() instanceof Player))
return;
Player p = (Player)event.getWhoClicked();
Player p = (Player)event.getWhoClicked();
if(p == null || !_openInventories.contains(p.getUniqueId())) {
event.setCancelled(true);
return;
@ -130,7 +127,7 @@ public class IconMenu implements Listener {
}
Plugin plugin = _plugin;
OptionClickEvent e = new OptionClickEvent((Player)event.getWhoClicked(), slot, _optionRegs[slot], this, event.isRightClick(), event.isLeftClick(), event.isShiftClick());
_handler.onOptionClick(e);
_handler.onOptionClick(e);
if (e.willClose()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

View File

@ -71,7 +71,7 @@ public final class ScoreB {
world = _player.getWorld().getName();
}
if( isScoreWorld( world)) {
if( isQuakeWorld( world)) {
if( _plugin._lobby.isinLobbyArea(_player.getLocation())) {
_player.setScoreboard(_board);
} else {
@ -83,9 +83,9 @@ public final class ScoreB {
return;
}
public Boolean isScoreWorld(String name) {
return _plugin._ScoreWorlds.contains(name);
public Boolean isQuakeWorld(String name) {
return _plugin._QuakeWorlds.contains(name);
}
}