测试版

This commit is contained in:
tianyu 2024-07-25 04:33:47 +08:00
commit ab223481fe
13 changed files with 1061 additions and 0 deletions

40
.gitignore vendored Normal file
View File

@ -0,0 +1,40 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
/.idea/
/out/

32
pom.xml Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DemonGemsSocket</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>public-rpg</id>
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,49 @@
package me.Demon.DemonGemsSocket;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public abstract class GemsAPI {
public static String getname(String games_key){
FileConfiguration yml = Main.plugin.getConfig();
return yml.getString("Games."+games_key+".name");
}
public static int getchance(String games_key){
FileConfiguration yml = Main.plugin.getConfig();
return yml.getInt("Games."+games_key+".chance");
}
public static String gettype(String games_key){
FileConfiguration yml = Main.plugin.getConfig();
return yml.getString("Games."+games_key+".type");
}
public static ItemStack getItems(String games_key){
FileConfiguration yml = Main.plugin.getConfig();
ItemStack item = yml.getItemStack("Items."+games_key).clone();
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL,1,true);
item.setItemMeta(meta);
return item;
}
public static String getGems_Key(ItemStack item){
ItemMeta meta = item.getItemMeta();
FileConfiguration yml = Main.plugin.getConfig();
for (String key : yml.getConfigurationSection("Games").getKeys(false)){
String name = yml.getString("Games."+key+".name");
if(meta.getDisplayName().equalsIgnoreCase(name)){
return key;
}
}
return null;
}
}

View File

@ -0,0 +1,39 @@
package me.Demon.DemonGemsSocket;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class GemsListGui implements Listener {
public static void OpenGui(Player p){
Inventory inv = Bukkit.createInventory(null,54,"宝石镶嵌 - 查看所有宝石");
FileConfiguration yml = Main.plugin.getConfig();
for (String key : yml.getConfigurationSection("Items").getKeys(false)){
ItemStack item = GemsAPI.getItems(key);
item.setAmount(1);
inv.addItem(item);
}
p.openInventory(inv);
}
@EventHandler
public void onclick(InventoryClickEvent e){
Player p = (Player) e.getWhoClicked();
if(e.getInventory() != null && "宝石镶嵌 - 查看所有宝石".equalsIgnoreCase(e.getInventory().getTitle())){
e.setCancelled(true);
if(e.getRawSlot() >= 0 && e.getRawSlot() < e.getInventory().getSize()) {
ItemStack item = e.getCurrentItem();
if(!Main.itemIsNull(item) &&!Main.itemIsLore(item)) {
p.getInventory().addItem(e.getCurrentItem());
}
}
}
}
}

View File

