- Change click tracking to track the items' names
- Only add the features item, if the user has unlocked features
This commit is contained in:
@@ -14,6 +14,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@@ -43,6 +44,7 @@ public class Inventories implements Listener {
|
||||
private static final HashMap<String, HashMap<Integer, Entry<Action, Object>>> invActions = new HashMap<>();
|
||||
private static final HashMap<String, String> invNames = new HashMap<>();
|
||||
private static final HashMap<String, HashMap<String, ItemStack>> items = new HashMap<>();
|
||||
private static final HashMap<String, String> itemNames = new HashMap<>();
|
||||
private static final HashMap<String, Entry<Action, Object>> itemActions = new HashMap<>();
|
||||
private static final HashMap<String, Integer> itemPositions = new HashMap<>();
|
||||
public static final HashMap<Player, Boolean> checkInteracts = new HashMap<>();
|
||||
@@ -63,13 +65,15 @@ public class Inventories implements Listener {
|
||||
for (String lang : Core.getAvailLangs()) {
|
||||
ItemStack stack = new ItemStack(m);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(nameColor + Core.getl(name, lang));
|
||||
String display = nameColor + Core.getl(name, lang);
|
||||
meta.setDisplayName(display);
|
||||
if (loreColor != null) {
|
||||
for (int i = 0; i < lores.length; i++) {
|
||||
lores[i] = loreColor + Core.getl(lores[i], lang);
|
||||
}
|
||||
meta.setLore(Arrays.asList(lores));
|
||||
}
|
||||
itemNames.put(display, type);
|
||||
stack.setItemMeta(meta);
|
||||
stacks.put(lang, stack);
|
||||
}
|
||||
@@ -228,13 +232,10 @@ public class Inventories implements Listener {
|
||||
if (event.hasItem()) {
|
||||
if (event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR) || event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK)) {
|
||||
final Player P = event.getPlayer();
|
||||
int slot = P.getInventory().getHeldItemSlot();
|
||||
if (itemPositions.containsValue(slot)) {
|
||||
String type = itemNames.get(P.getItemInHand().getItemMeta().getDisplayName());
|
||||
if (itemActions.containsKey(type)) {
|
||||
event.setCancelled(true);
|
||||
String item = Core.getKeyByValue(itemPositions, slot);
|
||||
if (itemActions.containsKey(item)) {
|
||||
executeAction(P, itemActions.get(item).getKey(), itemActions.get(item).getValue());
|
||||
}
|
||||
executeAction(P, itemActions.get(type).getKey(), itemActions.get(type).getValue());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AnuraCore.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -246,7 +247,7 @@ public class Inventories implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
event.getPlayer().getInventory().clear();
|
||||
addInvItems(event.getPlayer());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Inventories;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@@ -55,7 +56,12 @@ public class Features implements Listener {
|
||||
resetPlayerFeatures(P);
|
||||
playerFeatures.put(P, new ArrayList<Feature>());
|
||||
featureEnabled.put(P, new HashMap<Feature, Boolean>());
|
||||
boolean added = false;
|
||||
while (rs.next()) {
|
||||
if (!added) {
|
||||
P.getInventory().setItem(2, Inventories.getItem("CHARGE", P));
|
||||
added = true;
|
||||
}
|
||||
if (Feature.getById(rs.getInt("featureId")) != null) {
|
||||
this.addFeature(P, Feature.getById(rs.getInt("featureId")));
|
||||
featureEnabled.get(P).put(Feature.DOUBLE_JUMP, true);
|
||||
|
||||
@@ -262,18 +262,17 @@ public class Setup {
|
||||
|
||||
Inventories.buildInvItem("COMPASS", Material.COMPASS, "select_game", ChatColor.DARK_AQUA);
|
||||
Inventories.buildInvItem("SIGN", Material.SIGN, "Change language", ChatColor.DARK_GREEN);
|
||||
Inventories.buildInvItem("PAPER", Material.PAPER, "features_item", ChatColor.BLUE);
|
||||
Inventories.buildInvItem("CHARGE", Material.FIREBALL, "features_item", ChatColor.BLUE);
|
||||
Inventories.buildInvItem("DOOR", Material.WOOD_DOOR, "tp_to_spawn", ChatColor.YELLOW);
|
||||
Inventories.buildInvItem("EYE", Material.EYE_OF_ENDER, "inv_to_lobby", ChatColor.YELLOW);
|
||||
if (Core.getMainClass().getConfig().getString("server-name").equals("lobby")) {
|
||||
Inventories.setItemInPlayerInv("COMPASS", 0);
|
||||
Inventories.setItemInPlayerInv("SIGN", 1);
|
||||
Inventories.setItemInPlayerInv("PAPER", 2);
|
||||
Inventories.setItemInPlayerInv("DOOR", 8);
|
||||
}
|
||||
Inventories.registerItemAction("COMPASS", Inventories.Action.OPEN_INV, "GAMEMODES");
|
||||
Inventories.registerItemAction("SIGN", Inventories.Action.OPEN_INV, "LANGUAGE");
|
||||
Inventories.registerItemAction("PAPER", Inventories.Action.OPEN_INV, "FEATURES");
|
||||
Inventories.registerItemAction("CHARGE", Inventories.Action.OPEN_INV, "FEATURES");
|
||||
Inventories.registerItemAction("DOOR", Inventories.Action.COMMAND, "spawn");
|
||||
Inventories.registerItemAction("EYE", Inventories.Action.SERVER, "lobby");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Inventories;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.Features;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
Reference in New Issue
Block a user