Skip to content

Commit

Permalink
Merge branch 'main' into dev/m1sk9--support-minecraft-1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
m1sk9 authored Nov 8, 2024
2 parents 4fa53d0 + bcd2fd6 commit 12da097
Show file tree
Hide file tree
Showing 68 changed files with 2,307 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import space.yurisi.universecorev2.item.LevellingCustomItem;
import space.yurisi.universecorev2.item.UniverseItem;
import space.yurisi.universecorev2.item.ticket.GachaTicket;
import space.yurisi.universecorev2.item.ticket.GunTicket;
import space.yurisi.universecorev2.utils.Message;

import java.util.ArrayList;
Expand All @@ -36,7 +37,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
§6-- Give Universe Item Help --
§7/giveu add <ID> [レベル] [アイテム数] : 指定されたIDのアイテムをインベントリに追加します
§7/giveu list : 入手可能なアイテムのリストを表示します
§7/giveu ticket [枚数] : チケットを指定した枚数分インベントリに追加します
§7/giveu ticket <gacha | gun> [枚数] : ガチャや銃のチケットを指定した枚数分インベントリに追加します
§7/giveu help : このヘルプを表示します
""".split("\n");

Expand Down Expand Up @@ -99,12 +100,27 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
int amount;

if (args.length < 2) {
Message.sendErrorMessage(player, "[管理AI]", "チケットの種類をgachaかgunで指定してください。");
return false;
}

if(args.length < 3){
Message.sendErrorMessage(player, "[管理AI]", "枚数を指定してください。");
}

String ticketType = args[1];
ItemStack ticket;
if(ticketType.equalsIgnoreCase("gacha")){
ticket = UniverseItem.getItem(GachaTicket.id).getItem();
} else if(ticketType.equalsIgnoreCase("gun")) {
ticket = UniverseItem.getItem(GunTicket.id).getItem();
} else {
Message.sendErrorMessage(player, "[管理AI]", "チケットの種類をgachaかgunで指定してください。");
return false;
}

try {
amount = Integer.parseInt(args[1]);
amount = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
Message.sendErrorMessage(player, "[管理AI]", "枚数は数値で指定してください。");
return false;
Expand All @@ -115,7 +131,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return false;
}

ItemStack ticket = UniverseItem.getItem(GachaTicket.id).getItem();
for (int i = 1; i <= amount; i++) {
player.getInventory().addItem(ticket);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class UniverseItemKeyString {
public static final String ITEM_NAME = "item_name";
public static final String LEVEL = "level";
public static final String GACHA_TICKET = "gacha_ticket";
public static final String GUN_TICKET = "gun_ticket";
public static final String FISH = "fish";
public static final String FISH_SIZE = "fish_size";
public static final String GUN = "gun";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Long getAmmoFromUserId(Long user_id, GunType gunType) throws AmmoNotFound
case SG -> {
return ammo.getSg();
}
case SR -> {
case SR, SR_BOLT, SR_SEMI -> {
return ammo.getSr();
}
case LMG -> {
Expand Down Expand Up @@ -152,7 +152,7 @@ public void updateAmmo(Long user_id, Long newAmmo, GunType gunType) throws AmmoN
case SMG -> ammo.setSmg(newAmmo);
case AR -> ammo.setAr(newAmmo);
case SG -> ammo.setSg(newAmmo);
case SR -> ammo.setSr(newAmmo);
case SR, SR_BOLT, SR_SEMI -> ammo.setSr(newAmmo);
case LMG -> ammo.setLmg(newAmmo);
case EX -> ammo.setEx(newAmmo);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package space.yurisi.universecorev2.event.entity;

import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent;

public class ChangeBlockEvent implements Listener {

@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
if(event.getEntity().getType() == EntityType.ENDERMAN) {
event.setCancelled(true);
}
}
}
44 changes: 39 additions & 5 deletions src/main/java/space/yurisi/universecorev2/item/UniverseItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import space.yurisi.universecorev2.item.solar_system.*;
import space.yurisi.universecorev2.item.stick.BlockCopyStick;
import space.yurisi.universecorev2.item.ticket.GachaTicket;
import space.yurisi.universecorev2.item.ticket.GunTicket;
import space.yurisi.universecorev2.menu.MainMenu;

import java.util.HashMap;
Expand All @@ -39,6 +40,7 @@ public void register(){
items.put(SolarSystemLeggings.id, new SolarSystemLeggings());
items.put(SolarSystemBoots.id, new SolarSystemBoots());
items.put(GachaTicket.id, new GachaTicket());
items.put(GunTicket.id, new GunTicket());
items.put(RepairCream.id, new RepairCream());
items.put(BlockCopyStick.id, new BlockCopyStick());
items.put(FishingRod.id, new FishingRod());
Expand All @@ -52,6 +54,7 @@ public void register(){
items.put(M1911.id, new M1911());
items.put(MagazineBag.id, new MagazineBag());
items.put(TacticalLeggings.id, new TacticalLeggings());
items.put(TacticalVest.id, new TacticalVest());
items.put(MainMenuBook.id, new MainMenuBook());
}

Expand Down Expand Up @@ -90,9 +93,11 @@ public static Boolean isLevelingItem(ItemStack itemStack){
}


public static Boolean removeItem(Player player, String item_name){
public static Boolean removeItem(Player player, String item_name, int amount){
PlayerInventory inventory = player.getInventory();
NamespacedKey itemKey = new NamespacedKey(UniverseCoreV2.getInstance(), UniverseItemKeyString.ITEM_NAME);
int remainingAmount = amount;
int totalAmount = 0;

for (ItemStack item : inventory.getContents()) {
if (item != null && item.hasItemMeta()) {
Expand All @@ -103,12 +108,41 @@ public static Boolean removeItem(Player player, String item_name){
String isGachaTicket = container.get(itemKey, PersistentDataType.STRING);

if (Objects.equals(isGachaTicket, item_name)) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
totalAmount += item.getAmount();
if(totalAmount >= amount){
break;
}
}
}
}
}

if (totalAmount < amount) {
return false;
}

for (ItemStack item : inventory.getContents()) {
if (item != null && item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();

if (container.has(itemKey, PersistentDataType.STRING)) {
String isGachaTicket = container.get(itemKey, PersistentDataType.STRING);

if (Objects.equals(isGachaTicket, item_name)) {
int itemAmount = item.getAmount();
if (itemAmount <= remainingAmount) {
remainingAmount -= itemAmount;
player.sendMessage(remainingAmount + " " + item_name);
item.setAmount(0);
} else {
inventory.remove(item);
item.setAmount(itemAmount - remainingAmount);
remainingAmount = 0;
}

if (remainingAmount == 0) {
return true;
}
return true;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/space/yurisi/universecorev2/item/gun/F2.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public F2() {
);

this.type = GunType.AR;
this.equipmentType = GunType.PRIMARY;
this.magazineSize = 30;
this.burst = 2;
this.reloadTime = 3500;
Expand All @@ -38,14 +39,16 @@ public F2() {
this.volumeSound = 5.0F;
this.pitchSound = 0.8F;
this.flavorText = "§7フランスで開発された3点バースト式のアサルトライフル。高いレートと命中精度が特徴";
this.textureNumber = 5;
this.price = 4;
}

@Override
protected void registerItemFunction(){
default_setting = (item) -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setCustomModelData(5);
meta.setCustomModelData(textureNumber);
}
item.setItemMeta(meta);
return item;
Expand Down
57 changes: 47 additions & 10 deletions src/main/java/space/yurisi/universecorev2/item/gun/Gun.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import space.yurisi.universecorev2.UniverseCoreV2;
import space.yurisi.universecorev2.constants.UniverseItemKeyString;
import space.yurisi.universecorev2.item.CustomItem;
import space.yurisi.universecorev2.item.UniverseItem;
import space.yurisi.universecorev2.subplugins.universeguns.constants.GunType;

import java.util.List;
Expand All @@ -20,6 +21,8 @@ public abstract class Gun extends CustomItem {

protected GunType type;

protected GunType equipmentType;

protected int magazineSize;

protected int burst;
Expand Down Expand Up @@ -63,6 +66,10 @@ public abstract class Gun extends CustomItem {

protected String flavorText;

protected int textureNumber;

protected int price;

public Gun(String id, String name, ItemStack baseItem) {
super(id, name, baseItem);
}
Expand All @@ -71,6 +78,10 @@ public GunType getType(){
return this.type;
}

public GunType getEquipmentType(){
return this.equipmentType;
}

public int getMagazineSize(){
return this.magazineSize;
}
Expand Down Expand Up @@ -144,6 +155,18 @@ public float getPitchSound(){
return pitchSound;
}

public String getFlavorText(){
return flavorText;
}

public int getTextureNumber(){
return textureNumber;
}

public int getPrice(){
return price;
}

@Override
public ItemStack getItem(){
ItemStack item = getBaseItem().clone();
Expand All @@ -153,14 +176,14 @@ public ItemStack getItem(){
container.set(new NamespacedKey(UniverseCoreV2.getInstance(), UniverseItemKeyString.GUN), PersistentDataType.BOOLEAN, true);
container.set(new NamespacedKey(UniverseCoreV2.getInstance(), UniverseItemKeyString.GUN_SERIAL), PersistentDataType.STRING, UUID.randomUUID().toString());
meta.displayName(Component.text(name));
List<Component> lore = getComponents();
List<Component> lore = getGunComponents();
meta.lore(lore);
item.setItemMeta(meta);
return default_setting.apply(item);
}

private @NotNull List<Component> getComponents() {
String category = "§7カテゴリ: ";
public @NotNull List<Component> getGunComponents() {
String category = "§7カテゴリ: §b";
switch (type){
case AR:
category += "アサルトライフル";
Expand All @@ -171,7 +194,7 @@ public ItemStack getItem(){
case SG:
category += "ショットガン";
break;
case SR:
case SR, SR_SEMI, SR_BOLT:
category += "スナイパーライフル";
break;
case HG:
Expand All @@ -184,16 +207,25 @@ public ItemStack getItem(){
category += "特殊系";
break;
}
String equipmentCategory = "§7装備カテゴリ: §b";
switch (equipmentType){
case PRIMARY:
equipmentCategory += "プライマリ";
break;
case SECONDARY:
equipmentCategory += "セカンダリ";
break;
}
List<Component> lore = List.of(
Component.text(category),
Component.text("§7マガジンサイズ: " + magazineSize),
Component.text(7リロード時間: " + (double)reloadTime/1000 + "s"),
Component.text(flavorText)
Component.text(equipmentCategory),
Component.text(7マガジンサイズ: §b" + magazineSize),
Component.text("§7リロード時間: §b" + (double)reloadTime/1000 + "§7秒")
);
return lore;
}

public static boolean isGun(ItemStack itemStack){
public static Gun getGun(ItemStack itemStack){
ItemMeta meta = itemStack.getItemMeta();

PersistentDataContainer container = meta.getPersistentDataContainer();
Expand All @@ -206,8 +238,13 @@ public static boolean isGun(ItemStack itemStack){
|| !container.has(gunKey, PersistentDataType.BOOLEAN)
|| !container.has(gunSerialKey, PersistentDataType.STRING)
){
return false;
return null;
}
String itemID = container.get(itemKey, PersistentDataType.STRING);
CustomItem item = UniverseItem.getItem(itemID);
if((item instanceof Gun gun)){
return gun;
}
return true;
return null;
}
}
7 changes: 5 additions & 2 deletions src/main/java/space/yurisi/universecorev2/item/gun/L96A1.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public L96A1() {
ItemStack.of(Material.DIAMOND_HOE)
);

this.type = GunType.SR;
this.type = GunType.SR_BOLT;
this.equipmentType = GunType.PRIMARY;
this.magazineSize = 5;
this.burst = 0;
this.reloadTime = 5000;
Expand All @@ -37,14 +38,16 @@ public L96A1() {
this.volumeSound = 10.0F;
this.pitchSound = 0.8F;
this.flavorText = "§7イギリスで使用される軍用ボルトアクション式スナイパーライフル";
this.textureNumber = 2;
this.price = 10;
}

@Override
protected void registerItemFunction(){
default_setting = (item) -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setCustomModelData(2);
meta.setCustomModelData(textureNumber);
}
item.setItemMeta(meta);
return item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public M1911(){
);

this.type = GunType.HG;
this.equipmentType = GunType.SECONDARY;
this.magazineSize = 7;
this.burst = 0;
this.reloadTime = 800;
Expand All @@ -38,14 +39,16 @@ public M1911(){
this.volumeSound = 5.0F;
this.pitchSound = 2.0F;
this.flavorText = "§7アメリカで開発された自動拳銃。第一次世界大戦時代に生まれ、現在でも多くの国で使用されている";
this.textureNumber = 7;
this.price = 1;
}

@Override
protected void registerItemFunction(){
default_setting = (item) -> {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setCustomModelData(7);
meta.setCustomModelData(textureNumber);
}
item.setItemMeta(meta);
return item;
Expand Down
Loading

0 comments on commit 12da097

Please sign in to comment.