Skip to content

Commit

Permalink
fix Changer
Browse files Browse the repository at this point in the history
Signed-off-by: Mineshafter61 <[email protected]>
  • Loading branch information
Mineshafter61 committed Sep 8, 2024
1 parent 1765ff5 commit 1f040e6
Show file tree
Hide file tree
Showing 28 changed files with 273 additions and 219 deletions.
Binary file modified .gradle/8.8/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.8/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.8/checksums/sha1-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.8/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 1 addition & 1 deletion .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Sun Aug 04 10:18:49 SGT 2024
#Thu Aug 29 21:55:38 SGT 2024
gradle.version=8.8
Binary file modified .gradle/file-system.probe
Binary file not shown.
61 changes: 35 additions & 26 deletions src/main/java/mikeshafter/mikestcaddons/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import mikeshafter.mikestcaddons.util.AddonsUtil;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -62,16 +63,16 @@ public void throttleCmd (final CommandSender sender, final MikesTCAddons plugin,
if (throttle != null) ThrottleController.addThrottle(player, throttle);
}

@Command("swap <animation0> <animation1>")
@Command("swap <a1> <a2>")
@CommandDescription("Swaps two animations")
@Permission("mikestcaddons.swap")
public void swapCmd (final CommandSender sender, final MikesTCAddons plugin, final @Argument("animation0") String animation0, final @Argument("animation1") String animation1) {
public void swapCmd (final CommandSender sender, final MikesTCAddons plugin, final @Argument("a1") String a1, final @Argument("a2") String a2) {
if (!(sender instanceof Player player)) return;
MinecartGroup vehicle = CartPropertiesStore.getEditing(player).getHolder().getGroup();
if (vehicle == null || !vehicle.getProperties().hasOwnership(player)) return;

for (MinecartMember<?> member : vehicle) {
Swapper a = new Swapper(member, animation0, animation1);
Swapper a = new Swapper(member, a1, a2);
a.run();
}
}
Expand Down Expand Up @@ -129,54 +130,62 @@ public void decoupleCmd (final CommandSender sender, final MikesTCAddons plugin,
}

@Command("opengate <x> <y> <z> <direction> <time>")
@CommandDescription("Opens glass doors")
@CommandDescription("Opens glass doors. Time argument is in the HH:MM:SS format.")
@Permission("mikestcaddons.gate")
public void gateCmd (final CommandSender sender, final MikesTCAddons plugin, final @Argument("x") String x, final @Argument("y") String y, final @Argument("z") String z, final @Argument("direction") String direction, final @Argument("time") String time) {
long ticks = AddonsUtil.parseTicks(time);
World world;
if (ticks > 6000) {
sender.sendMessage("Cannot open a door for more than 5 minutes!");
return;
}
World w;
int X, Y, Z;
if (sender instanceof Player player) {
world = player.getWorld();
X = AddonsUtil.parseRelative(x, 'x', player.getLocation());
Y = AddonsUtil.parseRelative(y, 'y', player.getLocation());
Z = AddonsUtil.parseRelative(z, 'z', player.getLocation());
w = player.getWorld();
X = player.getLocation().getBlockX();
Y = player.getLocation().getBlockY();
Z = player.getLocation().getBlockZ();
}
else {
BlockCommandSender commandBlock = (BlockCommandSender) sender;
world = commandBlock.getBlock().getWorld();
X = AddonsUtil.parseRelative(x, 'x', commandBlock.getBlock().getLocation());
Y = AddonsUtil.parseRelative(y, 'y', commandBlock.getBlock().getLocation());
Z = AddonsUtil.parseRelative(z, 'z', commandBlock.getBlock().getLocation());
Block commandBlock = ((BlockCommandSender) sender).getBlock();
w = commandBlock.getWorld();
X = commandBlock.getLocation().getBlockX();
Y = commandBlock.getLocation().getBlockY();
Z = commandBlock.getLocation().getBlockZ();
}
X = AddonsUtil.parseRelative(x, X);
Y = AddonsUtil.parseRelative(y, Y);
Z = AddonsUtil.parseRelative(z, Z);
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;
};
AddonsUtil.openDoor(world, X, Y, Z, dir, ticks);
AddonsUtil.openDoor(w, X, Y, Z, dir, ticks);
}

