From 2c1f74a2cf1983372d39f314541adcf07f2cebc0 Mon Sep 17 00:00:00 2001 From: Driftay Date: Sat, 27 Jul 2019 23:38:24 -0400 Subject: [PATCH] Removed Shop (In Dev) --- .../massivecraft/factions/SaberFactions.java | 6 - .../massivecraft/factions/cmd/CmdShop.java | 26 --- .../com/massivecraft/factions/shop/Pair.java | 20 --- .../factions/shop/ShopBoosterGUI.java | 148 ------------------ .../massivecraft/factions/shop/ShopGUI.java | 59 ------- .../factions/shop/ShopPotionGUI.java | 122 --------------- .../shop/handlers/BoosterHandler.java | 28 ---- .../factions/shop/handlers/PotionHandler.java | 46 ------ 8 files changed, 455 deletions(-) delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdShop.java delete mode 100644 src/main/java/com/massivecraft/factions/shop/Pair.java delete mode 100644 src/main/java/com/massivecraft/factions/shop/ShopBoosterGUI.java delete mode 100644 src/main/java/com/massivecraft/factions/shop/ShopGUI.java delete mode 100644 src/main/java/com/massivecraft/factions/shop/ShopPotionGUI.java delete mode 100644 src/main/java/com/massivecraft/factions/shop/handlers/BoosterHandler.java delete mode 100644 src/main/java/com/massivecraft/factions/shop/handlers/PotionHandler.java diff --git a/src/main/java/com/massivecraft/factions/SaberFactions.java b/src/main/java/com/massivecraft/factions/SaberFactions.java index b88a3722..6790bd9b 100644 --- a/src/main/java/com/massivecraft/factions/SaberFactions.java +++ b/src/main/java/com/massivecraft/factions/SaberFactions.java @@ -10,8 +10,6 @@ import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.dynmap.EngineDynmap; import com.massivecraft.factions.listeners.*; -import com.massivecraft.factions.shop.handlers.BoosterHandler; -import com.massivecraft.factions.shop.handlers.PotionHandler; import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.Particles.ReflectionUtils; @@ -28,7 +26,6 @@ import net.milkbowl.vault.permission.Permission; import org.bukkit.*; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -232,9 +229,6 @@ public class SaberFactions extends MPlugin { log("Skript addon registered!"); } - this.getServer().getScheduler().runTaskTimerAsynchronously(this, new BoosterHandler(), 100L, 100L); - this.getServer().getScheduler().runTaskTimerAsynchronously(this, new PotionHandler(this), 100L, 100L); - getServer().getPluginManager().registerEvents(factionsPlayerListener = new FactionsPlayerListener(), this); // Register Event Handlers diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShop.java b/src/main/java/com/massivecraft/factions/cmd/CmdShop.java deleted file mode 100644 index bbae1ede..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShop.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.shop.ShopGUI; -import com.massivecraft.factions.zcore.util.TL; - -public class CmdShop extends FCommand { - - - public CmdShop() { - this.aliases.add("shop"); - this.senderMustBePlayer = true; - this.senderMustBeColeader = true; - } - - @Override - public void perform() { - ShopGUI shopGUI = new ShopGUI(p, fme); - shopGUI.build(); - fme.getPlayer().openInventory(shopGUI.getInventory()); - } - - @Override - public TL getUsageTranslation() { - return TL.COMMAND_SHOP_DESCRIPTION; - } -} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/shop/Pair.java b/src/main/java/com/massivecraft/factions/shop/Pair.java deleted file mode 100644 index 15848833..00000000 --- a/src/main/java/com/massivecraft/factions/shop/Pair.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.massivecraft.factions.shop; - -public class Pair { - private K key; - private V value; - - public Pair(K key, V value) { - this.key = key; - this.value = value; - } - - public K getKey() { - return this.key; - } - - public V getValue() { - return this.value; - } -} - diff --git a/src/main/java/com/massivecraft/factions/shop/ShopBoosterGUI.java b/src/main/java/com/massivecraft/factions/shop/ShopBoosterGUI.java deleted file mode 100644 index 394f6ce1..00000000 --- a/src/main/java/com/massivecraft/factions/shop/ShopBoosterGUI.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.massivecraft.factions.shop; - -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.SaberFactions; -import com.massivecraft.factions.util.FactionGUI; -import com.massivecraft.factions.zcore.util.TL; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.*; - -public class ShopBoosterGUI implements FactionGUI { - private SaberFactions plugin; - private FPlayer fPlayer; - private Inventory inventory; - private Map items; - - public ShopBoosterGUI(SaberFactions plugin, FPlayer fPlayer) { - this.items = new HashMap<>(); - this.plugin = plugin; - this.fPlayer = fPlayer; - this.inventory = plugin.getServer().createInventory(this, plugin.getConfig().getInt("BoosterGUISize") * 9, TL.SHOP_BOOSTER_TITLE.toString()); - } - - @Override - public void onClick(int slot, ClickType action) { - if (slot == plugin.getConfig().getInt("BackButtonSlot")) { - ShopGUI shopGUI = new ShopGUI(plugin, fPlayer); - shopGUI.build(); - fPlayer.getPlayer().openInventory(shopGUI.getInventory()); - return; - } - String booster = items.getOrDefault(slot, null); - if (booster == null) { - return; - } - ConfigurationSection section = plugin.getConfig().getConfigurationSection("BoosterGUI").getConfigurationSection(booster); - if (section == null) { - return; - } - Faction faction = fPlayer.getFaction(); - int max = plugin.getConfig().getInt("MaxActiveBooster"); - if (faction.getActivePotions().size() >= max) { - fPlayer.msg(TL.SHOP_GUI_BOOSTER_MAX_REACHED, max); - return; - } - if (fPlayer.getFaction().getBoosters().containsKey(booster)) { - fPlayer.msg(TL.SHOP_GUI_BOOSTER_ACTIVE_ALREADY_ACTIVE); - return; - } - int cost = section.getInt("PointCost"); - if (faction.getPoints() < cost) { - fPlayer.msg(TL.SHOP_GUI_BOOSTER_CANNOT_AFFORD, cost); - return; - } - String name = ChatColor.translateAlternateColorCodes('&', section.getString("Name")); - faction.setPoints(faction.getPoints() - cost); - String string; - String type = string = section.getString("Type"); - switch (string) { - case "COMMAND": { - for (String command : section.getStringList("Commands")) { - this.plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag())); - } - break; - } - case "COMMAND_ONLINE": { - for (FPlayer player : fPlayer.getFaction().getFPlayersWhereOnline(true)) { - for (String command2 : section.getStringList("Commands")) { - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command2.replace("%faction%", fPlayer.getFaction().getTag()).replace("%player_name%", player.getName()).replace("%player_uuid%", player.getPlayer().getUniqueId().toString())); - } - } - break; - } - case "COMMAND_OFFLINE": { - for (FPlayer player : fPlayer.getFaction().getFPlayers()) { - for (String command2 : section.getStringList("Commands")) { - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command2.replace("%faction%", fPlayer.getFaction().getTag()).replace("%player_name%", player.getName()).replace("%player_uuid%", this.plugin.getServer().getOfflinePlayer(player.getName()).getUniqueId().toString())); - } - } - break; - } - } - fPlayer.getFaction().getBoosters().put(booster, System.currentTimeMillis() + section.getInt("CooldownMinutes") * 60000); - faction.msg(TL.SHOP_POTION_GUI_ACTIVATED, fPlayer.getNameAndTitle(), name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase()); - build(); - fPlayer.getPlayer().openInventory(inventory); - } - - @Override - public void build() { - ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("BoosterGUI"); - if (configurationSection == null) { - return; - } - Set boosters = fPlayer.getFaction().getBoosters().keySet(); - for (String key : configurationSection.getKeys(false)) { - ConfigurationSection section = configurationSection.getConfigurationSection(key); - int slot = Integer.valueOf(key); - int price = section.getInt("PointCost"); - ItemStack itemStack = new ItemStack(Material.valueOf(section.getString("Material"))); - ItemMeta itemMeta = itemStack.getItemMeta(); - itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', section.getString("Name"))); - List loreLines = new ArrayList<>(); - for (String line : section.getStringList("Lore")) { - loreLines.add(ChatColor.translateAlternateColorCodes('&', line.replace("%price%", String.valueOf(price)))); - } - if (boosters.contains(key)) { - itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, true); - itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - loreLines.add(TL.SHOP_GUI_BOOSTER_ACTIVE_LORE_LINE.toString()); - } - itemMeta.setLore(loreLines); - itemStack.setItemMeta(itemMeta); - inventory.setItem(slot, itemStack); - items.put(slot, key); - } - ConfigurationSection backSection = plugin.getConfig().getConfigurationSection("BackButton"); - if (backSection != null) { - ItemStack backStack = new ItemStack(Material.valueOf(backSection.getString("Material"))); - ItemMeta backMeta = backStack.getItemMeta(); - backMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', backSection.getString("Name"))); - backStack.setItemMeta(backMeta); - inventory.setItem(plugin.getConfig().getInt("BackButtonSlot"), backStack); - } - ConfigurationSection pointsSection = plugin.getConfig().getConfigurationSection("PointsItem"); - if (pointsSection != null) { - ItemStack pointsStack = new ItemStack(Material.valueOf(pointsSection.getString("Material"))); - ItemMeta pointsMeta = pointsStack.getItemMeta(); - pointsMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', pointsSection.getString("Name").replace("%points%", String.valueOf(fPlayer.getFaction().getPoints())))); - pointsStack.setItemMeta(pointsMeta); - inventory.setItem(plugin.getConfig().getInt("PointsSlot"), pointsStack); - } - } - - public Inventory getInventory() { - return inventory; - } -} diff --git a/src/main/java/com/massivecraft/factions/shop/ShopGUI.java b/src/main/java/com/massivecraft/factions/shop/ShopGUI.java deleted file mode 100644 index add107a0..00000000 --- a/src/main/java/com/massivecraft/factions/shop/ShopGUI.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.shop; - -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.SaberFactions; -import com.massivecraft.factions.util.FactionGUI; -import com.massivecraft.factions.zcore.util.TL; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -public class ShopGUI implements FactionGUI { - private SaberFactions plugin; - private FPlayer fPlayer; - private Inventory inventory; - - public ShopGUI(SaberFactions plugin, FPlayer fPlayer) { - this.plugin = plugin; - this.fPlayer = fPlayer; - this.inventory = plugin.getServer().createInventory(this, 27, plugin.color(plugin.getConfig().getString("F-Shop.Gui-Title"))); - } - - @Override - public void onClick(int slot, ClickType action) { - if (slot == 11) { - ShopPotionGUI potionGUI = new ShopPotionGUI(plugin, fPlayer); - potionGUI.build(); - fPlayer.getPlayer().openInventory(potionGUI.getInventory()); - } else if (slot == 15) { - ShopBoosterGUI boosterGUI = new ShopBoosterGUI(plugin, fPlayer); - boosterGUI.build(); - fPlayer.getPlayer().openInventory(boosterGUI.getInventory()); - } - } - - @Override - public void build() { - ItemStack potionStack = new ItemStack(Material.POTION); - PotionMeta potionMeta = (PotionMeta) potionStack.getItemMeta(); - potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.REGENERATION, 1, 1), true); - potionMeta.setDisplayName(ChatColor.LIGHT_PURPLE + ChatColor.BOLD.toString() + "Potion Shop"); - potionStack.setItemMeta(potionMeta); - inventory.setItem(11, potionStack); - ItemStack boosterStack = new ItemStack(Material.GOLDEN_APPLE); - ItemMeta boosterMeta = boosterStack.getItemMeta(); - boosterMeta.setDisplayName(ChatColor.WHITE + ChatColor.BOLD.toString() + "Booster Shop"); - boosterStack.setItemMeta(boosterMeta); - inventory.setItem(15, boosterStack); - } - - public Inventory getInventory() { - return this.inventory; - } -} diff --git a/src/main/java/com/massivecraft/factions/shop/ShopPotionGUI.java b/src/main/java/com/massivecraft/factions/shop/ShopPotionGUI.java deleted file mode 100644 index 727c7653..00000000 --- a/src/main/java/com/massivecraft/factions/shop/ShopPotionGUI.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.massivecraft.factions.shop; - -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.SaberFactions; -import com.massivecraft.factions.util.FactionGUI; -import com.massivecraft.factions.zcore.util.TL; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.util.*; - -public class ShopPotionGUI implements FactionGUI { - private SaberFactions plugin; - private FPlayer fPlayer; - private Inventory inventory; - private Map>> items; - - public ShopPotionGUI(SaberFactions plugin, FPlayer fPlayer) { - this.items = new HashMap<>(); - this.plugin = plugin; - this.fPlayer = fPlayer; - this.inventory = plugin.getServer().createInventory(this, plugin.getConfig().getInt("PotionGUISize") * 9, TL.SHOP_POTION_TITLE.toString()); - } - - @Override - public void onClick(int slot, ClickType action) { - if (slot == plugin.getConfig().getInt("BackButtonSlot")) { - ShopGUI shopGUI = new ShopGUI(plugin, fPlayer); - shopGUI.build(); - fPlayer.getPlayer().openInventory(shopGUI.getInventory()); - return; - } - Pair> pair = items.getOrDefault(slot, null); - if (pair == null) { - return; - } - Faction faction = fPlayer.getFaction(); - int max = plugin.getConfig().getInt("MaxActivePotions"); - if (faction.getActivePotions().size() >= max) { - fPlayer.msg(TL.SHOP_POTION_GUI_MAX_REACHED, max); - return; - } - if (faction.getActivePotions().containsKey(pair.getKey())) { - fPlayer.msg(TL.SHOP_POTION_GUI_POTION_TYPE_ALREADY_ACTIVE); - return; - } - if (faction.getPoints() < pair.getValue().getValue()) { - fPlayer.msg(TL.SHOP_POTION_GUI_INSUFFICIENT_POINTS, pair.getValue().getValue()); - return; - } - faction.setPoints(faction.getPoints() - pair.getValue().getValue()); - faction.getActivePotions().put(pair.getKey(), new Pair<>(pair.getValue().getKey(), System.currentTimeMillis() + plugin.getConfig().getInt("PotionsLastHours") * 3600000)); - faction.msg(TL.SHOP_POTION_GUI_ACTIVATED, fPlayer.getNameAndTitle(), pair.getKey().substring(0, 1).toUpperCase() + pair.getKey().substring(1).toLowerCase().replace('_', ' ')); - build(); - fPlayer.getPlayer().openInventory(inventory); - } - - @Override - public void build() { - ConfigurationSection configurationSection = plugin.getConfig().getConfigurationSection("PotionShop"); - if (configurationSection == null) { - return; - } - Set activePotions = fPlayer.getFaction().getActivePotions().keySet(); - for (String key : configurationSection.getKeys(false)) { - ConfigurationSection section = configurationSection.getConfigurationSection(key); - int slot = Integer.valueOf(key); - int level = section.getInt("Level"); - int price = section.getInt("PointCost"); - String potionType = section.getString("PotionType"); - ItemStack itemStack = new ItemStack(Material.POTION); - PotionMeta itemMeta = (PotionMeta) itemStack.getItemMeta(); - itemMeta.addCustomEffect(new PotionEffect(PotionEffectType.getByName(potionType), 1, level), true); - itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', section.getString("Name"))); - List loreLines = new ArrayList<>(); - for (String line : section.getStringList("Lore")) { - loreLines.add(ChatColor.translateAlternateColorCodes('&', line).replace("%price%", String.valueOf(price))); - } - if (activePotions.contains(potionType)) { - itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, true); - itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - loreLines.add(TL.SHOP_POTION_GUI_ACTIVATED_LORE_LINE.toString()); - } - itemMeta.setLore(loreLines); - itemStack.setItemMeta(itemMeta); - inventory.setItem(slot, itemStack); - items.put(slot, new Pair<>(potionType, new Pair<>(level, price))); - } - ConfigurationSection backSection = plugin.getConfig().getConfigurationSection("BackButton"); - if (backSection != null) { - ItemStack backStack = new ItemStack(Material.valueOf(backSection.getString("Material"))); - ItemMeta backMeta = backStack.getItemMeta(); - backMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', backSection.getString("Name"))); - backStack.setItemMeta(backMeta); - inventory.setItem(plugin.getConfig().getInt("BackButtonSlot"), backStack); - } - ConfigurationSection pointsSection = plugin.getConfig().getConfigurationSection("PointsItem"); - if (pointsSection != null) { - ItemStack pointsStack = new ItemStack(Material.valueOf(pointsSection.getString("Material"))); - ItemMeta pointsMeta = pointsStack.getItemMeta(); - pointsMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', pointsSection.getString("Name").replace("%points%", String.valueOf(fPlayer.getFaction().getPoints())))); - pointsStack.setItemMeta(pointsMeta); - inventory.setItem(plugin.getConfig().getInt("PointsSlot"), pointsStack); - } - } - - public Inventory getInventory() { - return inventory; - } -} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/shop/handlers/BoosterHandler.java b/src/main/java/com/massivecraft/factions/shop/handlers/BoosterHandler.java deleted file mode 100644 index 7f0bc2ba..00000000 --- a/src/main/java/com/massivecraft/factions/shop/handlers/BoosterHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.massivecraft.factions.shop.handlers; - -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class BoosterHandler implements Runnable { - - @Override - public void run() { - final long currentTime = System.currentTimeMillis(); - for (final Faction faction : Factions.getInstance().getAllFactions()) { - final List remove = new ArrayList<>(); - for (final Map.Entry entry : faction.getBoosters().entrySet()) { - if (entry.getValue() < currentTime) { - remove.add(entry.getKey()); - } - } - - remove.forEach((r) ->{ - Long n = faction.getBoosters().remove(r); - }); - } - } -} diff --git a/src/main/java/com/massivecraft/factions/shop/handlers/PotionHandler.java b/src/main/java/com/massivecraft/factions/shop/handlers/PotionHandler.java deleted file mode 100644 index 622a975c..00000000 --- a/src/main/java/com/massivecraft/factions/shop/handlers/PotionHandler.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.massivecraft.factions.shop.handlers; - -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.SaberFactions; -import com.massivecraft.factions.shop.Pair; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class PotionHandler implements Runnable { - private SaberFactions plugin; - - public PotionHandler(SaberFactions plugin) { - this.plugin = plugin; - } - - @Override - public void run() { - long currentTime = System.currentTimeMillis(); - for (Faction faction : Factions.getInstance().getAllFactions()) { - List remove = new ArrayList(); - for (Map.Entry> entry : faction.getActivePotions().entrySet()) { - if (entry.getValue().getValue() < currentTime) { - remove.add(entry.getKey()); - } else { - PotionEffect potionEffect = new PotionEffect(PotionEffectType.getByName(entry.getKey()), 400, entry.getValue().getKey(), false, false); - for (FPlayer fPlayer : faction.getFPlayersWhereOnline(true)) { - if (!fPlayer.isInOwnTerritory()) { - continue; - } - this.plugin.getServer().getScheduler().runTask(this.plugin, () -> fPlayer.getPlayer().addPotionEffect(potionEffect, true)); - } - } - } - - remove.forEach(key -> { - Pair pair = faction.getActivePotions().remove(key); - }); - } - } -}