fix databázedev
parent
62e4c3a0be
commit
e17244deed
11 changed files with 214 additions and 19 deletions
@ -0,0 +1,44 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore; |
||||||
|
|
||||||
|
import org.bukkit.NamespacedKey; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.inventory.meta.ItemMeta; |
||||||
|
import org.bukkit.persistence.PersistentDataContainer; |
||||||
|
import org.bukkit.persistence.PersistentDataType; |
||||||
|
|
||||||
|
public class PDC { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void WritePlayerPDC(Player player, String key, PersistentDataType type, Object value){ |
||||||
|
NamespacedKey nKey = new NamespacedKey(MineconomiaCore.getPlugin(MineconomiaCore.class), key); |
||||||
|
PersistentDataContainer pdc = player.getPersistentDataContainer(); |
||||||
|
pdc.set(nKey, type, value); |
||||||
|
|
||||||
|
} |
||||||
|
public static Object GetPlayerPDC(Player player, String key, PersistentDataType type){ |
||||||
|
NamespacedKey nKey = new NamespacedKey(MineconomiaCore.getPlugin(MineconomiaCore.class), key); |
||||||
|
PersistentDataContainer pdc = player.getPersistentDataContainer(); |
||||||
|
return pdc.get(nKey, type); |
||||||
|
} |
||||||
|
public static void DeletePlayerPDC(Player player, String key){ |
||||||
|
NamespacedKey nKey = new NamespacedKey(MineconomiaCore.getPlugin(MineconomiaCore.class), key); |
||||||
|
PersistentDataContainer pdc = player.getPersistentDataContainer(); |
||||||
|
pdc.remove(nKey); |
||||||
|
|
||||||
|
} |
||||||
|
public static ItemMeta WriteItemMetaPDC(ItemMeta itemMeta, String key, PersistentDataType type, Object value){ |
||||||
|
NamespacedKey nKey = new NamespacedKey(MineconomiaCore.getPlugin(MineconomiaCore.class), key); |
||||||
|
PersistentDataContainer pdc = itemMeta.getPersistentDataContainer(); |
||||||
|
pdc.set(nKey, type, value); |
||||||
|
return itemMeta; |
||||||
|
|
||||||
|
} |
||||||
|
public static Object GetItemMetaPDC(ItemMeta itemMeta, String key, PersistentDataType type){ |
||||||
|
NamespacedKey nKey = new NamespacedKey(MineconomiaCore.getPlugin(MineconomiaCore.class), key); |
||||||
|
PersistentDataContainer pdc = itemMeta.getPersistentDataContainer(); |
||||||
|
return pdc.get(nKey, type); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -1,5 +0,0 @@ |
|||||||
package xyz.mineconomia.mineconomiacore.completers; |
|
||||||
//Zde nic zatím
|
|
||||||
public class mcore_completer { |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,8 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore; |
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration; |
||||||
|
|
||||||
|
public interface config { |
||||||
|
FileConfiguration config = MineconomiaCore.getPlugin(MineconomiaCore.class).getConfig(); |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,120 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore.events; |
||||||
|
|
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.ChatColor; |
||||||
|
import org.bukkit.Location; |
||||||
|
import org.bukkit.boss.BarColor; |
||||||
|
import org.bukkit.boss.BarStyle; |
||||||
|
import org.bukkit.boss.BossBar; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.event.EventHandler; |
||||||
|
import org.bukkit.event.Listener; |
||||||
|
import org.bukkit.event.player.PlayerInteractEvent; |
||||||
|
import org.bukkit.event.player.PlayerItemHeldEvent; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import org.bukkit.persistence.PersistentDataType; |
||||||
|
import xyz.mineconomia.mineconomiacore.PDC; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
|
||||||
|
//These events are handling every logic of the "special item"
|
||||||
|
//Special item = item that is essential to marking blocks for interaction with plugin creation and edit functions
|
||||||
|
public class specialEvents implements Listener { |
||||||
|
//Stores informative boss bars
|
||||||
|
public static HashMap<Player, BossBar> specialBossBars = new HashMap<>(); |
||||||
|
|
||||||
|
//Stores locations marked by player using special item
|
||||||
|
public static HashMap<Player, HashMap<String, Location>> specialPreLocations = new HashMap<>(); |
||||||
|
|
||||||
|
//Checks if player is holding special item in hand and if so deploys boss bar
|
||||||
|
@EventHandler |
||||||
|
public static void specialInHand(PlayerItemHeldEvent event){ |
||||||
|
Player player = event.getPlayer(); |
||||||
|
displayBossBar(player, player.getInventory().getItem(event.getNewSlot())); |
||||||
|
} |
||||||
|
@EventHandler |
||||||
|
public static void savePosition(PlayerInteractEvent event){ |
||||||
|
Player player = event.getPlayer(); |
||||||
|
if (event.getItem() != null){ |
||||||
|
if (isSpecial(event.getItem())){ |
||||||
|
event.setCancelled(true); |
||||||
|
switch (event.getAction()){ |
||||||
|
case LEFT_CLICK_BLOCK: |
||||||
|
specialPreLocations.get(player).put("loc1", Objects.requireNonNull(event.getClickedBlock()).getLocation()); |
||||||
|
break; |
||||||
|
case RIGHT_CLICK_BLOCK: |
||||||
|
specialPreLocations.get(player).put("loc2", Objects.requireNonNull(event.getClickedBlock()).getLocation()); |
||||||
|
} |
||||||
|
displayBossBar(player, event.getItem()); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void displayBossBar(Player player, ItemStack item){ |
||||||
|
if (!specialPreLocations.containsKey(player)){ |
||||||
|
specialPreLocations.put(player, new HashMap<>()); |
||||||
|
} |
||||||
|
if (specialBossBars.get(player) == null){ |
||||||
|
BossBar bossBar = Bukkit.createBossBar( "", BarColor.YELLOW , BarStyle.SOLID); |
||||||
|
|
||||||
|
specialBossBars.put(player, bossBar); |
||||||
|
} |
||||||
|
BossBar bossBar = specialBossBars.get(player); |
||||||
|
if (item != null){ |
||||||
|
if (isSpecial(item)){ |
||||||
|
String loc1String = "&6&lL &e(-,-,-,-)"; |
||||||
|
String loc2String = "&e(-,-,-,-) &6&lP"; |
||||||
|
|
||||||
|
HashMap<String, Location> playerLocations = specialPreLocations.get(player); |
||||||
|
bossBar.setProgress(0); |
||||||
|
|
||||||
|
if (playerLocations.containsKey("loc1")){ |
||||||
|
Location loc1 = playerLocations.get("loc1"); |
||||||
|
loc1String = "&6&lL &e(" |
||||||
|
+ loc1.getBlockX() |
||||||
|
+ "," |
||||||
|
+ loc1.getBlockY() |
||||||
|
+ "," |
||||||
|
+ loc1.getBlockZ() |
||||||
|
+ "," |
||||||
|
+ Objects.requireNonNull(loc1.getWorld()).getName() |
||||||
|
+ ")"; |
||||||
|
} |
||||||
|
if (playerLocations.containsKey("loc2")){ |
||||||
|
Location loc2 = playerLocations.get("loc2"); |
||||||
|
loc2String = "&e(" |
||||||
|
+ loc2.getBlockX() |
||||||
|
+ "," |
||||||
|
+ loc2.getBlockY() |
||||||
|
+ "," |
||||||
|
+ loc2.getBlockZ() |
||||||
|
+ "," |
||||||
|
+ Objects.requireNonNull(loc2.getWorld()).getName() |
||||||
|
+ ") &6&lP"; |
||||||
|
} |
||||||
|
|
||||||
|
String bossBarTitle = loc1String + " " + loc2String; |
||||||
|
switch (playerLocations.size()){ |
||||||
|
case 1: |
||||||
|
bossBar.setProgress(0.5); |
||||||
|
break; |
||||||
|
case 2: |
||||||
|
bossBarTitle = bossBarTitle.replace("&6","&2").replace("&e", "&a"); |
||||||
|
bossBar.setColor(BarColor.GREEN); |
||||||
|
bossBar.setProgress(1); |
||||||
|
} |
||||||
|
bossBar.setTitle(ChatColor.translateAlternateColorCodes('&', bossBarTitle)); |
||||||
|
bossBar.addPlayer(player); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
bossBar.removePlayer(player); |
||||||
|
} |
||||||
|
private static boolean isSpecial(ItemStack itemStack){ |
||||||
|
return PDC.GetItemMetaPDC(Objects.requireNonNull(itemStack.getItemMeta()), "special", PersistentDataType.BOOLEAN) != null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue