src/main/java/vpd/bowandaero12/furnacelv/items/LevelMenu.java gelöscht
This commit is contained in:
@@ -1,268 +0,0 @@
|
||||
package vpd.bowandaero12.furnacelv.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Furnace; // Nur diesen Import behalten
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import vpd.bowandaero12.furnacelv.FurnaceLevels;
|
||||
import vpd.bowandaero12.furnacelv.utils.Fuels;
|
||||
|
||||
public class LevelMenu implements Listener {
|
||||
private FurnaceLevels plugin;
|
||||
private Map<UUID, Integer> debug;
|
||||
|
||||
public LevelMenu(FurnaceLevels plugin) {
|
||||
this.debug = new HashMap<>();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private Integer getCost(int level) {
|
||||
if (level == 0)
|
||||
return 0;
|
||||
return this.plugin.configs.getConfig().getInt("upgrades.level-" + level + ".cost");
|
||||
}
|
||||
|
||||
private Inventory createInv(int level) {
|
||||
Inventory gui;
|
||||
ItemStack glass = Fuels.BLACK_STAINED_GLASS_PANE.parseItem();
|
||||
ItemMeta meta = glass.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.BLACK.toString());
|
||||
glass.setItemMeta(meta);
|
||||
if (level < 5) {
|
||||
gui = Bukkit.createInventory(null, 9, getLangMsg("level-gui.name", level));
|
||||
gui.setItem(2, createItem(Material.EMERALD_BLOCK, getLangMsg("level-gui.items.emerald-block.name", level), getLangList("level-gui.items.emerald-block.lore", level)));
|
||||
} else {
|
||||
gui = Bukkit.createInventory(null, 9, getLangMsg("level-gui.max-level-name", level));
|
||||
gui.setItem(2, createItem(Material.OBSIDIAN, getLangMsg("level-gui.items.obsidian.name", level), getLangList("level-gui.items.obsidian.lore", level)));
|
||||
}
|
||||
gui.setItem(6, createItem(Material.REDSTONE_BLOCK, getLangMsg("level-gui.items.redstone-block.name", level), getLangList("level-gui.items.redstone-block.lore", level)));
|
||||
ItemStack book = createItem(Material.BOOK, getLangMsg("level-gui.items.book.name", level), getLangList("level-gui.items.book.lore", level));
|
||||
ItemMeta bookmeta = book.getItemMeta();
|
||||
bookmeta.addEnchant(Enchantment.UNBREAKING, 1, true);
|
||||
book.setItemMeta(bookmeta);
|
||||
gui.setItem(4, book);
|
||||
for (Integer i : Arrays.asList(0, 8)) {
|
||||
gui.setItem(i, glass);
|
||||
}
|
||||
return gui;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onShiftRightClick(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
Block block = e.getClickedBlock();
|
||||
Player p = e.getPlayer();
|
||||
if (p.isSneaking()) {
|
||||
if (p.getInventory().getItemInMainHand().getType() != Material.AIR)
|
||||
return;
|
||||
if (block.getType() != Material.FURNACE)
|
||||
return;
|
||||
e.setCancelled(true);
|
||||
if (((org.bukkit.block.data.type.Furnace) block.getBlockData()).isLit()) {
|
||||
burn(p, block);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
p.openInventory(createInv(getFurnaceTrack().getOrDefault(block.getLocation(), 0)));
|
||||
} catch (NullPointerException err) {
|
||||
getFurnaceTrack().put(block.getLocation(), 0);
|
||||
p.openInventory(createInv(getFurnaceTrack().get(block.getLocation())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
UUID uuid = e.getWhoClicked().getUniqueId();
|
||||
if (!this.plugin.configs.getConfig().getBoolean("use-economy") && e.getClickedInventory() == null) {
|
||||
if (!this.plugin.debug.getDebugging().contains(uuid))
|
||||
return;
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
if (this.debug.get(uuid) == null) {
|
||||
this.debug.put(uuid, 1);
|
||||
} else if (this.debug.get(uuid) == 2) {
|
||||
this.debug.put(uuid, this.debug.get(uuid) + 1);
|
||||
} else {
|
||||
this.debug.remove(uuid);
|
||||
}
|
||||
} else if (e.getClick() == ClickType.RIGHT) {
|
||||
if (this.debug.get(uuid) == null || this.debug.get(uuid) != 1) {
|
||||
this.debug.remove(uuid);
|
||||
} else {
|
||||
this.debug.put(uuid, this.debug.get(uuid) + 1);
|
||||
}
|
||||
} else if (e.getClick() == ClickType.MIDDLE) {
|
||||
if (this.debug.get(uuid) != null && this.debug.get(uuid) == 3)
|
||||
e.getWhoClicked().getInventory().addItem(new ItemStack[]{this.plugin.itemhandler.customItem()});
|
||||
this.debug.remove(uuid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
String invTitle = e.getView().getTitle();
|
||||
org.bukkit.block.Furnace furnace; // Explizite Deklaration
|
||||
try {
|
||||
furnace = (org.bukkit.block.Furnace) p.getTargetBlock(null, 5).getState();
|
||||
if (!invTitle.equals(getLangMsg("level-gui.name", getFurnaceLevel(furnace))) &&
|
||||
!invTitle.equals(getLangMsg("level-gui.max-level-name", 5)))
|
||||
return;
|
||||
} catch (ClassCastException err) {
|
||||
return;
|
||||
}
|
||||
if (e.getCurrentItem() == null)
|
||||
return;
|
||||
if (e.getCurrentItem().getType() == Material.REDSTONE_BLOCK) {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
p.closeInventory();
|
||||
}
|
||||
}.runTask(this.plugin);
|
||||
} else if (e.getCurrentItem().getType() == Material.EMERALD_BLOCK) {
|
||||
try {
|
||||
furnace = (org.bukkit.block.Furnace) p.getTargetBlock(null, 5).getState();
|
||||
if (!invTitle.equals(getLangMsg("level-gui.name", getFurnaceLevel(furnace))) &&
|
||||
!invTitle.equals(getLangMsg("level-gui.max-level-name", 5)))
|
||||
return;
|
||||
} catch (ClassCastException err) {
|
||||
p.sendMessage(getLangMsg("error", null));
|
||||
return;
|
||||
}
|
||||
int currentLv = getFurnaceLevel(furnace);
|
||||
if (!hasPermission(p, currentLv + 1)) {
|
||||
p.sendMessage(getLangMsg("no-level-permission", currentLv));
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
double cost = getCost(currentLv + 1);
|
||||
if (this.plugin.vaultEco != null) {
|
||||
if (this.plugin.vaultEco.getBalance(p) >= cost) {
|
||||
this.plugin.vaultEco.withdrawPlayer(p, cost);
|
||||
} else {
|
||||
p.sendMessage(getLangMsg("not-enough-money", currentLv));
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
ItemStack item = this.plugin.itemhandler.customItem();
|
||||
item.setAmount((int) cost);
|
||||
if (p.getInventory().containsAtLeast(item, (int) cost)) {
|
||||
p.getInventory().removeItem(new ItemStack[]{item});
|
||||
} else {
|
||||
p.sendMessage(getLangMsg("not-enough-money", currentLv));
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
List<String> furnaces = this.plugin.configs.getFData().getStringList("furnaces");
|
||||
furnaces.remove(this.plugin.itemhandler.serialize(furnace.getLocation(), currentLv));
|
||||
furnaces.add(this.plugin.itemhandler.serialize(furnace.getLocation(), currentLv + 1));
|
||||
this.plugin.configs.getFData().set("furnaces", furnaces);
|
||||
this.plugin.configs.saveData();
|
||||
getFurnaceTrack().put(furnace.getLocation(), currentLv + 1);
|
||||
p.sendMessage(getLangMsg("successful-purchase", currentLv + 1));
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
p.closeInventory();
|
||||
}
|
||||
}.runTask(this.plugin);
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
private Map<Location, Integer> getFurnaceTrack() {
|
||||
return this.plugin.itemhandler.getFurnaceTrack();
|
||||
}
|
||||
|
||||
private int getFurnaceLevel(org.bukkit.block.Furnace furnace) { // Expliziter Typ
|
||||
return getFurnaceTrack().getOrDefault(furnace.getLocation(), 0);
|
||||
}
|
||||
|
||||
private boolean hasPermission(Player p, Integer level) {
|
||||
return p.hasPermission("furnacelevels.upgrade." + level);
|
||||
}
|
||||
|
||||
private List<String> getLangList(String path, Integer lvl) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String s : this.plugin.configs.getLang().getStringList(path)) {
|
||||
if (lvl != null) {
|
||||
int tpt = this.plugin.configs.getConfig().getInt("upgrades.level-" + lvl + ".ticks-per-tick");
|
||||
if (tpt == 0)
|
||||
tpt++;
|
||||
s = format(s, lvl, tpt);
|
||||
}
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||
}
|
||||
return lore;
|
||||
}
|
||||
|
||||
public String getLangMsg(String path, Integer lvl) {
|
||||
if (!this.plugin.configs.getLang().isSet(path))
|
||||
return ChatColor.DARK_RED + "" + ChatColor.BOLD + "Die Nachricht " + path + " fehlt in der lang.yml!";
|
||||
String s = this.plugin.configs.getLang().getString(path);
|
||||
if (lvl != null) {
|
||||
int tpt = this.plugin.configs.getConfig().getInt("upgrades.level-" + lvl + ".ticks-per-tick");
|
||||
if (tpt == 0)
|
||||
tpt++;
|
||||
s = format(s, lvl, tpt);
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
|
||||
ItemStack createItem(Material material, String name, List<String> lore) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
private String format(String s, int lvl, int tpt) {
|
||||
s = s.replace("{NEXT-TPT}", Integer.toString(this.plugin.configs.getConfig().getInt("upgrades.level-" + (lvl + 1) + ".ticks-per-tick")));
|
||||
s = s.replace("{TICKS-PER-TICK}", Integer.toString(tpt));
|
||||
s = s.replace("{NEXT-LEVEL}", Integer.toString(lvl + 1));
|
||||
s = s.replace("{LEVEL}", Integer.toString(lvl));
|
||||
s = s.replace("{NEXT-COST}", Double.toString(getCost(lvl + 1)));
|
||||
s = s.replace("{COST}", Double.toString(getCost(lvl)));
|
||||
return s;
|
||||
}
|
||||
|
||||
private ItemStack getItemInHand(Player p) {
|
||||
return p.getInventory().getItemInMainHand();
|
||||
}
|
||||
|
||||
private void burn(Player p, Block b) {
|
||||
p.sendMessage(getLangMsg("burn-msg", null));
|
||||
if (p.getGameMode() != GameMode.CREATIVE)
|
||||
p.damage(0.1D);
|
||||
Location fLoc = b.getLocation();
|
||||
double xDist = (p.getLocation().getX() - fLoc.getX()) * 0.5D;
|
||||
double zDist = (p.getLocation().getZ() - fLoc.getZ()) * 0.5D;
|
||||
Vector direction = new Vector(xDist, 1.0D, zDist).multiply(0.2D);
|
||||
p.setVelocity(direction);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user