Begun Adding ChestLogs

//TODO flat file, shift click registry
This commit is contained in:
Driftay 2019-08-18 09:19:41 -04:00
parent 49ec990c2f
commit fdb76f39f5
4 changed files with 131 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.cmd.CmdAutoHelp; import com.massivecraft.factions.cmd.CmdAutoHelp;
import com.massivecraft.factions.cmd.FCmdRoot; import com.massivecraft.factions.cmd.FCmdRoot;
import com.massivecraft.factions.cmd.chest.ChestLogsHandler;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.integration.dynmap.EngineDynmap; import com.massivecraft.factions.integration.dynmap.EngineDynmap;
@ -255,6 +256,7 @@ public class P extends MPlugin {
new RedstoneUpgrade(), new RedstoneUpgrade(),
new ShopClickPersistence(), new ShopClickPersistence(),
new MissionHandler(this), new MissionHandler(this),
new ChestLogsHandler(),
new SpawnerUpgrades() new SpawnerUpgrades()
}; };

View File

@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.cmd.alts.CmdAlts; import com.massivecraft.factions.cmd.alts.CmdAlts;
import com.massivecraft.factions.cmd.chest.CmdChest;
import com.massivecraft.factions.cmd.chest.CmdChestLogs;
import com.massivecraft.factions.cmd.claim.*; import com.massivecraft.factions.cmd.claim.*;
import com.massivecraft.factions.cmd.econ.CmdMoney; import com.massivecraft.factions.cmd.econ.CmdMoney;
import com.massivecraft.factions.cmd.logout.CmdLogout; import com.massivecraft.factions.cmd.logout.CmdLogout;
@ -133,6 +135,7 @@ public class FCmdRoot extends FCommand {
public CmdNotifications cmdNotifications = new CmdNotifications(); public CmdNotifications cmdNotifications = new CmdNotifications();
public CmdShop cmdShop = new CmdShop(); public CmdShop cmdShop = new CmdShop();
public CmdMissions cmdMissions = new CmdMissions(); public CmdMissions cmdMissions = new CmdMissions();
public CmdChestLogs cmdChestLogs = new CmdChestLogs();
public FCmdRoot() { public FCmdRoot() {
super(); super();
@ -245,6 +248,7 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdLowPower); this.addSubCommand(this.cmdLowPower);
this.addSubCommand(this.cmdTntFill); this.addSubCommand(this.cmdTntFill);
this.addSubCommand(this.cmdChest); this.addSubCommand(this.cmdChest);
this.addSubCommand(this.cmdChestLogs);
this.addSubCommand(this.cmdSetBanner); this.addSubCommand(this.cmdSetBanner);
this.addSubCommand(this.cmdStrikeSet); this.addSubCommand(this.cmdStrikeSet);
this.addSubCommand(this.cmdSpam); this.addSubCommand(this.cmdSpam);

View File

@ -0,0 +1,123 @@
package com.massivecraft.factions.cmd.chest;
import com.massivecraft.factions.FPlayers;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChestLogsHandler implements Listener {
public static HashMap<String, List<String>> removeMap = new HashMap<>();
public static HashMap<String, List<String>> addMap = new HashMap<>();
public static HashMap<String, Integer> totalMap = new HashMap<>();
public static int getAll(String uuid) {
int t = 0;
t = t + removeMap.get(uuid).size();
t = t + addMap.get(uuid).size();
return t;
}
public static int getAll() {
int t = 0;
for (Map.Entry<String, List<String>> entry : removeMap.entrySet()) {
t = t + entry.getValue().size();
}
for (Map.Entry<String, List<String>> entry : addMap.entrySet()) {
t = t + entry.getValue().size();
}
return t;
}
public void mapAdd(String uuid, String string) {
List<String> list = new ArrayList<>();
if (addMap.get(uuid) != null) {
list = addMap.get(uuid);
}
list.add(string);
addMap.remove(uuid);
addMap.put(uuid, list);
if (totalMap.get(uuid) == null) {
totalMap.put(uuid, 1);
} else {
int t = totalMap.get(uuid);
totalMap.remove(uuid);
totalMap.put(uuid, t + 1);
}
}
public void mapRemove(String uuid, String string) {
List<String> list = new ArrayList<>();
if (removeMap.get(uuid) != null) {
list = removeMap.get(uuid);
}
list.add(string);
removeMap.remove(uuid);
removeMap.put(uuid, list);
if (totalMap.get(uuid) == null) {
totalMap.put(uuid, 1);
} else {
int t = totalMap.get(uuid);
totalMap.remove(uuid);
totalMap.put(uuid, t + 1);
}
}
public String itemString(ItemStack itemStack) {
String s = "x" + itemStack.getAmount() + " " + itemStack.getType().name().toLowerCase();
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName()) {
s = s + " (" + itemStack.getItemMeta().getDisplayName() + ")";
}
return s.replace("_", " ");
}
@EventHandler
public void fChestInventoryClick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
Inventory topInventory = p.getOpenInventory().getTopInventory();
Inventory bottomInventory = p.getOpenInventory().getBottomInventory();
if (topInventory != null) {
if (topInventory.equals(FPlayers.getInstance().getByPlayer(p).getFaction().getChestInventory())) {
if (e.getClickedInventory() != null) {
if (e.getClickedInventory().equals(topInventory)) {
ItemStack current = e.getCurrentItem();
if(current == null) return;
ItemStack cursor = e.getCursor();
if (e.getClick().isShiftClick()) return;
if (cursor != null) {
if (current.getType().equals(Material.AIR)) {
if (!cursor.getType().equals(Material.AIR)) {
mapAdd(p.getName(), itemString(cursor));
}
} else {
if (!current.getType().equals(Material.AIR)) {
mapRemove(p.getName(), itemString(current));
}
}
}
} else {
if (e.getClickedInventory().equals(bottomInventory)) {
//clicking from bottom inventory
if (e.getClick().isShiftClick()) {
}
}
}
}
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd.chest;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
@ -42,10 +43,7 @@ public class CmdChest extends FCommand {
return; return;
} }
} }
me.openInventory(fme.getFaction().getChestInventory()); me.openInventory(fme.getFaction().getChestInventory());
} }
@Override @Override