Skip to content

Commit

Permalink
undebug
Browse files Browse the repository at this point in the history
Signed-off-by: Mineshafter61 <yuhang.061@gmail.com>
  • Loading branch information
Mineshafter61 committed Jul 29, 2024
1 parent 530545a commit 17efce8
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 349 deletions.
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.
236 changes: 103 additions & 133 deletions src/main/java/mikeshafter/mikestcaddons/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,160 +29,130 @@
@CommandContainer
public class Commands {

private final CloudSimpleHandler cloud = new CloudSimpleHandler();
private final CloudSimpleHandler cloud = new CloudSimpleHandler();

public CloudSimpleHandler getHandler() {
return cloud;
}
public CloudSimpleHandler getHandler () {return cloud;}

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");
}
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")
@Permission("mikestcaddons.throttle")
public void throttleCmd(
final CommandSender sender,
final MikesTCAddons plugin,
final @Argument("type") String throttleType
) {
// Command method here
@Command("throttle <type>")
@CommandDescription("Turns on or off throttle")
@Permission("mikestcaddons.throttle")
public void throttleCmd (final CommandSender sender, final MikesTCAddons plugin, final @Argument("type") String throttleType) {
// Command method here
}

@Command("swap <animation0> <animation1>")
@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) {
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);
a.run();
}
}

@Command("swap <animation0> <animation1>")
@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
) {
if (!(sender instanceof Player player)) return;
// Get vehicle
MinecartGroup vehicle = CartPropertiesStore.getEditing(player).getHolder().getGroup();
// Fail operation under these conditions
if (vehicle == null || !vehicle.getProperties().hasOwnership(player)) return;

for (MinecartMember<?> member : vehicle) {
Swapper a = new Swapper(member, animation0, animation1);
a.run();
}
@Command("changeitem <name> <item_type> <custom_model_data>")
@CommandDescription("Changes an item on the train to the item specified")
@Permission("mikestcaddons.changeitem")
public void changeItemCmd (final CommandSender sender, final MikesTCAddons plugin, final @Argument("name") String name, final @Argument("item_type") String material, final @Argument("custom_model_data") Integer customModelData) {
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) {
Changer a = new Changer(member, name, Material.getMaterial(material.toUpperCase()), customModelData);
a.run();
}
}

@Command("changeitem <name> <item_type> <custom_model_data>")
@CommandDescription("Changes an item on the train to the item specified")
@Permission("mikestcaddons.changeitem")
public void changeItemCmd(
final CommandSender sender,
final MikesTCAddons plugin,
final @Argument("name") String name,
final @Argument("item_type") String material,
final @Argument("custom_model_data") Integer customModelData
) {
if (!(sender instanceof Player player)) return;
// Get vehicle
MinecartGroup vehicle = CartPropertiesStore.getEditing(player).getHolder().getGroup();
// Fail operation under these conditions
if (vehicle == null || !vehicle.getProperties().hasOwnership(player)) return;

for (MinecartMember<?> member : vehicle) {
Changer a = new Changer(member, name, Material.getMaterial(material.toUpperCase()), customModelData);
a.run();
@Command("decouple <number>")
@CommandDescription("Decouples carts")
@Permission("mikestcaddons.decouple")
public void decoupleCmd (final CommandSender sender, final MikesTCAddons plugin, final @Argument("number") Integer n) {
if (!(sender instanceof Player player)) return;
MinecartGroup vehicle = CartPropertiesStore.getEditing(player).getHolder().getGroup();
int number = n;
if (number == 0 || vehicle == null || !vehicle.getProperties().hasOwnership(player)) return;

// Make the train into a list for easier editing
List<MinecartMember<?>> members = vehicle.stream().toList();
TrainProperties properties = vehicle.getProperties();
int size = members.size();
MinecartMember<?>[] newGroup = new MinecartMember<?>[Math.abs(number)];

// if the number to decouple is negative, decouple from the rear:
if (number < 0) {
number = -number;

for (int i = size - 1, j = 0; i > size - number; i--, j++) {
newGroup[j] = members.get(i);
vehicle.remove(i);
}
}

@Command("decouple <number>")
@CommandDescription("Decouples carts")
@Permission("mikestcaddons.decouple")
public void decoupleCmd(
final CommandSender sender,
final MikesTCAddons plugin,
final @Argument("number") Integer n
) {
if (!(sender instanceof Player player)) return;
// Get vehicle
MinecartGroup vehicle = CartPropertiesStore.getEditing(player).getHolder().getGroup();
// Fail operation under these conditions
int number = n;
if (number == 0 || vehicle == null || !vehicle.getProperties().hasOwnership(player)) return;

// Make the train into a list for easier editing
List<MinecartMember<?>> members = vehicle.stream().toList();
TrainProperties properties = vehicle.getProperties();
int size = members.size();
// New train from existing
MinecartMember<?>[] newGroup = new MinecartMember<?>[Math.abs(number)];

// if the number to decouple is negative, decouple from the rear:
if (number < 0) {
number = -number;

// Remove carts sequentially
for (int i = size - 1, j = 0; i > size - number; i--, j++) {
newGroup[j] = members.get(i);
vehicle.remove(i);
}
}
else {
// decouple from the front
for (int i = 0; i < number; i++) newGroup[i] = members.get(i);
vehicle.subList(0, number).clear();
}

// else decouple from the front
else {
// Remove carts sequentially
for (int i = 0; i < number; i++) newGroup[i] = members.get(i);
vehicle.subList(0, number).clear();
}
MinecartGroupStore.createSplitFrom(properties, newGroup);
}

// 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("z") String z, final @Argument("direction") String direction, final @Argument("time") String time) {
long ticks = AddonsUtil.parseTicks(time);
World world;
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());
}

@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("z") String z,
final @Argument("direction") String direction,
final @Argument("time") String time
) {
long ticks = AddonsUtil.parseTicks(time);
World world;
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());
} 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());
}
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);
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());
}
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);
}

