organisation and hologram interaction
This commit is contained in:
parent
f8d85374c9
commit
8441c06a17
19 changed files with 495 additions and 454 deletions
|
@ -2,12 +2,14 @@ package me.night.nullvalkyrie;
|
||||||
|
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
import io.github.cdimascio.dotenv.Dotenv;
|
import io.github.cdimascio.dotenv.Dotenv;
|
||||||
|
import me.night.nullvalkyrie.events.listeners.CustomItemEvents;
|
||||||
|
import me.night.nullvalkyrie.events.listeners.DamageEffectEvents;
|
||||||
|
import me.night.nullvalkyrie.events.listeners.NPCEvents;
|
||||||
|
import me.night.nullvalkyrie.events.listeners.ServerEvents;
|
||||||
import me.night.nullvalkyrie.ui.inventory.InventoryListener;
|
import me.night.nullvalkyrie.ui.inventory.InventoryListener;
|
||||||
import me.night.nullvalkyrie.database.NPCDataManager;
|
import me.night.nullvalkyrie.database.NPCDataManager;
|
||||||
import me.night.nullvalkyrie.discord.DiscordClientManager;
|
import me.night.nullvalkyrie.discord.DiscordClientManager;
|
||||||
import me.night.nullvalkyrie.enchantments.EnchantmentManager;
|
import me.night.nullvalkyrie.enchantments.EnchantmentManager;
|
||||||
import me.night.nullvalkyrie.events.*;
|
|
||||||
import me.night.nullvalkyrie.npc.*;
|
|
||||||
import me.night.nullvalkyrie.ui.ScoreboardListener;
|
import me.night.nullvalkyrie.ui.ScoreboardListener;
|
||||||
import me.night.nullvalkyrie.util.*;
|
import me.night.nullvalkyrie.util.*;
|
||||||
import me.night.nullvalkyrie.commands.*;
|
import me.night.nullvalkyrie.commands.*;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package me.night.nullvalkyrie.commands;
|
package me.night.nullvalkyrie.commands;
|
||||||
|
|
||||||
import me.night.nullvalkyrie.database.RankDataManager;
|
import me.night.nullvalkyrie.database.RankDataManager;
|
||||||
import me.night.nullvalkyrie.ui.Rank;
|
import me.night.nullvalkyrie.enums.Rank;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
|
@ -15,7 +15,7 @@ import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static me.night.nullvalkyrie.npc.NPCManager.*;
|
import static me.night.nullvalkyrie.entities.npcs.NPCManager.*;
|
||||||
|
|
||||||
|
|
||||||
public class NPCDataManager {
|
public class NPCDataManager {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package me.night.nullvalkyrie.database;
|
||||||
|
|
||||||
import com.mongodb.client.MongoCursor;
|
import com.mongodb.client.MongoCursor;
|
||||||
import com.mongodb.client.model.Filters;
|
import com.mongodb.client.model.Filters;
|
||||||
import me.night.nullvalkyrie.ui.Rank;
|
import me.night.nullvalkyrie.enums.Rank;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.conversions.Bson;
|
import org.bson.conversions.Bson;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package me.night.nullvalkyrie.npc;
|
package me.night.nullvalkyrie.entities.npcs;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
|
@ -1,4 +1,4 @@
|
||||||
package me.night.nullvalkyrie.npc;
|
package me.night.nullvalkyrie.entities.npcs;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
@ -11,8 +11,8 @@ import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public class Skin {
|
public class Skin {
|
||||||
private String texture;
|
private final String texture;
|
||||||
private String signature;
|
private final String signature;
|
||||||
public Skin(String texture, String signature) {
|
public Skin(String texture, String signature) {
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
this.signature = signature;
|
this.signature = signature;
|
|
@ -1,4 +1,4 @@
|
||||||
package me.night.nullvalkyrie.ui;
|
package me.night.nullvalkyrie.enums;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
|
@ -1,47 +1,38 @@
|
||||||
package me.night.nullvalkyrie.items;
|
package me.night.nullvalkyrie.enums;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
public enum Rarity {
|
public enum Rarity {
|
||||||
COMMON(ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON", ChatColor.WHITE.toString()),
|
COMMON(ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON", ChatColor.WHITE.toString()),
|
||||||
UNCOMMON(net.md_5.bungee.api.ChatColor.of("#31ff09").toString() + ChatColor.BOLD + "UNCOMMON", net.md_5.bungee.api.ChatColor.of("#31ff09").toString()),
|
UNCOMMON(net.md_5.bungee.api.ChatColor.of("#31ff09").toString() + ChatColor.BOLD + "UNCOMMON", net.md_5.bungee.api.ChatColor.of("#31ff09").toString()),
|
||||||
RARE(net.md_5.bungee.api.ChatColor.of("#2f57ae").toString() + ChatColor.BOLD + "RARE", net.md_5.bungee.api.ChatColor.of("#2f57ae").toString()),
|
RARE(net.md_5.bungee.api.ChatColor.of("#2f57ae").toString() + ChatColor.BOLD + "RARE", net.md_5.bungee.api.ChatColor.of("#2f57ae").toString()),
|
||||||
EPIC(net.md_5.bungee.api.ChatColor.of("#b201b2").toString() + ChatColor.BOLD + "EPIC", net.md_5.bungee.api.ChatColor.of("#b201b2").toString()),
|
EPIC(net.md_5.bungee.api.ChatColor.of("#b201b2").toString() + ChatColor.BOLD + "EPIC", net.md_5.bungee.api.ChatColor.of("#b201b2").toString()),
|
||||||
LEGENDARY(net.md_5.bungee.api.ChatColor.of("#ffa21b").toString() + ChatColor.BOLD + "LEGENDARY", net.md_5.bungee.api.ChatColor.of("#ffa21b").toString()),
|
LEGENDARY(net.md_5.bungee.api.ChatColor.of("#ffa21b").toString() + ChatColor.BOLD + "LEGENDARY", net.md_5.bungee.api.ChatColor.of("#ffa21b").toString()),
|
||||||
MYTHIC(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC", net.md_5.bungee.api.ChatColor.of("#ff23ff").toString()),
|
MYTHIC(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC", net.md_5.bungee.api.ChatColor.of("#ff23ff").toString()),
|
||||||
ULTRA(ChatColor.RED.toString() + ChatColor.BOLD + "ULTRA", ChatColor.RED.toString()),
|
ULTRA(ChatColor.RED.toString() + ChatColor.BOLD + "ULTRA", ChatColor.RED.toString()),
|
||||||
GRAND(net.md_5.bungee.api.ChatColor.of("#00fdff").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#00fdff").toString());
|
GRAND(net.md_5.bungee.api.ChatColor.of("#00fdff").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#00fdff").toString());
|
||||||
private String display;
|
private String display;
|
||||||
private String color;
|
private String color;
|
||||||
Rarity(String display, String color) {
|
Rarity(String display, String color) {
|
||||||
this.display = display;
|
this.display = display;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
public String getDisplay() {
|
public String getDisplay() {
|
||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
public static Rarity getRarity(String str) {
|
public static Rarity getRarity(String str) {
|
||||||
switch(str) {
|
return switch (str) {
|
||||||
case "COMMON":
|
case "COMMON" -> COMMON;
|
||||||
return COMMON;
|
case "UNCOMMON" -> UNCOMMON;
|
||||||
case "UNCOMMON":
|
case "RARE" -> RARE;
|
||||||
return UNCOMMON;
|
case "EPIC" -> EPIC;
|
||||||
case "RARE":
|
case "LEGENDARY" -> LEGENDARY;
|
||||||
return RARE;
|
case "MYTHIC" -> MYTHIC;
|
||||||
case "EPIC":
|
case "ULTRA" -> ULTRA;
|
||||||
return EPIC;
|
case "GRAND" -> GRAND;
|
||||||
case "LEGENDARY":
|
default -> COMMON;
|
||||||
return LEGENDARY;
|
};
|
||||||
case "MYTHIC":
|
}
|
||||||
return MYTHIC;
|
}
|
||||||
case "ULTRA":
|
|
||||||
return ULTRA;
|
|
||||||
case "GRAND":
|
|
||||||
return GRAND;
|
|
||||||
default:
|
|
||||||
return COMMON;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package me.night.nullvalkyrie.events.custom;
|
||||||
|
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
public class InteractHologramEvent extends Event implements Cancellable {
|
||||||
|
private boolean isCancelled;
|
||||||
|
public Player player;
|
||||||
|
public ArmorStand hologram;
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
public InteractHologramEvent(Player player, ArmorStand hologram) {
|
||||||
|
this.player = player;
|
||||||
|
this.hologram = hologram;
|
||||||
|
}
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
public ArmorStand getHologram() {
|
||||||
|
return hologram;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return isCancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
isCancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() { return HANDLERS; }
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package me.night.nullvalkyrie.npc;
|
package me.night.nullvalkyrie.events.custom;
|
||||||
|
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
import net.minecraft.server.level.EntityPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -7,12 +7,12 @@ import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class RightClickNPC extends Event implements Cancellable {
|
public class RightClickNPCEvent extends Event implements Cancellable {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final EntityPlayer npc;
|
private final EntityPlayer npc;
|
||||||
private boolean isCancelled;
|
private boolean isCancelled;
|
||||||
private static final HandlerList HANDLERS = new HandlerList();
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
public RightClickNPC(Player player, EntityPlayer npc) {
|
public RightClickNPCEvent(Player player, EntityPlayer npc) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
}
|
}
|
|
@ -1,366 +1,356 @@
|
||||||
package me.night.nullvalkyrie.events;
|
package me.night.nullvalkyrie.events.listeners;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||||
import me.night.nullvalkyrie.items.CustomItemManager;
|
import me.night.nullvalkyrie.items.CustomItemManager;
|
||||||
import me.night.nullvalkyrie.items.Pickaxe;
|
import me.night.nullvalkyrie.items.Pickaxe;
|
||||||
import me.night.nullvalkyrie.items.Rarity;
|
import me.night.nullvalkyrie.enums.Rarity;
|
||||||
import me.night.nullvalkyrie.Main;
|
import me.night.nullvalkyrie.Main;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.entity.*;
|
import org.bukkit.event.entity.*;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.Merchant;
|
import org.bukkit.inventory.Merchant;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CustomItemEvents implements Listener {
|
public class CustomItemEvents implements Listener {
|
||||||
private final Main main;
|
private final Main main;
|
||||||
|
|
||||||
public CustomItemEvents(Main main) {
|
public CustomItemEvents(Main main) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
|
||||||
if (e.getDamager().getType().equals(EntityType.SNOWBALL)) {
|
if (e.getDamager().getType().equals(EntityType.SNOWBALL)) {
|
||||||
Snowball sb = (Snowball) e.getDamager();
|
Snowball sb = (Snowball) e.getDamager();
|
||||||
Player pl = (Player) sb.getShooter();
|
Player pl = (Player) sb.getShooter();
|
||||||
if (pl.getInventory().getItemInMainHand().getItemMeta() != null) {
|
if (pl.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||||
String name = pl.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
String name = pl.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||||
if (name.equalsIgnoreCase(Rarity.ULTRA.getColor() + "Snow Gun")) {
|
if (name.equalsIgnoreCase(Rarity.ULTRA.getColor() + "Snow Gun")) {
|
||||||
((Snowball) e.getDamager()).setShooter(pl.getPlayer());
|
((Snowball) e.getDamager()).setShooter(pl.getPlayer());
|
||||||
e.setDamage(2000);
|
e.setDamage(2000);
|
||||||
} else if (name.equalsIgnoreCase("AA-12")) {
|
} else if (name.equalsIgnoreCase("AA-12")) {
|
||||||
e.setDamage(7);
|
e.setDamage(7);
|
||||||
} else {
|
} else {
|
||||||
e.setDamage(0);
|
e.setDamage(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerFish(PlayerFishEvent e) {
|
public void onPlayerFish(PlayerFishEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||||
if (name.equalsIgnoreCase(Rarity.RARE.getColor() + "Grappling Hook")) {
|
if (name.equalsIgnoreCase(Rarity.RARE.getColor() + "Grappling Hook")) {
|
||||||
if (e.getState().equals(PlayerFishEvent.State.REEL_IN)) {
|
if (e.getState().equals(PlayerFishEvent.State.REEL_IN)) {
|
||||||
Location change = e.getHook().getLocation().subtract(player.getLocation());
|
Location change = e.getHook().getLocation().subtract(player.getLocation());
|
||||||
player.setVelocity(change.toVector().multiply(0.4));
|
player.setVelocity(change.toVector().multiply(0.4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||||
if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||||
if (name.equalsIgnoreCase(Rarity.GRAND.getColor() + "Teleport Door")) {
|
if (name.equalsIgnoreCase(Rarity.GRAND.getColor() + "Teleport Door")) {
|
||||||
Block block = player.getTargetBlock(null, 12);
|
Block block = player.getTargetBlock(null, 12);
|
||||||
Location l = block.getLocation();
|
Location l = block.getLocation();
|
||||||
l.add(0, 1, 0);
|
l.add(0, 1, 0);
|
||||||
float yaw = player.getEyeLocation().getYaw();
|
float yaw = player.getEyeLocation().getYaw();
|
||||||
float pitch = player.getEyeLocation().getPitch();
|
float pitch = player.getEyeLocation().getPitch();
|
||||||
l.setYaw(yaw);
|
l.setYaw(yaw);
|
||||||
l.setPitch(pitch);
|
l.setPitch(pitch);
|
||||||
player.teleport(l);
|
player.teleport(l);
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 10, 10);
|
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 10, 10);
|
||||||
} else if (name.equalsIgnoreCase(Rarity.ULTRA.getColor() + "Snow Gun")) {
|
} else if (name.equalsIgnoreCase(Rarity.ULTRA.getColor() + "Snow Gun")) {
|
||||||
Snowball s = player.launchProjectile(Snowball.class, player.getLocation().getDirection());
|
Snowball s = player.launchProjectile(Snowball.class, player.getLocation().getDirection());
|
||||||
s.setVelocity(player.getLocation().getDirection().multiply(10));
|
s.setVelocity(player.getLocation().getDirection().multiply(10));
|
||||||
|
|
||||||
ItemStack weapon = player.getInventory().getItemInMainHand();
|
ItemStack weapon = player.getInventory().getItemInMainHand();
|
||||||
ItemMeta weaponMeta = weapon.getItemMeta();
|
ItemMeta weaponMeta = weapon.getItemMeta();
|
||||||
if (weaponMeta != null) {
|
if (weaponMeta != null) {
|
||||||
PersistentDataContainer container = weaponMeta.getPersistentDataContainer();
|
PersistentDataContainer container = weaponMeta.getPersistentDataContainer();
|
||||||
NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo");
|
NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo");
|
||||||
int ammo = container.get(ammoKey, PersistentDataType.INTEGER);
|
int ammo = container.get(ammoKey, PersistentDataType.INTEGER);
|
||||||
container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1);
|
container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1);
|
||||||
int max = container.get(CustomItemManager.keys.get(name + ".maxload"), PersistentDataType.INTEGER);
|
int max = container.get(CustomItemManager.keys.get(name + ".maxload"), PersistentDataType.INTEGER);
|
||||||
weapon.setItemMeta(weaponMeta);
|
weapon.setItemMeta(weaponMeta);
|
||||||
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + max + " )")));
|
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + max + " )")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
|
} else if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
|
||||||
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
||||||
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||||
arrow.setShooter(player);
|
arrow.setShooter(player);
|
||||||
arrow.setDamage(50);
|
arrow.setDamage(50);
|
||||||
Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5));
|
a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5));
|
||||||
a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||||
a1.setShooter(player);
|
a1.setShooter(player);
|
||||||
a1.setDamage(50);
|
a1.setDamage(50);
|
||||||
Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5));
|
a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5));
|
||||||
a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||||
a2.setShooter(player);
|
a2.setShooter(player);
|
||||||
a2.setDamage(50);
|
a2.setDamage(50);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
||||||
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
||||||
arrow.setShooter(player);
|
arrow.setShooter(player);
|
||||||
arrow.setDamage(50);
|
arrow.setDamage(50);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
} else if (e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||||
if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
|
if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
|
||||||
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
||||||
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||||
arrow.setShooter(player);
|
arrow.setShooter(player);
|
||||||
arrow.setDamage(50);
|
arrow.setDamage(50);
|
||||||
Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5));
|
a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5));
|
||||||
a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||||
a1.setShooter(player);
|
a1.setShooter(player);
|
||||||
a1.setDamage(50);
|
a1.setDamage(50);
|
||||||
Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5));
|
a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5));
|
||||||
a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||||
a2.setShooter(player);
|
a2.setShooter(player);
|
||||||
a2.setDamage(50);
|
a2.setDamage(50);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
||||||
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||||
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
||||||
arrow.setShooter(player);
|
arrow.setShooter(player);
|
||||||
arrow.setDamage(50);
|
arrow.setDamage(50);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityShoot(EntityShootBowEvent e) {
|
public void onEntityShoot(EntityShootBowEvent e) {
|
||||||
if (e.getProjectile() instanceof Arrow) {
|
if (e.getProjectile() instanceof Arrow) {
|
||||||
if (e.getEntity() instanceof Player) {
|
if (e.getEntity() instanceof Player player) {
|
||||||
Player player = (Player) e.getEntity();
|
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||||
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
|
||||||
if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
|
e.setCancelled(true);
|
||||||
e.setCancelled(true);
|
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
||||||
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
e.setCancelled(true);
|
||||||
e.setCancelled(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler
|
||||||
@EventHandler
|
public void onProjectileHit(ProjectileHitEvent e) {
|
||||||
public void onProjectileHit(ProjectileHitEvent e) {
|
if (e.getEntity().getShooter() instanceof Player shooter) {
|
||||||
if (e.getEntity().getShooter() instanceof Player) {
|
if (shooter.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||||
Player shooter = (Player) e.getEntity().getShooter();
|
String name = shooter.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||||
if (shooter.getInventory().getItemInMainHand().getItemMeta() != null) {
|
if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
|
||||||
String name = shooter.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
if (e.getHitBlock() == null) {
|
||||||
if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
|
Location l = e.getHitEntity().getLocation();
|
||||||
if (e.getHitBlock() == null) {
|
e.getEntity().setShooter(shooter);
|
||||||
Location l = e.getHitEntity().getLocation();
|
e.getHitEntity().getWorld().createExplosion(l.getX(), l.getY(), l.getZ(), 100, false, false);
|
||||||
e.getEntity().setShooter(shooter);
|
} else if (e.getHitEntity() == null) {
|
||||||
e.getHitEntity().getWorld().createExplosion(l.getX(), l.getY(), l.getZ(), 100, false, false);
|
Location l = e.getHitBlock().getLocation();
|
||||||
} else if (e.getHitEntity() == null) {
|
e.getHitBlock().getWorld().createExplosion(l.getX(), l.getY(), l.getZ(), 100, false, false);
|
||||||
Location l = e.getHitBlock().getLocation();
|
}
|
||||||
e.getHitBlock().getWorld().createExplosion(l.getX(), l.getY(), l.getZ(), 100, false, false);
|
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
||||||
}
|
Arrow arrow = (Arrow) e.getEntity();
|
||||||
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
|
Location al = arrow.getLocation();
|
||||||
Arrow arrow = (Arrow) e.getEntity();
|
arrow.setShooter(shooter);
|
||||||
Location al = arrow.getLocation();
|
shooter.getWorld().createExplosion(al, 100, false, false);
|
||||||
arrow.setShooter(shooter);
|
}
|
||||||
shooter.getWorld().createExplosion(al, 100, false, false);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler
|
||||||
|
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||||
@EventHandler
|
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG) {
|
||||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
event.setCancelled(true);
|
||||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG) {
|
}
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler
|
||||||
|
public void Projectile(ProjectileLaunchEvent e) {
|
||||||
@EventHandler
|
if (e.getEntity().getShooter() instanceof Player player) {
|
||||||
public void Projectile(ProjectileLaunchEvent e) {
|
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||||
if (e.getEntity().getShooter() instanceof Player) {
|
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||||
Player player = (Player) e.getEntity().getShooter();
|
if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
|
||||||
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
Egg s = (Egg) e.getEntity();
|
||||||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
s.setVelocity(player.getLocation().getDirection().multiply(10));
|
||||||
if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
|
}
|
||||||
Egg s = (Egg) e.getEntity();
|
}
|
||||||
s.setVelocity(player.getLocation().getDirection().multiply(10));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler
|
||||||
}
|
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent e) {
|
||||||
|
int x = e.getBlockClicked().getX() + e.getBlockFace().getModX();
|
||||||
@EventHandler
|
int y = e.getBlockClicked().getY() + e.getBlockFace().getModY();
|
||||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent e) {
|
int z = e.getBlockClicked().getZ() + e.getBlockFace().getModZ();
|
||||||
int x = e.getBlockClicked().getX() + e.getBlockFace().getModX();
|
Player player = e.getPlayer();
|
||||||
int y = e.getBlockClicked().getY() + e.getBlockFace().getModY();
|
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||||
int z = e.getBlockClicked().getZ() + e.getBlockFace().getModZ();
|
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||||
Player player = e.getPlayer();
|
if (name.equalsIgnoreCase(Rarity.EPIC.getColor() + "Infinite Water Bucket")) {
|
||||||
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
e.getPlayer().getWorld().getBlockAt(x, y, z).setType(Material.WATER);
|
||||||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
e.setCancelled(true);
|
||||||
if (name.equalsIgnoreCase(Rarity.EPIC.getColor() + "Infinite Water Bucket")) {
|
} else if (name.equalsIgnoreCase(Rarity.EPIC.getColor() + "Infinite Lava Bucket")) {
|
||||||
e.getPlayer().getWorld().getBlockAt(x, y, z).setType(Material.WATER);
|
e.getPlayer().getWorld().getBlockAt(x, y, z).setType(Material.LAVA);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else if (name.equalsIgnoreCase(Rarity.EPIC.getColor() + "Infinite Lava Bucket")) {
|
}
|
||||||
e.getPlayer().getWorld().getBlockAt(x, y, z).setType(Material.LAVA);
|
}
|
||||||
e.setCancelled(true);
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler
|
||||||
}
|
public void onDamage(EntityDamageByEntityEvent e) {
|
||||||
|
if (e.getEntity() instanceof Player) {
|
||||||
@EventHandler
|
Player player = (Player) e.getEntity();
|
||||||
public void onDamage(EntityDamageByEntityEvent e) {
|
// if ((player.getHealth() - e.getDamage()) <= 0) {
|
||||||
if (e.getEntity() instanceof Player) {
|
// e.setCancelled(true);
|
||||||
Player player = (Player) e.getEntity();
|
// Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation();
|
||||||
// if ((player.getHealth() - e.getDamage()) <= 0) {
|
// player.teleport(loc);
|
||||||
// e.setCancelled(true);
|
// for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
// Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation();
|
// p.sendMessage(e.getDamager() instanceof Player
|
||||||
// player.teleport(loc);
|
// ? ChatColor.RED + player.getName() + " has been killed by " + e.getDamager().getName()
|
||||||
// for (Player p : Bukkit.getOnlinePlayers()) {
|
// : ChatColor.RED + player.getName() + " died");
|
||||||
// p.sendMessage(e.getDamager() instanceof Player
|
// p.hidePlayer(player);
|
||||||
// ? ChatColor.RED + player.getName() + " has been killed by " + e.getDamager().getName()
|
// }
|
||||||
// : ChatColor.RED + player.getName() + " died");
|
// new BukkitRunnable() {
|
||||||
// p.hidePlayer(player);
|
// @Override
|
||||||
// }
|
// public void run() {
|
||||||
// new BukkitRunnable() {
|
// for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
// @Override
|
// p.showPlayer(player);
|
||||||
// public void run() {
|
// }
|
||||||
// for (Player p : Bukkit.getOnlinePlayers()) {
|
// player.setHealth(20);
|
||||||
// p.showPlayer(player);
|
// player.teleport(generateRandomCoord(9, Bukkit.getWorld("world")));
|
||||||
// }
|
// }
|
||||||
// player.setHealth(20);
|
// }.runTaskLater(main, 100L);
|
||||||
// player.teleport(generateRandomCoord(9, Bukkit.getWorld("world")));
|
// countDown(player, new int[]{5});
|
||||||
// }
|
// }
|
||||||
// }.runTaskLater(main, 100L);
|
}
|
||||||
// countDown(player, new int[]{5});
|
|
||||||
// }
|
}
|
||||||
}
|
|
||||||
|
private int taskID;
|
||||||
}
|
|
||||||
|
public void countDown(Player player, int[] a) {
|
||||||
private int taskID;
|
taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, () -> {
|
||||||
|
player.sendTitle(ChatColor.RED + "YOU DIED!", ChatColor.GREEN + "You will revive in " + a[0] + " seconds", 0, 20, 0);
|
||||||
public void countDown(Player player, int[] a) {
|
a[0]--;
|
||||||
taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, () -> {
|
if (a[0] == 0) {
|
||||||
player.sendTitle(ChatColor.RED + "YOU DIED!", ChatColor.GREEN + "You will revive in " + a[0] + " seconds", 0, 20, 0);
|
Bukkit.getScheduler().cancelTask(taskID);
|
||||||
a[0]--;
|
}
|
||||||
if (a[0] == 0) {
|
}, 0L, 20L);
|
||||||
Bukkit.getScheduler().cancelTask(taskID);
|
}
|
||||||
}
|
|
||||||
}, 0L, 20L);
|
private final Map<UUID, Merchant> villagerlist = new HashMap<>();
|
||||||
}
|
|
||||||
|
@EventHandler
|
||||||
private final Map<UUID, Merchant> villagerlist = new HashMap<>();
|
public void onClick(PlayerInteractEntityEvent e) {
|
||||||
|
Player p = e.getPlayer();
|
||||||
@EventHandler
|
Entity clickedEntity = e.getRightClicked();
|
||||||
public void onClick(PlayerInteractEntityEvent e) {
|
if (clickedEntity instanceof Creeper) {
|
||||||
Player p = e.getPlayer();
|
if (p.getInventory().getItemInMainHand().getType() != Material.STICK) return;
|
||||||
Entity clickedEntity = e.getRightClicked();
|
clickedEntity.remove();
|
||||||
if (clickedEntity instanceof Creeper) {
|
Location loc = clickedEntity.getLocation();
|
||||||
if (p.getInventory().getItemInMainHand().getType() != Material.STICK) return;
|
Villager villager = (Villager) p.getWorld().spawnEntity(loc, EntityType.VILLAGER);
|
||||||
clickedEntity.remove();
|
villager.setProfession(Villager.Profession.TOOLSMITH);
|
||||||
Location loc = clickedEntity.getLocation();
|
List<MerchantRecipe> recipes = new ArrayList<>();
|
||||||
Villager villager = (Villager) p.getWorld().spawnEntity(loc, EntityType.VILLAGER);
|
MerchantRecipe bread = new MerchantRecipe(new ItemStack(Material.BREAD, 3), 10);
|
||||||
villager.setProfession(Villager.Profession.TOOLSMITH);
|
bread.addIngredient(new ItemStack(Material.EMERALD, 10));
|
||||||
List<MerchantRecipe> recipes = new ArrayList<>();
|
recipes.add(bread);
|
||||||
MerchantRecipe bread = new MerchantRecipe(new ItemStack(Material.BREAD, 3), 10);
|
|
||||||
bread.addIngredient(new ItemStack(Material.EMERALD, 10));
|
MerchantRecipe tntStick = new MerchantRecipe(CustomItemManager.produceItem("Terminator"), 10);
|
||||||
recipes.add(bread);
|
tntStick.addIngredient(CustomItemManager.produceItem("Widow Sword"));
|
||||||
|
recipes.add(tntStick);
|
||||||
MerchantRecipe tntStick = new MerchantRecipe(CustomItemManager.produceItem("Terminator"), 10);
|
Merchant merchant = Bukkit.createMerchant("Exchange here");
|
||||||
tntStick.addIngredient(CustomItemManager.produceItem("Widow Sword"));
|
merchant.setRecipes(recipes);
|
||||||
recipes.add(tntStick);
|
villagerlist.put(villager.getUniqueId(), merchant);
|
||||||
Merchant merchant = Bukkit.createMerchant("Exchange here");
|
p.spawnParticle(Particle.END_ROD, loc, 30, 0, 1, 0, 0.2);
|
||||||
merchant.setRecipes(recipes);
|
p.openMerchant(merchant, true);
|
||||||
villagerlist.put(villager.getUniqueId(), merchant);
|
}
|
||||||
p.spawnParticle(Particle.END_ROD, loc, 30, 0, 1, 0, 0.2);
|
if (e.getRightClicked() instanceof Villager) {
|
||||||
p.openMerchant(merchant, true);
|
Merchant merchant = villagerlist.get(clickedEntity.getUniqueId());
|
||||||
}
|
if (merchant == null) return;
|
||||||
if (e.getRightClicked() instanceof Villager) {
|
e.setCancelled(true);
|
||||||
Merchant merchant = villagerlist.get(clickedEntity.getUniqueId());
|
p.openMerchant(merchant, true);
|
||||||
if (merchant == null) return;
|
}
|
||||||
e.setCancelled(true);
|
}
|
||||||
p.openMerchant(merchant, true);
|
private final HashMap<Location, Integer> blockStages = new HashMap<>();
|
||||||
}
|
private final HashMap<UUID, Long> miningCooldown = new HashMap<>();
|
||||||
}
|
@EventHandler
|
||||||
|
public void onAnimationEvent(PlayerAnimationEvent e) { //Material blockType, int mineInterval, Pickaxe x
|
||||||
// For hologram clicks to change page
|
Player player = e.getPlayer();
|
||||||
// @EventHandler
|
UUID uuid = player.getUniqueId();
|
||||||
// public void onEntityInteract(EntityInteractEvent e) {
|
if (!player.getGameMode().equals(GameMode.SURVIVAL)) return;
|
||||||
// System.out.println(e.getEntity().getLocation());
|
if (miningCooldown.containsKey(uuid) && (miningCooldown.get(uuid) > System.currentTimeMillis())) return;
|
||||||
// e.getEntity().setCustomName(ChatColor.RED + "Changed name since you ust clicked lol");
|
else miningCooldown.remove(uuid);
|
||||||
// }
|
|
||||||
private final HashMap<Location, Integer> blockStages = new HashMap<>();
|
if (!e.getAnimationType().equals(PlayerAnimationType.ARM_SWING)) return;
|
||||||
private final HashMap<UUID, Long> miningCooldown = new HashMap<>();
|
Block block = player.getTargetBlockExact(4);
|
||||||
@EventHandler
|
if (block == null) return;
|
||||||
public void onAnimationEvent(PlayerAnimationEvent e) { //Material blockType, int mineInterval, Pickaxe x
|
|
||||||
Player player = e.getPlayer();
|
Pickaxe pickaxe = new Pickaxe(player.getInventory().getItemInMainHand());
|
||||||
UUID uuid = player.getUniqueId();
|
List<Material> materialsThatCanBeMinedFast = pickaxe.multimap.get(pickaxe.getMaterial()); // to get all materials that the pickaxe can mine
|
||||||
if (!player.getGameMode().equals(GameMode.SURVIVAL)) return;
|
if (!materialsThatCanBeMinedFast.contains(block.getType())) return;
|
||||||
if (miningCooldown.containsKey(uuid) && (miningCooldown.get(uuid) > System.currentTimeMillis())) return;
|
|
||||||
else miningCooldown.remove(uuid);
|
long miningPerPhase = pickaxe.getMiningPerPhase(block.getType());
|
||||||
|
miningCooldown.put(uuid, System.currentTimeMillis() + miningPerPhase);
|
||||||
if (!e.getAnimationType().equals(PlayerAnimationType.ARM_SWING)) return;
|
int blockStage = blockStages.getOrDefault(block.getLocation(), 0);
|
||||||
Block block = player.getTargetBlockExact(4);
|
blockStage = blockStage == 10 ? 0 : blockStage + 1;
|
||||||
if (block == null) return;
|
blockStages.put(block.getLocation(), blockStage);
|
||||||
|
sendBlockDamage(player, block);
|
||||||
Pickaxe pickaxe = new Pickaxe(player.getInventory().getItemInMainHand());
|
if (blockStage == 0) {
|
||||||
List<Material> materialsThatCanBeMinedFast = pickaxe.multimap.get(pickaxe.getMaterial()); // to get all materials that the pickaxe can mine
|
blockStages.remove(block.getLocation());
|
||||||
if (!materialsThatCanBeMinedFast.contains(block.getType())) return;
|
block.breakNaturally();
|
||||||
|
}
|
||||||
long miningPerPhase = pickaxe.getMiningPerPhase(block.getType());
|
}
|
||||||
miningCooldown.put(uuid, System.currentTimeMillis() + miningPerPhase);
|
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||||
int blockStage = blockStages.getOrDefault(block.getLocation(), 0);
|
|
||||||
blockStage = blockStage == 10 ? 0 : blockStage + 1;
|
public void sendBlockDamage(Player player, Block block) {
|
||||||
blockStages.put(block.getLocation(), blockStage);
|
Location location = block.getLocation();
|
||||||
sendBlockDamage(player, block);
|
int locationId = location.getBlockX() + location.getBlockY() + location.getBlockZ();
|
||||||
if (blockStage == 0) {
|
PacketContainer packet = manager.createPacket(PacketType.Play.Server.BLOCK_BREAK_ANIMATION);
|
||||||
blockStages.remove(block.getLocation());
|
packet.getIntegers().write(0, locationId); // set entity ID to the location
|
||||||
block.breakNaturally();
|
packet.getBlockPositionModifier().write(0, new BlockPosition(location.toVector())); // set the block location
|
||||||
}
|
packet.getIntegers().write(1, blockStages.get(location)); // set the damage to blockStage
|
||||||
}
|
try {
|
||||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
manager.sendServerPacket(player, packet);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
public void sendBlockDamage(Player player, Block block) {
|
e.printStackTrace();
|
||||||
Location location = block.getLocation();
|
}
|
||||||
int locationId = location.getBlockX() + location.getBlockY() + location.getBlockZ();
|
}
|
||||||
PacketContainer packet = manager.createPacket(PacketType.Play.Server.BLOCK_BREAK_ANIMATION);
|
|
||||||
packet.getIntegers().write(0, locationId); // set entity ID to the location
|
|
||||||
packet.getBlockPositionModifier().write(0, new BlockPosition(location.toVector())); // set the block location
|
|
||||||
packet.getIntegers().write(1, blockStages.get(location)); // set the damage to blockStage
|
|
||||||
try {
|
|
||||||
manager.sendServerPacket(player, packet);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package me.night.nullvalkyrie.events;
|
package me.night.nullvalkyrie.events.listeners;
|
||||||
|
|
||||||
import me.night.nullvalkyrie.Main;
|
import me.night.nullvalkyrie.Main;
|
||||||
import me.night.nullvalkyrie.util.Util;
|
import me.night.nullvalkyrie.util.Util;
|
|
@ -1,5 +1,7 @@
|
||||||
package me.night.nullvalkyrie.npc;
|
package me.night.nullvalkyrie.events.listeners;
|
||||||
|
|
||||||
|
import me.night.nullvalkyrie.events.custom.RightClickNPCEvent;
|
||||||
|
import me.night.nullvalkyrie.entities.npcs.NPCManager;
|
||||||
import me.night.nullvalkyrie.util.Util;
|
import me.night.nullvalkyrie.util.Util;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutEntity;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntity;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation;
|
import net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation;
|
||||||
|
@ -13,7 +15,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
public class NPCEvents implements Listener {
|
public class NPCEvents implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClick(RightClickNPC e) {
|
public void onClick(RightClickNPCEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
if (e.getNPC().getBukkitEntity().getName().equalsIgnoreCase(Util.color("&1&lRB18"))) {
|
if (e.getNPC().getBukkitEntity().getName().equalsIgnoreCase(Util.color("&1&lRB18"))) {
|
||||||
player.sendMessage(Util.color("Hi"));
|
player.sendMessage(Util.color("Hi"));
|
|
@ -1,6 +1,7 @@
|
||||||
package me.night.nullvalkyrie.events;
|
package me.night.nullvalkyrie.events.listeners;
|
||||||
|
|
||||||
import me.night.nullvalkyrie.npc.PacketInjector;
|
import me.night.nullvalkyrie.events.custom.InteractHologramEvent;
|
||||||
|
import me.night.nullvalkyrie.packets.PacketInjector;
|
||||||
import me.night.nullvalkyrie.util.Util;
|
import me.night.nullvalkyrie.util.Util;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -37,6 +38,11 @@ public class ServerEvents implements Listener {
|
||||||
} catch (Exception ee) {
|
} catch (Exception ee) {
|
||||||
ee.printStackTrace();
|
ee.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@EventHandler
|
||||||
|
public void onClickHologram(InteractHologramEvent e) {
|
||||||
|
if (e.getHologram().getCustomName().equals(ChatColor.GOLD + "Click me to change!!!")) {
|
||||||
|
System.out.println(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package me.night.nullvalkyrie.items;
|
package me.night.nullvalkyrie.items;
|
||||||
|
|
||||||
import me.night.nullvalkyrie.Main;
|
import me.night.nullvalkyrie.Main;
|
||||||
|
import me.night.nullvalkyrie.enums.Rarity;
|
||||||
import me.night.nullvalkyrie.util.Util;
|
import me.night.nullvalkyrie.util.Util;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -13,8 +14,6 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -102,7 +101,6 @@ public class CustomItemManager {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setItemRecipe(NamespacedKey key, ItemStack i, int ingredient, String shape1, String shape2, String shape3, List<Material> ingredients) {
|
public static void setItemRecipe(NamespacedKey key, ItemStack i, int ingredient, String shape1, String shape2, String shape3, List<Material> ingredients) {
|
||||||
// ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(main, "widow_sword"), widow_sword);
|
// ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(main, "widow_sword"), widow_sword);
|
||||||
// wither_sword_recipe.shape(" A ", " A "," B ");
|
// wither_sword_recipe.shape(" A ", " A "," B ");
|
||||||
|
@ -111,20 +109,6 @@ public class CustomItemManager {
|
||||||
// Bukkit.addRecipe(wither_sword_recipe);
|
// Bukkit.addRecipe(wither_sword_recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YamlConfiguration loadConfig(String path) {
|
|
||||||
File f = new File(Main.getPlugin(Main.class).getDataFolder(), path);
|
|
||||||
if (!f.exists()) {
|
|
||||||
try {
|
|
||||||
f.createNewFile();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return YamlConfiguration.loadConfiguration(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void updateYamlFilesToPlugin(String path) {
|
public static void updateYamlFilesToPlugin(String path) {
|
||||||
File file = new File(Main.getPlugin(Main.class).getDataFolder(), path);
|
File file = new File(Main.getPlugin(Main.class).getDataFolder(), path);
|
||||||
if (!file.exists()) Main.getPlugin(Main.class).saveResource(path, true);
|
if (!file.exists()) Main.getPlugin(Main.class).saveResource(path, true);
|
||||||
|
|
|
@ -1,47 +1,70 @@
|
||||||
package me.night.nullvalkyrie.npc;
|
package me.night.nullvalkyrie.packets;
|
||||||
|
|
||||||
import io.netty.channel.ChannelDuplexHandler;
|
import io.netty.channel.ChannelDuplexHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
import me.night.nullvalkyrie.Main;
|
import me.night.nullvalkyrie.Main;
|
||||||
|
import me.night.nullvalkyrie.entities.npcs.NPCManager;
|
||||||
|
import me.night.nullvalkyrie.events.custom.InteractHologramEvent;
|
||||||
|
import me.night.nullvalkyrie.events.custom.RightClickNPCEvent;
|
||||||
import net.minecraft.network.protocol.game.PacketPlayInUseEntity;
|
import net.minecraft.network.protocol.game.PacketPlayInUseEntity;
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
import net.minecraft.server.level.EntityPlayer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class PacketHandler extends ChannelDuplexHandler {
|
public class PacketHandler extends ChannelDuplexHandler {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public PacketHandler(Player player) {
|
public PacketHandler(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||||
super.write(ctx, msg, promise);
|
super.write(ctx, msg, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext c, Object packet) throws Exception {
|
public void channelRead(ChannelHandlerContext c, Object packet) throws Exception {
|
||||||
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
|
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
|
||||||
PacketPlayInUseEntity pk = (PacketPlayInUseEntity) packet;
|
PacketPlayInUseEntity pk = (PacketPlayInUseEntity) packet;
|
||||||
int entityID = (int) PacketInjector.getFieldValue(packet, "a");
|
int entityID = (int) PacketInjector.getFieldValue(packet, "a");
|
||||||
boolean sneak = (boolean) PacketInjector.getFieldValue(packet, "c");
|
boolean sneak = (boolean) PacketInjector.getFieldValue(packet, "c");
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Entity entity : Bukkit.getWorld("world").getEntities()) {
|
||||||
|
if (entity.getEntityId() == entityID && entity.getType() == EntityType.ARMOR_STAND){
|
||||||
|
Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, (ArmorStand) entity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
|
||||||
Field type = pk.getClass().getDeclaredField("b");
|
Field type = pk.getClass().getDeclaredField("b");
|
||||||
type.setAccessible(true);
|
type.setAccessible(true);
|
||||||
Object data = type.get(pk);
|
Object data = type.get(pk);
|
||||||
if (data.toString().split("\\$")[1].charAt(0) == 'e') { return; }
|
if (data.toString().split("\\$")[1].charAt(0) == 'e') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Field hand = data.getClass().getDeclaredField("a");
|
Field hand = data.getClass().getDeclaredField("a");
|
||||||
hand.setAccessible(true);
|
hand.setAccessible(true);
|
||||||
if (!hand.get(data).toString().equals("MAIN_HAND")) { return; }
|
if (!hand.get(data).toString().equals("MAIN_HAND")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
//Right Click
|
//Right Click
|
||||||
for (EntityPlayer npcs : NPCManager.getNPCs()) {
|
for (EntityPlayer npcs : NPCManager.getNPCs()) {
|
||||||
if (npcs.ae() == entityID && sneak) {
|
if (npcs.ae() == entityID && sneak) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Bukkit.getPluginManager().callEvent(new RightClickNPC(player, npcs));
|
Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs));
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package me.night.nullvalkyrie.npc;
|
package me.night.nullvalkyrie.packets;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import net.minecraft.server.level.EntityPlayer;
|
import net.minecraft.server.level.EntityPlayer;
|
|
@ -1,6 +1,7 @@
|
||||||
package me.night.nullvalkyrie.ui;
|
package me.night.nullvalkyrie.ui;
|
||||||
|
|
||||||
import me.night.nullvalkyrie.database.RankDataManager;
|
import me.night.nullvalkyrie.database.RankDataManager;
|
||||||
|
import me.night.nullvalkyrie.enums.Rank;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.*;
|
import org.bukkit.scoreboard.*;
|
||||||
|
|
|
@ -2,7 +2,8 @@ package me.night.nullvalkyrie.ui;
|
||||||
|
|
||||||
import me.night.nullvalkyrie.Main;
|
import me.night.nullvalkyrie.Main;
|
||||||
import me.night.nullvalkyrie.database.RankDataManager;
|
import me.night.nullvalkyrie.database.RankDataManager;
|
||||||
import me.night.nullvalkyrie.npc.NPCManager;
|
import me.night.nullvalkyrie.enums.Rank;
|
||||||
|
import me.night.nullvalkyrie.entities.npcs.NPCManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
Loading…
Reference in a new issue