Commit ae2d1fe4 authored by github-actions's avatar github-actions Committed by Melledy
Browse files

Fix whitespace [skip actions]

parent 510d564b
...@@ -24,7 +24,7 @@ public class TowerSystem extends BaseGameSystem { ...@@ -24,7 +24,7 @@ public class TowerSystem extends BaseGameSystem {
private TowerScheduleConfig towerScheduleConfig; private TowerScheduleConfig towerScheduleConfig;
public synchronized void load(){ public synchronized void load() {
try (Reader fileReader = DataLoader.loadReader("TowerSchedule.json")) { try (Reader fileReader = DataLoader.loadReader("TowerSchedule.json")) {
towerScheduleConfig = Grasscutter.getGsonFactory().fromJson(fileReader, TowerScheduleConfig.class); towerScheduleConfig = Grasscutter.getGsonFactory().fromJson(fileReader, TowerScheduleConfig.class);
} catch (Exception e) { } catch (Exception e) {
...@@ -36,9 +36,9 @@ public class TowerSystem extends BaseGameSystem { ...@@ -36,9 +36,9 @@ public class TowerSystem extends BaseGameSystem {
return towerScheduleConfig; return towerScheduleConfig;
} }
public TowerScheduleData getCurrentTowerScheduleData(){ public TowerScheduleData getCurrentTowerScheduleData() {
var data = GameData.getTowerScheduleDataMap().get(towerScheduleConfig.getScheduleId()); var data = GameData.getTowerScheduleDataMap().get(towerScheduleConfig.getScheduleId());
if(data == null){ if (data == null) {
Grasscutter.getLogger().error("Could not get current tower schedule data by schedule id {}, please check your resource files", Grasscutter.getLogger().error("Could not get current tower schedule data by schedule id {}, please check your resource files",
towerScheduleConfig.getScheduleId()); towerScheduleConfig.getScheduleId());
} }
...@@ -56,29 +56,29 @@ public class TowerSystem extends BaseGameSystem { ...@@ -56,29 +56,29 @@ public class TowerSystem extends BaseGameSystem {
return getCurrentTowerScheduleData().getSchedules().get(0).getFloorList(); return getCurrentTowerScheduleData().getSchedules().get(0).getFloorList();
} }
public int getNextFloorId(int floorId){ public int getNextFloorId(int floorId) {
var entranceFloors = getCurrentTowerScheduleData().getEntranceFloorId(); var entranceFloors = getCurrentTowerScheduleData().getEntranceFloorId();
var scheduleFloors = getScheduleFloors(); var scheduleFloors = getScheduleFloors();
var nextId = 0; var nextId = 0;
// find in entrance floors first // find in entrance floors first
for(int i=0;i<entranceFloors.size()-1;i++){ for (int i=0;i<entranceFloors.size()-1;i++) {
if(floorId == entranceFloors.get(i)){ if (floorId == entranceFloors.get(i)) {
nextId = entranceFloors.get(i+1); nextId = entranceFloors.get(i+1);
} }
} }
if(floorId == entranceFloors.get(entranceFloors.size()-1)){ if (floorId == entranceFloors.get(entranceFloors.size()-1)) {
nextId = scheduleFloors.get(0); nextId = scheduleFloors.get(0);
} }
if(nextId != 0){ if (nextId != 0) {
return nextId; return nextId;
} }
// find in schedule floors // find in schedule floors
for(int i=0; i < scheduleFloors.size() - 1; i++){ for (int i=0; i < scheduleFloors.size() - 1; i++) {
if(floorId == scheduleFloors.get(i)){ if (floorId == scheduleFloors.get(i)) {
nextId = scheduleFloors.get(i + 1); nextId = scheduleFloors.get(i + 1);
} }
}return nextId; }return nextId;
......
...@@ -186,8 +186,8 @@ public class Scene { ...@@ -186,8 +186,8 @@ public class Scene {
this.challenge = challenge; this.challenge = challenge;
} }
public void addDungeonSettleObserver(DungeonSettleListener dungeonSettleListener){ public void addDungeonSettleObserver(DungeonSettleListener dungeonSettleListener) {
if(dungeonSettleListeners == null){ if (dungeonSettleListeners == null) {
dungeonSettleListeners = new ArrayList<>(); dungeonSettleListeners = new ArrayList<>();
} }
dungeonSettleListeners.add(dungeonSettleListener); dungeonSettleListeners.add(dungeonSettleListener);
...@@ -303,12 +303,12 @@ public class Scene { ...@@ -303,12 +303,12 @@ public class Scene {
player.sendPacket(new PacketSceneEntityAppearNotify(entity)); player.sendPacket(new PacketSceneEntityAppearNotify(entity));
} }
public void addEntities(Collection<? extends GameEntity> entities){ public void addEntities(Collection<? extends GameEntity> entities) {
addEntities(entities, VisionType.VISION_TYPE_BORN); addEntities(entities, VisionType.VISION_TYPE_BORN);
} }
public synchronized void addEntities(Collection<? extends GameEntity> entities, VisionType visionType) { public synchronized void addEntities(Collection<? extends GameEntity> entities, VisionType visionType) {
if(entities == null || entities.isEmpty()){ if (entities == null || entities.isEmpty()) {
return; return;
} }
for (GameEntity entity : entities) { for (GameEntity entity : entities) {
...@@ -420,7 +420,7 @@ public class Scene { ...@@ -420,7 +420,7 @@ public class Scene {
public void onTick() { public void onTick() {
// disable script for home // disable script for home
if (this.getSceneType() == SceneType.SCENE_HOME_WORLD || this.getSceneType() == SceneType.SCENE_HOME_ROOM){ if (this.getSceneType() == SceneType.SCENE_HOME_WORLD || this.getSceneType() == SceneType.SCENE_HOME_ROOM) {
return; return;
} }
if (this.getScriptManager().isInit()) { if (this.getScriptManager().isInit()) {
...@@ -432,7 +432,7 @@ public class Scene { ...@@ -432,7 +432,7 @@ public class Scene {
// Triggers // Triggers
this.scriptManager.checkRegions(); this.scriptManager.checkRegions();
if(challenge != null){ if (challenge != null) {
challenge.onCheckTimeOut(); challenge.onCheckTimeOut();
} }
...@@ -446,7 +446,7 @@ public class Scene { ...@@ -446,7 +446,7 @@ public class Scene {
return level; return level;
} }
public void checkNpcGroup(){ public void checkNpcGroup() {
Set<SceneNpcBornEntry> npcBornEntries = ConcurrentHashMap.newKeySet(); Set<SceneNpcBornEntry> npcBornEntries = ConcurrentHashMap.newKeySet();
for (Player player : this.getPlayers()) { for (Player player : this.getPlayers()) {
npcBornEntries.addAll(loadNpcForPlayer(player)); npcBornEntries.addAll(loadNpcForPlayer(player));
...@@ -458,7 +458,7 @@ public class Scene { ...@@ -458,7 +458,7 @@ public class Scene {
.map(SceneNpcBornEntry::getGroupId) .map(SceneNpcBornEntry::getGroupId)
.toList(); .toList();
if(toUnload.size() > 0){ if (toUnload.size() > 0) {
broadcastPacket(new PacketGroupUnloadNotify(toUnload)); broadcastPacket(new PacketGroupUnloadNotify(toUnload));
Grasscutter.getLogger().debug("Unload NPC Group {}", toUnload); Grasscutter.getLogger().debug("Unload NPC Group {}", toUnload);
} }
...@@ -480,7 +480,7 @@ public class Scene { ...@@ -480,7 +480,7 @@ public class Scene {
Set<SpawnDataEntry> visible = new HashSet<>(); Set<SpawnDataEntry> visible = new HashSet<>();
for (var block : loadedGridBlocks) { for (var block : loadedGridBlocks) {
var spawns = spawnLists.get(block); var spawns = spawnLists.get(block);
if(spawns!=null) { if (spawns!=null) {
visible.addAll(spawns); visible.addAll(spawns);
} }
} }
...@@ -524,7 +524,7 @@ public class Scene { ...@@ -524,7 +524,7 @@ public class Scene {
gadget.setConfigId(entry.getConfigId()); gadget.setConfigId(entry.getConfigId());
gadget.setSpawnEntry(entry); gadget.setSpawnEntry(entry);
int state = entry.getGadgetState(); int state = entry.getGadgetState();
if(state>0) { if (state>0) {
gadget.setState(state); gadget.setState(state);
} }
gadget.buildContent(); gadget.buildContent();
...@@ -562,7 +562,7 @@ public class Scene { ...@@ -562,7 +562,7 @@ public class Scene {
} }
} }
public List<SceneBlock> getPlayerActiveBlocks(Player player){ public List<SceneBlock> getPlayerActiveBlocks(Player player) {
// consider the borders' entities of blocks, so we check if contains by index // consider the borders' entities of blocks, so we check if contains by index
return SceneIndexManager.queryNeighbors(getScriptManager().getBlocksIndex(), return SceneIndexManager.queryNeighbors(getScriptManager().getBlocksIndex(),
player.getPosition().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange); player.getPosition().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
...@@ -585,11 +585,11 @@ public class Scene { ...@@ -585,11 +585,11 @@ public class Scene {
} }
} }
for(var block : visible){ for (var block : visible) {
if (!this.getLoadedBlocks().contains(block)) { if (!this.getLoadedBlocks().contains(block)) {
this.onLoadBlock(block, this.getPlayers()); this.onLoadBlock(block, this.getPlayers());
this.getLoadedBlocks().add(block); this.getLoadedBlocks().add(block);
}else{ }else {
// dynamic load the groups for players in a loaded block // dynamic load the groups for players in a loaded block
var toLoad = this.getPlayers().stream() var toLoad = this.getPlayers().stream()
.filter(p -> block.contains(p.getPosition())) .filter(p -> block.contains(p.getPosition()))
...@@ -601,7 +601,7 @@ public class Scene { ...@@ -601,7 +601,7 @@ public class Scene {
} }
} }
public List<SceneGroup> playerMeetGroups(Player player, SceneBlock block){ public List<SceneGroup> playerMeetGroups(Player player, SceneBlock block) {
List<SceneGroup> sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPosition().toDoubleArray(), List<SceneGroup> sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPosition().toDoubleArray(),
Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange); Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
...@@ -631,8 +631,8 @@ public class Scene { ...@@ -631,8 +631,8 @@ public class Scene {
Grasscutter.getLogger().info("Scene {} Block {} loaded.", this.getId(), block.id); Grasscutter.getLogger().info("Scene {} Block {} loaded.", this.getId(), block.id);
} }
public void onLoadGroup(List<SceneGroup> groups){ public void onLoadGroup(List<SceneGroup> groups) {
if(groups == null || groups.isEmpty()){ if (groups == null || groups.isEmpty()) {
return; return;
} }
for (SceneGroup group : groups) { for (SceneGroup group : groups) {
...@@ -690,10 +690,10 @@ public class Scene { ...@@ -690,10 +690,10 @@ public class Scene {
} }
for (SceneGroup group : block.groups.values()) { for (SceneGroup group : block.groups.values()) {
if(group.triggers != null){ if (group.triggers != null) {
group.triggers.values().forEach(getScriptManager()::deregisterTrigger); group.triggers.values().forEach(getScriptManager()::deregisterTrigger);
} }
if(group.regions != null){ if (group.regions != null) {
group.regions.values().forEach(getScriptManager()::deregisterRegion); group.regions.values().forEach(getScriptManager()::deregisterRegion);
} }
} }
...@@ -763,7 +763,7 @@ public class Scene { ...@@ -763,7 +763,7 @@ public class Scene {
} }
} }
public void addItemEntity(int itemId, int amount, GameEntity bornForm){ public void addItemEntity(int itemId, int amount, GameEntity bornForm) {
ItemData itemData = GameData.getItemDataMap().get(itemId); ItemData itemData = GameData.getItemDataMap().get(itemId);
if (itemData == null) { if (itemData == null) {
return; return;
...@@ -780,13 +780,13 @@ public class Scene { ...@@ -780,13 +780,13 @@ public class Scene {
addEntity(entity); addEntity(entity);
} }
} }
public void loadNpcForPlayerEnter(Player player){ public void loadNpcForPlayerEnter(Player player) {
this.npcBornEntrySet.addAll(loadNpcForPlayer(player)); this.npcBornEntrySet.addAll(loadNpcForPlayer(player));
} }
private List<SceneNpcBornEntry> loadNpcForPlayer(Player player){ private List<SceneNpcBornEntry> loadNpcForPlayer(Player player) {
var pos = player.getPosition(); var pos = player.getPosition();
var data = GameData.getSceneNpcBornData().get(getId()); var data = GameData.getSceneNpcBornData().get(getId());
if(data == null){ if (data == null) {
return List.of(); return List.of();
} }
...@@ -797,7 +797,7 @@ public class Scene { ...@@ -797,7 +797,7 @@ public class Scene {
.filter(i -> !this.npcBornEntrySet.contains(i)) .filter(i -> !this.npcBornEntrySet.contains(i))
.toList(); .toList();
if(sceneNpcBornEntries.size() > 0){ if (sceneNpcBornEntries.size() > 0) {
this.broadcastPacket(new PacketGroupSuiteNotify(sceneNpcBornEntries)); this.broadcastPacket(new PacketGroupSuiteNotify(sceneNpcBornEntries));
Grasscutter.getLogger().debug("Loaded Npc Group Suite {}", sceneNpcBornEntries); Grasscutter.getLogger().debug("Loaded Npc Group Suite {}", sceneNpcBornEntries);
} }
...@@ -805,17 +805,17 @@ public class Scene { ...@@ -805,17 +805,17 @@ public class Scene {
} }
public void loadGroupForQuest(List<QuestGroupSuite> sceneGroupSuite) { public void loadGroupForQuest(List<QuestGroupSuite> sceneGroupSuite) {
if(!scriptManager.isInit()){ if (!scriptManager.isInit()) {
return; return;
} }
sceneGroupSuite.forEach(i -> { sceneGroupSuite.forEach(i -> {
var group = scriptManager.getGroupById(i.getGroup()); var group = scriptManager.getGroupById(i.getGroup());
if(group == null){ if (group == null) {
return; return;
} }
var suite = group.getSuiteByIndex(i.getSuite()); var suite = group.getSuiteByIndex(i.getSuite());
if(suite == null){ if (suite == null) {
return; return;
} }
scriptManager.addGroupSuite(group, suite); scriptManager.addGroupSuite(group, suite);
......
...@@ -62,7 +62,7 @@ public class SpawnDataEntry { ...@@ -62,7 +62,7 @@ public class SpawnDataEntry {
return rot; return rot;
} }
public GridBlockId getBlockId(){ public GridBlockId getBlockId() {
int scale = GridBlockId.getScale(gadgetId); int scale = GridBlockId.getScale(gadgetId);
return new GridBlockId(group.sceneId,scale, return new GridBlockId(group.sceneId,scale,
(int)(pos.getX() / GameDepot.BLOCK_SIZE[scale]), (int)(pos.getX() / GameDepot.BLOCK_SIZE[scale]),
...@@ -133,7 +133,7 @@ public class SpawnDataEntry { ...@@ -133,7 +133,7 @@ public class SpawnDataEntry {
return Objects.hash(sceneId, scale, x, z); return Objects.hash(sceneId, scale, x, z);
} }
public static GridBlockId[] getAdjacentGridBlockIds(int sceneId, Position pos){ public static GridBlockId[] getAdjacentGridBlockIds(int sceneId, Position pos) {
GridBlockId[] results = new GridBlockId[5*5*GameDepot.BLOCK_SIZE.length]; GridBlockId[] results = new GridBlockId[5*5*GameDepot.BLOCK_SIZE.length];
int t=0; int t=0;
for (int scale = 0; scale < GameDepot.BLOCK_SIZE.length; scale++) { for (int scale = 0; scale < GameDepot.BLOCK_SIZE.length; scale++) {
...@@ -148,7 +148,7 @@ public class SpawnDataEntry { ...@@ -148,7 +148,7 @@ public class SpawnDataEntry {
return results; return results;
} }
public static int getScale(int gadgetId){ public static int getScale(int gadgetId) {
return 0;//you should implement here,this is index of GameDepot.BLOCK_SIZE return 0;//you should implement here,this is index of GameDepot.BLOCK_SIZE
} }
} }
......
...@@ -30,7 +30,7 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -30,7 +30,7 @@ public class WorldDataSystem extends BaseGameSystem {
private final Map<String, ChestInteractHandler> chestInteractHandlerMap; // chestType-Handler private final Map<String, ChestInteractHandler> chestInteractHandlerMap; // chestType-Handler
private final Map<String, SceneGroup> sceneInvestigationGroupMap; // <sceneId_groupId, Group> private final Map<String, SceneGroup> sceneInvestigationGroupMap; // <sceneId_groupId, Group>
public WorldDataSystem(GameServer server){ public WorldDataSystem(GameServer server) {
super(server); super(server);
this.chestInteractHandlerMap = new HashMap<>(); this.chestInteractHandlerMap = new HashMap<>();
this.sceneInvestigationGroupMap = new ConcurrentHashMap<>(); this.sceneInvestigationGroupMap = new ConcurrentHashMap<>();
...@@ -38,11 +38,11 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -38,11 +38,11 @@ public class WorldDataSystem extends BaseGameSystem {
loadChestConfig(); loadChestConfig();
} }
public synchronized void loadChestConfig(){ public synchronized void loadChestConfig() {
// set the special chest first // set the special chest first
chestInteractHandlerMap.put("SceneObj_Chest_Flora", new BossChestInteractHandler()); chestInteractHandlerMap.put("SceneObj_Chest_Flora", new BossChestInteractHandler());
try(Reader reader = DataLoader.loadReader("ChestReward.json")) { try (Reader reader = DataLoader.loadReader("ChestReward.json")) {
List<ChestReward> chestReward = Grasscutter.getGsonFactory().fromJson( List<ChestReward> chestReward = Grasscutter.getGsonFactory().fromJson(
reader, reader,
TypeToken.getParameterized(List.class, ChestReward.class).getType()); TypeToken.getParameterized(List.class, ChestReward.class).getType());
...@@ -60,21 +60,21 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -60,21 +60,21 @@ public class WorldDataSystem extends BaseGameSystem {
return chestInteractHandlerMap; return chestInteractHandlerMap;
} }
public RewardPreviewData getRewardByBossId(int monsterId){ public RewardPreviewData getRewardByBossId(int monsterId) {
var investigationMonsterData = GameData.getInvestigationMonsterDataMap().values().parallelStream() var investigationMonsterData = GameData.getInvestigationMonsterDataMap().values().parallelStream()
.filter(imd -> imd.getMonsterIdList() != null && !imd.getMonsterIdList().isEmpty()) .filter(imd -> imd.getMonsterIdList() != null && !imd.getMonsterIdList().isEmpty())
.filter(imd -> imd.getMonsterIdList().get(0) == monsterId) .filter(imd -> imd.getMonsterIdList().get(0) == monsterId)
.findFirst(); .findFirst();
if(investigationMonsterData.isEmpty()){ if (investigationMonsterData.isEmpty()) {
return null; return null;
} }
return GameData.getRewardPreviewDataMap().get(investigationMonsterData.get().getRewardPreviewId()); return GameData.getRewardPreviewDataMap().get(investigationMonsterData.get().getRewardPreviewId());
} }
private SceneGroup getInvestigationGroup(int sceneId, int groupId){ private SceneGroup getInvestigationGroup(int sceneId, int groupId) {
var key = sceneId + "_" + groupId; var key = sceneId + "_" + groupId;
if(!sceneInvestigationGroupMap.containsKey(key)){ if (!sceneInvestigationGroupMap.containsKey(key)) {
var group = SceneGroup.of(groupId).load(sceneId); var group = SceneGroup.of(groupId).load(sceneId);
sceneInvestigationGroupMap.putIfAbsent(key, group); sceneInvestigationGroupMap.putIfAbsent(key, group);
return group; return group;
...@@ -82,7 +82,7 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -82,7 +82,7 @@ public class WorldDataSystem extends BaseGameSystem {
return sceneInvestigationGroupMap.get(key); return sceneInvestigationGroupMap.get(key);
} }
public int getMonsterLevel(SceneMonster monster, World world){ public int getMonsterLevel(SceneMonster monster, World world) {
// Calculate level // Calculate level
int level = monster.level; int level = monster.level;
WorldLevelData worldLevelData = GameData.getWorldLevelDataMap().get(world.getWorldLevel()); WorldLevelData worldLevelData = GameData.getWorldLevelDataMap().get(world.getWorldLevel());
...@@ -98,14 +98,14 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -98,14 +98,14 @@ public class WorldDataSystem extends BaseGameSystem {
var sceneId = imd.getCityData().getSceneId(); var sceneId = imd.getCityData().getSceneId();
var group = getInvestigationGroup(sceneId, groupId); var group = getInvestigationGroup(sceneId, groupId);
if(group == null || group.monsters == null){ if (group == null || group.monsters == null) {
return null; return null;
} }
var monster = group.monsters.values().stream() var monster = group.monsters.values().stream()
.filter(x -> x.monster_id == monsterId) .filter(x -> x.monster_id == monsterId)
.findFirst(); .findFirst();
if(monster.isEmpty()){ if (monster.isEmpty()) {
return null; return null;
} }
...@@ -122,9 +122,9 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -122,9 +122,9 @@ public class WorldDataSystem extends BaseGameSystem {
.setRefreshInterval(Integer.MAX_VALUE) .setRefreshInterval(Integer.MAX_VALUE)
.setPos(monster.get().pos.toProto()); .setPos(monster.get().pos.toProto());
if("Boss".equals(imd.getMonsterCategory())){ if ("Boss".equals(imd.getMonsterCategory())) {
var bossChest = group.searchBossChestInGroup(); var bossChest = group.searchBossChestInGroup();
if(bossChest.isPresent()){ if (bossChest.isPresent()) {
builder.setResin(bossChest.get().resin); builder.setResin(bossChest.get().resin);
builder.setBossChestNum(bossChest.get().take_num); builder.setBossChestNum(bossChest.get().take_num);
} }
...@@ -132,9 +132,9 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -132,9 +132,9 @@ public class WorldDataSystem extends BaseGameSystem {
return builder.build(); return builder.build();
} }
public List<InvestigationMonsterOuterClass.InvestigationMonster> getInvestigationMonstersByCityId(Player player, int cityId){ public List<InvestigationMonsterOuterClass.InvestigationMonster> getInvestigationMonstersByCityId(Player player, int cityId) {
var cityData = GameData.getCityDataMap().get(cityId); var cityData = GameData.getCityDataMap().get(cityId);
if(cityData == null){ if (cityData == null) {
Grasscutter.getLogger().warn("City not exist {}", cityId); Grasscutter.getLogger().warn("City not exist {}", cityId);
return List.of(); return List.of();
} }
......
...@@ -37,7 +37,7 @@ public class PacketOpcodesUtils { ...@@ -37,7 +37,7 @@ public class PacketOpcodesUtils {
Field[] fields = PacketOpcodes.class.getFields(); Field[] fields = PacketOpcodes.class.getFields();
for (Field f : fields) { for (Field f : fields) {
if(f.getType().equals(int.class)) { if (f.getType().equals(int.class)) {
try { try {
opcodeMap.put(f.getInt(null), f.getName()); opcodeMap.put(f.getInt(null), f.getName());
} catch (Exception e) { } catch (Exception e) {
......
...@@ -30,7 +30,7 @@ public abstract class Plugin { ...@@ -30,7 +30,7 @@ public abstract class Plugin {
* @param identifier The plugin's identifier. * @param identifier The plugin's identifier.
*/ */
private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) { private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) {
if(this.identifier != null) { if (this.identifier != null) {
Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt."); Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt.");
return; return;
} }
...@@ -40,7 +40,7 @@ public abstract class Plugin { ...@@ -40,7 +40,7 @@ public abstract class Plugin {
this.dataFolder = new File(PLUGIN(), identifier.name); this.dataFolder = new File(PLUGIN(), identifier.name);
this.logger = LoggerFactory.getLogger(identifier.name); this.logger = LoggerFactory.getLogger(identifier.name);
if(!this.dataFolder.exists() && !this.dataFolder.mkdirs()) { if (!this.dataFolder.exists() && !this.dataFolder.mkdirs()) {
Grasscutter.getLogger().warn("Failed to create plugin data folder for " + this.identifier.name); Grasscutter.getLogger().warn("Failed to create plugin data folder for " + this.identifier.name);
return; return;
} }
...@@ -50,7 +50,7 @@ public abstract class Plugin { ...@@ -50,7 +50,7 @@ public abstract class Plugin {
* The plugin's identifier instance. * The plugin's identifier instance.
* @return An instance of {@link PluginIdentifier}. * @return An instance of {@link PluginIdentifier}.
*/ */
public final PluginIdentifier getIdentifier(){ public final PluginIdentifier getIdentifier() {
return this.identifier; return this.identifier;
} }
......
...@@ -72,7 +72,7 @@ public final class PluginManager { ...@@ -72,7 +72,7 @@ public final class PluginManager {
List<PluginData> dependencies = new ArrayList<>(); List<PluginData> dependencies = new ArrayList<>();
// Initialize all plugins. // Initialize all plugins.
for(var plugin : plugins) { for (var plugin : plugins) {
try { try {
URL url = plugin.toURI().toURL(); URL url = plugin.toURI().toURL();
try (URLClassLoader loader = new URLClassLoader(new URL[]{url})) { try (URLClassLoader loader = new URLClassLoader(new URL[]{url})) {
...@@ -109,7 +109,7 @@ public final class PluginManager { ...@@ -109,7 +109,7 @@ public final class PluginManager {
fileReader.close(); fileReader.close();
// Check if the plugin has alternate dependencies. // Check if the plugin has alternate dependencies.
if(pluginConfig.loadAfter != null && pluginConfig.loadAfter.length > 0) { if (pluginConfig.loadAfter != null && pluginConfig.loadAfter.length > 0) {
// Add the plugin to a "load later" list. // Add the plugin to a "load later" list.
dependencies.add(new PluginData( dependencies.add(new PluginData(
pluginInstance, PluginIdentifier.fromPluginConfig(pluginConfig), pluginInstance, PluginIdentifier.fromPluginConfig(pluginConfig),
...@@ -131,9 +131,9 @@ public final class PluginManager { ...@@ -131,9 +131,9 @@ public final class PluginManager {
// Load plugins with dependencies. // Load plugins with dependencies.
int depth = 0; final int maxDepth = 30; int depth = 0; final int maxDepth = 30;
while(!dependencies.isEmpty()) { while (!dependencies.isEmpty()) {
// Check if the depth is too high. // Check if the depth is too high.
if(depth >= maxDepth) { if (depth >= maxDepth) {
Grasscutter.getLogger().error("Failed to load plugins with dependencies."); Grasscutter.getLogger().error("Failed to load plugins with dependencies.");
break; break;
} }
...@@ -143,7 +143,7 @@ public final class PluginManager { ...@@ -143,7 +143,7 @@ public final class PluginManager {
var pluginData = dependencies.get(0); var pluginData = dependencies.get(0);
// Check if the plugin's dependencies are loaded. // Check if the plugin's dependencies are loaded.
if(!this.plugins.keySet().containsAll(List.of(pluginData.getDependencies()))) { if (!this.plugins.keySet().containsAll(List.of(pluginData.getDependencies()))) {
depth++; // Increase depth counter. depth++; // Increase depth counter.
continue; // Continue to next plugin. continue; // Continue to next plugin.
} }
......
...@@ -45,8 +45,8 @@ public class SceneBlock { ...@@ -45,8 +45,8 @@ public class SceneBlock {
pos.getZ() <= this.max.getZ() && pos.getZ() >= this.min.getZ(); pos.getZ() <= this.max.getZ() && pos.getZ() >= this.min.getZ();
} }
public SceneBlock load(int sceneId, Bindings bindings){ public SceneBlock load(int sceneId, Bindings bindings) {
if(this.loaded){ if (this.loaded) {
return this; return this;
} }
this.sceneId = sceneId; this.sceneId = sceneId;
......
...@@ -75,8 +75,8 @@ public class SceneGroup { ...@@ -75,8 +75,8 @@ public class SceneGroup {
return this.bindings; return this.bindings;
} }
public synchronized SceneGroup load(int sceneId){ public synchronized SceneGroup load(int sceneId) {
if(this.loaded){ if (this.loaded) {
return this; return this;
} }
// Set flag here so if there is no script, we don't call this function over and over again. // Set flag here so if there is no script, we don't call this function over and over again.
......
...@@ -33,7 +33,7 @@ public class SceneMeta { ...@@ -33,7 +33,7 @@ public class SceneMeta {
return new SceneMeta().load(sceneId); return new SceneMeta().load(sceneId);
} }
public SceneMeta load(int sceneId){ public SceneMeta load(int sceneId) {
// Get compiled script if cached // Get compiled script if cached
CompiledScript cs = ScriptLoader.getScriptByPath( CompiledScript cs = ScriptLoader.getScriptByPath(
SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "." + ScriptLoader.getScriptType())); SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "." + ScriptLoader.getScriptType()));
......
...@@ -150,11 +150,11 @@ public final class GameServer extends KcpServer { ...@@ -150,11 +150,11 @@ public final class GameServer extends KcpServer {
this.chatManager = chatManager; this.chatManager = chatManager;
} }
private static InetSocketAddress getAdapterInetSocketAddress(){ private static InetSocketAddress getAdapterInetSocketAddress() {
InetSocketAddress inetSocketAddress; InetSocketAddress inetSocketAddress;
if(GAME_INFO.bindAddress.equals("")){ if (GAME_INFO.bindAddress.equals("")) {
inetSocketAddress=new InetSocketAddress(GAME_INFO.bindPort); inetSocketAddress=new InetSocketAddress(GAME_INFO.bindPort);
}else{ }else {
inetSocketAddress=new InetSocketAddress( inetSocketAddress=new InetSocketAddress(
GAME_INFO.bindAddress, GAME_INFO.bindAddress,
GAME_INFO.bindPort GAME_INFO.bindPort
......
...@@ -84,7 +84,7 @@ public class GameServerPacketHandler { ...@@ -84,7 +84,7 @@ public class GameServerPacketHandler {
// Invoke event. // Invoke event.
ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload); event.call(); ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload); event.call();
if(!event.isCanceled()) // If event is not canceled, continue. if (!event.isCanceled()) // If event is not canceled, continue.
handler.handle(session, header, event.getPacketData()); handler.handle(session, header, event.getPacketData());
} catch (Exception ex) { } catch (Exception ex) {
// TODO Remove this when no more needed // TODO Remove this when no more needed
......
...@@ -45,9 +45,9 @@ public class GameSession implements GameSessionManager.KcpChannel { ...@@ -45,9 +45,9 @@ public class GameSession implements GameSessionManager.KcpChannel {
} }
public InetSocketAddress getAddress() { public InetSocketAddress getAddress() {
try{ try {
return tunnel.getAddress(); return tunnel.getAddress();
}catch (Throwable ignore){ }catch (Throwable ignore) {
return null; return null;
} }
} }
...@@ -138,7 +138,7 @@ public class GameSession implements GameSessionManager.KcpChannel { ...@@ -138,7 +138,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
// DO NOT REMOVE (unless we find a way to validate code before sending to client which I don't think we can) // DO NOT REMOVE (unless we find a way to validate code before sending to client which I don't think we can)
// Stop WindSeedClientNotify from being sent for security purposes. // Stop WindSeedClientNotify from being sent for security purposes.
if(PacketOpcodesUtils.BANNED_PACKETS.contains(packet.getOpcode())) { if (PacketOpcodesUtils.BANNED_PACKETS.contains(packet.getOpcode())) {
return; return;
} }
...@@ -169,7 +169,7 @@ public class GameSession implements GameSessionManager.KcpChannel { ...@@ -169,7 +169,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
// Invoke event. // Invoke event.
SendPacketEvent event = new SendPacketEvent(this, packet); event.call(); SendPacketEvent event = new SendPacketEvent(this, packet); event.call();
if(!event.isCanceled()) { // If event is not cancelled, continue. if (!event.isCanceled()) { // If event is not cancelled, continue.
tunnel.writeData(event.getPacket().build()); tunnel.writeData(event.getPacket().build());
} }
} }
...@@ -200,7 +200,7 @@ public class GameSession implements GameSessionManager.KcpChannel { ...@@ -200,7 +200,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
// Packet sanity check // Packet sanity check
int const1 = packet.readShort(); int const1 = packet.readShort();
if (const1 != 17767) { if (const1 != 17767) {
if(allDebug){ if (allDebug) {
Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect 17767",const1); Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect 17767",const1);
} }
return; // Bad packet return; // Bad packet
...@@ -217,7 +217,7 @@ public class GameSession implements GameSessionManager.KcpChannel { ...@@ -217,7 +217,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
// Sanity check #2 // Sanity check #2
int const2 = packet.readShort(); int const2 = packet.readShort();
if (const2 != -30293) { if (const2 != -30293) {
if(allDebug){ if (allDebug) {
Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect -30293",const2); Grasscutter.getLogger().error("Bad Data Package Received: got {} ,expect -30293",const2);
} }
return; // Bad packet return; // Bad packet
...@@ -267,7 +267,7 @@ public class GameSession implements GameSessionManager.KcpChannel { ...@@ -267,7 +267,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
} }
try { try {
send(new BasePacket(PacketOpcodes.ServerDisconnectClientNotify)); send(new BasePacket(PacketOpcodes.ServerDisconnectClientNotify));
}catch (Throwable ignore){ }catch (Throwable ignore) {
Grasscutter.getLogger().warn("closing {} error",getAddress().getAddress().getHostAddress()); Grasscutter.getLogger().warn("closing {} error",getAddress().getAddress().getHostAddress());
} }
tunnel = null; tunnel = null;
......
...@@ -35,7 +35,7 @@ public final class HttpServer { ...@@ -35,7 +35,7 @@ public final class HttpServer {
config.enforceSsl = HTTP_ENCRYPTION.useEncryption; config.enforceSsl = HTTP_ENCRYPTION.useEncryption;
// Configure HTTP policies. // Configure HTTP policies.
if(HTTP_POLICIES.cors.enabled) { if (HTTP_POLICIES.cors.enabled) {
var allowedOrigins = HTTP_POLICIES.cors.allowedOrigins; var allowedOrigins = HTTP_POLICIES.cors.allowedOrigins;
if (allowedOrigins.length > 0) if (allowedOrigins.length > 0)
config.enableCorsForOrigin(allowedOrigins); config.enableCorsForOrigin(allowedOrigins);
...@@ -43,7 +43,7 @@ public final class HttpServer { ...@@ -43,7 +43,7 @@ public final class HttpServer {
} }
// Configure debug logging. // Configure debug logging.
if(DISPATCH_INFO.logRequests == ServerDebugMode.ALL) if (DISPATCH_INFO.logRequests == ServerDebugMode.ALL)
config.enableDevLogging(); config.enableDevLogging();
// Disable compression on static files. // Disable compression on static files.
...@@ -61,11 +61,11 @@ public final class HttpServer { ...@@ -61,11 +61,11 @@ public final class HttpServer {
ServerConnector serverConnector ServerConnector serverConnector
= new ServerConnector(server); = new ServerConnector(server);
if(HTTP_ENCRYPTION.useEncryption) { if (HTTP_ENCRYPTION.useEncryption) {
var sslContextFactory = new SslContextFactory.Server(); var sslContextFactory = new SslContextFactory.Server();
var keystoreFile = new File(HTTP_ENCRYPTION.keystore); var keystoreFile = new File(HTTP_ENCRYPTION.keystore);
if(!keystoreFile.exists()) { if (!keystoreFile.exists()) {
HTTP_ENCRYPTION.useEncryption = false; HTTP_ENCRYPTION.useEncryption = false;
HTTP_ENCRYPTION.useInRouting = false; HTTP_ENCRYPTION.useInRouting = false;
...@@ -112,7 +112,7 @@ public final class HttpServer { ...@@ -112,7 +112,7 @@ public final class HttpServer {
public HttpServer addRouter(Class<? extends Router> router, Object... args) { public HttpServer addRouter(Class<? extends Router> router, Object... args) {
// Get all constructor parameters. // Get all constructor parameters.
Class<?>[] types = new Class<?>[args.length]; Class<?>[] types = new Class<?>[args.length];
for(var argument : args) for (var argument : args)
types[args.length - 1] = argument.getClass(); types[args.length - 1] = argument.getClass();
try { // Create a router instance & apply routes. try { // Create a router instance & apply routes.
...@@ -130,9 +130,9 @@ public final class HttpServer { ...@@ -130,9 +130,9 @@ public final class HttpServer {
*/ */
public void start() throws UnsupportedEncodingException { public void start() throws UnsupportedEncodingException {
// Attempt to start the HTTP server. // Attempt to start the HTTP server.
if(HTTP_INFO.bindAddress.equals("")){ if (HTTP_INFO.bindAddress.equals("")) {
this.express.listen(HTTP_INFO.bindPort); this.express.listen(HTTP_INFO.bindPort);
}else{ }else {
this.express.listen(HTTP_INFO.bindAddress, HTTP_INFO.bindPort); this.express.listen(HTTP_INFO.bindAddress, HTTP_INFO.bindPort);
} }
...@@ -147,7 +147,7 @@ public final class HttpServer { ...@@ -147,7 +147,7 @@ public final class HttpServer {
@Override public void applyRoutes(Express express, Javalin handle) { @Override public void applyRoutes(Express express, Javalin handle) {
express.get("/", (request, response) -> { express.get("/", (request, response) -> {
File file = new File(HTTP_STATIC_FILES.indexFile); File file = new File(HTTP_STATIC_FILES.indexFile);
if(!file.exists()) if (!file.exists())
response.send(""" response.send("""
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
...@@ -173,12 +173,12 @@ public final class HttpServer { ...@@ -173,12 +173,12 @@ public final class HttpServer {
public static class UnhandledRequestRouter implements Router { public static class UnhandledRequestRouter implements Router {
@Override public void applyRoutes(Express express, Javalin handle) { @Override public void applyRoutes(Express express, Javalin handle) {
handle.error(404, context -> { handle.error(404, context -> {
if(DISPATCH_INFO.logRequests == ServerDebugMode.MISSING) if (DISPATCH_INFO.logRequests == ServerDebugMode.MISSING)
Grasscutter.getLogger().info(translate("messages.dispatch.unhandled_request_error", context.method(), context.url())); Grasscutter.getLogger().info(translate("messages.dispatch.unhandled_request_error", context.method(), context.url()));
context.contentType("text/html"); context.contentType("text/html");
File file = new File(HTTP_STATIC_FILES.errorFile); File file = new File(HTTP_STATIC_FILES.errorFile);
if(!file.exists()) if (!file.exists())
context.result(""" context.result("""
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
......
...@@ -60,7 +60,7 @@ public final class RegionHandler implements Router { ...@@ -60,7 +60,7 @@ public final class RegionHandler implements Router {
List<String> usedNames = new ArrayList<>(); // List to check for potential naming conflicts. List<String> usedNames = new ArrayList<>(); // List to check for potential naming conflicts.
var configuredRegions = new ArrayList<>(List.of(DISPATCH_INFO.regions)); var configuredRegions = new ArrayList<>(List.of(DISPATCH_INFO.regions));
if(SERVER.runMode != ServerRunMode.HYBRID && configuredRegions.size() == 0) { if (SERVER.runMode != ServerRunMode.HYBRID && configuredRegions.size() == 0) {
Grasscutter.getLogger().error("[Dispatch] There are no game servers available. Exiting due to unplayable state."); Grasscutter.getLogger().error("[Dispatch] There are no game servers available. Exiting due to unplayable state.");
System.exit(1); System.exit(1);
} else if (configuredRegions.size() == 0) } else if (configuredRegions.size() == 0)
...@@ -136,11 +136,11 @@ public final class RegionHandler implements Router { ...@@ -136,11 +136,11 @@ public final class RegionHandler implements Router {
// Get region data. // Get region data.
String regionData = "CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw=="; String regionData = "CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw==";
if (request.query().values().size() > 0) { if (request.query().values().size() > 0) {
if(region != null) if (region != null)
regionData = region.getBase64(); regionData = region.getBase64();
} }
if( versionName.contains("2.7.5") || versionName.contains("2.8.")) { if ( versionName.contains("2.7.5") || versionName.contains("2.8.")) {
try { try {
QueryCurrentRegionEvent event = new QueryCurrentRegionEvent(regionData); event.call(); QueryCurrentRegionEvent event = new QueryCurrentRegionEvent(regionData); event.call();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment