-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from AlbertoRutigliano/player-classes
Player classes
- Loading branch information
Showing
10 changed files
with
286 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 76 additions & 46 deletions
122
src/main/java/lar/minecraft/hg/commands/ClassCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,76 @@ | ||
package lar.minecraft.hg.commands; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import lar.minecraft.hg.SpigotPlugin; | ||
import lar.minecraft.hg.entities.PlayerExtra; | ||
import lar.minecraft.hg.enums.MessageKey; | ||
import lar.minecraft.hg.enums.PlayerClass; | ||
import lar.minecraft.hg.managers.PlayerManager; | ||
import lar.minecraft.hg.utils.MessageUtils; | ||
|
||
public class ClassCommand implements CommandExecutor { | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
PlayerClass cmdName = PlayerClass.valueOf(command.getName().toLowerCase()); | ||
|
||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
if (cmdName != null && !PlayerManager.playerExtras.isEmpty() && (SpigotPlugin.isWaitingForStart() || SpigotPlugin.isLobby())) { | ||
PlayerExtra playerExtra = PlayerManager.playerExtras.get(player.getUniqueId()); | ||
|
||
if (playerExtra != null) { | ||
// Check command selection: only premium users or who won last match can use premium classes | ||
if (!cmdName.isPremium() || playerExtra.isPremium() || playerExtra.isLastWinner()) { | ||
playerExtra.setPlayerClass(cmdName); | ||
PlayerManager.playerExtras.put(player.getUniqueId(), playerExtra); | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_selected, cmdName.name())); | ||
player.playSound(player, cmdName.getSound(), 10.0f, 10.0f); | ||
} else { | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_premium)); | ||
} | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_not_selected)); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} | ||
package lar.minecraft.hg.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabExecutor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.util.StringUtil; | ||
|
||
import lar.minecraft.hg.SpigotPlugin; | ||
import lar.minecraft.hg.entities.PlayerExtra; | ||
import lar.minecraft.hg.enums.MessageKey; | ||
import lar.minecraft.hg.enums.PlayerClass; | ||
import lar.minecraft.hg.managers.PlayerManager; | ||
import lar.minecraft.hg.utils.MessageUtils; | ||
|
||
public class ClassCommand implements CommandExecutor, TabExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
if (args.length == 1) { | ||
PlayerClass className = PlayerClass.valueOf(args[0].toLowerCase()); | ||
|
||
if (className != null && !PlayerManager.playerExtras.isEmpty() && (SpigotPlugin.isWaitingForStart() || SpigotPlugin.isLobby())) { | ||
PlayerExtra playerExtra = PlayerManager.playerExtras.get(player.getUniqueId()); | ||
|
||
if (playerExtra != null) { | ||
// Check command selection: only premium users or who won last match can use premium classes | ||
if (!className.isPremium() || playerExtra.isPremium() || playerExtra.isLastWinner()) { | ||
playerExtra.setPlayerClass(className); | ||
PlayerManager.playerExtras.put(player.getUniqueId(), playerExtra); | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_selected, className.name())); | ||
player.playSound(player, className.getSound(), 10.0f, 10.0f); | ||
} else { | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_premium)); | ||
} | ||
} else { | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_not_selected)); | ||
return true; | ||
} | ||
} else { | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_not_selected)); | ||
} | ||
} else { | ||
player.sendMessage(MessageUtils.getMessage(MessageKey.class_not_selected)); | ||
return true; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { | ||
List<String> completions = new ArrayList<>(); | ||
|
||
if (args.length == 1) { | ||
List<String> tempList = Arrays.stream(PlayerClass.values()) | ||
.map(Enum::name) | ||
.collect(Collectors.toList()); | ||
StringUtil.copyPartialMatches(args[0], tempList, completions); | ||
return completions; | ||
} | ||
|
||
Collections.sort(completions); | ||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.