@ -0,0 +1,125 @@
package me.Demon.DemonGemsSocket.Item;
import me.Demon.DemonGemsSocket.GemsAPI;
import me.Demon.DemonGemsSocket.Main;
import me.Demon.DemonGemsSocket.listener.GemsGui;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class Rod_Unlock implements Listener {
public static ItemStack setItem_UnlockEvent(ItemStack items){
ItemStack item = items.clone();
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.getLore();
for (int i = 0;i < lore.size();i++){
String s = lore.get(i);
if (s.contains("§7- < §1§5§r§7已锁定§1§5§r§7 >")){
lore.set(i,Main.EmptyLore);
break;
}
}
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
// 玩家在背包中点击献祭宝典拿起来点击魂环事件
@EventHandler
public void onOpenclick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
if (e.getInventory().getType() == InventoryType.CRAFTING) {
// 判断点击起来的物品是否是拆除器
int type = 0;
ItemStack book = e.getCursor();
if (!Main.itemIsNull(book) && !Main.itemIsLore(book)) {
ItemMeta meta = book.getItemMeta();
if(meta.getDisplayName().equalsIgnoreCase("§7[§e宝石§7]§d小黑子开孔器")){
type = 1;
}else if(meta.getDisplayName().equalsIgnoreCase("§7[§e宝石§7]§d顶级开孔器")){
type = 2;
}
}else{
return;
}
// 获取点击物品是否是魂环
ItemStack item = e.getCurrentItem();
if(!Main.itemIsNull(item) && !Main.itemIsLore(item)) {
ItemMeta meta = item.getItemMeta();
if(type == 1) {
if (!book.getItemMeta().getDisplayName().equalsIgnoreCase("§7[§e宝石§7]§d小黑子开孔器")) {
return;
}
if (book.getAmount() >= 2) {
p.sendMessage(Main.prefix + "开孔失败,每次最多使用一个开孔器");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
if (!meta.getLore().contains("§7- < §1§5§r§7已锁定§1§5§r§7 >")) {
p.sendMessage(Main.prefix + "开孔失败,该物品可能并不存在为解锁宝石槽");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
if (item.getAmount() >= 2) {
p.sendMessage(Main.prefix + "开孔失败,每次最多为一个物品进行此操作。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
if(Main.getRandomInt(100,1) >= 40){
e.setCursor(new ItemStack(Material.AIR));
p.sendMessage(Main.prefix + "开孔失败,损失了一个 §7[§e宝石§7]§d小黑子开孔器");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
// 扣除物品
e.setCursor(new ItemStack(Material.AIR));
// 修改物品的Lore
ItemStack new_item = setItem_UnlockEvent(item);
e.setCurrentItem(new_item);
p.sendMessage(Main.prefix + "开孔成功,已解锁宝石槽位一个。");
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
} else {
if (!book.getItemMeta().getDisplayName().equalsIgnoreCase("§7[§e宝石§7]§d顶级开孔器")) {
return;
}
if (book.getAmount() >= 2) {
p.sendMessage(Main.prefix + "开孔失败,每次最多使用一个开孔器");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
if (!meta.getLore().contains("§7- < §1§5§r§7已锁定§1§5§r§7 >")) {
p.sendMessage(Main.prefix + "开孔失败,该物品可能并不存在为解锁宝石槽");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
if (item.getAmount() >= 2) {
p.sendMessage(Main.prefix + "开孔失败,每次最多为一个物品进行此操作。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
// 扣除物品
e.setCursor(new ItemStack(Material.AIR));
// 修改物品的Lore
ItemStack new_item = setItem_UnlockEvent(item);
e.setCurrentItem(new_item);
p.sendMessage(Main.prefix + "开孔成功,已解锁宝石槽位一个。");
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
}
}
}
}
}

View File

@ -0,0 +1,192 @@
package me.Demon.DemonGemsSocket;
import me.Demon.DemonGemsSocket.Item.Rod_Unlock;
import me.Demon.DemonGemsSocket.Remove.GemRemove;
import me.Demon.DemonGemsSocket.listener.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
public class Main extends JavaPlugin {
public static Main plugin;
public static String prefix = "§7[§6宝石§7] §f";
public static String EmptyLore = "§7- < §1§5§r§7空§1§5§r§7 >";
public static HashMap<String, String> GemHashMap = new HashMap<>();
@Override
public void onEnable() {
plugin = this;
saveDefaultConfig();
for (String gemKey : getConfig().getConfigurationSection("Games").getKeys(false)) {
String name = getConfig().getString("Games." + gemKey + ".name");
String replore = "§1§6§r§8- §8< " + name + " §8>§1§6§r";
GemHashMap.put(replore, gemKey);
}
Bukkit.getConsoleSender().sendMessage("§6[宝石镶嵌] §f载入宝石: §e" + GemHashMap.size() + "");
Bukkit.getPluginManager().registerEvents(new GemsListGui(), plugin);
Bukkit.getPluginManager().registerEvents(new GemsOpen(), plugin);
Bukkit.getPluginManager().registerEvents(new GemsGuiEvent(), plugin);
Bukkit.getPluginManager().registerEvents(new GemsGuiClose(), plugin);
Bukkit.getPluginManager().registerEvents(new Rod_Unlock(), plugin);
Bukkit.getPluginManager().registerEvents(new GemRemove(), plugin);
Bukkit.getConsoleSender().sendMessage("§6[宝石镶嵌] §a插件成功载入Server");
Bukkit.getConsoleSender().sendMessage("§6[宝石镶嵌] §a妖魂QQ:1763917516");
}
public void onDisable() {
Bukkit.getConsoleSender().sendMessage("§6[宝石镶嵌] §c插件已正常关闭");
}
public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
if (CommandLabel.equalsIgnoreCase("socketpro") && sender.isOp()) {
if (args.length == 0) {
sender.sendMessage("§r");
sender.sendMessage("§e------- ======= §6镶嵌宝石系统 §e======= -------");
sender.sendMessage("§2/socketpro open §f- §2打开宝石库");
sender.sendMessage("§2/socketpro chaichu §f- §2打开拆除台");
sender.sendMessage("§2/socketpro giveall §e[宝石代号] §f- §2给予在线玩家1颗宝石");
sender.sendMessage("§2/socketpro give §e[宝石代号] §2<数量> §f- §2给予宝石");
sender.sendMessage("§2/socketpro give §e[宝石代号] §2<数量> §b<玩家> §f- §2给予宝石");
sender.sendMessage("§2/socketpro givepro §e[宝石代号] §2<数量> §b<玩家> §f- §2给予神护宝石");
sender.sendMessage("§e------- ======= §6镶嵌宝石系统 §e======= -------");
sender.sendMessage("§r");
}
// socket give <gems_key> <amount> <player>
if (args.length == 1 && args[0].equalsIgnoreCase("open")) {
GemsListGui.OpenGui((Player) sender);
}
if (args.length == 1 && args[0].equalsIgnoreCase("chaichu")) {
GemRemove.OpenGui((Player) sender);
}
if (args.length == 2 && args[0].equalsIgnoreCase("giveall")) {
String gems_key = args[1];
if (GemsAPI.getchance(gems_key) <= 10) {
sender.sendMessage(Main.prefix + "宝石可能不存在,请检查配置。");
return true;
}
int cont = 0;
int amount = 1;
ItemStack item = GemsAPI.getItems(gems_key);
item.setAmount(amount);
for (Player p : Bukkit.getOnlinePlayers()) {
p.getInventory().addItem(item);
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
p.sendMessage(Main.prefix + "你从 §e" + sender.getName() + " §a那收到了一颗 §r" + item.getItemMeta().getDisplayName());
cont++;
}
sender.sendMessage(Main.prefix + "本次总计发放 §e" + cont + "颗 §r" + item.getItemMeta().getDisplayName());
}
if (args.length == 3 && args[0].equalsIgnoreCase("give")) {
String gems_key = args[1];
if (GemsAPI.getchance(gems_key) <= 10) {
sender.sendMessage(Main.prefix + "宝石可能不存在,请检查配置。");
return true;
}
int amount = Integer.parseInt(args[2]);
if (amount < 1) {
sender.sendMessage(Main.prefix + "宝石数量必须大于或等于1。");
return true;
}
Player p = (Player) sender;
ItemStack item = GemsAPI.getItems(gems_key);
item.setAmount(amount);
p.getInventory().addItem(item);
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
sender.sendMessage(Main.prefix + "给予 §6" + amount + "x" + item.getItemMeta().getDisplayName() + " §a给 §e" + p.getName());
}
if (args.length == 4 && args[0].equalsIgnoreCase("give")) {
String gems_key = args[1];
if (GemsAPI.getchance(gems_key) <= 10) {
sender.sendMessage(Main.prefix + "宝石可能不存在,请检查配置。");
return true;
}
int amount = Integer.parseInt(args[2]);
if (amount < 1) {
sender.sendMessage(Main.prefix + "宝石数量必须大于或等于1。");
return true;
}
Player p = Bukkit.getPlayer(args[3]);
if (p != null) {
ItemStack item = GemsAPI.getItems(gems_key);
item.setAmount(amount);
p.getInventory().addItem(item);
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
sender.sendMessage(Main.prefix + "给予 §6" + amount + "x" + item.getItemMeta().getDisplayName() + " §a给 §e" + p.getName());
} else {
sender.sendMessage(Main.prefix + "目标玩家不在线。");
}
}
if (args.length == 4 && args[0].equalsIgnoreCase("givepro")) {
String gems_key = args[1];
if (GemsAPI.getchance(gems_key) <= 10) {
sender.sendMessage(Main.prefix + "宝石可能不存在,请检查配置。");
return true;
}
int amount = Integer.parseInt(args[2]);
if (amount < 1) {
sender.sendMessage(Main.prefix + "宝石数量必须大于或等于1。");
return true;
}
Player p = Bukkit.getPlayer(args[3]);
if (p != null) {
ItemStack item = GemsAPI.getItems(gems_key);
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.getLore();
for (int i = 0; i < lore.size(); i++) {
String s = lore.get(i);
if (s.contains("§e▶ §7神护: §c§l✘")) {
lore.set(i, "§e▶ §7神护: §a§l✔");
break;
}
}
meta.setLore(lore);
item.setItemMeta(meta);
p.getInventory().addItem(item);
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
sender.sendMessage(Main.prefix + "给予 §6" + amount + "x" + item.getItemMeta().getDisplayName() + " §a给 §e" + p.getName());
} else {
sender.sendMessage(Main.prefix + "目标玩家不在线。");
}
}
}
return false;
}
public static boolean itemIsNull(ItemStack item) {
return item == null || item.getType() == Material.AIR;
}
public static boolean itemIsLore(ItemStack item) {
return item.getItemMeta().getLore() == null;
}
public static int getRandomInt(int max, int mix) {
return new Random().nextInt(max) + mix;
}
public static int getEmptySlotCount(Player p) {
int count = 0;
Inventory inv = p.getInventory();
for (int i = 0; i < 36; i++) {
ItemStack item = inv.getItem(i);
if (itemIsNull(item)) {
count++;
}
}
return count;
}
}

View File

@ -0,0 +1,193 @@
package me.Demon.DemonGemsSocket.Remove;
import me.Demon.DemonGemsSocket.GemsAPI;
import me.Demon.DemonGemsSocket.Main;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class GemRemove implements Listener {
@EventHandler
public void onclick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if (inv != null && "战争领域 - 宝石拆除台".equalsIgnoreCase(inv.getTitle())) {
int slot = e.getRawSlot();
ItemStack click_item = e.getCurrentItem();
if (slot >= 0 && slot < 27) {
e.setCancelled(true);
if (slot == 20) {
if (click_item.getTypeId() == 160) {
ItemStack item = e.getCursor();
if (!Main.itemIsNull(item) && !Main.itemIsLore(item)) {
inv.setItem(slot, item);
e.setCursor(new ItemStack(Material.AIR));
setCheckGem(inv, item);
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, (float) 0.6, (float) 1.8);
} else {
p.sendMessage(Main.prefix + "该物品无法放入槽位中.");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, (float) 0.6, (float) 1.8);
}
} else {
if (!Main.itemIsNull(e.getCursor())) {
p.sendMessage(Main.prefix + "请将物品槽中的物品取出后再放入.");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, (float) 0.6, (float) 1.8);
return;
}
for (int i = 0; i < 9; i++) {
e.getInventory().setItem(i, glass(0, "§7[§c宝石槽§7]"));
}
e.setCursor(e.getCurrentItem());
e.getInventory().setItem(slot, glass(0, "§7[§6装备槽§7]"));
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, (float) 0.6, (float) 1.8);
}
}
if (slot == 24) {
if (click_item.getTypeId() == 160) {
ItemStack item = e.getCursor();
if (!Main.itemIsNull(item) && !Main.itemIsLore(item)) {
ItemMeta meta = item.getItemMeta();
if (!meta.getDisplayName().contains("拆除器")) {
p.sendMessage(Main.prefix + "该槽位只能放入宝石拆除器.");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, (float) 0.6, (float) 1.8);
return;
}
inv.setItem(slot, item);
e.setCursor(new ItemStack(Material.AIR));
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, (float) 0.6, (float) 1.8);
} else {
p.sendMessage(Main.prefix + "该物品无法放入槽位中.");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, (float) 0.6, (float) 1.8);
}
} else {
if (!Main.itemIsNull(e.getCursor())) {
p.sendMessage(Main.prefix + "请将物品槽中的物品取出后再放入.");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, (float) 0.6, (float) 1.8);
return;
}
e.setCursor(e.getCurrentItem());
e.getInventory().setItem(slot, glass(0, "§7[§6拆除器§7]"));
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, (float) 0.6, (float) 1.8);
}
}
if (slot < 9) {
ItemStack item = e.getCurrentItem();
if (!Main.itemIsLore(item)) {
// 获取拆除槽物品是否存在.
ItemStack chaichu = inv.getItem(24);
if (Main.itemIsNull(chaichu) || Main.itemIsLore(chaichu)) {
p.sendMessage(Main.prefix + "拆除失败,你需要放一个拆除器.");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, (float) 0.6, (float) 1.8);
return;
}
int type = 1;
if (chaichu.getItemMeta().getLore().contains("§e▶ §7成功几率: §a100%")) {
type = 2;
}
if (type == 1) {
if (Main.getRandomInt(100, 1) >= 35) {
inv.setItem(24, glass(0, "§7[§6拆除器§7]"));
p.sendMessage(Main.prefix + "拆除失败,损失了一个 §7[§e宝石§7]§d小黑子拆除器");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, (float) 0.6, (float) 1.8);
return;
}
}
// 设置玩家物品的lore为空
ItemStack zb_item = inv.getItem(20).clone();
ItemMeta zb_meta = zb_item.getItemMeta();
int line = Integer.parseInt(item.getItemMeta().getDisplayName().split("§8#")[1]);
List<String> lore = zb_meta.getLore();
lore.set(line, Main.EmptyLore);
zb_meta.setLore(lore);
zb_item.setItemMeta(zb_meta);
inv.setItem(20, zb_item);
// 给予玩家宝石
ItemStack gem_item = recoverGemItems(e.getCurrentItem());
p.getInventory().addItem(gem_item);
// 执行拆除成功的操作
inv.setItem(slot, glass(0, "§7[§c宝石槽§7]"));
inv.setItem(24, glass(0, "§7[§6拆除器§7]"));
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, (float) 0.6, (float) 1.8);
}
}
}
}
}
public static ItemStack recoverGemItems(ItemStack items) {
ItemStack item = items.clone();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(meta.getDisplayName().split("§8#")[0]);
item.setItemMeta(meta);
return item;
}
public static void setCheckGem(Inventory inv, ItemStack item) {
List<String> gemList = getGemCheckList(item);
if (gemList.size() >= 1) {
for (int i = 0; i < gemList.size(); i++) {
String gemKey = gemList.get(i).split("#")[0];
String line = gemList.get(i).split("#")[1];
ItemStack gem_item = GemsAPI.getItems(gemKey);
ItemMeta meta = gem_item.getItemMeta();
meta.setDisplayName(meta.getDisplayName() + "§8#" + line);
gem_item.setItemMeta(meta);
inv.setItem(i, gem_item);
}
}
}
public static List<String> getGemCheckList(ItemStack item) {
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.getLore();
List<String> GemList = new ArrayList<>();
for (int i = 0; i < lore.size(); i++) {
String s = lore.get(i);
if (s.startsWith("§1§6§r§8- §8< ")) {
if (Main.GemHashMap.get(s) != null) {
String GemKey = Main.GemHashMap.get(s);
GemList.add(GemKey + "#" + i);
}
}
}
return GemList;
}
public static void OpenGui(Player p) {
Inventory inv = Bukkit.createInventory(null, 27, "战争领域 - 宝石拆除台");
for (int i = 0; i < 9; i++) {
inv.setItem(i, glass(0, "§7[§c宝石槽§7]"));
}
for (int i = 9; i < 27; i++) {
inv.setItem(i, glass(15, "§r"));
}
inv.setItem(19, glass(4, "§7[[§a▧▧§7]]"));
inv.setItem(20, glass(0, "§7[§6装备槽§7]"));
inv.setItem(21, glass(4, "§7[[§a▧▧§7]]"));
inv.setItem(25, glass(1, "§7[[§a▧▧§7]]"));
inv.setItem(24, glass(0, "§7[§6拆除器§7]"));
inv.setItem(23, glass(1, "§7[[§a▧▧§7]]"));
p.openInventory(inv);
}
public static ItemStack glass(int data, String name) {
ItemStack item = new ItemStack(160, 1, (short) data);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
return item;
}
}

