mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-09 17:53:17 +08:00
Fix whitespace [skip actions]
This commit is contained in:
parent
d1d39db56c
commit
025e5d3c1c
@ -246,7 +246,7 @@ public final class Grasscutter {
|
||||
public static Language getLanguage(String langCode) {
|
||||
return Language.getLanguage(langCode);
|
||||
}
|
||||
|
||||
|
||||
public static ServerRunMode getRunMode() {
|
||||
return Grasscutter.runModeOverride != null ? Grasscutter.runModeOverride : SERVER.runMode;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ public class ResourceLoader {
|
||||
GameData.proudSkillGroupLevels
|
||||
.computeIfAbsent(data.getProudSkillGroupId(), i -> new IntArraySet())
|
||||
.add(data.getLevel()));
|
||||
GameData.getAvatarSkillDataMap().forEach((id, data) ->
|
||||
GameData.getAvatarSkillDataMap().forEach((id, data) ->
|
||||
GameData.avatarSkillLevels.put((int) id, GameData.proudSkillGroupLevels.get(data.getProudSkillGroupId())));
|
||||
}
|
||||
|
||||
|
@ -10,39 +10,39 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
@ResourceType(name = "DailyDungeonConfigData.json")
|
||||
public class DailyDungeonData extends GameResource {
|
||||
private int id;
|
||||
private int[] monday;
|
||||
private int[] tuesday;
|
||||
private int[] wednesday;
|
||||
private int[] thursday;
|
||||
private int[] friday;
|
||||
private int[] saturday;
|
||||
private int[] sunday;
|
||||
|
||||
private static final int[] empty = new int[0];
|
||||
private final Int2ObjectMap<int[]> map;
|
||||
|
||||
public DailyDungeonData() {
|
||||
this.map = new Int2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int[] getDungeonsByDay(int day) {
|
||||
return map.getOrDefault(day, empty);
|
||||
}
|
||||
private int id;
|
||||
private int[] monday;
|
||||
private int[] tuesday;
|
||||
private int[] wednesday;
|
||||
private int[] thursday;
|
||||
private int[] friday;
|
||||
private int[] saturday;
|
||||
private int[] sunday;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
map.put(Calendar.MONDAY, monday);
|
||||
map.put(Calendar.TUESDAY, tuesday);
|
||||
map.put(Calendar.WEDNESDAY, wednesday);
|
||||
map.put(Calendar.THURSDAY, thursday);
|
||||
map.put(Calendar.FRIDAY, friday);
|
||||
map.put(Calendar.SATURDAY, saturday);
|
||||
map.put(Calendar.SUNDAY, sunday);
|
||||
}
|
||||
private static final int[] empty = new int[0];
|
||||
private final Int2ObjectMap<int[]> map;
|
||||
|
||||
public DailyDungeonData() {
|
||||
this.map = new Int2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int[] getDungeonsByDay(int day) {
|
||||
return map.getOrDefault(day, empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
map.put(Calendar.MONDAY, monday);
|
||||
map.put(Calendar.TUESDAY, tuesday);
|
||||
map.put(Calendar.WEDNESDAY, wednesday);
|
||||
map.put(Calendar.THURSDAY, thursday);
|
||||
map.put(Calendar.FRIDAY, friday);
|
||||
map.put(Calendar.SATURDAY, saturday);
|
||||
map.put(Calendar.SUNDAY, sunday);
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ public class ItemData extends GameResource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Getter
|
||||
public static class WeaponProperty {
|
||||
private FightProperty propType;
|
||||
|
@ -50,10 +50,10 @@ public final class DatabaseManager {
|
||||
// Set mapper options.
|
||||
MapperOptions mapperOptions = MapperOptions.builder()
|
||||
.storeEmpties(true).storeNulls(false).build();
|
||||
|
||||
|
||||
// Create data store.
|
||||
gameDatastore = Morphia.createDatastore(gameMongoClient, DATABASE.game.collection, mapperOptions);
|
||||
|
||||
|
||||
// Map classes.
|
||||
Class<?>[] entities = new Reflections(Grasscutter.class.getPackageName())
|
||||
.getTypesAnnotatedWith(Entity.class)
|
||||
@ -71,15 +71,15 @@ public final class DatabaseManager {
|
||||
|
||||
if (SERVER.runMode == ServerRunMode.GAME_ONLY) {
|
||||
MongoClient dispatchMongoClient = MongoClients.create(DATABASE.server.connectionUri);
|
||||
|
||||
|
||||
dispatchDatastore = Morphia.createDatastore(dispatchMongoClient, DATABASE.server.collection, mapperOptions);
|
||||
dispatchDatastore.getMapper().map(new Class<?>[] {DatabaseCounter.class, Account.class});
|
||||
|
||||
|
||||
// Ensure indexes for dispatch datastore
|
||||
ensureIndexes(dispatchDatastore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensures the database indexes exist and rebuilds them if there is an error with them
|
||||
* @param datastore The datastore to ensure indexes on
|
||||
|
@ -39,11 +39,11 @@ public class GameHome {
|
||||
ConcurrentHashMap<Integer, HomeSceneItem> sceneMap;
|
||||
Set<Integer> unlockedHomeBgmList;
|
||||
|
||||
public void save(){
|
||||
public void save() {
|
||||
DatabaseHelper.saveHome(this);
|
||||
}
|
||||
|
||||
public static GameHome getByUid(Integer uid){
|
||||
public static GameHome getByUid(Integer uid) {
|
||||
var home = DatabaseHelper.getHomeByUid(uid);
|
||||
if (home == null) {
|
||||
home = GameHome.create(uid);
|
||||
@ -51,7 +51,7 @@ public class GameHome {
|
||||
return home;
|
||||
}
|
||||
|
||||
public static GameHome create(Integer uid){
|
||||
public static GameHome create(Integer uid) {
|
||||
return GameHome.of()
|
||||
.ownerUid(uid)
|
||||
.level(1)
|
||||
@ -62,7 +62,7 @@ public class GameHome {
|
||||
public HomeSceneItem getHomeSceneItem(int sceneId) {
|
||||
return sceneMap.computeIfAbsent(sceneId, e -> {
|
||||
var defaultItem = GameData.getHomeworldDefaultSaveData().get(sceneId);
|
||||
if (defaultItem != null){
|
||||
if (defaultItem != null) {
|
||||
Grasscutter.getLogger().info("Set player {} home {} to initial setting", ownerUid, sceneId);
|
||||
return HomeSceneItem.parseFrom(defaultItem, sceneId);
|
||||
}
|
||||
@ -87,7 +87,7 @@ public class GameHome {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public HomeWorldLevelData getLevelData(){
|
||||
public HomeWorldLevelData getLevelData() {
|
||||
return GameData.getHomeWorldLevelDataMap().get(level);
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,10 @@ public class HomeSceneItem {
|
||||
.build();
|
||||
}
|
||||
|
||||
public void update(HomeSceneArrangementInfo arrangementInfo){
|
||||
for(var blockItem : arrangementInfo.getBlockArrangementInfoListList()){
|
||||
public void update(HomeSceneArrangementInfo arrangementInfo) {
|
||||
for (var blockItem : arrangementInfo.getBlockArrangementInfoListList()) {
|
||||
var block = this.blockItems.get(blockItem.getBlockId());
|
||||
if(block == null){
|
||||
if (block == null) {
|
||||
Grasscutter.getLogger().warn("Could not found the Home Block {}", blockItem.getBlockId());
|
||||
continue;
|
||||
}
|
||||
@ -61,20 +61,20 @@ public class HomeSceneItem {
|
||||
this.tmpVersion = arrangementInfo.getTmpVersion();
|
||||
}
|
||||
|
||||
public int getRoomSceneId(){
|
||||
if(mainHouse == null || mainHouse.getAsItem() == null){
|
||||
public int getRoomSceneId() {
|
||||
if (mainHouse == null || mainHouse.getAsItem() == null) {
|
||||
return 0;
|
||||
}
|
||||
return mainHouse.getAsItem().getRoomSceneId();
|
||||
}
|
||||
|
||||
public int calComfort(){
|
||||
public int calComfort() {
|
||||
return this.blockItems.values().stream()
|
||||
.mapToInt(HomeBlockItem::calComfort)
|
||||
.sum();
|
||||
}
|
||||
|
||||
public HomeSceneArrangementInfo toProto(){
|
||||
public HomeSceneArrangementInfo toProto() {
|
||||
var proto = HomeSceneArrangementInfo.newBuilder();
|
||||
blockItems.values().forEach(b -> proto.addBlockArrangementInfoList(b.toProto()));
|
||||
|
||||
@ -87,7 +87,7 @@ public class HomeSceneItem {
|
||||
.setUnk2700BJHAMKKECEI(homeBgmId)
|
||||
.setTmpVersion(tmpVersion);
|
||||
|
||||
if(mainHouse != null){
|
||||
if (mainHouse != null) {
|
||||
proto.setMainHouse(mainHouse.toProto());
|
||||
}
|
||||
return proto.build();
|
||||
|
@ -39,59 +39,59 @@ import lombok.Setter;
|
||||
|
||||
@Entity(value = "items", useDiscriminator = false)
|
||||
public class GameItem {
|
||||
@Id private ObjectId id;
|
||||
@Indexed private int ownerId;
|
||||
@Getter @Setter private int itemId;
|
||||
@Getter @Setter private int count;
|
||||
|
||||
@Transient @Getter private long guid; // Player unique id
|
||||
@Transient @Getter @Setter private ItemData itemData;
|
||||
|
||||
// Equips
|
||||
@Getter @Setter private int level;
|
||||
@Getter @Setter private int exp;
|
||||
@Getter @Setter private int totalExp;
|
||||
@Getter @Setter private int promoteLevel;
|
||||
@Getter @Setter private boolean locked;
|
||||
|
||||
// Weapon
|
||||
@Getter private List<Integer> affixes;
|
||||
@Getter @Setter private int refinement = 0;
|
||||
|
||||
// Relic
|
||||
@Getter @Setter private int mainPropId;
|
||||
@Getter private List<Integer> appendPropIdList;
|
||||
|
||||
@Getter @Setter private int equipCharacter;
|
||||
@Transient @Getter @Setter private int weaponEntityId;
|
||||
|
||||
public GameItem() {
|
||||
// Morphia only
|
||||
}
|
||||
|
||||
public GameItem(int itemId) {
|
||||
this(GameData.getItemDataMap().get(itemId));
|
||||
}
|
||||
|
||||
public GameItem(int itemId, int count) {
|
||||
this(GameData.getItemDataMap().get(itemId), count);
|
||||
}
|
||||
@Id private ObjectId id;
|
||||
@Indexed private int ownerId;
|
||||
@Getter @Setter private int itemId;
|
||||
@Getter @Setter private int count;
|
||||
|
||||
@Transient @Getter private long guid; // Player unique id
|
||||
@Transient @Getter @Setter private ItemData itemData;
|
||||
|
||||
// Equips
|
||||
@Getter @Setter private int level;
|
||||
@Getter @Setter private int exp;
|
||||
@Getter @Setter private int totalExp;
|
||||
@Getter @Setter private int promoteLevel;
|
||||
@Getter @Setter private boolean locked;
|
||||
|
||||
// Weapon
|
||||
@Getter private List<Integer> affixes;
|
||||
@Getter @Setter private int refinement = 0;
|
||||
|
||||
// Relic
|
||||
@Getter @Setter private int mainPropId;
|
||||
@Getter private List<Integer> appendPropIdList;
|
||||
|
||||
@Getter @Setter private int equipCharacter;
|
||||
@Transient @Getter @Setter private int weaponEntityId;
|
||||
|
||||
public GameItem() {
|
||||
// Morphia only
|
||||
}
|
||||
|
||||
public GameItem(int itemId) {
|
||||
this(GameData.getItemDataMap().get(itemId));
|
||||
}
|
||||
|
||||
public GameItem(int itemId, int count) {
|
||||
this(GameData.getItemDataMap().get(itemId), count);
|
||||
}
|
||||
|
||||
public GameItem(ItemParamData itemParamData) {
|
||||
this(itemParamData.getId(), itemParamData.getCount());
|
||||
}
|
||||
|
||||
public GameItem(ItemData data) {
|
||||
this(data, 1);
|
||||
}
|
||||
|
||||
public GameItem(ItemData data, int count) {
|
||||
this.itemId = data.getId();
|
||||
this.itemData = data;
|
||||
|
||||
public GameItem(ItemParamData itemParamData) {
|
||||
this(itemParamData.getId(), itemParamData.getCount());
|
||||
}
|
||||
|
||||
public GameItem(ItemData data) {
|
||||
this(data, 1);
|
||||
}
|
||||
|
||||
public GameItem(ItemData data, int count) {
|
||||
this.itemId = data.getId();
|
||||
this.itemData = data;
|
||||
|
||||
switch (data.getItemType()) {
|
||||
case ITEM_VIRTUAL:
|
||||
this.count = count;
|
||||
this.count = count;
|
||||
break;
|
||||
case ITEM_WEAPON:
|
||||
this.count = 1;
|
||||
@ -114,72 +114,72 @@ public class GameItem {
|
||||
if (mainPropData != null) {
|
||||
this.mainPropId = mainPropData.getId();
|
||||
}
|
||||
// Create extra stats
|
||||
// Create extra stats
|
||||
this.addAppendProps(data.getAppendPropNum());
|
||||
break;
|
||||
default:
|
||||
this.count = Math.min(count, data.getStackLimit());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
public int getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setOwner(Player player) {
|
||||
this.ownerId = player.getUid();
|
||||
this.guid = player.getNextGameGuid();
|
||||
}
|
||||
public void setOwner(Player player) {
|
||||
this.ownerId = player.getUid();
|
||||
this.guid = player.getNextGameGuid();
|
||||
}
|
||||
|
||||
public ObjectId getObjectId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ItemType getItemType() {
|
||||
return this.itemData.getItemType();
|
||||
}
|
||||
public ObjectId getObjectId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static int getMinPromoteLevel(int level) {
|
||||
if (level > 80) {
|
||||
return 6;
|
||||
} else if (level > 70) {
|
||||
return 5;
|
||||
} else if (level > 60) {
|
||||
return 4;
|
||||
} else if (level > 50) {
|
||||
return 3;
|
||||
} else if (level > 40) {
|
||||
return 2;
|
||||
} else if (level > 20) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public ItemType getItemType() {
|
||||
return this.itemData.getItemType();
|
||||
}
|
||||
|
||||
public static int getMinPromoteLevel(int level) {
|
||||
if (level > 80) {
|
||||
return 6;
|
||||
} else if (level > 70) {
|
||||
return 5;
|
||||
} else if (level > 60) {
|
||||
return 4;
|
||||
} else if (level > 50) {
|
||||
return 3;
|
||||
} else if (level > 40) {
|
||||
return 2;
|
||||
} else if (level > 20) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getEquipSlot() {
|
||||
return this.getItemData().getEquipType().getValue();
|
||||
}
|
||||
|
||||
public boolean isEquipped() {
|
||||
return this.getEquipCharacter() > 0;
|
||||
}
|
||||
|
||||
public boolean isDestroyable() {
|
||||
return !this.isLocked() && !this.isEquipped();
|
||||
}
|
||||
|
||||
public void addAppendProp() {
|
||||
if (this.appendPropIdList == null) {
|
||||
this.appendPropIdList = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (this.appendPropIdList.size() < 4) {
|
||||
this.addNewAppendProp();
|
||||
} else {
|
||||
this.upgradeRandomAppendProp();
|
||||
}
|
||||
}
|
||||
|
||||
public int getEquipSlot() {
|
||||
return this.getItemData().getEquipType().getValue();
|
||||
}
|
||||
|
||||
public boolean isEquipped() {
|
||||
return this.getEquipCharacter() > 0;
|
||||
}
|
||||
|
||||
public boolean isDestroyable() {
|
||||
return !this.isLocked() && !this.isEquipped();
|
||||
}
|
||||
|
||||
public void addAppendProp() {
|
||||
if (this.appendPropIdList == null) {
|
||||
this.appendPropIdList = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (this.appendPropIdList.size() < 4) {
|
||||
this.addNewAppendProp();
|
||||
} else {
|
||||
this.upgradeRandomAppendProp();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAppendProps(int quantity) {
|
||||
int num = Math.max(quantity, 0);
|
||||
for (int i = 0; i < num; i++) {
|
||||
@ -199,165 +199,165 @@ public class GameItem {
|
||||
return props;
|
||||
}
|
||||
|
||||
private void addNewAppendProp() {
|
||||
private void addNewAppendProp() {
|
||||
List<ReliquaryAffixData> affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId());
|
||||
|
||||
if (affixList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build blacklist - Dont add same stat as main/sub stat
|
||||
|
||||
if (affixList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build blacklist - Dont add same stat as main/sub stat
|
||||
Set<FightProperty> blacklist = this.getAppendFightProperties();
|
||||
ReliquaryMainPropData mainPropData = GameData.getReliquaryMainPropDataMap().get(this.mainPropId);
|
||||
if (mainPropData != null) {
|
||||
blacklist.add(mainPropData.getFightProp());
|
||||
}
|
||||
|
||||
// Build random list
|
||||
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
||||
for (ReliquaryAffixData affix : affixList) {
|
||||
if (!blacklist.contains(affix.getFightProp())) {
|
||||
randomList.add(affix.getWeight(), affix);
|
||||
}
|
||||
}
|
||||
|
||||
if (randomList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
ReliquaryMainPropData mainPropData = GameData.getReliquaryMainPropDataMap().get(this.mainPropId);
|
||||
if (mainPropData != null) {
|
||||
blacklist.add(mainPropData.getFightProp());
|
||||
}
|
||||
|
||||
// Add random stat
|
||||
ReliquaryAffixData affixData = randomList.next();
|
||||
this.appendPropIdList.add(affixData.getId());
|
||||
}
|
||||
|
||||
private void upgradeRandomAppendProp() {
|
||||
// Build random list
|
||||
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
||||
for (ReliquaryAffixData affix : affixList) {
|
||||
if (!blacklist.contains(affix.getFightProp())) {
|
||||
randomList.add(affix.getWeight(), affix);
|
||||
}
|
||||
}
|
||||
|
||||
if (randomList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add random stat
|
||||
ReliquaryAffixData affixData = randomList.next();
|
||||
this.appendPropIdList.add(affixData.getId());
|
||||
}
|
||||
|
||||
private void upgradeRandomAppendProp() {
|
||||
List<ReliquaryAffixData> affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId());
|
||||
|
||||
if (affixList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build whitelist
|
||||
|
||||
if (affixList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build whitelist
|
||||
Set<FightProperty> whitelist = this.getAppendFightProperties();
|
||||
|
||||
// Build random list
|
||||
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
||||
for (ReliquaryAffixData affix : affixList) {
|
||||
if (whitelist.contains(affix.getFightProp())) {
|
||||
randomList.add(affix.getUpgradeWeight(), affix);
|
||||
}
|
||||
}
|
||||
|
||||
// Add random stat
|
||||
ReliquaryAffixData affixData = randomList.next();
|
||||
this.appendPropIdList.add(affixData.getId());
|
||||
}
|
||||
|
||||
@PostLoad
|
||||
public void onLoad() {
|
||||
if (this.itemData == null) {
|
||||
this.itemData = GameData.getItemDataMap().get(getItemId());
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (this.count > 0 && this.ownerId > 0) {
|
||||
DatabaseHelper.saveItem(this);
|
||||
} else if (this.getObjectId() != null) {
|
||||
DatabaseHelper.deleteItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
public SceneWeaponInfo createSceneWeaponInfo() {
|
||||
SceneWeaponInfo.Builder weaponInfo = SceneWeaponInfo.newBuilder()
|
||||
.setEntityId(this.getWeaponEntityId())
|
||||
.setItemId(this.getItemId())
|
||||
.setGuid(this.getGuid())
|
||||
.setLevel(this.getLevel())
|
||||
.setGadgetId(this.getItemData().getGadgetId())
|
||||
.setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(getAffixes().size() > 0));
|
||||
|
||||
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
||||
for (int affix : this.getAffixes()) {
|
||||
weaponInfo.putAffixMap(affix, this.getRefinement());
|
||||
}
|
||||
}
|
||||
|
||||
return weaponInfo.build();
|
||||
}
|
||||
|
||||
public SceneReliquaryInfo createSceneReliquaryInfo() {
|
||||
SceneReliquaryInfo relicInfo = SceneReliquaryInfo.newBuilder()
|
||||
.setItemId(this.getItemId())
|
||||
.setGuid(this.getGuid())
|
||||
.setLevel(this.getLevel())
|
||||
.build();
|
||||
|
||||
return relicInfo;
|
||||
}
|
||||
// Build random list
|
||||
WeightedList<ReliquaryAffixData> randomList = new WeightedList<>();
|
||||
for (ReliquaryAffixData affix : affixList) {
|
||||
if (whitelist.contains(affix.getFightProp())) {
|
||||
randomList.add(affix.getUpgradeWeight(), affix);
|
||||
}
|
||||
}
|
||||
|
||||
public Weapon toWeaponProto() {
|
||||
Weapon.Builder weapon = Weapon.newBuilder()
|
||||
.setLevel(this.getLevel())
|
||||
.setExp(this.getExp())
|
||||
.setPromoteLevel(this.getPromoteLevel());
|
||||
// Add random stat
|
||||
ReliquaryAffixData affixData = randomList.next();
|
||||
this.appendPropIdList.add(affixData.getId());
|
||||
}
|
||||
|
||||
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
||||
for (int affix : this.getAffixes()) {
|
||||
weapon.putAffixMap(affix, this.getRefinement());
|
||||
}
|
||||
}
|
||||
@PostLoad
|
||||
public void onLoad() {
|
||||
if (this.itemData == null) {
|
||||
this.itemData = GameData.getItemDataMap().get(getItemId());
|
||||
}
|
||||
}
|
||||
|
||||
return weapon.build();
|
||||
}
|
||||
public void save() {
|
||||
if (this.count > 0 && this.ownerId > 0) {
|
||||
DatabaseHelper.saveItem(this);
|
||||
} else if (this.getObjectId() != null) {
|
||||
DatabaseHelper.deleteItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Reliquary toReliquaryProto() {
|
||||
Reliquary.Builder relic = Reliquary.newBuilder()
|
||||
.setLevel(this.getLevel())
|
||||
.setExp(this.getExp())
|
||||
.setPromoteLevel(this.getPromoteLevel())
|
||||
.setMainPropId(this.getMainPropId())
|
||||
.addAllAppendPropIdList(this.getAppendPropIdList());
|
||||
public SceneWeaponInfo createSceneWeaponInfo() {
|
||||
SceneWeaponInfo.Builder weaponInfo = SceneWeaponInfo.newBuilder()
|
||||
.setEntityId(this.getWeaponEntityId())
|
||||
.setItemId(this.getItemId())
|
||||
.setGuid(this.getGuid())
|
||||
.setLevel(this.getLevel())
|
||||
.setGadgetId(this.getItemData().getGadgetId())
|
||||
.setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(getAffixes().size() > 0));
|
||||
|
||||
return relic.build();
|
||||
}
|
||||
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
||||
for (int affix : this.getAffixes()) {
|
||||
weaponInfo.putAffixMap(affix, this.getRefinement());
|
||||
}
|
||||
}
|
||||
|
||||
public Item toProto() {
|
||||
Item.Builder proto = Item.newBuilder()
|
||||
.setGuid(this.getGuid())
|
||||
.setItemId(this.getItemId());
|
||||
|
||||
switch (getItemType()) {
|
||||
case ITEM_WEAPON:
|
||||
Weapon weapon = this.toWeaponProto();
|
||||
proto.setEquip(Equip.newBuilder().setWeapon(weapon).setIsLocked(this.isLocked()).build());
|
||||
break;
|
||||
case ITEM_RELIQUARY:
|
||||
Reliquary relic = this.toReliquaryProto();
|
||||
proto.setEquip(Equip.newBuilder().setReliquary(relic).setIsLocked(this.isLocked()).build());
|
||||
break;
|
||||
case ITEM_FURNITURE:
|
||||
Furniture furniture = Furniture.newBuilder()
|
||||
.setCount(getCount())
|
||||
.build();
|
||||
proto.setFurniture(furniture);
|
||||
break;
|
||||
default:
|
||||
Material material = Material.newBuilder()
|
||||
.setCount(getCount())
|
||||
.build();
|
||||
proto.setMaterial(material);
|
||||
break;
|
||||
}
|
||||
|
||||
return proto.build();
|
||||
}
|
||||
return weaponInfo.build();
|
||||
}
|
||||
|
||||
public ItemHint toItemHintProto() {
|
||||
return ItemHint.newBuilder().setItemId(getItemId()).setCount(getCount()).setIsNew(false).build();
|
||||
}
|
||||
public SceneReliquaryInfo createSceneReliquaryInfo() {
|
||||
SceneReliquaryInfo relicInfo = SceneReliquaryInfo.newBuilder()
|
||||
.setItemId(this.getItemId())
|
||||
.setGuid(this.getGuid())
|
||||
.setLevel(this.getLevel())
|
||||
.build();
|
||||
|
||||
public ItemParam toItemParam() {
|
||||
return ItemParam.newBuilder().setItemId(this.getItemId()).setCount(this.getCount()).build();
|
||||
}
|
||||
return relicInfo;
|
||||
}
|
||||
|
||||
public Weapon toWeaponProto() {
|
||||
Weapon.Builder weapon = Weapon.newBuilder()
|
||||
.setLevel(this.getLevel())
|
||||
.setExp(this.getExp())
|
||||
.setPromoteLevel(this.getPromoteLevel());
|
||||
|
||||
if (this.getAffixes() != null && this.getAffixes().size() > 0) {
|
||||
for (int affix : this.getAffixes()) {
|
||||
weapon.putAffixMap(affix, this.getRefinement());
|
||||
}
|
||||
}
|
||||
|
||||
return weapon.build();
|
||||
}
|
||||
|
||||
public Reliquary toReliquaryProto() {
|
||||
Reliquary.Builder relic = Reliquary.newBuilder()
|
||||
.setLevel(this.getLevel())
|
||||
.setExp(this.getExp())
|
||||
.setPromoteLevel(this.getPromoteLevel())
|
||||
.setMainPropId(this.getMainPropId())
|
||||
.addAllAppendPropIdList(this.getAppendPropIdList());
|
||||
|
||||
return relic.build();
|
||||
}
|
||||
|
||||
public Item toProto() {
|
||||
Item.Builder proto = Item.newBuilder()
|
||||
.setGuid(this.getGuid())
|
||||
.setItemId(this.getItemId());
|
||||
|
||||
switch (getItemType()) {
|
||||
case ITEM_WEAPON:
|
||||
Weapon weapon = this.toWeaponProto();
|
||||
proto.setEquip(Equip.newBuilder().setWeapon(weapon).setIsLocked(this.isLocked()).build());
|
||||
break;
|
||||
case ITEM_RELIQUARY:
|
||||
Reliquary relic = this.toReliquaryProto();
|
||||
proto.setEquip(Equip.newBuilder().setReliquary(relic).setIsLocked(this.isLocked()).build());
|
||||
break;
|
||||
case ITEM_FURNITURE:
|
||||
Furniture furniture = Furniture.newBuilder()
|
||||
.setCount(getCount())
|
||||
.build();
|
||||
proto.setFurniture(furniture);
|
||||
break;
|
||||
default:
|
||||
Material material = Material.newBuilder()
|
||||
.setCount(getCount())
|
||||
.build();
|
||||
proto.setMaterial(material);
|
||||
break;
|
||||
}
|
||||
|
||||
return proto.build();
|
||||
}
|
||||
|
||||
public ItemHint toItemHintProto() {
|
||||
return ItemHint.newBuilder().setItemId(getItemId()).setCount(getCount()).setIsNew(false).build();
|
||||
}
|
||||
|
||||
public ItemParam toItemParam() {
|
||||
return ItemParam.newBuilder().setItemId(this.getItemId()).setCount(this.getCount()).build();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class PlayerCodex {
|
||||
@Getter private Set<Integer> unlockedReliquary;
|
||||
@Getter private Set<Integer> unlockedReliquarySuitCodex;
|
||||
|
||||
public PlayerCodex(){
|
||||
public PlayerCodex() {
|
||||
this.unlockedWeapon = new HashSet<>();
|
||||
this.unlockedAnimal = new HashMap<>();
|
||||
this.unlockedMaterial = new HashSet<>();
|
||||
@ -38,7 +38,7 @@ public class PlayerCodex {
|
||||
this.unlockedReliquarySuitCodex = new HashSet<>();
|
||||
}
|
||||
|
||||
public PlayerCodex(Player player){
|
||||
public PlayerCodex(Player player) {
|
||||
this();
|
||||
this.player = player;
|
||||
}
|
||||
@ -48,7 +48,7 @@ public class PlayerCodex {
|
||||
this.fixReliquaries();
|
||||
}
|
||||
|
||||
public void checkAddedItem(GameItem item){
|
||||
public void checkAddedItem(GameItem item) {
|
||||
val itemData = item.getItemData();
|
||||
val itemId = item.getItemId();
|
||||
switch (itemData.getItemType()) {
|
||||
@ -85,7 +85,7 @@ public class PlayerCodex {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkAnimal(GameEntity target, CodexAnimalData.CountType countType){
|
||||
public void checkAnimal(GameEntity target, CodexAnimalData.CountType countType) {
|
||||
if (target instanceof EntityMonster) {
|
||||
val monsterId = ((EntityMonster) target).getMonsterData().getId();
|
||||
val codexAnimal = GameData.getCodexAnimalDataMap().get(monsterId);
|
||||
@ -101,7 +101,7 @@ public class PlayerCodex {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkUnlockedSuits(int reliquaryId){
|
||||
public void checkUnlockedSuits(int reliquaryId) {
|
||||
GameData.getCodexReliquaryArrayList().stream()
|
||||
.filter(x -> !this.getUnlockedReliquarySuitCodex().contains(x.getId()))
|
||||
.filter(x -> x.containsId(reliquaryId))
|
||||
@ -127,4 +127,4 @@ public class PlayerCodex {
|
||||
.forEach(x -> this.getUnlockedReliquarySuitCodex().add(x.getId()));
|
||||
this.player.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public abstract class ItemUseAddEnergy extends ItemUseAction {
|
||||
var activeTeam = teamManager.getActiveTeam();
|
||||
// On-field vs off-field multiplier.
|
||||
// The on-field character gets full amount, off-field characters get less depending on the team size.
|
||||
final float offFieldRatio = switch(activeTeam.size()) {
|
||||
final float offFieldRatio = switch (activeTeam.size()) {
|
||||
case 2 -> 0.8f;
|
||||
case 3 -> 0.7f;
|
||||
default -> 0.6f;
|
||||
|
@ -570,7 +570,7 @@ public class InventorySystem extends BaseGameSystem {
|
||||
|
||||
// Calc exp
|
||||
int expGain = 0;
|
||||
|
||||
|
||||
var data = GameData.getItemDataMap().get(itemId);
|
||||
if (data != null) {
|
||||
var actions = data.getItemUseActions();
|
||||
|
@ -85,10 +85,10 @@ public class WorldDataSystem extends BaseGameSystem {
|
||||
return level;
|
||||
}
|
||||
private InvestigationMonsterOuterClass.InvestigationMonster getInvestigationMonster(Player player, InvestigationMonsterData imd) {
|
||||
if(imd.getGroupIdList().isEmpty() || imd.getMonsterIdList().isEmpty()){
|
||||
if (imd.getGroupIdList().isEmpty() || imd.getMonsterIdList().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
var groupId = imd.getGroupIdList().get(0);
|
||||
var monsterId = imd.getMonsterIdList().get(0);
|
||||
var sceneId = imd.getCityData().getSceneId();
|
||||
|
@ -30,28 +30,28 @@ import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ScriptLoader {
|
||||
private static ScriptEngineManager sm;
|
||||
private static ScriptEngineManager sm;
|
||||
@Getter private static ScriptEngine engine;
|
||||
private static ScriptEngineFactory factory;
|
||||
private static ScriptEngineFactory factory;
|
||||
@Getter private static Serializer serializer;
|
||||
@Getter private static ScriptLib scriptLib;
|
||||
@Getter private static LuaValue scriptLibLua;
|
||||
/**
|
||||
* suggest GC to remove it if the memory is less
|
||||
*/
|
||||
private static Map<String, SoftReference<CompiledScript>> scriptsCache = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* sceneId - SceneMeta
|
||||
*/
|
||||
private static Map<Integer, SoftReference<SceneMeta>> sceneMetaCache = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* suggest GC to remove it if the memory is less
|
||||
*/
|
||||
private static Map<String, SoftReference<CompiledScript>> scriptsCache = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* sceneId - SceneMeta
|
||||
*/
|
||||
private static Map<Integer, SoftReference<SceneMeta>> sceneMetaCache = new ConcurrentHashMap<>();
|
||||
|
||||
public synchronized static void init() throws Exception {
|
||||
if (sm != null) {
|
||||
throw new Exception("Script loader already initialized");
|
||||
}
|
||||
public synchronized static void init() throws Exception {
|
||||
if (sm != null) {
|
||||
throw new Exception("Script loader already initialized");
|
||||
}
|
||||
|
||||
// Create script engine
|
||||
sm = new ScriptEngineManager();
|
||||
// Create script engine
|
||||
sm = new ScriptEngineManager();
|
||||
engine = sm.getEngineByName("luaj");
|
||||
factory = getEngine().getFactory();
|
||||
|
||||
@ -60,61 +60,61 @@ public class ScriptLoader {
|
||||
|
||||
// Set engine to replace require as a temporary fix to missing scripts
|
||||
LuajContext ctx = (LuajContext) engine.getContext();
|
||||
ctx.globals.set("require", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue arg0) {
|
||||
return LuaValue.ZERO;
|
||||
}
|
||||
});
|
||||
ctx.globals.set("require", new OneArgFunction() {
|
||||
@Override
|
||||
public LuaValue call(LuaValue arg0) {
|
||||
return LuaValue.ZERO;
|
||||
}
|
||||
});
|
||||
|
||||
LuaTable table = new LuaTable();
|
||||
Arrays.stream(EntityType.values()).forEach(e -> table.set(e.name().toUpperCase(), e.getValue()));
|
||||
ctx.globals.set("EntityType", table);
|
||||
LuaTable table = new LuaTable();
|
||||
Arrays.stream(EntityType.values()).forEach(e -> table.set(e.name().toUpperCase(), e.getValue()));
|
||||
ctx.globals.set("EntityType", table);
|
||||
|
||||
LuaTable table1 = new LuaTable();
|
||||
Arrays.stream(QuestState.values()).forEach(e -> table1.set(e.name().toUpperCase(), e.getValue()));
|
||||
ctx.globals.set("QuestState", table1);
|
||||
|
||||
ctx.globals.set("EventType", CoerceJavaToLua.coerce(new EventType())); // TODO - make static class to avoid instantiating a new class every scene
|
||||
ctx.globals.set("GadgetState", CoerceJavaToLua.coerce(new ScriptGadgetState()));
|
||||
ctx.globals.set("RegionShape", CoerceJavaToLua.coerce(new ScriptRegionShape()));
|
||||
ctx.globals.set("EventType", CoerceJavaToLua.coerce(new EventType())); // TODO - make static class to avoid instantiating a new class every scene
|
||||
ctx.globals.set("GadgetState", CoerceJavaToLua.coerce(new ScriptGadgetState()));
|
||||
ctx.globals.set("RegionShape", CoerceJavaToLua.coerce(new ScriptRegionShape()));
|
||||
|
||||
scriptLib = new ScriptLib();
|
||||
scriptLibLua = CoerceJavaToLua.coerce(scriptLib);
|
||||
ctx.globals.set("ScriptLib", scriptLibLua);
|
||||
}
|
||||
scriptLib = new ScriptLib();
|
||||
scriptLibLua = CoerceJavaToLua.coerce(scriptLib);
|
||||
ctx.globals.set("ScriptLib", scriptLibLua);
|
||||
}
|
||||
|
||||
public static <T> Optional<T> tryGet(SoftReference<T> softReference){
|
||||
try{
|
||||
return Optional.ofNullable(softReference.get());
|
||||
}catch (NullPointerException npe){
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
public static <T> Optional<T> tryGet(SoftReference<T> softReference) {
|
||||
try {
|
||||
return Optional.ofNullable(softReference.get());
|
||||
}catch (NullPointerException npe) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public static CompiledScript getScriptByPath(String path) {
|
||||
var sc = tryGet(scriptsCache.get(path));
|
||||
if (sc.isPresent()) {
|
||||
return sc.get();
|
||||
}
|
||||
@Deprecated(forRemoval = true)
|
||||
public static CompiledScript getScriptByPath(String path) {
|
||||
var sc = tryGet(scriptsCache.get(path));
|
||||
if (sc.isPresent()) {
|
||||
return sc.get();
|
||||
}
|
||||
|
||||
Grasscutter.getLogger().debug("Loading script " + path);
|
||||
Grasscutter.getLogger().debug("Loading script " + path);
|
||||
|
||||
File file = new File(path);
|
||||
File file = new File(path);
|
||||
|
||||
if (!file.exists()) return null;
|
||||
if (!file.exists()) return null;
|
||||
|
||||
try (FileReader fr = new FileReader(file)) {
|
||||
var script = ((Compilable) getEngine()).compile(fr);
|
||||
scriptsCache.put(path, new SoftReference<>(script));
|
||||
return script;
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error("Loading script {} failed!", path, e);
|
||||
return null;
|
||||
}
|
||||
try (FileReader fr = new FileReader(file)) {
|
||||
var script = ((Compilable) getEngine()).compile(fr);
|
||||
scriptsCache.put(path, new SoftReference<>(script));
|
||||
return script;
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error("Loading script {} failed!", path, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static CompiledScript getScript(String path) {
|
||||
var sc = tryGet(scriptsCache.get(path));
|
||||
@ -136,12 +136,12 @@ public class ScriptLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static SceneMeta getSceneMeta(int sceneId) {
|
||||
return tryGet(sceneMetaCache.get(sceneId)).orElseGet(() -> {
|
||||
var instance = SceneMeta.of(sceneId);
|
||||
sceneMetaCache.put(sceneId, new SoftReference<>(instance));
|
||||
return instance;
|
||||
});
|
||||
}
|
||||
public static SceneMeta getSceneMeta(int sceneId) {
|
||||
return tryGet(sceneMetaCache.get(sceneId)).orElseGet(() -> {
|
||||
var instance = SceneMeta.of(sceneId);
|
||||
sceneMetaCache.put(sceneId, new SoftReference<>(instance));
|
||||
return instance;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,18 +11,18 @@ import emu.grasscutter.server.game.GameSession;
|
||||
@Opcodes(PacketOpcodes.EvtCreateGadgetNotify)
|
||||
public class HandlerEvtCreateGadgetNotify extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload);
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload);
|
||||
|
||||
// Sanity check - dont add duplicate entities
|
||||
if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) {
|
||||
return;
|
||||
}
|
||||
// Sanity check - dont add duplicate entities
|
||||
if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create entity and summon in world
|
||||
// Create entity and summon in world
|
||||
var gadgetId = notify.getConfigId();
|
||||
EntityClientGadget gadget = switch (gadgetId) {
|
||||
EntityClientGadget gadget = switch (gadgetId) {
|
||||
//Solar Isotoma.
|
||||
case EntitySolarIsotomaClientGadget.GADGET_ID ->
|
||||
new EntitySolarIsotomaClientGadget(session.getPlayer().getScene(), session.getPlayer(), notify);
|
||||
@ -33,6 +33,6 @@ public class HandlerEvtCreateGadgetNotify extends PacketHandler {
|
||||
};
|
||||
|
||||
session.getPlayer().getScene().onPlayerCreateGadget(gadget);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,14 +7,14 @@ import emu.grasscutter.net.proto.SceneTimeNotifyOuterClass.SceneTimeNotify;
|
||||
|
||||
public class PacketSceneTimeNotify extends BasePacket {
|
||||
|
||||
public PacketSceneTimeNotify(Player player) {
|
||||
super(PacketOpcodes.SceneTimeNotify);
|
||||
public PacketSceneTimeNotify(Player player) {
|
||||
super(PacketOpcodes.SceneTimeNotify);
|
||||
|
||||
SceneTimeNotify proto = SceneTimeNotify.newBuilder()
|
||||
.setSceneId(player.getSceneId())
|
||||
.setSceneTime(player.getScene().getSceneTime())
|
||||
.build();
|
||||
SceneTimeNotify proto = SceneTimeNotify.newBuilder()
|
||||
.setSceneId(player.getSceneId())
|
||||
.setSceneTime(player.getScene().getSceneTime())
|
||||
.build();
|
||||
|
||||
this.setData(proto);
|
||||
}
|
||||
this.setData(proto);
|
||||
}
|
||||
}
|
||||
|
@ -111,93 +111,93 @@ public final class FileUtils {
|
||||
return SCRIPTS_PATH.resolve(path);
|
||||
}
|
||||
|
||||
public static void write(String dest, byte[] bytes) {
|
||||
Path path = Path.of(dest);
|
||||
|
||||
try {
|
||||
Files.write(path, bytes);
|
||||
} catch (IOException e) {
|
||||
Grasscutter.getLogger().warn("Failed to write file: " + dest);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] read(String dest) {
|
||||
return read(Path.of(dest));
|
||||
}
|
||||
public static void write(String dest, byte[] bytes) {
|
||||
Path path = Path.of(dest);
|
||||
|
||||
public static byte[] read(Path path) {
|
||||
try {
|
||||
return Files.readAllBytes(path);
|
||||
} catch (IOException e) {
|
||||
Grasscutter.getLogger().warn("Failed to read file: " + path);
|
||||
}
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
try {
|
||||
Files.write(path, bytes);
|
||||
} catch (IOException e) {
|
||||
Grasscutter.getLogger().warn("Failed to write file: " + dest);
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream readResourceAsStream(String resourcePath) {
|
||||
return Grasscutter.class.getResourceAsStream(resourcePath);
|
||||
}
|
||||
public static byte[] read(String dest) {
|
||||
return read(Path.of(dest));
|
||||
}
|
||||
|
||||
public static byte[] readResource(String resourcePath) {
|
||||
try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) {
|
||||
return is.readAllBytes();
|
||||
} catch (Exception exception) {
|
||||
Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
public static byte[] read(Path path) {
|
||||
try {
|
||||
return Files.readAllBytes(path);
|
||||
} catch (IOException e) {
|
||||
Grasscutter.getLogger().warn("Failed to read file: " + path);
|
||||
}
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public static byte[] read(File file) {
|
||||
return read(file.getPath());
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public static void copyResource(String resourcePath, String destination) {
|
||||
try {
|
||||
byte[] resource = FileUtils.readResource(resourcePath);
|
||||
FileUtils.write(destination, resource);
|
||||
} catch (Exception exception) {
|
||||
Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFilenameWithoutPath(String fileName) {
|
||||
if (fileName.indexOf(".") > 0) {
|
||||
return fileName.substring(0, fileName.lastIndexOf("."));
|
||||
} else {
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
public static InputStream readResourceAsStream(String resourcePath) {
|
||||
return Grasscutter.class.getResourceAsStream(resourcePath);
|
||||
}
|
||||
|
||||
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
|
||||
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException {
|
||||
List<Path> result = null;
|
||||
public static byte[] readResource(String resourcePath) {
|
||||
try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) {
|
||||
return is.readAllBytes();
|
||||
} catch (Exception exception) {
|
||||
Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
// file walks JAR
|
||||
result = Files.walk(JAR_FILE_SYSTEM.getPath(folder))
|
||||
.filter(Files::isRegularFile)
|
||||
.collect(Collectors.toList());
|
||||
} catch (Exception e) {
|
||||
// Eclipse puts resources in its bin folder
|
||||
File f = new File(System.getProperty("user.dir") + folder);
|
||||
|
||||
if (!f.exists() || f.listFiles().length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static String readToString(InputStream file) throws IOException {
|
||||
byte[] content = file.readAllBytes();
|
||||
public static byte[] read(File file) {
|
||||
return read(file.getPath());
|
||||
}
|
||||
|
||||
return new String(content, StandardCharsets.UTF_8);
|
||||
}
|
||||
public static void copyResource(String resourcePath, String destination) {
|
||||
try {
|
||||
byte[] resource = FileUtils.readResource(resourcePath);
|
||||
FileUtils.write(destination, resource);
|
||||
} catch (Exception exception) {
|
||||
Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFilenameWithoutPath(String fileName) {
|
||||
if (fileName.indexOf(".") > 0) {
|
||||
return fileName.substring(0, fileName.lastIndexOf("."));
|
||||
} else {
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
|
||||
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
|
||||
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException {
|
||||
List<Path> result = null;
|
||||
|
||||
try {
|
||||
// file walks JAR
|
||||
result = Files.walk(JAR_FILE_SYSTEM.getPath(folder))
|
||||
.filter(Files::isRegularFile)
|
||||
.collect(Collectors.toList());
|
||||
} catch (Exception e) {
|
||||
// Eclipse puts resources in its bin folder
|
||||
File f = new File(System.getProperty("user.dir") + folder);
|
||||
|
||||
if (!f.exists() || f.listFiles().length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static String readToString(InputStream file) throws IOException {
|
||||
byte[] content = file.readAllBytes();
|
||||
|
||||
return new String(content, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user