@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; int X, Y, Z; if (sender instanceof Player player) {
world = player.getWorld(); X = AddonsUtil.parseRelative(x, 'x', player.getLocation());
World world;
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());
} else {
BlockCommandSender commandBlock = (BlockCommandSender) sender; world = commandBlock.getBlock().getWorld();
}
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());
Expand Down
51 changes: 26 additions & 25 deletions src/main/java/mikeshafter/mikestcaddons/attachments/Changer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@
import java.util.List;

public class Changer extends RecurseHelper {
private final String name;
private final Material type;
private final int data;

public Changer(MinecartMember<?> member, String name, Material type, int data) {
super(member);
this.name = name;
this.type = type;
this.data = data;
}

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

ItemStack item = node.get("item", ItemStack.class);
var meta = item.getItemMeta();
item.setType(this.type);
meta.setCustomModelData(this.data);
item.setItemMeta(meta);
node.set("item", item);

return node;
}

private final String name;
private final Material type;
private final int data;

public Changer (MinecartMember<?> member, String name, Material type, int data) {
super(member);
this.name = name;
this.type = type;
this.data = data;
}

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

ItemStack item = node.get("item", ItemStack.class);
var meta = item.getItemMeta();
item.setType(this.type);
meta.setCustomModelData(this.data);
item.setItemMeta(meta);
node.set("item", item);

return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,40 @@
import java.util.Set;

public abstract class RecurseHelper {
final MinecartMember<?> member;

public RecurseHelper(MinecartMember<?> member) {
this.member = member;
}
final MinecartMember<?> member;

public RecurseHelper (MinecartMember<?> member) {this.member = member;}

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

ConfigurationNode attachmentsNode = fullConfig.getNode("attachments");
Set<ConfigurationNode> attachmentsSet = attachmentsNode.getNodes();
ConfigurationNode attachmentsNode = fullConfig.getNode("attachments");
Set<ConfigurationNode> attachmentsSet = attachmentsNode.getNodes();

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

this.member.getProperties().getModel().update(fullConfig);
}

private ConfigurationNode recurse(ConfigurationNode node) {
ConfigurationNode attachmentsNode = node.getNode("attachments");
Set<ConfigurationNode> attachmentsSet = attachmentsNode.getNodes();
this.member.getProperties().getModel().update(fullConfig);
}

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

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

return call(node);
}

protected abstract ConfigurationNode call(ConfigurationNode node);
return call(node);
}

protected abstract ConfigurationNode call (ConfigurationNode node);
}
Loading

0 comments on commit 17efce8

Please sign in to comment.