@Command("closegate <x> <y> <z>")
@CommandDescription("Closes 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("z") String z) {
World world;
World w;
int X, Y, Z;
if (sender instanceof Player player) {
world = player.getWorld();
X = AddonsUtil.parseRelative(x, 'x', player.getLocation());
Y = AddonsUtil.parseRelative(y, 'y', player.getLocation());
Z = AddonsUtil.parseRelative(z, 'z', player.getLocation());
w = player.getWorld();
X = player.getLocation().getBlockX();
Y = player.getLocation().getBlockY();
Z = player.getLocation().getBlockZ();
}
else {
BlockCommandSender commandBlock = (BlockCommandSender) sender;
world = commandBlock.getBlock().getWorld();
X = AddonsUtil.parseRelative(x, 'x', commandBlock.getBlock().getLocation());
Y = AddonsUtil.parseRelative(y, 'y', commandBlock.getBlock().getLocation());
Z = AddonsUtil.parseRelative(z, 'z', commandBlock.getBlock().getLocation());
} AddonsUtil.closeDoor(world, X, Y, Z);
Block commandBlock = ((BlockCommandSender) sender).getBlock();
w = commandBlock.getWorld();
X = commandBlock.getLocation().getBlockX();
Y = commandBlock.getLocation().getBlockY();
Z = commandBlock.getLocation().getBlockZ();
}
AddonsUtil.closeDoor(w, X, Y, Z);
}

}
17 changes: 13 additions & 4 deletions src/main/java/mikeshafter/mikestcaddons/MikesTCAddons.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.bergerkiller.bukkit.common.protocol.PacketType;
import com.bergerkiller.bukkit.common.utils.PacketUtil;
import com.bergerkiller.bukkit.tc.TrainCarts;
import com.bergerkiller.bukkit.tc.properties.registry.TCPropertyRegistry;
import com.bergerkiller.bukkit.tc.signactions.SignAction;
import mikeshafter.mikestcaddons.attachments.SignActionAttachment;
import mikeshafter.mikestcaddons.attachments.SignActionSwap;
import mikeshafter.mikestcaddons.dynamics.PSDListener;
import mikeshafter.mikestcaddons.dynamics.SignActionPSD;
import mikeshafter.mikestcaddons.rh.RHProperties;
import mikeshafter.mikestcaddons.throttle.ThrottleController;
import mikeshafter.mikestcaddons.util.AddonsUtil;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -18,7 +21,15 @@ public final class MikesTCAddons extends JavaPlugin {
private final SignActionPSD signActionPSD = new SignActionPSD();
private final SignActionAttachment signActionAttachment = new SignActionAttachment();

@Override
private final Commands commands = new Commands();

@Override
public void onLoad () {
TCPropertyRegistry propertyRegistry = new TCPropertyRegistry(TrainCarts.plugin, commands.getHandler());
propertyRegistry.registerAll(RHProperties.class);
}

@Override
public void onDisable() {
// Plugin shutdown logic
SignAction.unregister(signActionSwap);
Expand All @@ -32,9 +43,7 @@ public void onDisable() {
@Override
public void onEnable() {
this.saveDefaultConfig();

Commands commands = new Commands();
commands.enable(this);
this.commands.enable(this);

SignAction.register(signActionSwap);
SignAction.register(signActionAttachment);
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/mikeshafter/mikestcaddons/attachments/Changer.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mikeshafter.mikestcaddons.attachments;

import com.bergerkiller.bukkit.common.config.ConfigurationNode;
import com.bergerkiller.bukkit.common.inventory.CommonItemStack;
import com.bergerkiller.bukkit.tc.controller.MinecartMember;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;

public class Changer extends RecurseHelper {
Expand All @@ -21,18 +21,15 @@ public Changer (MinecartMember<?> member, String name, Material type, int data)
}

@Override
protected ConfigurationNode call (ConfigurationNode node) {
protected void call (ConfigurationNode node) {
List<String> names = node.getList("names", String.class);
if (!names.contains(this.name)) return node;
if (!names.contains(this.name)) return;

ItemStack item = node.get("item", ItemStack.class);
ItemMeta meta = item.getItemMeta();
item.setType(this.type);
if (meta != null && this.data != 0) {
meta.setCustomModelData(this.data);
item.setItemMeta(meta);
}
node.set("item", item);
return node;
var c = CommonItemStack.copyOf(item);
c.setCustomModelData(this.data);
if (this.type != null) c.setType(this.type);

node.set("item", c.toBukkit());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mikeshafter.mikestcaddons.attachments;
import com.bergerkiller.bukkit.common.config.ConfigurationNode;
import com.bergerkiller.bukkit.tc.controller.MinecartMember;
import java.util.ArrayDeque;

public abstract class RecurseHelper {

Expand All @@ -9,34 +10,16 @@ public abstract class RecurseHelper {
public RecurseHelper (MinecartMember<?> member) {this.member = member;}

public void run () {
var fullConfig = this.member.getProperties().getModel().getConfig();

var attachmentsNode = fullConfig.getNode("attachments");
var attachmentsSet = attachmentsNode.getNodes();

if (attachmentsSet != null) {
for (var innerNode : attachmentsSet) {
attachmentsNode.set(innerNode.getPath(), recurse(innerNode));
fullConfig.set("attachments", attachmentsNode);
}
ArrayDeque<ConfigurationNode> stack = new ArrayDeque<>();
ConfigurationNode node = this.member.getProperties().getModel().getConfig();
stack.addFirst(node);
while (!stack.isEmpty()) {
stack.addAll(node.getNodeList("attachments"));
call(node);
node = stack.removeFirst();
}

this.member.getProperties().getModel().sync();
}

private ConfigurationNode recurse (ConfigurationNode node) {
var attachmentsNode = node.getNode("attachments");
var attachmentsSet = attachmentsNode.getNodes();

if (attachmentsSet != null) {
for (var innerNode : attachmentsSet) {
attachmentsNode.set(innerNode.getPath(), recurse(innerNode));
node.set("attachments", attachmentsNode);
}
}

return call(node);
}

protected abstract ConfigurationNode call (ConfigurationNode node);
protected abstract void call (ConfigurationNode node);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ public class SignActionAttachment extends SignAction {

@Override
public boolean match (SignActionEvent info) {
return info.isType("attachment");
return info.isType("attachment", "changeitem");
}

@Override
public void execute (SignActionEvent info) {
/*
[train]
attachment
<name>
<item_type> <custom_model_data>
*/

if ((info.isTrainSign() || info.isCartSign()) && info.isAction(SignActionType.GROUP_ENTER, SignActionType.MEMBER_ENTER, SignActionType.REDSTONE_ON) && info.isPowered()) {
String name = info.getLine(2);
String[] newItem = info.getLine(3).split(" ");
Material material = Material.valueOf(newItem[0].toUpperCase());
int customModelData = Integer.parseInt(newItem[1]);
String[] newItem = info.getLine(3).split(" ", 2);
Material material = null;
int customModelData;
if (newItem.length == 2) {
material = Material.valueOf(newItem[0].toUpperCase());
customModelData = Integer.parseInt(newItem[1]);
}
else {customModelData = Integer.parseInt(newItem[0]);}

for (MinecartMember<?> member : info.getMembers()) {
Changer a = new Changer(member, name, material, customModelData);
Expand All @@ -36,7 +34,6 @@ public void execute (SignActionEvent info) {
}
}


@Override
public boolean build (SignChangeActionEvent event) {
return SignBuildOptions.create().setName("attachment changer").setDescription("changes named attachments").handle(event.getPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public boolean match (SignActionEvent info) {

@Override
public void execute (SignActionEvent info) {
// When a [train] sign is placed, activate when powered by redstone when the train
// goes over the sign, or when redstone is activated.
if ((info.isTrainSign() || info.isCartSign()) && info.isAction(SignActionType.GROUP_ENTER, SignActionType.MEMBER_ENTER, SignActionType.REDSTONE_ON) && info.isPowered()) {
for (MinecartMember<?> member : info.getMembers()) {
Swapper a = new Swapper(member, "door_L", "door_R");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Swapper (MinecartMember<?> member, String a, String b) {
}

@Override
protected ConfigurationNode call (ConfigurationNode node) {
protected void call (ConfigurationNode node) {
ConfigurationNode animations = node.getNode("animations");
Object ab = animations.contains(a) ? animations.getNode(a) : null;
Object ba = animations.contains(b) ? animations.getNode(b) : null;
Expand All @@ -25,7 +25,6 @@ protected ConfigurationNode call (ConfigurationNode node) {
if (ba != null) animations.set(a, ba);

node.set("animations", animations);
return node;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public void onSignChange (SignChangeEvent event) {
String t = parseComponent(event.line(0));
if (t.equalsIgnoreCase("[psd]")) {
event.getPlayer().sendMessage(Component.text("You have created a PSD sign!"));
SignActionPSD.updatePSD();
}
}

Expand Down
Loading

0 comments on commit 1f040e6

Please sign in to comment.