Skip to content

Commit

Permalink
reintroduce psd commands
Browse files Browse the repository at this point in the history
Signed-off-by: Mineshafter61 <[email protected]>
  • Loading branch information
Mineshafter61 committed Jul 6, 2024
1 parent 03d4dcf commit f672ab4
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 391 deletions.
18 changes: 0 additions & 18 deletions .classpath

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 16
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 16
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
Expand Down
Binary file modified .gradle/8.8/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.8/checksums/sha1-checksums.bin
Binary file not shown.
40 changes: 0 additions & 40 deletions .project

This file was deleted.

54 changes: 47 additions & 7 deletions src/main/java/mikeshafter/mikestcaddons/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import com.bergerkiller.bukkit.tc.properties.TrainProperties;
import mikeshafter.mikestcaddons.attachments.Changer;
import mikeshafter.mikestcaddons.attachments.Swapper;
import mikeshafter.mikestcaddons.util.Util;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.incendo.cloud.annotations.Argument;
Expand All @@ -35,8 +39,7 @@ public void enable(MikesTCAddons plugin) {
cloud.enable(plugin);
cloud.annotations(this);
cloud.helpCommand(Collections.singletonList("mikestcaddons"), "Shows information about all of Mike's TC Addons' commands");
}

}

@Command("throttle <type>")
@CommandDescription("Turns on or off throttle")
Expand All @@ -47,7 +50,7 @@ public void throttleCmd(
final @Argument("type") String throttleType
) {
// Command method here
}
}

@Command("swap <animation0> <animation1>")
@CommandDescription("Swaps two animations")
Expand All @@ -72,7 +75,7 @@ public void swapCmd(

@Command("changeitem <name> <item_type> <custom_model_data>")
@CommandDescription("Changes an item on the train to the item specified")
@Permission("mikestcaddons.swap")
@Permission("mikestcaddons.changeitem")
public void changeItemCmd(
final CommandSender sender,
final MikesTCAddons plugin,
Expand All @@ -90,11 +93,11 @@ public void changeItemCmd(
Changer a = new Changer(member, name, Material.getMaterial(material.toUpperCase()), customModelData);
a.run();
}
}
}

@Command("decouple <number>")
@CommandDescription("Decouples carts")
@Permission("mikestcaddons.throttle")
@Permission("mikestcaddons.decouple")
public void decoupleCmd(
final CommandSender sender,
final MikesTCAddons plugin,
Expand Down Expand Up @@ -134,6 +137,43 @@ public void decoupleCmd(

// Create new train and store
MinecartGroupStore.createSplitFrom(properties, newGroup);
}

@Command("opengate <x> <y> <z> <direction> <time>")
@CommandDescription("Opens glass doors")
@Permission("mikestcaddons.gate")
public void gateCmd(
final CommandSender sender,
final MikesTCAddons plugin,
final @Argument("x") String x,
final @Argument("y") String y,
final @Argument("y") String z,
final @Argument("direction") String direction,
final @Argument("time") String time
) {
long ticks = Util.parseTicks(time);
World world;
int X, Y, Z;
if (sender instanceof Player player) {
world = player.getWorld();
X = Util.parseRelative(x, 'x', player.getLocation());
Y = Util.parseRelative(y, 'y', player.getLocation());
Z = Util.parseRelative(z, 'z', player.getLocation());
} else {
BlockCommandSender commandBlock = (BlockCommandSender) sender;
world = commandBlock.getBlock().getWorld();
X = Util.parseRelative(x, 'x', commandBlock.getBlock().getLocation());
Y = Util.parseRelative(y, 'y', commandBlock.getBlock().getLocation());
Z = Util.parseRelative(z, 'z', commandBlock.getBlock().getLocation());
}
BlockFace dir = switch (direction.toUpperCase()) {
case "S", "SOUTH" -> BlockFace.SOUTH;
case "N", "NORTH" -> BlockFace.NORTH;
case "E", "EAST" -> BlockFace.EAST;
case "W", "WEST" -> BlockFace.WEST;
default -> BlockFace.SELF;
};
Util.openDoor(world, X, Y, Z, dir, ticks);
}

}
}
15 changes: 4 additions & 11 deletions src/main/java/mikeshafter/mikestcaddons/MikesTCAddons.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,28 @@
import mikeshafter.mikestcaddons.attachments.SignActionAttachment;
import mikeshafter.mikestcaddons.attachments.SignActionSwap;
import mikeshafter.mikestcaddons.dynamics.SignActionPSD;
import mikeshafter.mikestcaddons.throttle.ThrottleManager;
import mikeshafter.mikestcaddons.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Level;

