Commit 56efeb2f authored by memetrollsXD's avatar memetrollsXD Committed by GitHub
Browse files

Merge branch 'development' into memetrollsXD-patch-1

parents 8d1c571c 027bd28a
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.VehicleSpawnReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketVehicleSpawnRsp;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.VehicleSpawnReq)
public class HandlerVehicleSpawnReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
VehicleSpawnReqOuterClass.VehicleSpawnReq req = VehicleSpawnReqOuterClass.VehicleSpawnReq.parseFrom(payload);
session.send(new PacketVehicleSpawnRsp(session.getPlayer(), req.getVehicleId(), req.getPointId(), new Position(req.getPos()), new Position(req.getRot())));
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.BuyGoodsRspOuterClass;
import emu.grasscutter.net.proto.ShopGoodsOuterClass;
public class PacketBuyGoodsRsp extends BasePacket {
public PacketBuyGoodsRsp(int shopType, int boughtNum, ShopGoodsOuterClass.ShopGoods sg) {
super(PacketOpcodes.BuyGoodsRsp);
BuyGoodsRspOuterClass.BuyGoodsRsp buyGoodsRsp = BuyGoodsRspOuterClass.BuyGoodsRsp.newBuilder()
.setShopType(shopType)
.setBoughtNum(boughtNum)
.addGoodsList(ShopGoodsOuterClass.ShopGoods.newBuilder()
.mergeFrom(sg)
.setBoughtNum(boughtNum)
).build();
this.setData(buyGoodsRsp);
}
}
...@@ -11,7 +11,7 @@ public class PacketChangeAvatarRsp extends BasePacket { ...@@ -11,7 +11,7 @@ public class PacketChangeAvatarRsp extends BasePacket {
super(PacketOpcodes.ChangeAvatarRsp); super(PacketOpcodes.ChangeAvatarRsp);
ChangeAvatarRsp p = ChangeAvatarRsp.newBuilder() ChangeAvatarRsp p = ChangeAvatarRsp.newBuilder()
.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) .setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE)
.setCurGuid(guid) .setCurGuid(guid)
.build(); .build();
......
...@@ -14,32 +14,23 @@ import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent; ...@@ -14,32 +14,23 @@ import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64;
import java.util.List; import java.util.List;
public class PacketGetAllMailRsp extends BasePacket { public class PacketGetAllMailRsp extends BasePacket {
public PacketGetAllMailRsp(Player player, boolean isGiftMail) { public PacketGetAllMailRsp(Player player, boolean isGiftMail) {
super(PacketOpcodes.GetAllMailRsp); super(PacketOpcodes.GetAllMailRsp);
GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder();
if (isGiftMail) { if (isGiftMail) {
// TODO: Gift Mail proto.setIsGiftMail(true);
// Make sure to send the stupid empty packet
Base64.Decoder decoder = Base64.getDecoder();
byte[] rsp = decoder.decode("IAE=");
try {
GetAllMailRsp var = GetAllMailRsp.parseFrom(rsp);
this.setData(var.toBuilder().build());
} catch (Exception e) {
}
} else { } else {
proto.setIsGiftMail(false);
if (player.getAllMail().size() != 0) { // Make sure the player has mail if (player.getAllMail().size() != 0) { // Make sure the player has mail
GetAllMailRsp.Builder proto = GetAllMailRsp.newBuilder();
List<MailData> mailDataList = new ArrayList<MailData>(); List<MailData> mailDataList = new ArrayList<MailData>();
for (Mail message : player.getAllMail()) { for (Mail message : player.getAllMail()) {
if(message.stateValue == 1) { // Make sure it isn't a gift if(message.stateValue == 1) { // Make sure it isn't a gift
if (message.expireTime > (int) Instant.now().getEpochSecond()) { // Make sure the message isn't expired (The game won't show expired mail, but I don't want to send unnecessary information). if (message.expireTime > (int) Instant.now().getEpochSecond()) { // Make sure the message isn't expired (The game won't show expired mail, but I don't want to send unnecessary information).
if(mailDataList.size() <= 1000) { // Make sure that there isn't over 1000 messages in the mailbox. (idk what will happen if there is but the game probably won't like it.) if(mailDataList.size() <= 1000) { // Make sure that there isn't over 1000 messages in the mailbox. (idk what will happen if there is but the game probably won't like it.)
...@@ -79,17 +70,8 @@ public class PacketGetAllMailRsp extends BasePacket { ...@@ -79,17 +70,8 @@ public class PacketGetAllMailRsp extends BasePacket {
proto.addAllMailList(mailDataList); proto.addAllMailList(mailDataList);
proto.setIsTruncated(mailDataList.size() <= 1000 ? false : true); // When enabled this will send a notification to the user telling them their inbox is full and they should delete old messages when opening the mailbox. proto.setIsTruncated(mailDataList.size() <= 1000 ? false : true); // When enabled this will send a notification to the user telling them their inbox is full and they should delete old messages when opening the mailbox.
this.setData(proto.build());
} else {
// Make sure to send the stupid empty packet
Base64.Decoder decoder = Base64.getDecoder();
byte[] rsp = decoder.decode("IAE=");
try {
GetAllMailRsp var = GetAllMailRsp.parseFrom(rsp);
this.setData(var.toBuilder().build());
} catch (Exception e) {}
} }
} }
this.setData(proto.build());
} }
} }
...@@ -8,7 +8,7 @@ import emu.grasscutter.net.packet.PacketOpcodes; ...@@ -8,7 +8,7 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief; import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief;
import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState; import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState;
import emu.grasscutter.net.proto.GetPlayerFriendListRspOuterClass.GetPlayerFriendListRsp; import emu.grasscutter.net.proto.GetPlayerFriendListRspOuterClass.GetPlayerFriendListRsp;
import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
import emu.grasscutter.net.proto.PlatformTypeOuterClass; import emu.grasscutter.net.proto.PlatformTypeOuterClass;
public class PacketGetPlayerFriendListRsp extends BasePacket { public class PacketGetPlayerFriendListRsp extends BasePacket {
...@@ -20,7 +20,7 @@ public class PacketGetPlayerFriendListRsp extends BasePacket { ...@@ -20,7 +20,7 @@ public class PacketGetPlayerFriendListRsp extends BasePacket {
.setUid(GameConstants.SERVER_CONSOLE_UID) .setUid(GameConstants.SERVER_CONSOLE_UID)
.setNickname("Server") .setNickname("Server")
.setLevel(1) .setLevel(1)
.setAvatarId(HeadImage.newBuilder().setAvatarId(GameConstants.MAIN_CHARACTER_FEMALE).getAvatarId()) .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(GameConstants.MAIN_CHARACTER_FEMALE))
.setWorldLevel(0) .setWorldLevel(0)
.setSignature("") .setSignature("")
.setLastActiveTime((int) (System.currentTimeMillis() / 1000f)) .setLastActiveTime((int) (System.currentTimeMillis() / 1000f))
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.shop.ShopInfo;
import emu.grasscutter.game.shop.ShopManager;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetShopRspOuterClass.GetShopRsp; import emu.grasscutter.net.proto.GetShopRspOuterClass;
import emu.grasscutter.net.proto.ItemParamOuterClass;
import emu.grasscutter.net.proto.ShopGoodsOuterClass.ShopGoods;
import emu.grasscutter.net.proto.ShopOuterClass.Shop; import emu.grasscutter.net.proto.ShopOuterClass.Shop;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class PacketGetShopRsp extends BasePacket { public class PacketGetShopRsp extends BasePacket {
public PacketGetShopRsp(int shopType) { public PacketGetShopRsp(Player inv, int shopType) {
super(PacketOpcodes.GetShopRsp); super(PacketOpcodes.GetShopRsp);
GetShopRsp proto = GetShopRsp.newBuilder() // TODO: CityReputationLevel
.setShop(Shop.newBuilder().setShopType(shopType)) Shop.Builder shop = Shop.newBuilder()
.build(); .setShopType(shopType)
.setCityId(1) //mock
this.setData(proto); .setCityReputationLevel(10); //mock
ShopManager manager = Grasscutter.getGameServer().getShopManager();
if (manager.getShopData().get(shopType) != null) {
List<ShopInfo> list = manager.getShopData().get(shopType);
List<ShopGoods> goodsList = new ArrayList<>();
for (ShopInfo info : list) {
ShopGoods.Builder goods = ShopGoods.newBuilder()
.setGoodsId(info.getGoodsId())
.setGoodsItem(ItemParamOuterClass.ItemParam.newBuilder().setItemId(info.getGoodsItem().getId()).setCount(info.getGoodsItem().getCount()).build())
.setScoin(info.getScoin())
.setHcoin(info.getHcoin())
.setBoughtNum(inv.getGoodsLimitNum(info.getGoodsId()))
.setBuyLimit(info.getBuyLimit())
.setBeginTime(info.getBeginTime())
.setEndTime(info.getEndTime())
.setNextRefreshTime(info.getNextRefreshTime())
.setMinLevel(info.getMinLevel())
.setMaxLevel(info.getMaxLevel())
.addAllPreGoodsIdList(info.getPreGoodsIdList())
.setMcoin(info.getMcoin())
.setDisableType(info.getDisableType())
.setSecondarySheetId(info.getSecondarySheetId());
if (info.getCostItemList() != null) {
goods.addAllCostItemList(info.getCostItemList().stream().map(x -> ItemParamOuterClass.ItemParam.newBuilder().setItemId(x.getId()).setCount(x.getCount()).build()).collect(Collectors.toList()));
}
goodsList.add(goods.build());
}
shop.addAllGoodsList(goodsList);
}
this.setData(GetShopRspOuterClass.GetShopRsp.newBuilder().setShop(shop).build());
} }
} }
...@@ -3,7 +3,7 @@ package emu.grasscutter.server.packet.send; ...@@ -3,7 +3,7 @@ package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
import emu.grasscutter.net.proto.SetPlayerHeadImageRspOuterClass.SetPlayerHeadImageRsp; import emu.grasscutter.net.proto.SetPlayerHeadImageRspOuterClass.SetPlayerHeadImageRsp;
public class PacketSetPlayerHeadImageRsp extends BasePacket { public class PacketSetPlayerHeadImageRsp extends BasePacket {
...@@ -12,7 +12,7 @@ public class PacketSetPlayerHeadImageRsp extends BasePacket { ...@@ -12,7 +12,7 @@ public class PacketSetPlayerHeadImageRsp extends BasePacket {
super(PacketOpcodes.SetPlayerHeadImageRsp); super(PacketOpcodes.SetPlayerHeadImageRsp);
SetPlayerHeadImageRsp proto = SetPlayerHeadImageRsp.newBuilder() SetPlayerHeadImageRsp proto = SetPlayerHeadImageRsp.newBuilder()
.setAvatarId(HeadImage.newBuilder().setAvatarId(player.getHeadImage()).getAvatarId()) .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(player.getHeadImage()))
.build(); .build();
this.setData(proto); this.setData(proto);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.UpdatePlayerShowAvatarListRspOuterClass.UpdatePlayerShowAvatarListRsp;
import java.util.List;
public class PacketUpdatePlayerShowAvatarListRsp extends BasePacket {
public PacketUpdatePlayerShowAvatarListRsp(boolean isShowAvatar, List<Integer> avatarIds) {
super(PacketOpcodes.UpdatePlayerShowAvatarListRsp);
UpdatePlayerShowAvatarListRsp proto = UpdatePlayerShowAvatarListRsp.newBuilder()
.setIsShowAvatar(isShowAvatar)
.addAllShowAvatarIdList(avatarIds)
.setRetcode(0)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.VehicleInteractTypeOuterClass.VehicleInteractType;
import emu.grasscutter.net.proto.VehicleInteractRspOuterClass.VehicleInteractRsp;
import emu.grasscutter.net.proto.VehicleMemberOuterClass.VehicleMember;
public class PacketVehicleInteractRsp extends BasePacket {
public PacketVehicleInteractRsp(Player player, int entityId, VehicleInteractType interactType) {
super(PacketOpcodes.VehicleInteractRsp);
VehicleInteractRsp.Builder proto = VehicleInteractRsp.newBuilder();
GameEntity vehicle = player.getScene().getEntityById(entityId);
if(vehicle != null) {
proto.setEntityId(vehicle.getId());
proto.setInteractType(interactType);
VehicleMember vehicleMember = VehicleMember.newBuilder()
.setUid(player.getUid())
.setAvatarGuid(player.getTeamManager().getCurrentCharacterGuid())
.build();
proto.setMember(vehicleMember);
}
this.setData(proto.build());
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.entity.EntityVehicle;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.VehicleSpawnRspOuterClass.VehicleSpawnRsp;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
public class PacketVehicleSpawnRsp extends BasePacket {
public PacketVehicleSpawnRsp(Player player, int vehicleId, int pointId, Position pos, Position rot) {
super(PacketOpcodes.VehicleSpawnRsp);
VehicleSpawnRsp.Builder proto = VehicleSpawnRsp.newBuilder();
EntityVehicle vehicle = new EntityVehicle(player.getScene(), player, vehicleId, pointId, pos, rot);
switch (vehicleId) {
// TODO: Not hardcode this. Waverider (skiff)
case 45001001,45001002 -> {
vehicle.addFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 10000);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_BASE_ATTACK, 100);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, 100);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 10000);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, 0);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
vehicle.addFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 10000);
}
default -> {}
}
player.getScene().addEntity(vehicle);
proto.setVehicleId(vehicleId);
proto.setEntityId(vehicle.getId());
this.setData(proto.build());
}
}
package emu.grasscutter.task; package emu.grasscutter.task;
import org.quartz.JobDataMap;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -27,4 +29,6 @@ public @interface Task { ...@@ -27,4 +29,6 @@ public @interface Task {
String taskName() default "NO_NAME"; String taskName() default "NO_NAME";
String taskCronExpression() default "0 0 0 0 0 ?"; String taskCronExpression() default "0 0 0 0 0 ?";
String triggerName() default "NO_NAME"; String triggerName() default "NO_NAME";
boolean executeImmediatelyAfterReset() default false;
boolean executeImmediately() default false;
} }
package emu.grasscutter.task; package emu.grasscutter.task;
import org.quartz.Job; import org.quartz.*;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; @PersistJobDataAfterExecution
public class TaskHandler implements Job {
public void restartExecute() throws JobExecutionException {
execute(null);
}
public void onEnable() {
public interface TaskHandler extends Job {
default void execute(JobExecutionContext context) throws JobExecutionException {
} }
public void onDisable() {
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// TODO Auto-generated method stub
}
} }
package emu.grasscutter.task; package emu.grasscutter.task;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.player.Player; import org.quartz.*;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory; import org.quartz.impl.StdSchedulerFactory;
import org.quartz.spi.MutableTrigger;
import org.reflections.Reflections; import org.reflections.Reflections;
import java.util.*; import java.util.*;
...@@ -23,6 +12,7 @@ import java.util.*; ...@@ -23,6 +12,7 @@ import java.util.*;
public final class TaskMap { public final class TaskMap {
private final Map<String, TaskHandler> tasks = new HashMap<>(); private final Map<String, TaskHandler> tasks = new HashMap<>();
private final Map<String, Task> annotations = new HashMap<>(); private final Map<String, Task> annotations = new HashMap<>();
private final Map<String, TaskHandler> afterReset = new HashMap<>();
private final SchedulerFactory schedulerFactory = new StdSchedulerFactory(); private final SchedulerFactory schedulerFactory = new StdSchedulerFactory();
public TaskMap() { public TaskMap() {
...@@ -37,6 +27,46 @@ public final class TaskMap { ...@@ -37,6 +27,46 @@ public final class TaskMap {
return Grasscutter.getGameServer().getTaskMap(); return Grasscutter.getGameServer().getTaskMap();
} }
public void resetNow() {
// Unregister all tasks
for (TaskHandler task : this.tasks.values()) {
unregisterTask(task);
}
// Run all afterReset tasks
for (TaskHandler task : this.afterReset.values()) {
try {
task.restartExecute();
} catch (Exception e) {
e.printStackTrace();
}
}
// Remove all afterReset tasks
this.afterReset.clear();
// Register all tasks
for (TaskHandler task : this.tasks.values()) {
registerTask(task.getClass().getAnnotation(Task.class).taskName(), task);
}
}
public TaskMap unregisterTask(TaskHandler task) {
this.tasks.remove(task.getClass().getAnnotation(Task.class).taskName());
this.annotations.remove(task.getClass().getAnnotation(Task.class).taskName());
try {
Scheduler scheduler = schedulerFactory.getScheduler();
scheduler.deleteJob(new JobKey(task.getClass().getAnnotation(Task.class).taskName()));
} catch (SchedulerException e) {
e.printStackTrace();
}
task.onDisable();
return this;
}
public TaskMap registerTask(String taskName, TaskHandler task) { public TaskMap registerTask(String taskName, TaskHandler task) {
Task annotation = task.getClass().getAnnotation(Task.class); Task annotation = task.getClass().getAnnotation(Task.class);
this.annotations.put(taskName, annotation); this.annotations.put(taskName, annotation);
...@@ -56,7 +86,11 @@ public final class TaskMap { ...@@ -56,7 +86,11 @@ public final class TaskMap {
.build(); .build();
scheduler.scheduleJob(job, convTrigger); scheduler.scheduleJob(job, convTrigger);
scheduler.start();
if (annotation.executeImmediately()) {
task.execute(null);
}
task.onEnable();
} catch (SchedulerException e) { } catch (SchedulerException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -83,12 +117,24 @@ public final class TaskMap { ...@@ -83,12 +117,24 @@ public final class TaskMap {
try { try {
Task taskData = annotated.getAnnotation(Task.class); Task taskData = annotated.getAnnotation(Task.class);
Object object = annotated.newInstance(); Object object = annotated.newInstance();
if (object instanceof TaskHandler) if (object instanceof TaskHandler) {
this.registerTask(taskData.taskName(), (TaskHandler) object); this.registerTask(taskData.taskName(), (TaskHandler) object);
else Grasscutter.getLogger().error("Class " + annotated.getName() + " is not a TaskHandler!"); if (taskData.executeImmediatelyAfterReset()) {
this.afterReset.put(taskData.taskName(), (TaskHandler) object);
}
} else {
Grasscutter.getLogger().error("Class " + annotated.getName() + " is not a TaskHandler!");
}
} catch (Exception exception) { } catch (Exception exception) {
Grasscutter.getLogger().error("Failed to register task handler for " + annotated.getSimpleName(), exception); Grasscutter.getLogger().error("Failed to register task handler for " + annotated.getSimpleName(), exception);
} }
}); });
try {
Scheduler scheduler = schedulerFactory.getScheduler();
scheduler.start();
} catch (SchedulerException e) {
e.printStackTrace();
}
} }
} }
package emu.grasscutter.task.tasks; package emu.grasscutter.task.tasks;
import emu.grasscutter.database.DatabaseManager; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.task.Task; import emu.grasscutter.task.Task;
import emu.grasscutter.task.TaskHandler; import emu.grasscutter.task.TaskHandler;
import java.util.List;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
@Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger") @Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger")
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system) // taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system)
public final class MoonCard implements TaskHandler { public class MoonCard extends TaskHandler {
@Override
public void onEnable() {
Grasscutter.getLogger().info("[Task] MoonCard task enabled.");
}
@Override
public void onDisable() {
Grasscutter.getLogger().info("[Task] MoonCard task disabled.");
}
@Override @Override
public void execute(JobExecutionContext context) throws JobExecutionException { public synchronized void execute(JobExecutionContext context) throws JobExecutionException {
List<Player> players = DatabaseManager.getDatastore().find(Player.class).stream().toList(); Grasscutter.getGameServer().getPlayers().forEach((uid, player) -> {
for (Player player : players) {
if (player.isOnline()) { if (player.isOnline()) {
if (player.inMoonCard()) { if (player.inMoonCard()) {
player.getTodayMoonCard(); player.getTodayMoonCard();
} }
} }
} });
} }
} }
...@@ -33,7 +33,7 @@ if not "%JAVA_PATH%" == "DO_NOT_CHECK_PATH" ( ...@@ -33,7 +33,7 @@ if not "%JAVA_PATH%" == "DO_NOT_CHECK_PATH" (
goto :EXIT goto :EXIT
) )
) else set JAVA_PATH= ) else set JAVA_PATH=
if not exist "%SERVER_PATH%grasscutter.jar" ( if not exist "%SERVER_PATH%%SERVER_JAR_NAME%" (
call :LOG [ERROR] Server jar not found. call :LOG [ERROR] Server jar not found.
goto :EXIT goto :EXIT
) )
...@@ -129,7 +129,7 @@ del /f /q "%temp%\db.vbs" >nul 2>nul ...@@ -129,7 +129,7 @@ del /f /q "%temp%\db.vbs" >nul 2>nul
:GAME :GAME
call :LOG [INFO] Starting server... call :LOG [INFO] Starting server...
"%JAVA_PATH%java.exe" -jar "%SERVER_PATH%grasscutter.jar" "%JAVA_PATH%java.exe" -jar "%SERVER_PATH%%SERVER_JAR_NAME%"
call :LOG [INFO] Server stopped call :LOG [INFO] Server stopped
:EXIT :EXIT
......
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