View File

@ -0,0 +1,73 @@
package me.Demon.DemonGemsSocket.listener;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class GemsGui {
public static void OpenGui(Player p,ItemStack gems_Items){
Inventory inv = Bukkit.createInventory(null,27,"§9§l宝石镶嵌系统");
for (int i = 0; i < 27;i++){
inv.setItem(i,glass(15,"§8§l[§e§l!§8§l]"));
}
inv.setItem(1,sign_show("物品信息","§7将装备放置下方槽位"));
inv.setItem(2,sign_show("镶嵌宝石","§7将宝石放置下方槽位"));
inv.setItem(10,glass(0,"§7[§6请放入装备§7]"));
inv.setItem(11,gems_Items);
inv.setItem(16,ok_butt());
inv.setItem(15,sign_show("温馨提示","§c宝石镶嵌后无法取出"));
inv.setItem(14,no_butt());
p.openInventory(inv);
}
public static ItemStack ok_butt(){
ItemStack item = new ItemStack(Material.WOOL,1,(short)13);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§8§m §r");
List<String> lore = new ArrayList<>();
lore.add("§8§l[ §a§l确认操作 §8§l]");
lore.add("§8§m §r");
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
public static ItemStack no_butt(){
ItemStack item = new ItemStack(Material.WOOL,1,(short)14);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§8§m §r");
List<String> lore = new ArrayList<>();
lore.add("§8§l[ §c§l取消操作 §8§l]");
lore.add("§8§m §r");
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
public static ItemStack sign_show(String name,String info){
ItemStack item = new ItemStack(Material.SIGN);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§8[§a"+name+"§8]");
List<String> lore = new ArrayList<>();
lore.add("§3§m §r");
lore.add(info);
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
public static ItemStack glass(int data,String name){
ItemStack item = new ItemStack(160,1,(short) data);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
return item;
}
}

View File

@ -0,0 +1,27 @@
package me.Demon.DemonGemsSocket.listener;
import me.Demon.DemonGemsSocket.Main;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
public class GemsGuiClose implements Listener {
@EventHandler
public void onclose(InventoryCloseEvent e) {
Player p = (Player) e.getPlayer();
Inventory inv = e.getInventory();
if (inv != null && inv.getTitle().equalsIgnoreCase("§9§l宝石镶嵌系统")) {
if(!Main.itemIsNull(inv.getItem(10)) && !Main.itemIsLore(inv.getItem(10))){
p.getInventory().addItem(inv.getItem(10));
}
if(!Main.itemIsNull(inv.getItem(11)) && !Main.itemIsLore(inv.getItem(11))){
p.getInventory().addItem(inv.getItem(11));
}
}
}
}

View File

@ -0,0 +1,136 @@
package me.Demon.DemonGemsSocket.listener;
import me.Demon.DemonGemsSocket.GemsAPI;
import me.Demon.DemonGemsSocket.Main;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class GemsGuiEvent implements Listener {
@EventHandler
public void onGemsGuiClick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if (e.getInventory() != null && inv.getTitle().equalsIgnoreCase("§9§l宝石镶嵌系统")) {
e.setCancelled(true);
if (e.getRawSlot() >= inv.getSize()) {
ItemStack item = e.getCurrentItem();
if (!Main.itemIsNull(item) && !Main.itemIsLore(item)) {
ItemMeta meta = item.getItemMeta();
if (meta.getLore().contains(Main.EmptyLore)) {
inv.setItem(10, item);
e.setCurrentItem(new ItemStack(Material.AIR));
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
} else {
p.sendMessage(Main.prefix + "镶嵌失败,该物品没有可以空余宝石槽。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
}
}
}
if (e.getRawSlot() == 10) {
if (!Main.itemIsLore(e.getCurrentItem())) {
p.getInventory().addItem(e.getCurrentItem());
inv.setItem(10, GemsGui.glass(0, "§7[§6请放入装备§7]"));
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
}
}
if (e.getRawSlot() == 16) {
ItemStack item = inv.getItem(10).clone();
if (Main.itemIsLore(item) || !item.getItemMeta().getLore().contains(Main.EmptyLore)) {
p.sendMessage(Main.prefix + "镶嵌失败,该物品没有可以空余宝石槽。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
ItemStack gems = inv.getItem(11).clone();
if (GemsAPI.getGems_Key(gems) == null) {
p.sendMessage(Main.prefix + "宝石配置出现错误,请联系管理员。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
String Gems_Key = GemsAPI.getGems_Key(gems);
if (GemsAPI.gettype(Gems_Key).equalsIgnoreCase("Armor")) {
if (!isArmor(item)) {
p.sendMessage(Main.prefix + "镶嵌失败,这是一颗防具宝石。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
} else if (GemsAPI.gettype(Gems_Key).equalsIgnoreCase("Weapon")) {
if (isArmor(item)) {
p.sendMessage(Main.prefix + "镶嵌失败,这是一颗武器宝石。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
}
int chance = GemsAPI.getchance(Gems_Key);
String replore = "§1§6§r§8- §8< " + GemsAPI.getname(Gems_Key) + " §8>§1§6§r";
if (gems.getItemMeta().getLore().contains("§e▶ §7神护: §a§l✔")) {
GemsXiruEvant(inv, p, item, replore);
return;
}
if (Main.getRandomInt(100, 1) < chance) {
GemsXiruEvant(inv, p, item, replore);
} else {
inv.setItem(11, GemsGui.glass(15, "板子"));
p.sendMessage(Main.prefix + "镶嵌失败,不要灰心继续努力!下一个会成功镶嵌的!");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
p.closeInventory();
}
}
if (e.getRawSlot() == 14) {
p.closeInventory();
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
}
}
}
public static void GemsXiruEvant(Inventory inv, Player p, ItemStack item, String replore) {
inv.setItem(10, GemsGui.glass(15, "板子"));
inv.setItem(11, GemsGui.glass(15, "板子"));
p.closeInventory();
p.getInventory().addItem(AddGemsItemsEvant(item, replore));
p.sendMessage(Main.prefix + "镶嵌成功,装备已自动回到背包中。");
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
}
public static ItemStack AddGemsItemsEvant(ItemStack item, String replore) {
ItemStack items = item.clone();
ItemMeta meta = items.getItemMeta();
List<String> lore = meta.getLore();
for (int i = 0; i < lore.size(); i++) {
String s = lore.get(i);
if (s.contains(Main.EmptyLore)) {
lore.set(i, replore);
break;
}
}
meta.setLore(lore);
items.setItemMeta(meta);
return items;
}
//判断物品是否是防具
public static boolean isArmor(ItemStack item) {
Material material = item.getType();
if (material.name().contains("_HELMET")) {
return true;
} else if (material.name().contains("_CHESTPLATE")) {
return true;
} else if (material.name().contains("_LEGGINGS")) {
return true;
} else if (material.name().contains("_BOOTS")) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,43 @@
package me.Demon.DemonGemsSocket.listener;
import me.Demon.DemonGemsSocket.GemsAPI;
import me.Demon.DemonGemsSocket.Main;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
public class GemsOpen implements Listener {
@EventHandler
public void onClickGems(PlayerInteractEvent e){
Player p = e.getPlayer();
ItemStack item = p.getItemInHand();
if(!Main.itemIsNull(item) && !Main.itemIsLore(item)){
ItemMeta meta = item.getItemMeta();
if(meta.getLore().contains("§c提示: §7手持宝石右键镶嵌")){
if(item.getAmount() >= 2) {
p.sendMessage(Main.prefix + "镶嵌失败,每次最多镶嵌一颗宝石。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
if (GemsAPI.getGems_Key(item) == null) {
p.sendMessage(Main.prefix + "宝石配置出现错误,请联系管理员。");
p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1, 2);
return;
}
GemsGui.OpenGui(p, item);
p.getInventory().setItemInHand(new ItemStack(Material.AIR));
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
}
}
}
}

View File

@ -0,0 +1,106 @@
Games:
红宝石1:
chance: 80.0
name: §c红宝石 §cI
sxLore: "§1§6§r§8- §8< %name% §8>§1§6§r"
Items:
红宝石1:
==: org.bukkit.inventory.ItemStack
type: INK_SACK
damage: 1
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: §c红宝石 §cI
lore:
- "§8§l§m-----------------------"
- "§e▶ §7种类: §f宝石"
- "§e▶ §7神护: §c§l✘"
- "§e▶ §7适合物品: §f武器"
- "§e▶ §7成功几率: §a80%"
- "§8§l§m-----------------------"
- "§8§l[§4§l!§8§l] §7宝石效果:"
- "§6§l» §7增加§c攻击伤害 §f+4"
- ""
- "§c提示: §7打开背包,拿起宝石"
- "§7然后放在要镶嵌的物品上"
红宝石2:
==: org.bukkit.inventory.ItemStack
type: INK_SACK
damage: 1
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: §c红宝石 §cII
lore:
- "§8§l§m-----------------------"
- "§e▶ §7种类: §f宝石"
- "§e▶ §7神护: §c§l✘"
- "§e▶ §7适合物品: §f武器"
- "§e▶ §7成功几率: §a68%"
- "§8§l§m-----------------------"
- "§8§l[§4§l!§8§l] §7宝石效果:"
- "§6§l» §7增加§c攻击伤害 §f+6"
- ""
- "§c提示: §7打开背包,拿起宝石"
- "§7然后放在要镶嵌的物品上"
红宝石3:
==: org.bukkit.inventory.ItemStack
type: INK_SACK
damage: 1
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: §c红宝石 §cIII
lore:
- "§8§l§m-----------------------"
- "§e▶ §7种类: §f宝石"
- "§e▶ §7神护: §c§l✘"
- "§e▶ §7适合物品: §f武器"
- "§e▶ §7成功几率: §a56%"
- "§8§l§m-----------------------"
- "§8§l[§4§l!§8§l] §7宝石效果:"
- "§6§l» §7增加§c攻击伤害 §f+8"
- ""
- "§c提示: §7打开背包,拿起宝石"
- "§7然后放在要镶嵌的物品上"
红宝石4:
==: org.bukkit.inventory.ItemStack
type: INK_SACK
damage: 1
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: §c红宝石 §cIV
lore:
- "§8§l§m-----------------------"
- "§e▶ §7种类: §f宝石"
- "§e▶ §7神护: §c§l✘"
- "§e▶ §7适合物品: §f武器"
- "§e▶ §7成功几率: §a44%"
- "§8§l§m-----------------------"
- "§8§l[§4§l!§8§l] §7宝石效果:"
- "§6§l» §7增加§c攻击伤害 §f+12"
- ""
- "§c提示: §7打开背包,拿起宝石"
- "§7然后放在要镶嵌的物品上"
红宝石5:
==: org.bukkit.inventory.ItemStack
type: INK_SACK
damage: 1
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: §c红宝石 §cV
lore:
- "§8§l§m-----------------------"
- "§e▶ §7种类: §f宝石"
- "§e▶ §7神护: §c§l✘"
- "§e▶ §7适合物品: §f武器"
- "§e▶ §7成功几率: §a44%"
- "§8§l§m-----------------------"
- "§8§l[§4§l!§8§l] §7宝石效果:"
- "§6§l» §7增加§c攻击伤害 §f+16"
- ""
- "§c提示: §7打开背包,拿起宝石"
- "§7然后放在要镶嵌的物品上"

View File

@ -0,0 +1,6 @@
name: DemonGemsSocket
main: me.Demon.DemonGemsSocket.Main
version: 2.0.3
commands:
socketpro:
#socket load Gems 翡翠宝石