Skip to content

Commit

Permalink
Bump version and fill in gamemode tab completions
Browse files Browse the repository at this point in the history
  • Loading branch information
felixklauke committed Apr 4, 2020
1 parent de4f917 commit 31a699d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ allprojects {
apply plugin: 'maven-publish'

group = 'com.mysteryworlds.crucio'
version = '1.0.2'
version = '1.0.3'

sourceCompatibility = '11'
targetCompatibility = '11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum GameMode {
CREATIVE(
org.bukkit.GameMode.CREATIVE,
org.bukkit.GameMode.SURVIVAL,
List.of("adventure", "1")
List.of("creative", "1")
),
ADVENTURE(
org.bukkit.GameMode.ADVENTURE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.mysteryworlds.crucio.gamemode;

import com.mysteryworlds.crucio.i18n.I18n;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;

public final class GameModeCommand implements CommandExecutor, TabCompleter {
private final I18n i18n;
Expand Down Expand Up @@ -74,9 +78,10 @@ private boolean changeGameMode(
}

private boolean changeGameModeOther(
Command command, CommandSender sender,
String targetName,
String gameMode
Command command,
CommandSender sender,
String gameMode,
String targetName
) {
if (!sender.hasPermission("crucio.command.gamemode.other")) {
sender.sendMessage(command.getPermissionMessage());
Expand All @@ -89,6 +94,7 @@ private boolean changeGameModeOther(
}
var mode = GameMode.fromString(gameMode);
mode.apply(player);
sender.sendMessage(i18n.translatePrefixedMessage("command-gamemode-changed-other", targetName, mode.name()));
return true;
}

Expand All @@ -99,6 +105,26 @@ public List<String> onTabComplete(
String alias,
String[] args
) {
return null;
switch (args.length) {
case 1: {
return StringUtil.copyPartialMatches(
args[0],
List.copyOf(GameMode.gameModeAliases()),
new ArrayList<>()
);
}
case 2: {
var playerNames = Bukkit.getOnlinePlayers().stream()
.map(HumanEntity::getName)
.collect(Collectors.toUnmodifiableList());
return StringUtil.copyPartialMatches(
args[1],
List.copyOf(playerNames),
new ArrayList<>()
);
}
default:
return List.of();
}
}
}

0 comments on commit 31a699d

Please sign in to comment.