-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
726001e
commit 66dafb0
Showing
8 changed files
with
276 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/mori01231/lifecore/command/TrashProtectCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.mori01231.lifecore.command; | ||
|
||
import com.github.mori01231.lifecore.LifeCore; | ||
import com.github.mori01231.lifecore.gui.TrashProtectScreen; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabExecutor; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class TrashProtectCommand implements TabExecutor { | ||
private final LifeCore plugin; | ||
|
||
public TrashProtectCommand(@NotNull LifeCore plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (!(sender instanceof Player)) { | ||
sender.sendMessage("This command can only be executed by players."); | ||
return true; | ||
} | ||
Player player = (Player) sender; | ||
player.openInventory(new TrashProtectScreen(plugin, player).getInventory()); | ||
return true; | ||
} | ||
|
||
@Override | ||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { | ||
return Collections.emptyList(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/github/mori01231/lifecore/config/TrashProtectConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.mori01231.lifecore.config | ||
|
||
import kotlinx.serialization.Serializable | ||
import java.util.UUID | ||
|
||
@Serializable | ||
data class TrashProtectConfig( | ||
val players: MutableMap<String, MutableSet<String>> = mutableMapOf(), | ||
) { | ||
/** | ||
* Returns the mutable set of rarities that the player has enabled drop protection for. | ||
*/ | ||
operator fun get(uuid: UUID): MutableSet<String> = | ||
players.computeIfAbsent(uuid.toString()) { mutableSetOf() } | ||
|
||
/** | ||
* Returns true if the player has enabled drop protection for the given rarity. | ||
*/ | ||
fun contains(uuid: UUID, item: String): Boolean { | ||
return this[uuid].contains(item) | ||
} | ||
|
||
/** | ||
* Toggles the drop protection for the given rarity for the given player. | ||
*/ | ||
fun toggle(uuid: UUID, item: String) { | ||
if (contains(uuid, item)) { | ||
this[uuid].remove(item) | ||
} else { | ||
this[uuid].add(item) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
src/main/java/com/github/mori01231/lifecore/gui/TrashProtectScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package com.github.mori01231.lifecore.gui; | ||
|
||
import com.github.mori01231.lifecore.LifeCore; | ||
import com.github.mori01231.lifecore.util.ItemUtil; | ||
import net.azisaba.rarity.api.RarityAPIProvider; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Material; | ||
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.InventoryHolder; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collections; | ||
|
||
public class TrashProtectScreen implements InventoryHolder { | ||
private final Inventory inventory = Bukkit.createInventory(this, 9, "TrashProtect"); | ||
private final LifeCore plugin; | ||
private final Player player; | ||
|
||
public TrashProtectScreen(@NotNull LifeCore plugin, @NotNull Player player) { | ||
this.plugin = plugin; | ||
this.player = player; | ||
reset(); | ||
} | ||
|
||
public void reset() { | ||
String noRarityLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "no_rarity") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
String commonName = RarityAPIProvider.get().getRarityById("common").getDisplayName(player); | ||
String commonLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "common") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
String uncommonName = RarityAPIProvider.get().getRarityById("uncommon").getDisplayName(player); | ||
String uncommonLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "uncommon") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
String rareName = RarityAPIProvider.get().getRarityById("rare").getDisplayName(player); | ||
String rareLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "rare") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
String epicName = RarityAPIProvider.get().getRarityById("epic").getDisplayName(player); | ||
String epicLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "epic") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
String legendaryName = RarityAPIProvider.get().getRarityById("legendary").getDisplayName(player); | ||
String legendaryLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "legendary") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
String mythicName = RarityAPIProvider.get().getRarityById("mythic").getDisplayName(player); | ||
String mythicLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "mythic") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
String specialName = RarityAPIProvider.get().getRarityById("special").getDisplayName(player); | ||
String specialLore = plugin.getTrashProtectConfig().contains(player.getUniqueId(), "special") ? ChatColor.GREEN + "有効" : ChatColor.RED + "無効"; | ||
inventory.setItem(0, ItemUtil.createItemStack(Material.PAPER, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.WHITE + "レア度が付与されていないアイテム"); | ||
meta.setLore(Collections.singletonList(noRarityLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(1, ItemUtil.createItemStack(Material.COBBLESTONE, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', commonName)); | ||
meta.setLore(Collections.singletonList(commonLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(2, ItemUtil.createItemStack(Material.IRON_BLOCK, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', uncommonName)); | ||
meta.setLore(Collections.singletonList(uncommonLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(3, ItemUtil.createItemStack(Material.GOLD_BLOCK, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', rareName)); | ||
meta.setLore(Collections.singletonList(rareLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(4, ItemUtil.createItemStack(Material.EMERALD_BLOCK, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', epicName)); | ||
meta.setLore(Collections.singletonList(epicLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(5, ItemUtil.createItemStack(Material.DIAMOND_BLOCK, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', legendaryName)); | ||
meta.setLore(Collections.singletonList(legendaryLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(6, ItemUtil.createItemStack(Material.ENCHANTED_GOLDEN_APPLE, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', mythicName)); | ||
meta.setLore(Collections.singletonList(mythicLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(7, ItemUtil.createItemStack(Material.NETHER_STAR, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', specialName)); | ||
meta.setLore(Collections.singletonList(specialLore)); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
inventory.setItem(8, ItemUtil.createItemStack(Material.BARRIER, 1, item -> { | ||
ItemMeta meta = item.getItemMeta(); | ||
if (meta != null) { | ||
meta.setDisplayName(ChatColor.RED + "閉じる"); | ||
item.setItemMeta(meta); | ||
} | ||
})); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Inventory getInventory() { | ||
return inventory; | ||
} | ||
|
||
public static class EventListener implements Listener { | ||
private final LifeCore plugin; | ||
|
||
public EventListener(@NotNull LifeCore plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@EventHandler | ||
public void onClick(InventoryClickEvent e) { | ||
if (!(e.getInventory().getHolder() instanceof TrashProtectScreen)) { | ||
return; | ||
} | ||
e.setCancelled(true); | ||
if (e.getClickedInventory() == null || !(e.getClickedInventory().getHolder() instanceof TrashProtectScreen)) { | ||
return; | ||
} | ||
TrashProtectScreen screen = (TrashProtectScreen) e.getInventory().getHolder(); | ||
switch (e.getSlot()) { | ||
case 0: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "no_rarity"); | ||
break; | ||
} | ||
case 1: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "common"); | ||
break; | ||
} | ||
case 2: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "uncommon"); | ||
break; | ||
} | ||
case 3: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "rare"); | ||
break; | ||
} | ||
case 4: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "epic"); | ||
break; | ||
} | ||
case 5: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "legendary"); | ||
break; | ||
} | ||
case 6: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "mythic"); | ||
break; | ||
} | ||
case 7: { | ||
plugin.getTrashProtectConfig().toggle(screen.player.getUniqueId(), "special"); | ||
break; | ||
} | ||
case 8: { | ||
screen.player.closeInventory(); | ||
return; | ||
} | ||
} | ||
screen.reset(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters