Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,38 @@
<parent>
<groupId>com.github.civclassic</groupId>
<artifactId>civclassic-parent</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</parent>

<groupId>sh.okx.railswitch</groupId>
<artifactId>RailSwitch</artifactId>
<packaging>jar</packaging>
<version>1.5.1</version>
<version>1.6.0</version>
<name>RailSwitch</name>
<url>https://github.com/civclassic/railswitch</url>

<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>vg.civcraft.mc.civmodcore</groupId>
<groupId>com.github.civclassic</groupId>
<artifactId>CivModCore</artifactId>
<version>1.8.2</version>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>vg.civcraft.mc.namelayer</groupId>
<groupId>com.github.civclassic</groupId>
<artifactId>NameLayer</artifactId>
<version>2.14.1</version>
<version>2.15.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>vg.civcraft.mc.citadel</groupId>
<groupId>com.github.civclassic</groupId>
<artifactId>Citadel</artifactId>
<version>4.1.1</version>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -49,6 +48,10 @@
<id>civ-github-repo</id>
<url>https://raw.githubusercontent.com/CivClassic/artifacts/master/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
</project>

22 changes: 9 additions & 13 deletions src/main/java/sh/okx/railswitch/RailSwitchPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,32 @@
import sh.okx.railswitch.settings.SettingsManager;
import sh.okx.railswitch.switches.SwitchListener;
import vg.civcraft.mc.civmodcore.ACivMod;
import vg.civcraft.mc.civmodcore.command.AikarCommandManager;
import vg.civcraft.mc.civmodcore.commands.CommandManager;