public final class MikesTCAddons extends JavaPlugin {

private final SignActionSwap signActionSwap = new SignActionSwap();
private final SignActionPSD signActionRHStation = new SignActionPSD();
private final SignActionPSD signActionPSD = new SignActionPSD();
private final SignActionAttachment signActionAttachment = new SignActionAttachment();

@Override
public void onDisable() {
// Plugin shutdown logic
SignAction.unregister(signActionSwap);
SignAction.unregister(signActionRHStation);
SignAction.unregister(signActionPSD);
SignAction.unregister(signActionAttachment);

Util.gates.forEach((gate) -> gate.closeGate(true));
Util.gates.forEach((location, gate) -> gate.closeGate(true));
this.getLogger().log(Level.INFO, "Mike's TC Addons has been disabled!");
for (Player player : Bukkit.getOnlinePlayers()) ThrottleManager.removeThrottle(player);
}


@Override
public void onEnable() {
this.saveDefaultConfig();
Expand All @@ -40,9 +35,7 @@ public void onEnable() {

SignAction.register(signActionSwap);
SignAction.register(signActionAttachment);
SignAction.register(signActionRHStation);

this.getServer().getPluginManager().registerEvents(new ThrottleManager(), this);
SignAction.register(signActionPSD);

this.getLogger().log(Level.INFO, "Mike's TC Addons has been enabled!");
}
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/mikeshafter/mikestcaddons/config/CustomConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@ public CustomConfig (String name) {
}

config = new YamlConfiguration();
try { config.load(file); }
catch (Exception e) { e.printStackTrace(); }
try { config.load(file); } catch (Exception e) {
plugin.getLogger().warning(e.getLocalizedMessage());
}
}

public void save () {
try { config.save(file); }
catch (Exception e) { e.printStackTrace(); }
try { config.save(file); } catch (Exception e) {
plugin.getLogger().warning(e.getLocalizedMessage());
}
}

protected Plugin getConfigPlugin () { return this.plugin; }

public void saveDefaultConfig () {
if (!file.exists()) { plugin.saveResource(name, false); }
}
public void saveDefaultConfig() {
if (!file.exists()) {
plugin.saveResource(name, false);
}
}

public File getFile () {return file;}

Expand All @@ -47,7 +51,9 @@ public YamlConfiguration get () {
return config;
}

public Object get (String path) {return this.config.get(path);}
public Object get(String path) {
return this.config.get(path);
}

public String getString (String path) {
var s = this.config.getString(path);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mikeshafter/mikestcaddons/config/Sequences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mikeshafter.mikestcaddons.config;
public class Sequences extends CustomConfig {

public Sequences() {
super("sequences");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mikeshafter.mikestcaddons.dynamics;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;

public class PSDRelayCreate implements Listener {
@EventHandler
public void onSignChange(SignChangeEvent event) {
TextComponent t = (TextComponent) event.line(0);
if (t != null && t.content().equalsIgnoreCase("[psd]")) {
event.getPlayer().sendMessage(Component.text("You have created a PSD sign!"));
}
}
}
10 changes: 0 additions & 10 deletions src/main/java/mikeshafter/mikestcaddons/dynamics/PlatformGate.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;


public class PlatformGate {
private static final List<PlatformGate> activeGates = new ArrayList<>();
private final Block block;
private final BlockData blockData;
private final Location blockLoc;
Expand All @@ -41,10 +37,6 @@ public PlatformGate(Block block, BlockFace openDirection, long openTime) {
this.blockData = block.getBlockData();
}

public static List<PlatformGate> getActiveGates() {
return activeGates;
}

private BlockFace getOpenDirection() {
return this.openDirection;
}
Expand Down Expand Up @@ -91,7 +83,6 @@ private void doCloseGate() {
this.killFallingSand();
this.getBlock().setBlockData(this.blockData);
}, (45 - this.remainCount));
activeGates.remove(this);
}

private void teleportFallingSand(Entity entity, Vector direction, int count, boolean canCancel) {
Expand All @@ -109,7 +100,6 @@ private void teleportFallingSand(Entity entity, Vector direction, int count, boo
}

public void activateGate() {
activeGates.add(this);
this.spawnFallingBlock();
Bukkit.getScheduler().runTaskLater(plugin, () -> this.getBlock().setType(Material.AIR), 5L);
this.task = Bukkit.getScheduler().runTaskLater(plugin, () -> {
Expand Down
Loading

0 comments on commit f672ab4

Please sign in to comment.