This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,047 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: build plugin | ||
|
||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build_plugin: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
java-version: '18' | ||
distribution: 'adopt' | ||
- name: Build with Maven | ||
run: mvn --batch-mode package | ||
- name: upload artifacts | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: MinigamesQuests | ||
path: target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/ericlam/mc/mgquests/MinigameQuestListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.ericlam.mc.mgquests; | ||
|
||
import com.ericlam.mc.mgquests.config.QuestMessage; | ||
import com.ericlam.mc.mgquests.manager.ProgressManager; | ||
import com.ericlam.mc.mgquests.manager.QuestsStatsManager; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class MinigameQuestListener implements Listener { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MinigameQuestListener.class); | ||
@Inject | ||
private QuestsStatsManager questsStatsManager; | ||
|
||
@Inject | ||
private ProgressManager progressManager; | ||
|
||
@Inject | ||
private QuestMessage message; | ||
|
||
|
||
@EventHandler | ||
public void onPlayerJoin(PlayerJoinEvent e) { | ||
var player = e.getPlayer(); | ||
questsStatsManager.loadPlayerStats(player.getUniqueId()) | ||
.thenCompose(cache -> { | ||
try { | ||
return progressManager.loadAllResults(player.getUniqueId(), cache); | ||
} catch (QuestException qe) { | ||
var err = message.getLang().get(qe.getPath(), qe.getArgs()); | ||
LOGGER.warn(err); | ||
player.sendMessage(err); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
}).whenComplete((v, ex) -> { | ||
if (ex != null) { | ||
LOGGER.error("Error when loading player stats", ex); | ||
player.sendMessage("&c任務資料加載失敗: " + ex.getMessage()); | ||
} else { | ||
LOGGER.info("Player {} quests stats updated", player.getName()); | ||
} | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/ericlam/mc/mgquests/command/QuestsCancelCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.ericlam.mc.mgquests.command; | ||
|
||
import com.ericlam.mc.eld.annotations.CommandArg; | ||
import com.ericlam.mc.eld.annotations.Commander; | ||
import com.ericlam.mc.eld.bukkit.CommandNode; | ||
import com.ericlam.mc.mgquests.config.QuestMessage; | ||
import com.ericlam.mc.mgquests.manager.QuestsManager; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import javax.inject.Inject; | ||
|
||
@Commander( | ||
name = "cancel", | ||
description = "取消任務" | ||
) | ||
public class QuestsCancelCommand implements CommandNode { | ||
|
||
@Inject | ||
private QuestsManager questsManager; | ||
|
||
@Inject | ||
private QuestMessage message; | ||
|
||
@CommandArg(order = 1) | ||
private String questId; | ||
|
||
@CommandArg(order = 2, optional = true) | ||
private OfflinePlayer player; | ||
|
||
@Override | ||
public void execute(CommandSender commandSender) { | ||
if (player == null){ | ||
|
||
if (!(commandSender instanceof Player p)){ | ||
commandSender.sendMessage("§c你必須是玩家才能使用此指令"); | ||
return; | ||
} else { | ||
this.player = p; | ||
} | ||
|
||
} | ||
|
||
questsManager.cancelQuest(player.getUniqueId(), questId).whenComplete((v, ex) -> { | ||
if (ex != null){ | ||
ex.printStackTrace(); | ||
commandSender.sendMessage(message.getLang().get("operation-failed", ex.getMessage())); | ||
}else{ | ||
commandSender.sendMessage(message.getLang().get("operation-success")); | ||
} | ||
}); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/ericlam/mc/mgquests/command/QuestsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.ericlam.mc.mgquests.command; | ||
|
||
import com.ericlam.mc.eld.annotations.Commander; | ||
import com.ericlam.mc.eld.bukkit.CommandNode; | ||
import org.bukkit.command.CommandSender; | ||
|
||
@Commander( | ||
name = "quests", | ||
description = "quests 主指令", | ||
permission = "mgquests.admin" | ||
) | ||
public class QuestsCommand implements CommandNode { | ||
@Override | ||
public void execute(CommandSender commandSender) { | ||
|
||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/ericlam/mc/mgquests/command/QuestsReloadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.ericlam.mc.mgquests.command; | ||
|
||
import com.ericlam.mc.eld.annotations.Commander; | ||
import com.ericlam.mc.eld.annotations.InjectPool; | ||
import com.ericlam.mc.eld.bukkit.CommandNode; | ||
import com.ericlam.mc.eld.configurations.GroupConfig; | ||
import com.ericlam.mc.mgquests.config.GameTable; | ||
import com.ericlam.mc.mgquests.config.QuestConfig; | ||
import com.ericlam.mc.mgquests.config.QuestMessage; | ||
import com.ericlam.mc.mgquests.config.QuestObject; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import javax.inject.Inject; | ||
|
||
@Commander( | ||
name = "reload", | ||
description = "reload configuration" | ||
) | ||
public class QuestsReloadCommand implements CommandNode { | ||
|
||
@Inject | ||
private QuestConfig config; | ||
|
||
@Inject | ||
private QuestMessage message; | ||
|
||
@InjectPool | ||
private GroupConfig<QuestObject> questObjects; | ||
|
||
@InjectPool | ||
private GroupConfig<GameTable> gameTables; | ||
|
||
@Override | ||
public void execute(CommandSender commandSender) { | ||
config.getController().reload(); | ||
message.getController().reload(); | ||
questObjects.fetch(); | ||
gameTables.fetch(); | ||
commandSender.sendMessage(message.getLang().get("reload")); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/ericlam/mc/mgquests/config/QuestConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ericlam.mc.mgquests.config; | ||
|
||
import com.ericlam.mc.eld.annotations.Resource; | ||
import com.ericlam.mc.eld.components.Configuration; | ||
|
||
@Resource(locate = "config.yml") | ||
public class QuestConfig extends Configuration { | ||
|
||
public int progress_bar_count; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/ericlam/mc/mgquests/config/QuestMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.ericlam.mc.mgquests.config; | ||
|
||
import com.ericlam.mc.eld.annotations.Prefix; | ||
import com.ericlam.mc.eld.annotations.Resource; | ||
import com.ericlam.mc.eld.components.LangConfiguration; | ||
|
||
@Resource(locate = "lang.yml") | ||
@Prefix(path = "prefix") | ||
public class QuestMessage extends LangConfiguration { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/ericlam/mc/mgquests/config/QuestObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ericlam.mc.mgquests.config; | ||
|
||
import com.ericlam.mc.eld.annotations.GroupResource; | ||
import com.ericlam.mc.eld.components.GroupConfiguration; | ||
|
||
import java.util.Map; | ||
|
||
@GroupResource( | ||
folder = "quests", | ||
preloads = {"win-5-mcinf-hourly", "kill-20-mcinf-daily"} | ||
) | ||
public class QuestObject extends GroupConfiguration { | ||
|
||
public String type; | ||
public Map<String, Double> targets; | ||
public TimeDuration timeLimit; | ||
|
||
public TimeDuration coolDown; | ||
|
||
public static class TimeDuration { | ||
public long time; | ||
public String type; | ||
} | ||
|
||
} |
Oops, something went wrong.