测试版

This commit is contained in:
tianyu 2024-07-24 20:45:58 +08:00
commit f23d4d4ae1
7 changed files with 233 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>DemonChestPreview</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,79 @@
package me.Demon.DemonChestPreview.Command;
import me.Demon.DemonChestPreview.Main;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class ChestCommand implements CommandExecutor, TabExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player p = (Player) sender;
if (args.length == 1) {
if (args[0].equalsIgnoreCase("add") && sender.isOp()) {
Block targetBlock = p.getTargetBlock(null, 5);
if (targetBlock != null && targetBlock.getType() == Material.CHEST) {
String loc = getLoc(targetBlock);
if (!Main.previewList.contains(loc)) {
List<String> list = Main.previewList;
list.add(loc);
Main.plugin.getConfig().set("ChestLoc", list);
Main.plugin.saveConfig();
p.sendMessage(Main.prefix + "已添加箱子展示箱 §7#" + loc);
} else {
p.sendMessage(Main.prefix + "此箱子已存在展示坐标内.");
}
} else {
p.sendMessage(Main.prefix + "添加失败,指向的物品类型不是箱子.");
}
} else if (args[0].equalsIgnoreCase("del") && sender.isOp()) {
Block targetBlock = p.getTargetBlock(null, 5);
if (targetBlock != null && targetBlock.getType() == Material.CHEST) {
String loc = getLoc(targetBlock);
if (Main.previewList.contains(loc)) {
List<String> list = Main.previewList;
list.remove(loc);
Main.plugin.getConfig().set("ChestLoc", list);
Main.plugin.saveConfig();
p.sendMessage(Main.prefix + "已删除箱子展示箱 §7#" + loc);
} else {
p.sendMessage(Main.prefix + "此箱子不存在展示坐标内.");
}
} else {
p.sendMessage(Main.prefix + "删除失败,指向的物品类型不是箱子.");
}
}
}
return false;
}
private static String getLoc(Block targetBlock) {
Location chestLocation = targetBlock.getLocation();
String world = chestLocation.getWorld().getName();
int x = chestLocation.getBlockX();
int y = chestLocation.getBlockY();
int z = chestLocation.getBlockZ();
return world + "," + x + "," + y + "," + z;
}
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> list = new ArrayList<>();
if (args.length == 1) {
if (sender.isOp()) {
list.add("add");
list.add("del");
}
return list;
}
return null;
}
}

View File

@ -0,0 +1,43 @@
package me.Demon.DemonChestPreview.Listener;
import me.Demon.DemonChestPreview.Main;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
public class PreviewEvent implements Listener {
@EventHandler
public void onChestClick(InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if (inv.getHolder() instanceof BlockState) {
BlockState blockState = (BlockState) inv.getHolder();
Location chestLocation = blockState.getLocation();
String world = chestLocation.getWorld().getName();
int x = chestLocation.getBlockX();
int y = chestLocation.getBlockY();
int z = chestLocation.getBlockZ();
String loc = world + "," + x + "," + y + "," + z;
if (Main.previewList.contains(loc)) {
if (inv.getType() == InventoryType.CHEST && !p.isOp()) {
if (e.getClick() == ClickType.DOUBLE_CLICK || e.getClick() == ClickType.SHIFT_LEFT || e.getClick() == ClickType.SHIFT_RIGHT) {
e.setCancelled(true);
p.closeInventory();
p.sendMessage("§7点击速度过快,请慢一点。");
p.playSound(p.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1.0F, 2.0F);
return;
}
e.setCancelled(true);
}
}
}
}
}

View File

@ -0,0 +1,33 @@
package me.Demon.DemonChestPreview;
import me.Demon.DemonChestPreview.Command.ChestCommand;
import me.Demon.DemonChestPreview.Listener.PreviewEvent;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
public class Main extends JavaPlugin {
public static Main plugin;
public static String prefix = "§7[§6箱子展示§7] §f";
public static List<String> previewList = new ArrayList<>();
public void onEnable() {
plugin = this;
saveDefaultConfig();
Bukkit.getServer().getPluginManager().registerEvents(new PreviewEvent(), plugin);
getCommand("dcpreview").setExecutor(new ChestCommand());
getCommand("dcpreview").setTabCompleter(new ChestCommand());
previewList.addAll(getConfig().getStringList("ChestLoc"));
Bukkit.getConsoleSender().sendMessage("§f[§6!§f] §aDemonChestPreview (" + this.getDescription().getVersion() + ") §f开始加载");
Bukkit.getConsoleSender().sendMessage("§f[§6!§f] §b已加载展示箱: §f" + previewList.size() + " §b个");
Bukkit.getConsoleSender().sendMessage("§f[§6!§f] §aDemonChestPreview §f加载完成,祝你使用愉快!");
Bukkit.getConsoleSender().sendMessage("§f[§6!§f] §f作者QQ号: §c32282861");
}
public void onDisable() {
Bukkit.getConsoleSender().sendMessage("§f[§6!§f] §eDemonChestPreview §c卸载完成,下次再见!");
}
}

View File

@ -0,0 +1 @@
ChestLoc: {}

View File

@ -0,0 +1,5 @@
name: DemonChestPreview
main: me.Demon.DemonChestPreview.Main
version: 1.0
commands:
dcpreview: