Skip to content

Commit

Permalink
Updated to 1.17.1
Browse files Browse the repository at this point in the history
Signed-off-by: Mineshafter61 <yuhang.061@gmail.com>
  • Loading branch information
Mineshafter61 committed Sep 3, 2021
1 parent d2bd79a commit 3a3cb4a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
17 changes: 12 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@

<groupId>mikeshafter</groupId>
<artifactId>OldThrottle</artifactId>
<version>1.17.1b1</version>
<version>1.17.1b2</version>
<packaging>jar</packaging>

<name>OldThrottle</name>

<properties>
<java.version>1.8</java.version>
<java.version>16</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>https://repository.apache.org/snapshots/</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
Expand All @@ -30,7 +37,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.3.0-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -83,13 +90,13 @@
<dependency>
<groupId>com.bergerkiller.bukkit</groupId>
<artifactId>TrainCarts</artifactId>
<version>1.16.5-v2-SNAPSHOT</version>
<version>1.17.1-v2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bergerkiller.bukkit</groupId>
<artifactId>BKCommonLib</artifactId>
<version>1.16.5-v2-SNAPSHOT</version>
<version>1.17.1-v2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/mikeshafter/oldthrottle/Throttle.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ public void emergencyBrake(Player player) {

@EventHandler
public void dismount(EntityDismountEvent event) {
if (event.getEntity() instanceof Player) {

Player player = (Player) event.getEntity();
if (event.getEntity() instanceof Player player) {

if (speedHashMap.containsKey(player)) {
emergencyBrake(player);
}
Expand Down
58 changes: 23 additions & 35 deletions src/main/java/mikeshafter/oldthrottle/TrainAnnounce.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNul
if (command.getName().equalsIgnoreCase("ta")) {

// If sent from player
if (sender instanceof Player && sender.hasPermission("OldThrottle.ta")) {
Player player = (Player) sender;
if (sender instanceof Player player && sender.hasPermission("OldThrottle.ta")) {
String message = colourise(String.join(" ", args));
player.sendMessage("Sent message: "+message);

Expand All @@ -50,14 +49,12 @@ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNul


// If sent from command block
} else if (sender instanceof BlockCommandSender) {
BlockCommandSender commandSender = (BlockCommandSender) sender;
} else if (sender instanceof BlockCommandSender commandSender) {
Block commandBlock = commandSender.getBlock();
AdvancedMessage message = advancedMessage(args);

// Check if message has flags
if (message instanceof RadiusMessage) {
RadiusMessage radiusMessage = (RadiusMessage) message;
if (message instanceof RadiusMessage radiusMessage) {
Location location = radiusMessage instanceof RadiusMessageCoordinates ?
new Location(commandBlock.getWorld(), ((RadiusMessageCoordinates) radiusMessage).getX(), ((RadiusMessageCoordinates) radiusMessage).getY(), ((RadiusMessageCoordinates) radiusMessage).getZ())
: commandBlock.getLocation();
Expand All @@ -76,8 +73,7 @@ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNul
return true;
}
}
} else if (message instanceof AdvancedMessageBox) {
AdvancedMessageBox messageBox = (AdvancedMessageBox) message;
} else if (message instanceof AdvancedMessageBox messageBox) {
int x = messageBox.getX();
int y = messageBox.getY();
int z = messageBox.getZ();
Expand Down Expand Up @@ -113,31 +109,28 @@ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNul
else if (command.getName().equalsIgnoreCase("tj")) {

// If sent from player
if (sender instanceof Player && sender.hasPermission("OldThrottle.tj")) {
Player player = (Player) sender;
if (sender instanceof Player player && sender.hasPermission("OldThrottle.tj")) {
String message = String.join(" ", args);
player.sendMessage("Sent message:");
sendJsonMessage(player, message);

// Get the train the player is in
for (MinecartMember<?> member : MinecartGroupStore.get(player.getVehicle())) {

// Get every player passenger
for (Player passenger : member.getEntity().getPlayerPassengers()) {
sendJsonMessage(passenger, message);
}
}
return true;

// If sent from command block
} else if (sender instanceof BlockCommandSender) {
BlockCommandSender commandSender = (BlockCommandSender) sender;
} else if (sender instanceof BlockCommandSender commandSender) {
Block commandBlock = commandSender.getBlock();
AdvancedMessage message = advancedMessage(args);

// Check if message has flags
if (message instanceof RadiusMessage) {
RadiusMessage radiusMessage = (RadiusMessage) message;
if (message instanceof RadiusMessage radiusMessage) {
Location location = radiusMessage instanceof RadiusMessageCoordinates ?
new Location(commandBlock.getWorld(), ((RadiusMessageCoordinates) radiusMessage).getX(), ((RadiusMessageCoordinates) radiusMessage).getY(), ((RadiusMessageCoordinates) radiusMessage).getZ())
: commandBlock.getLocation();
Expand All @@ -156,8 +149,7 @@ else if (command.getName().equalsIgnoreCase("tj")) {
return true;
}
}
} else if (message instanceof AdvancedMessageBox) {
AdvancedMessageBox messageBox = (AdvancedMessageBox) message;
} else if (message instanceof AdvancedMessageBox messageBox) {
int x = messageBox.getX();
int y = messageBox.getY();
int z = messageBox.getZ();
Expand Down Expand Up @@ -192,7 +184,7 @@ else if (command.getName().equalsIgnoreCase("tj")) {

public static String colourise(String message) {
Matcher matcher = HEX_PATTERN.matcher(ChatColor.translateAlternateColorCodes('&', message));
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();

while (matcher.find()) {
matcher.appendReplacement(buffer, ChatColor.of(matcher.group(1)).toString());
Expand All @@ -202,22 +194,18 @@ public static String colourise(String message) {
}

private AdvancedMessage advancedMessage(String[] args) {
switch (args[0]) {
case "-r":
return new RadiusMessage(String.join(" ", Arrays.copyOfRange(args, 2, args.length)), Integer.parseUnsignedInt(args[1]));
case "-rxyz":
return new RadiusMessageCoordinates(
String.join(" ", Arrays.copyOfRange(args, 2, args.length)),
Integer.parseUnsignedInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4])
);
case "-d":
return new AdvancedMessageBox(
String.join(" ", Arrays.copyOfRange(args, 2, args.length)),
Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6])
);
default:
return new AdvancedMessage(String.join(" ", args));
}
return switch (args[0]) {
case "-r" -> new RadiusMessage(String.join(" ", Arrays.copyOfRange(args, 2, args.length)), Integer.parseUnsignedInt(args[1]));
case "-rxyz" -> new RadiusMessageCoordinates(
String.join(" ", Arrays.copyOfRange(args, 2, args.length)),
Integer.parseUnsignedInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4])
);
case "-d" -> new AdvancedMessageBox(
String.join(" ", Arrays.copyOfRange(args, 2, args.length)),
Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6])
);
default -> new AdvancedMessage(String.join(" ", args));
};
}

private void sendJsonMessage(Player player, String message) {
Expand Down

0 comments on commit 3a3cb4a

Please sign in to comment.