Skip to content

Commit

Permalink
新增页码滚动功能和直接打开不同页码的指令
Browse files Browse the repository at this point in the history
  • Loading branch information
KlNon committed Aug 20, 2022
1 parent 792071a commit 31056ed
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.example</groupId>
<artifactId>clearItem</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.2.2-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
Expand Down
40 changes: 23 additions & 17 deletions src/main/java/com/mcsyr/clearitem/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -140,24 +141,29 @@ public void onInventoryClose(InventoryCloseEvent event) {
// 上下页(标题相同)
public void onPageClick(InventoryClickEvent event){
if(event.getView().getTitle().startsWith(Main.PublicDustbinName)){
if(event.getCurrentItem().getItemMeta().getDisplayName().equals(Main.PublicDustbinPrePageName)){
event.setCancelled(true);
int count=Integer.parseInt(event.getView().getTitle().substring(event.getView().getTitle().length()-2,event.getView().getTitle().length()-1))-1;
if(count>0){
count--;
}
Player player = (Player) event.getWhoClicked();
player.closeInventory();
player.openInventory(Dustbin.DustbinList.get(count));
}else if(event.getCurrentItem().getItemMeta().getDisplayName().equals(Main.PublicDustbinNextPageName)){
event.setCancelled(true);
int count=Integer.parseInt(event.getView().getTitle().substring(event.getView().getTitle().length()-2,event.getView().getTitle().length()-1))-1;
if(count<Dustbin.DustbinList.size()-1){
count++;
if(event.getCurrentItem().hasItemMeta() && event.getCurrentItem().getItemMeta().hasDisplayName()){
if(event.getCurrentItem().getItemMeta().getDisplayName().equals(Main.PublicDustbinPrePageName)){
event.setCancelled(true);
int count=Integer.parseInt(event.getView().getTitle().substring(event.getView().getTitle().length()-2,event.getView().getTitle().length()-1))-1;
if(count>0){
count--;
}else {
count=Dustbin.DustbinList.size()-1;
}
Player player = (Player) event.getWhoClicked();
player.closeInventory();
player.openInventory(Dustbin.DustbinList.get(count));
}else if(event.getCurrentItem().getItemMeta().getDisplayName().equals(Main.PublicDustbinNextPageName)){
event.setCancelled(true);
int count=Integer.parseInt(event.getView().getTitle().substring(event.getView().getTitle().length()-2,event.getView().getTitle().length()-1))-1;
if(count<Dustbin.DustbinList.size()-1){
count++;
}else
count=0;
Player player = (Player) event.getWhoClicked();
player.closeInventory();
player.openInventory(Dustbin.DustbinList.get(count));
}
Player player = (Player) event.getWhoClicked();
player.closeInventory();
player.openInventory(Dustbin.DustbinList.get(count));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mcsyr/clearitem/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class Main extends JavaPlugin {

public static Map<Player, Inventory> PlayerPrivateDustbin = new HashMap<>();

public static String Version = "3.2.1";
public static String Version = "3.2.2";

public Main() {
}
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/mcsyr/clearitem/command.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
Player player = (Player)sender;
if (args[0].equalsIgnoreCase("open")) {
if (Main.PublicDustbinEnable) {

((Player)sender).openInventory(Dustbin.DustbinList.get(0));
sender.sendMessage(Main.PublicDustbinAction + Main.PublicDustbinName);
} else {
Expand Down Expand Up @@ -74,9 +73,24 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
if (args[0].equalsIgnoreCase("clean")) {
sender.sendMessage("§b[ClearItem] §f公共垃圾桶清理中");
tools.cleanPublicDustbin();
Dustbin.page();
return true;
}
}
}else if(args.length==2){
Player player = (Player)sender;
if (args[0].equalsIgnoreCase("open")) {
int num=Integer.parseInt(args[1]);
if(Character.isDigit(num)&&Main.PublicDustbinEnable){

player.openInventory(Dustbin.DustbinList.get((num-1)%5));
sender.sendMessage(Main.PublicDustbinAction + Main.PublicDustbinName);
}else {
sender.sendMessage( "公共垃圾箱已被服务器禁用!");
}

return true;
}
}

this.showHelp(sender);
Expand All @@ -102,6 +116,9 @@ private void showHelp(CommandSender sender) {
sender.sendMessage(Main.PublicDustbinName + " §f打开公共垃圾箱");
sender.sendMessage(Main.PublicDustbinName + " §f§l/citem open");
sender.sendMessage("§7");
sender.sendMessage(Main.PublicDustbinName + " §f打开公共垃圾箱具体页");
sender.sendMessage(Main.PublicDustbinName + " §f§l/citem open [num]");
sender.sendMessage("§7");
sender.sendMessage(Main.PublicDustbinName + " §f打开私人垃圾箱");
sender.sendMessage(Main.PublicDustbinName + " §f§l/citem discard");
sender.sendMessage("§7");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ClearItem
main: com.mcsyr.clearitem.Main
softdepend: [PlaceholderAPI]
version: 3.2.1-SNAPSHOT
version: 3.2.2-SNAPSHOT
author: Luo_ma & KlNon
commands:
clearitem:
Expand Down
Binary file removed target/classes/com/mcsyr/clearitem/Event.class
Binary file not shown.
Binary file removed target/classes/com/mcsyr/clearitem/command.class
Binary file not shown.

0 comments on commit 31056ed

Please sign in to comment.