Add more useful commands

This commit is contained in:
Xander 2024-09-21 13:38:50 +02:00
parent d6d3803025
commit df86f61828
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
17 changed files with 341 additions and 7 deletions

8
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

1
.idea/.name Normal file
View file

@ -0,0 +1 @@
mc13dtl

View file

@ -0,0 +1,9 @@
<component name="ArtifactManager">
<artifact type="jar" name="mc13dtl.main:jar">
<output-path>$PROJECT_DIR$/../MC/plugins</output-path>
<root id="archive" name="mc13dtl.main.jar">
<element id="module-output" name="mc13dtl.main" />
<element id="file-copy" path="$PROJECT_DIR$/src/main/resources/plugin.yml" />
</root>
</artifact>
</component>

6
.idea/compiler.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="21" />
</component>
</project>

17
.idea/gradle.xml Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

25
.idea/jarRepositories.xml Normal file
View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://repo.papermc.io/repository/maven-public/" />
</remote-repository>
</component>
</project>

10
.idea/misc.xml Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/../MC/plugins" />
</component>
</project>

9
.idea/modules.xml Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/mc13dtl.main.iml" filepath="$PROJECT_DIR$/.idea/modules/mc13dtl.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/mc13dtl.test.iml" filepath="$PROJECT_DIR$/.idea/modules/mc13dtl.test.iml" />
</modules>
</component>
</project>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
<component name="McpModuleSettings">
<option name="srgType" value="SRG" />
</component>
</module>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>MCP</platformType>
<platformType>PAPER</platformType>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
<component name="McpModuleSettings">
<option name="srgType" value="SRG" />
</component>
</module>

124
.idea/uiDesigner.xml Normal file
View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View file

@ -1,5 +1,6 @@
package gent.zeus.mc13dtl;
import gent.zeus.mc13dtl.gamestate.*;
import gent.zeus.mc13dtl.group.GroupAddCommand;
import gent.zeus.mc13dtl.group.GroupRemoveCommand;
import gent.zeus.mc13dtl.group.SetScoreCommand;
@ -8,9 +9,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import gent.zeus.mc13dtl.events.EventRunner;
import gent.zeus.mc13dtl.gamestate.GameStateHandler;
import gent.zeus.mc13dtl.gamestate.StartGameCommand;
import gent.zeus.mc13dtl.gamestate.TogglePauseCommand;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
@ -28,8 +26,10 @@ public class MC13DTL extends JavaPlugin {
Commands commands = event.registrar();
commands.register("start-game", "Start a game of 13 days to live", new StartGameCommand());
commands.register("toggle-pause", "Toggle paused state", new TogglePauseCommand());
commands.register("group-add", "Add player to team", new GroupAddCommand());
commands.register("set-score", "Set the score of a team", new SetScoreCommand());
commands.register("set-day", "Set the day to the specified number", new SetDayCommand());
commands.register("execute-event", "Execute given event number now", new ExecuteEventCommand());
commands.register("group-add", "Add player to team", new GroupAddCommand());
commands.register("group-remove", "Remove player from team", new GroupRemoveCommand());
});
BukkitScheduler scheduler = this.getServer().getScheduler();

View file

@ -40,6 +40,10 @@ public abstract class Event implements Listener, Runnable {
EventRunner.currentEvents.remove(this);
}
protected void eventTimeEnded() {
eventFailed();
}
protected void eventSuccess() {
MC13DTL.board.sendMessageToTeam(team, Component.text("Congratulations! You survived this event").color(NamedTextColor.GREEN));
MC13DTL.board.addScore(team, scoreOnSuccess);

View file

@ -15,6 +15,7 @@ import gent.zeus.mc13dtl.MC13DTL;
public class EventRunner implements Runnable {
static List<Event> currentEvents = new ArrayList<>();
public static List<Integer> startTimes = List.of(5000);
private long day;
@ -24,11 +25,19 @@ public class EventRunner implements Runnable {
NamespacedKey eventKey = new NamespacedKey(MC13DTL.instance, "last-event-day");
long lastRunDay = world.getPersistentDataContainer().get(eventKey, PersistentDataType.LONG);
day = Bukkit.getWorld("world").getFullTime() / 24000;
if (day > lastRunDay && Bukkit.getWorld("world").getTime() >= 14000) {
while (!currentEvents.isEmpty()) {
Event event = currentEvents.getFirst();
if (day > lastRunDay && !currentEvents.isEmpty()) {
for (Event event : currentEvents) {
event.eventTimeEnded();
}
// When event doesn't properly handle eventTimeEnded
for (Event event : currentEvents) {
event.eventFailed();
}
}
if (day > lastRunDay && day < startTimes.size() && Bukkit.getWorld("world").getTime() >= startTimes.get((int) day)) {
List<Team> teams = MC13DTL.board.getTeams().stream().toList();
List<Difficulty> difficulties = getDifficulties(teams);

View file

@ -0,0 +1,36 @@
package gent.zeus.mc13dtl.gamestate;
import gent.zeus.mc13dtl.MC13DTL;
import gent.zeus.mc13dtl.events.EventRunner;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
public class ExecuteEventCommand implements BasicCommand {
@Override
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
World world = Bukkit.getWorld("world");
try {
if (args.length == 1) {
int day = Integer.parseInt(args[0]);
world.setFullTime(day * 24000 + EventRunner.startTimes.get(day));
NamespacedKey eventKey = new NamespacedKey(MC13DTL.instance, "last-event-day");
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day - 1L);
commandSourceStack.getSender().sendMessage("Day set to " + day);
} else {
commandSourceStack.getSender().sendMessage("usage: /execute-day <day>");
}
} catch (NumberFormatException ex) {
commandSourceStack.getSender().sendMessage("usage: /execute-day <NUMBER>");
}
}
@Override
public String permission() {
return "13dtl.manage-game";
}
}

View file

@ -0,0 +1,35 @@
package gent.zeus.mc13dtl.gamestate;
import gent.zeus.mc13dtl.MC13DTL;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
public class SetDayCommand implements BasicCommand {
@Override
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
World world = Bukkit.getWorld("world");
try {
if (args.length == 1) {
int day = Integer.parseInt(args[0]);
world.setFullTime(day * 24000);
NamespacedKey eventKey = new NamespacedKey(MC13DTL.instance, "last-event-day");
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day - 1L);
commandSourceStack.getSender().sendMessage("Day set to " + day);
} else {
commandSourceStack.getSender().sendMessage("usage: /set-day <day>");
}
} catch (NumberFormatException ex) {
commandSourceStack.getSender().sendMessage("usage: /set-day <NUMBER>");
}
}
@Override
public String permission() {
return "13dtl.manage-game";
}
}