/**
* The Rail Switch plugin class
*/
public final class RailSwitchPlugin extends ACivMod implements Listener {

private static AikarCommandManager commands;
private CommandManager commandManager;

@Override
public void onEnable() {
useNewCommandHandler = false;
super.onEnable();
SettingsManager.init(this);
registerListener(new CitadelGlue());
registerListener(new CitadelGlue(this));
registerListener(new SwitchListener());
commands = new AikarCommandManager(this) {
@Override
public void registerCommands() {
registerCommand(new DestinationCommand());
}
};
commandManager = new CommandManager(this);
commandManager.init();
commandManager.registerCommand(new DestinationCommand());
}

@Override
public void onDisable() {
SettingsManager.reset();
if (commands != null) {
commands.reset();
commands = null;
if (commandManager != null) {
commandManager.reset();
commandManager = null;
}
super.onDisable();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package sh.okx.railswitch.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.Syntax;
import org.bukkit.entity.Player;
import sh.okx.railswitch.settings.SettingsManager;
import vg.civcraft.mc.civmodcore.command.AikarCommand;

/**
* Continued support for setting and resetting your destination via a command.
*/
public final class DestinationCommand extends AikarCommand {
public final class DestinationCommand extends BaseCommand {

@CommandAlias("dest|destination|setdestination|switch|setswitch|setsw")
@Description("Set your rail destination(s)")
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/sh/okx/railswitch/glue/CitadelGlue.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package sh.okx.railswitch.glue;

import org.bukkit.block.Block;
import org.bukkit.plugin.Plugin;
import vg.civcraft.mc.citadel.Citadel;
import vg.civcraft.mc.citadel.ReinforcementManager;
import vg.civcraft.mc.citadel.model.Reinforcement;
import vg.civcraft.mc.civmodcore.util.DependencyGlue;
import vg.civcraft.mc.civmodcore.util.NullUtils;
import vg.civcraft.mc.civmodcore.utilities.DependencyGlue;
import vg.civcraft.mc.civmodcore.utilities.NullUtils;
import vg.civcraft.mc.civmodcore.world.WorldUtils;

/**
Expand All @@ -15,13 +16,12 @@ public final class CitadelGlue extends DependencyGlue {

private ReinforcementManager manager;

public CitadelGlue() {
super("Citadel");
public CitadelGlue(Plugin plugin) {
super(plugin, "Citadel");
}

@Override
public boolean isSafeToUse() {
if (!super.isSafeToUse()) {
if (!super.isDependencyEnabled()) {
return false;
}
if (this.manager == null) {
Expand All @@ -30,16 +30,6 @@ public boolean isSafeToUse() {
return true;
}

@Override
protected void onGlueEnabled() {
this.manager = Citadel.getInstance().getReinforcementManager();
}

@Override
protected void onGlueDisabled() {
this.manager = null;
}

/**
* Do two blocks, representing the sign and the rail, have the same reinforcement group?
*
Expand All @@ -64,4 +54,13 @@ public boolean doSignAndRailHaveSameReinforcement(Block sign, Block rail) {
railReinforcement.getGroup());
}

@Override
protected void onDependencyEnabled() {
this.manager = Citadel.getInstance().getReinforcementManager();
}

@Override
protected void onDependencyDisabled() {
this.manager = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import vg.civcraft.mc.civmodcore.playersettings.impl.StringSetting;
import vg.civcraft.mc.civmodcore.players.settings.impl.StringSetting;

/**
* Setting representing a player's destination.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sh/okx/railswitch/settings/RailSwitchMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import vg.civcraft.mc.civmodcore.playersettings.PlayerSettingAPI;
import vg.civcraft.mc.civmodcore.playersettings.gui.MenuSection;
import vg.civcraft.mc.civmodcore.players.settings.PlayerSettingAPI;
import vg.civcraft.mc.civmodcore.players.settings.gui.MenuSection;

/**
* The menu for RailSwitch. This is what all RailSwitch settings will be registered to.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sh/okx/railswitch/settings/ResetSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import vg.civcraft.mc.civmodcore.playersettings.gui.MenuSection;
import vg.civcraft.mc.civmodcore.playersettings.impl.StringSetting;
import vg.civcraft.mc.civmodcore.players.settings.gui.MenuSection;
import vg.civcraft.mc.civmodcore.players.settings.impl.StringSetting;

/**
* ResetSetting, a setting that functions more like a GUI button than an actual setting.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/sh/okx/railswitch/switches/SwitchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockRedstoneEvent;
import sh.okx.railswitch.RailSwitchPlugin;
import sh.okx.railswitch.glue.CitadelGlue;
import sh.okx.railswitch.settings.SettingsManager;
import vg.civcraft.mc.civmodcore.entities.EntityUtils;
import vg.civcraft.mc.civmodcore.world.WorldUtils;

/**
Expand All @@ -26,7 +26,7 @@ public class SwitchListener implements Listener {

public static final String WILDCARD = "*";

public static final CitadelGlue CITADEL_GLUE = new CitadelGlue();
public static final CitadelGlue CITADEL_GLUE = new CitadelGlue(RailSwitchPlugin.getPlugin(RailSwitchPlugin.class));

/**
* Event handler for rail switches. Will determine if a switch exists at the target location, and if so will process
Expand Down Expand Up @@ -62,7 +62,7 @@ public void onSwitchTrigger(BlockRedstoneEvent event) {
Player player = null; {
double searchDistance = Double.MAX_VALUE;
for (Entity entity : block.getWorld().getNearbyEntities(block.getLocation(), 3, 3, 3)) {
if (!EntityUtils.isPlayer(entity)) {
if (!(entity instanceof Player)) {
continue;
}
Entity vehicle = entity.getVehicle();
Expand All @@ -83,7 +83,7 @@ public void onSwitchTrigger(BlockRedstoneEvent event) {
return;
}
// If Citadel is enabled, check that the sign and the rail are on the same group
if (CITADEL_GLUE.isEnabled()) {
if (CITADEL_GLUE.isSafeToUse()) {
if (!CITADEL_GLUE.doSignAndRailHaveSameReinforcement(above, block)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version: ${project.version}
main: sh.okx.railswitch.RailSwitchPlugin
depend: [CivModCore]
softdepend: [Citadel, NameLayer]
api-version: 1.14
api-version: 1.17
authors: [Okx, Protonull]
description: Easily make rail switches for automated destination selection
commands:
dest: {}
dest: {}