Skip to content

Commit a04cdfb

Browse files
committed
版本更新至:3.73
重写:Language2 模块重写,允许单项语言多种类型 新增:Language2 工具新增 [sound] 类型! 新增:BookFormatter 工具,代码来自其他开源项目,代码已经过 60% 的重新开发。
1 parent 3534343 commit a04cdfb

21 files changed

+1386
-165
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package me.skymc.taboolib.bookformatter;
2+
3+
import org.bukkit.Achievement;
4+
5+
import java.util.HashMap;
6+
7+
import static org.bukkit.Achievement.*;
8+
9+
@SuppressWarnings("deprecation")
10+
public final class BookAchievement {
11+
12+
private static final HashMap<Achievement, String> achievements = new HashMap<>();
13+
14+
static {
15+
achievements.put(OPEN_INVENTORY, "openInventory");
16+
achievements.put(MINE_WOOD, "mineWood");
17+
achievements.put(BUILD_WORKBENCH, "buildWorkBench");
18+
achievements.put(BUILD_PICKAXE, "buildPickaxe");
19+
achievements.put(BUILD_FURNACE, "buildFurnace");
20+
achievements.put(ACQUIRE_IRON, "aquireIron");
21+
achievements.put(BUILD_HOE, "buildHoe");
22+
achievements.put(MAKE_BREAD, "makeBread");
23+
achievements.put(BAKE_CAKE,"bakeCake");
24+
achievements.put(BUILD_BETTER_PICKAXE,"buildBetterPickaxe");
25+
achievements.put(COOK_FISH,"cookFish");
26+
achievements.put(ON_A_RAIL,"onARail");
27+
achievements.put(BUILD_SWORD,"buildSword");
28+
achievements.put(KILL_ENEMY,"killEnemy");
29+
achievements.put(KILL_COW,"killCow");
30+
achievements.put(FLY_PIG,"flyPig");
31+
achievements.put(SNIPE_SKELETON,"snipeSkeleton");
32+
achievements.put(GET_DIAMONDS,"diamonds");
33+
achievements.put(NETHER_PORTAL,"portal");
34+
achievements.put(GHAST_RETURN,"ghast");
35+
achievements.put(GET_BLAZE_ROD,"blazerod");
36+
achievements.put(BREW_POTION,"potion");
37+
achievements.put(END_PORTAL,"thEnd");
38+
achievements.put(THE_END,"theEnd2");
39+
achievements.put(ENCHANTMENTS,"enchantments");
40+
achievements.put(OVERKILL,"overkill");
41+
achievements.put(BOOKCASE,"bookacase");
42+
achievements.put(EXPLORE_ALL_BIOMES,"exploreAllBiomes");
43+
achievements.put(SPAWN_WITHER,"spawnWither");
44+
achievements.put(KILL_WITHER,"killWither");
45+
achievements.put(FULL_BEACON,"fullBeacon");
46+
achievements.put(BREED_COW,"breedCow");
47+
achievements.put(DIAMONDS_TO_YOU,"diamondsToYou");
48+
achievements.put(OVERPOWERED, "overpowered");
49+
}
50+
51+
/**
52+
* Gets the json id from the bukkit achievement passed as argument
53+
* @param achievement the achievement
54+
* @return the achievement's id or null if not found
55+
*/
56+
public static String toId(Achievement achievement) {
57+
return achievements.get(achievement);
58+
}
59+
60+
private BookAchievement(){
61+
62+
}
63+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package me.skymc.taboolib.bookformatter;
2+
3+
import me.skymc.taboolib.bookformatter.builder.BookBuilder;
4+
import me.skymc.taboolib.events.CustomBookOpenEvent;
5+
6+
import org.bukkit.Bukkit;
7+
import org.bukkit.Material;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.inventory.ItemStack;
10+
11+
@SuppressWarnings("deprecation")
12+
public final class BookFormatter {
13+
14+
/**
15+
* Opens a book GUI to the player
16+
* @param p the player
17+
* @param book the book to be opened
18+
*/
19+
public static void openPlayer(Player p, ItemStack book) {
20+
CustomBookOpenEvent event = new CustomBookOpenEvent(p, book, false);
21+
//Call the CustomBookOpenEvent
22+
Bukkit.getPluginManager().callEvent(event);
23+
//Check if it's cancelled
24+
if(event.isCancelled()) {
25+
return;
26+
}
27+
28+
//Close inventory currently
29+
p.closeInventory();
30+
//Store the previous item
31+
ItemStack hand = p.getItemInHand();
32+
p.setItemInHand(event.getBook());
33+
34+
//Opening the GUI
35+
BookReflection.openBook(p, event.getBook(), event.getHand() == CustomBookOpenEvent.Hand.OFF_HAND);
36+
37+
//Returning whatever was on hand.
38+
p.setItemInHand(hand);
39+
}
40+
41+
/**
42+
* Opens a book GUI to the player, Bypass the {@link CustomBookOpenEvent}
43+
* @param p the player
44+
* @param book the book to be opened
45+
*/
46+
public static void forceOpen(Player p, ItemStack book) {
47+
//Close inventory currently
48+
p.closeInventory();
49+
//Store the previous item
50+
ItemStack hand = p.getItemInHand();
51+
p.setItemInHand(book);
52+
53+
//Opening the GUI
54+
BookReflection.openBook(p, book, false);
55+
56+
//Returning whatever was on hand.
57+
p.setItemInHand(hand);
58+
}
59+
60+
/**
61+
* Creates a BookBuilder instance with a written book as the Itemstack's type
62+
* @return
63+
*/
64+
public static BookBuilder writtenBook() {
65+
return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK));
66+
}
67+
68+
/**
69+
* Creates a BookBuilder instance with a written book as the Itemstack's type
70+
* @return
71+
*/
72+
public static BookBuilder writtenBook(String title, String author) {
73+
return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK), title, author);
74+
}
75+
}

0 commit comments

Comments
 (0)