测试版
This commit is contained in:
commit
628c7560b8
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
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
|
37
pom.xml
Normal file
37
pom.xml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?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>DemonBuildShop</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>
|
||||
<dependency>
|
||||
<groupId>me.Demon.DemonPlugin</groupId>
|
||||
<artifactId>DemonAPI</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
112
src/main/java/me/Demon/DemonBuildShop/Main.java
Normal file
112
src/main/java/me/Demon/DemonBuildShop/Main.java
Normal file
|
@ -0,0 +1,112 @@
|
|||
package me.Demon.DemonBuildShop;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
public static Main plugin;
|
||||
public static String prefix = "§7[§建筑商店§7] §f";
|
||||
public static List<Player> LockAccount = new ArrayList<>();
|
||||
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
saveDefaultConfig();
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new gui_1(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new gui_2(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new gui_3(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new gui_4(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new gui_5(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new gui_6(), plugin);
|
||||
Bukkit.getConsoleSender().sendMessage("§a[建材商城] §f插件成功载入服务器.");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
Bukkit.getConsoleSender().sendMessage("§c[建材商城] §f插件已经从服务器中卸载.");
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
|
||||
if (CommandLabel.equalsIgnoreCase("buildshop")) {
|
||||
if (args.length == 0) {
|
||||
gui_1.OpenGui((Player) sender);
|
||||
} else if (args.length == 1 && sender.isOp()) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
reloadConfig();
|
||||
sender.sendMessage(prefix + "配置文件重载完成。");
|
||||
} else {
|
||||
OpenGui((Player) sender, Integer.parseInt(args[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclose(InventoryCloseEvent e) {
|
||||
Player p = (Player) e.getPlayer();
|
||||
if (e.getView().getTitle().contains("创建配置文件#")) {
|
||||
int amount = 0;
|
||||
String key = e.getView().getTitle().replace("创建配置文件#", "");
|
||||
getConfig().set("ItemShop_" + key, null);
|
||||
for (int i = 0; i < e.getInventory().getSize(); i++) {
|
||||
ItemStack items = e.getInventory().getItem(i);
|
||||
if (!DemonAPI.itemIsNull(items)) {
|
||||
getConfig().set("ItemShop_" + key + "." + i + ".price", 4);
|
||||
items.setAmount(64);
|
||||
getConfig().set("ItemShop_" + key + "." + i + ".items", items);
|
||||
saveConfig();
|
||||
amount++;
|
||||
}
|
||||
}
|
||||
p.sendMessage("创建配置物品总计: §a" + amount + "个");
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenGui(Player p, int key) {
|
||||
Inventory inv = Bukkit.createInventory(null, 54, "创建配置文件#" + key);
|
||||
String str = "ItemShop_" + key;
|
||||
FileConfiguration yml = Main.plugin.getConfig();
|
||||
if (yml.getString(str) != null) {
|
||||
for (String slot_key : yml.getConfigurationSection(str).getKeys(false)) {
|
||||
ItemStack item = yml.getItemStack(str + "." + slot_key + ".items");
|
||||
int slot = Integer.parseInt(slot_key);
|
||||
inv.setItem(slot, item);
|
||||
}
|
||||
}
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
public static String getTime(String format) {
|
||||
Date date = Calendar.getInstance().getTime();
|
||||
SimpleDateFormat datatime = new SimpleDateFormat(format);
|
||||
return datatime.format(date);
|
||||
}
|
||||
|
||||
public static ItemStack BackBook(String name) {
|
||||
ItemStack item = new ItemStack(Material.BOOK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
98
src/main/java/me/Demon/DemonBuildShop/gui_1.java
Normal file
98
src/main/java/me/Demon/DemonBuildShop/gui_1.java
Normal file
|
@ -0,0 +1,98 @@
|
|||
package me.Demon.DemonBuildShop;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import me.skymc.taboomenu.TabooMenuAPI;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class gui_1 implements Listener {
|
||||
|
||||
public static String inv_title = "建材商店(第一页)";
|
||||
public static String Next_String = "ItemShop_1";
|
||||
public static FileConfiguration yml = Main.plugin.getConfig();
|
||||
|
||||
public static void OpenGui(Player p){
|
||||
Inventory inv = Bukkit.createInventory(null,54,inv_title);
|
||||
if(yml.getConfigurationSection(Next_String) != null) {
|
||||
for (String slot : yml.getConfigurationSection(Next_String).getKeys(false)) {
|
||||
double price = yml.getDouble(Next_String+"." + slot + ".price");
|
||||
ItemStack items = yml.getItemStack(Next_String+"." + slot + ".items").clone();
|
||||
inv.setItem(Integer.parseInt(slot), shopItems(items, price));
|
||||
}
|
||||
}
|
||||
inv.setItem(45,arrow(Material.BARRIER,"§c无法进行翻页!"));
|
||||
inv.setItem(49, Main.BackBook("§a返回菜单"));
|
||||
inv.setItem(53,arrow(Material.ARROW,"§a下一页"));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
public static ItemStack shopItems(ItemStack items,double price){
|
||||
ItemStack item = items.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(DemonAPI.getItemName(item));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7价格: "+(int) price+"点券");
|
||||
lore.add("§7数量: "+item.getAmount()+"个");
|
||||
lore.add("§a§l✔§7点击购买");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack arrow(Material material, String name){
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e){
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if(inv_title.equalsIgnoreCase(e.getView().getTitle())){
|
||||
e.setCancelled(true);
|
||||
if(e.getRawSlot() == 45){
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
return;
|
||||
}
|
||||
if(e.getRawSlot() == 53){
|
||||
gui_2.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
return;
|
||||
}
|
||||
if(e.getRawSlot() == 49){
|
||||
TabooMenuAPI.openMenu(p,"商城菜单",true);
|
||||
}
|
||||
if(e.getRawSlot() >= 0 && e.getRawSlot() < 45){
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if(!DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)){
|
||||
String str = Next_String+"."+e.getRawSlot()+".";
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
//获取这个物品多少钱
|
||||
int price = yml.getInt(str+"price");
|
||||
if(!DemonAPI.hasPoints(p,price)){
|
||||
p.sendMessage(Main.prefix + "你需要§d" + price + "§f点券才能操作.");
|
||||
return;
|
||||
}
|
||||
DemonAPI.takePoints(p,price);
|
||||
p.getInventory().addItem(yml.getItemStack(str+"items").clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
99
src/main/java/me/Demon/DemonBuildShop/gui_2.java
Normal file
99
src/main/java/me/Demon/DemonBuildShop/gui_2.java
Normal file
|
@ -0,0 +1,99 @@
|
|||
package me.Demon.DemonBuildShop;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import me.skymc.taboomenu.TabooMenuAPI;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class gui_2 implements Listener {
|
||||
|
||||
public static String inv_title = "建材商店(第二页)";
|
||||
public static String Next_String = "ItemShop_2";
|
||||
public static FileConfiguration yml = Main.plugin.getConfig();
|
||||
|
||||
public static void OpenGui(Player p) {
|
||||
Inventory inv = Bukkit.createInventory(null, 54, inv_title);
|
||||
if (yml.getConfigurationSection(Next_String) != null) {
|
||||
for (String slot : yml.getConfigurationSection(Next_String).getKeys(false)) {
|
||||
double price = yml.getDouble(Next_String + "." + slot + ".price");
|
||||
ItemStack items = yml.getItemStack(Next_String + "." + slot + ".items").clone();
|
||||
inv.setItem(Integer.parseInt(slot), shopItems(items, price));
|
||||
}
|
||||
}
|
||||
inv.setItem(45, arrow(Material.ARROW, "§a上一页"));
|
||||
inv.setItem(49, Main.BackBook("§a返回菜单"));
|
||||
inv.setItem(53, arrow(Material.ARROW, "§a下一页"));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
public static ItemStack shopItems(ItemStack items, double price) {
|
||||
ItemStack item = items.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(DemonAPI.getItemName(item));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7价格: " + (int) price + "点券");
|
||||
lore.add("§7数量: " + item.getAmount() + "个");
|
||||
lore.add("§a§l✔§7点击购买");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack arrow(Material material, String name) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (inv_title.equalsIgnoreCase(e.getView().getTitle())) {
|
||||
e.setCancelled(true);
|
||||
if (e.getRawSlot() == 45) {
|
||||
gui_1.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
return;
|
||||
}
|
||||
if (e.getRawSlot() == 53) {
|
||||
gui_3.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
return;
|
||||
}
|
||||
if (e.getRawSlot() == 49) {
|
||||
TabooMenuAPI.openMenu(p, "商城菜单", true);
|
||||
}
|
||||
if (e.getRawSlot() >= 0 && e.getRawSlot() < 45) {
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if (!DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)) {
|
||||
String str = "ItemShop_" + 2 + "." + e.getRawSlot() + ".";
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
//获取这个物品多少钱
|
||||
int price = yml.getInt(str + "price");
|
||||
if (!DemonAPI.hasPoints(p, price)) {
|
||||
p.sendMessage(Main.prefix + "你需要§d" + price + "§f点券才能操作.");
|
||||
return;
|
||||
}
|
||||
DemonAPI.takePoints(p, price);
|
||||
p.getInventory().addItem(yml.getItemStack(str + "items").clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
99
src/main/java/me/Demon/DemonBuildShop/gui_3.java
Normal file
99
src/main/java/me/Demon/DemonBuildShop/gui_3.java
Normal file
|
@ -0,0 +1,99 @@
|
|||
package me.Demon.DemonBuildShop;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import me.skymc.taboomenu.TabooMenuAPI;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class gui_3 implements Listener {
|
||||
|
||||
public static String inv_title = "建材商店(第三页)";
|
||||
public static String Next_String = "ItemShop_3";
|
||||
public static FileConfiguration yml = Main.plugin.getConfig();
|
||||
|
||||
public static void OpenGui(Player p) {
|
||||
//获取玩家点券余额
|
||||
Inventory inv = Bukkit.createInventory(null, 54, inv_title);
|
||||
if (yml.getConfigurationSection(Next_String) != null) {
|
||||
for (String slot : yml.getConfigurationSection(Next_String).getKeys(false)) {
|
||||
double price = yml.getDouble(Next_String + "." + slot + ".price");
|
||||
ItemStack items = yml.getItemStack(Next_String + "." + slot + ".items").clone();
|
||||
inv.setItem(Integer.parseInt(slot), shopItems(items, price));
|
||||
}
|
||||
}
|
||||
inv.setItem(45, arrow(Material.ARROW, "§a上一页"));
|
||||
inv.setItem(49, Main.BackBook("§a返回菜单"));
|
||||
inv.setItem(53, arrow(Material.BARRIER, "§c最后一页了!"));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
public static ItemStack shopItems(ItemStack items, double price) {
|
||||
ItemStack item = items.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(DemonAPI.getItemName(item));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7价格: " + (int) price + "点券");
|
||||
lore.add("§7数量: " + item.getAmount() + "个");
|
||||
lore.add("§a§l✔§7点击购买");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack arrow(Material material, String name) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (inv_title.equalsIgnoreCase(e.getView().getTitle())) {
|
||||
e.setCancelled(true);
|
||||
if (e.getRawSlot() == 45) {
|
||||
gui_2.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
return;
|
||||
}
|
||||
if (e.getRawSlot() == 53) {
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
return;
|
||||
}
|
||||
if (e.getRawSlot() == 49) {
|
||||
TabooMenuAPI.openMenu(p, "商城菜单", true);
|
||||
}
|
||||
if (e.getRawSlot() >= 0 && e.getRawSlot() < 45) {
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if (!DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)) {
|
||||
String str = Next_String + "." + e.getRawSlot() + ".";
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
//获取这个物品多少钱
|
||||
int price = yml.getInt(str + "price");
|
||||
if (!DemonAPI.hasPoints(p, price)) {
|
||||
p.sendMessage(Main.prefix + "你需要§d" + price + "§f点券才能操作.");
|
||||
return;
|
||||
}
|
||||
DemonAPI.takePoints(p, price);
|
||||
p.getInventory().addItem(yml.getItemStack(str + "items").clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
src/main/java/me/Demon/DemonBuildShop/gui_4.java
Normal file
100
src/main/java/me/Demon/DemonBuildShop/gui_4.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package me.Demon.DemonBuildShop;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import me.skymc.taboomenu.TabooMenuAPI;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class gui_4 implements Listener {
|
||||
|
||||
public static String inv_title = "建材商店(第四页)";
|
||||
public static String Next_String = "ItemShop_4";
|
||||
public static FileConfiguration yml = Main.plugin.getConfig();
|
||||
|
||||
public static void OpenGui(Player p) {
|
||||
Inventory inv = Bukkit.createInventory(null, 54, inv_title);
|
||||
if (yml.getConfigurationSection(Next_String) != null) {
|
||||
for (String slot : yml.getConfigurationSection(Next_String).getKeys(false)) {
|
||||
double price = yml.getDouble(Next_String + "." + slot + ".price");
|
||||
ItemStack items = yml.getItemStack(Next_String + "." + slot + ".items").clone();
|
||||
inv.setItem(Integer.parseInt(slot), shopItems(items, price));
|
||||
}
|
||||
}
|
||||
inv.setItem(45, arrow(Material.ARROW, "§a上一页"));
|
||||
inv.setItem(49, Main.BackBook("§a返回菜单"));
|
||||
inv.setItem(53, arrow(Material.ARROW, "§a下一页"));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
public static ItemStack shopItems(ItemStack items, double price) {
|
||||
ItemStack item = items.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(DemonAPI.getItemName(item));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7价格: " + (int) price + "点券");
|
||||
lore.add("§7数量: " + item.getAmount() + "个");
|
||||
lore.add("§a§l✔§7点击购买");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack arrow(Material material, String name) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (inv_title.equalsIgnoreCase(e.getView().getTitle())) {
|
||||
e.setCancelled(true);
|
||||
if (e.getRawSlot() == 45) {
|
||||
gui_3.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
return;
|
||||
}
|
||||
if (e.getRawSlot() == 53) {
|
||||
gui_5.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
return;
|
||||
}
|
||||
if (e.getRawSlot() == 49) {
|
||||
TabooMenuAPI.openMenu(p, "商城菜单", true);
|
||||
}
|
||||
if (e.getRawSlot() >= 0 && e.getRawSlot() < 45) {
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if (!DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)) {
|
||||
String str = Next_String + "." + e.getRawSlot() + ".";
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 2);
|
||||
//获取这个物品多少钱
|
||||
int price = yml.getInt(str + "price");
|
||||
if (!DemonAPI.hasPoints(p, price)) {
|
||||
p.sendMessage(Main.prefix + "你需要§d" + price + "§f点券才能操作.");
|
||||
p.closeInventory();
|
||||
return;
|
||||
}
|
||||
DemonAPI.takePoints(p, price);
|
||||
p.getInventory().addItem(yml.getItemStack(str + "items").clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
src/main/java/me/Demon/DemonBuildShop/gui_5.java
Normal file
100
src/main/java/me/Demon/DemonBuildShop/gui_5.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package me.Demon.DemonBuildShop;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import me.skymc.taboomenu.TabooMenuAPI;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class gui_5 implements Listener {
|
||||
|
||||
public static String inv_title = "建材商店(第五页)";
|
||||
public static String Next_String = "ItemShop_5";
|
||||
public static FileConfiguration yml = Main.plugin.getConfig();
|
||||
|
||||
public static void OpenGui(Player p){
|
||||
Inventory inv = Bukkit.createInventory(null,54,inv_title);
|
||||
if(yml.getConfigurationSection(Next_String) != null) {
|
||||
for (String slot : yml.getConfigurationSection(Next_String).getKeys(false)) {
|
||||
double price = yml.getDouble(Next_String+"." + slot + ".price");
|
||||
ItemStack items = yml.getItemStack(Next_String+"." + slot + ".items").clone();
|
||||
inv.setItem(Integer.parseInt(slot), shopItems(items, price));
|
||||
}
|
||||
}
|
||||
inv.setItem(45,arrow(Material.ARROW,"§a上一页"));
|
||||
inv.setItem(49, Main.BackBook("§a返回菜单"));
|
||||
inv.setItem(53,arrow(Material.ARROW,"§a下一页"));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
public static ItemStack shopItems(ItemStack items,double price){
|
||||
ItemStack item = items.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(DemonAPI.getItemName(item));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7价格: "+(int) price+"点券");
|
||||
lore.add("§7数量: "+item.getAmount()+"个");
|
||||
lore.add("§a§l✔§7点击购买");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack arrow(Material material, String name){
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e){
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if(inv_title.equalsIgnoreCase(e.getView().getTitle())){
|
||||
e.setCancelled(true);
|
||||
if(e.getRawSlot() == 45){
|
||||
gui_4.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
return;
|
||||
}
|
||||
if(e.getRawSlot() == 53){
|
||||
gui_6.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
return;
|
||||
}
|
||||
if(e.getRawSlot() == 49){
|
||||
TabooMenuAPI.openMenu(p,"商城菜单",true);
|
||||
}
|
||||
if(e.getRawSlot() >= 0 && e.getRawSlot() < 45){
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if(!DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)){
|
||||
String str = Next_String+"."+e.getRawSlot()+".";
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
//获取这个物品多少钱
|
||||
int price = yml.getInt(str+"price");
|
||||
if(!DemonAPI.hasPoints(p,price)){
|
||||
p.sendMessage(Main.prefix + "你需要§d" + price + "§f点券才能操作.");
|
||||
p.closeInventory();
|
||||
return;
|
||||
}
|
||||
DemonAPI.takePoints(p,price);
|
||||
p.getInventory().addItem(yml.getItemStack(str+"items").clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
src/main/java/me/Demon/DemonBuildShop/gui_6.java
Normal file
100
src/main/java/me/Demon/DemonBuildShop/gui_6.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package me.Demon.DemonBuildShop;
|
||||
|
||||
import cn.hamster3.api.HamsterAPI;
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import me.skymc.taboomenu.TabooMenuAPI;
|
||||
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.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class gui_6 implements Listener {
|
||||
|
||||
public static String inv_title = "建材商店(第六页)";
|
||||
public static String Next_String = "ItemShop_6";
|
||||
public static FileConfiguration yml = Main.plugin.getConfig();
|
||||
|
||||
public static void OpenGui(Player p){
|
||||
Inventory inv = Bukkit.createInventory(null,54,inv_title);
|
||||
if(yml.getConfigurationSection(Next_String) != null) {
|
||||
for (String slot : yml.getConfigurationSection(Next_String).getKeys(false)) {
|
||||
double price = yml.getDouble(Next_String+"." + slot + ".price");
|
||||
ItemStack items = yml.getItemStack(Next_String+"." + slot + ".items").clone();
|
||||
inv.setItem(Integer.parseInt(slot), shopItems(items, price));
|
||||
}
|
||||
}
|
||||
inv.setItem(45,arrow(Material.ARROW,"§a上一页"));
|
||||
inv.setItem(49, Main.BackBook("§a返回菜单"));
|
||||
inv.setItem(53,arrow(Material.BARRIER,"§c最后一页了!"));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
public static ItemStack shopItems(ItemStack items,double price){
|
||||
ItemStack item = items.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(DemonAPI.getItemName(item));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7价格: "+(int) price+"点券");
|
||||
lore.add("§7数量: "+item.getAmount()+"个");
|
||||
lore.add("§a§l✔§7点击购买");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack arrow(Material material, String name){
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e){
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if(inv_title.equalsIgnoreCase(e.getView().getTitle())){
|
||||
e.setCancelled(true);
|
||||
if(e.getRawSlot() == 45){
|
||||
gui_5.OpenGui(p);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
return;
|
||||
}
|
||||
if(e.getRawSlot() == 53){
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
return;
|
||||
}
|
||||
if(e.getRawSlot() == 49){
|
||||
TabooMenuAPI.openMenu(p,"商城菜单",true);
|
||||
}
|
||||
if(e.getRawSlot() >= 0 && e.getRawSlot() < 45){
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if(!DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)){
|
||||
String str = Next_String+"."+e.getRawSlot()+".";
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK,1,2);
|
||||
//获取这个物品多少钱
|
||||
int price = yml.getInt(str+"price");
|
||||
if(!DemonAPI.hasPoints(p,price)){
|
||||
p.sendMessage(Main.prefix + "你需要§d" + price + "§f点券才能操作.");
|
||||
p.closeInventory();
|
||||
return;
|
||||
}
|
||||
DemonAPI.takePoints(p,price);
|
||||
p.getInventory().addItem(yml.getItemStack(str+"items").clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
0
src/main/resources/config.yml
Normal file
0
src/main/resources/config.yml
Normal file
7
src/main/resources/plugin.yml
Normal file
7
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
name: DemonBuildShop
|
||||
main: me.Demon.DemonBuildShop.Main
|
||||
version: 1.0
|
||||
depend:
|
||||
- DemonAPI
|
||||
commands:
|
||||
buildshop:
|
Loading…
Reference in New Issue
Block a user