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

@ -50,6 +50,7 @@ public class PlayerListener implements Listener {
Action action = event.getAction(); Action action = event.getAction();
ItemStack hand = player.getInventory().getItemInMainHand(); ItemStack hand = player.getInventory().getItemInMainHand();
Arena arena = _plugin._am.getArenabyPlayer(player); Arena arena = _plugin._am.getArenabyPlayer(player);
if(arena == null) { if(arena == null) {
Block block = event.getClickedBlock(); 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) { if ((action == Action.LEFT_CLICK_BLOCK || action == Action.RIGHT_CLICK_BLOCK) && _plugin._lobby.isinLobbyWall(event.getClickedBlock().getLocation()) && block.getState() instanceof Sign) {
@ -65,7 +66,7 @@ public class PlayerListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; 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._shop.getMainShop(player);
_plugin._imm.show(player); _plugin._imm.show(player);
event.setCancelled(true); event.setCancelled(true);
@ -134,8 +135,8 @@ public class PlayerListener implements Listener {
} }
} }
public Boolean isScoreWorld(String name) { public Boolean isQuakeWorld(String name) {
if (_plugin._ScoreWorlds.contains(name)) { if (_plugin._QuakeWorlds.contains(name)) {
return true; return true;
} }
return false; return false;
@ -245,7 +246,9 @@ public class PlayerListener implements Listener {
public void onPlayerTeleport(PlayerTeleportEvent event) { public void onPlayerTeleport(PlayerTeleportEvent event) {
Player p = event.getPlayer(); 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())) { if (_plugin._scores.containsKey(p.getName())) {
_plugin._scores.get(p.getName()).displayScoreB( event.getTo().getWorld().getName()); _plugin._scores.get(p.getName()).displayScoreB( event.getTo().getWorld().getName());

View File

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

View File

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

View File

@ -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,24 +46,9 @@ public class Task implements Runnable {
resetTime(arena); resetTime(arena);
return; return;
} }
if (_plugin._shopWorlds.contains(p.getWorld().getName()) && !p.getInventory().contains(_plugin._shop.getShop()) && Quake.hasPermission(p, "Quake.Shop")) {
ItemStack[] arritemStack = p.getInventory().getContents(); if (isQuakeWorld(p.getWorld().getName())) {
int n3 = arritemStack.length; _plugin._shop.displayShopItem( p, "");
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); giveScoreBoard(p);
} }
} }
@ -77,8 +62,8 @@ public class Task implements Runnable {
} }
} }
public Boolean isScoreWorld(String name) { public Boolean isQuakeWorld(String name) {
if (_plugin._ScoreWorlds.contains(name)) { if (_plugin._QuakeWorlds.contains(name)) {
return true; return true;
} }
return false; return false;

View File

@ -101,11 +101,9 @@ public class IconMenu implements Listener {
public void onInventoryClose(InventoryCloseEvent event) { public void onInventoryClose(InventoryCloseEvent event) {
if(!(event.getPlayer() instanceof Player)) if(!(event.getPlayer() instanceof Player))
return; return;
Player p = (Player)event.getPlayer(); Player p = (Player)event.getPlayer();
if(!_openInventories.contains(p.getUniqueId())) if(!_openInventories.contains(p.getUniqueId()))
return; return;
if(_autodestroy) { if(_autodestroy) {
destroy(); destroy();
} }
@ -115,7 +113,6 @@ public class IconMenu implements Listener {
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
if(!(event.getInventory().getHolder() instanceof Player)) if(!(event.getInventory().getHolder() instanceof Player))
return; return;
Player p = (Player)event.getWhoClicked(); Player p = (Player)event.getWhoClicked();
if(p == null || !_openInventories.contains(p.getUniqueId())) { if(p == null || !_openInventories.contains(p.getUniqueId())) {
event.setCancelled(true); event.setCancelled(true);

View File

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