use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.
the class MinigameUtils method giveMinigameTool.
/**
* Gives the defined player a Minigame tool.
* @param player - The player to give the tool to.
* @return The Minigame Tool
*/
public static MinigameTool giveMinigameTool(MinigamePlayer player) {
Material toolMat = Material.getMaterial(Minigames.plugin.getConfig().getString("tool"));
if (toolMat == null) {
toolMat = Material.BLAZE_ROD;
player.sendMessage("Invalid material type! Please check the configuration to see if it has been typed correctly! Default type given instead.", "error");
}
ItemStack tool = new ItemStack(toolMat);
MinigameTool mgTool = new MinigameTool(tool);
player.getPlayer().getInventory().addItem(mgTool.getTool());
return mgTool;
}
use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.
the class NodeToolMode method onSetMode.
@Override
public void onSetMode(final MinigamePlayer player, MinigameTool tool) {
tool.addSetting("Node", "None");
final Menu m = new Menu(2, "Node Selection", player);
if (player.isInMenu()) {
m.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, player.getMenu()), m.getSize() - 9);
}
final MinigameTool ftool = tool;
m.addItem(new MenuItemString("Node Name", Material.PAPER, new Callback<String>() {
@Override
public void setValue(String value) {
ftool.changeSetting("Node", value);
}
@Override
public String getValue() {
return ftool.getSetting("Node");
}
}));
if (tool.getMinigame() != null) {
// Node selection menu
RegionModule module = RegionModule.getMinigameModule(tool.getMinigame());
Menu nodeMenu = new Menu(6, "Nodes", player);
List<MenuItem> items = new ArrayList<MenuItem>();
for (final Node node : module.getNodes()) {
MenuItemCustom item = new MenuItemCustom(node.getName(), Material.STONE_BUTTON);
// Set the node and go back to the main menu
item.setClick(new InteractionInterface() {
@Override
public Object interact(Object object) {
ftool.changeSetting("Node", node.getName());
m.displayMenu(player);
return object;
}
});
items.add(item);
}
nodeMenu.addItems(items);
nodeMenu.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, m), nodeMenu.getSize() - 9);
m.addItem(new MenuItemPage("Edit Node", Material.STONE_BUTTON, nodeMenu));
}
m.displayMenu(player);
}
use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.
the class MenuItemToolMode method onClick.
public ItemStack onClick() {
MinigamePlayer ply = getContainer().getViewer();
if (MinigameUtils.hasMinigameTool(ply)) {
MinigameTool tool = MinigameUtils.getMinigameTool(ply);
if (tool.getMode() != null)
tool.getMode().onUnsetMode(ply, tool);
tool.setMode(mode);
tool.getMode().onSetMode(ply, tool);
}
return getItem();
}
use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.
the class MenuItemToolTeam method onClick.
@Override
public ItemStack onClick() {
super.onClick();
MinigamePlayer ply = getContainer().getViewer();
if (MinigameUtils.hasMinigameTool(ply)) {
MinigameTool tool = MinigameUtils.getMinigameTool(ply);
tool.setTeam(TeamColor.matchColor(value.getValue().replace(" ", "_")));
}
return getItem();
}
use of au.com.mineauz.minigames.tool.MinigameTool in project Minigames by AddstarMC.
the class Events method playerInterract.
@EventHandler
public void playerInterract(PlayerInteractEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply == null)
return;
if (ply.isInMinigame() && !ply.canInteract()) {
event.setCancelled(true);
return;
}
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.DRAGON_EGG) {
if (!ply.getMinigame().allowDragonEggTeleport()) {
event.setCancelled(true);
return;
}
}
if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.getPlayer().hasPermission("minigame.sign.use.details")) {
Block cblock = event.getClickedBlock();
if (cblock.getState() instanceof Sign && !event.isCancelled()) {
Sign sign = (Sign) cblock.getState();
if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[Minigame]")) {
if ((sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Join") || sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Bet")) && !ply.isInMinigame()) {
Minigame mgm = mdata.getMinigame(sign.getLine(2));
if (mgm != null && (!mgm.getUsePermissions() || event.getPlayer().hasPermission("minigame.join." + mgm.getName(false).toLowerCase()))) {
if (!mgm.isEnabled()) {
event.getPlayer().sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.notEnabled"));
} else {
event.getPlayer().sendMessage(ChatColor.GREEN + MinigameUtils.getLang("minigame.info.description"));
String status = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.status.title");
if (!mgm.hasPlayers()) {
status += " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.status.empty");
} else if (mgm.getMpTimer() == null || mgm.getMpTimer().getPlayerWaitTimeLeft() > 0) {
status += " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.status.waitingForPlayers");
} else {
status += " " + ChatColor.RED + MinigameUtils.getLang("minigame.info.status.started");
}
if (mgm.getType() != MinigameType.SINGLEPLAYER) {
event.getPlayer().sendMessage(status);
if (mgm.canLateJoin())
event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.lateJoin.msg") + " " + ChatColor.GREEN + MinigameUtils.getLang("minigame.info.lateJoin.enabled"));
else
event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.lateJoin.msg") + " " + ChatColor.RED + MinigameUtils.getLang("minigame.info.lateJoin.disabled"));
}
if (mgm.getMinigameTimer() != null) {
event.getPlayer().sendMessage(ChatColor.AQUA + "Time left: " + MinigameUtils.convertTime(mgm.getMinigameTimer().getTimeLeft()));
}
if (mgm.isTeamGame()) {
String sc = "";
int c = 0;
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
c++;
sc += t.getColor().getColor().toString() + " " + t.getScore() + ChatColor.WHITE;
if (c != TeamsModule.getMinigameModule(mgm).getTeams().size()) {
sc += " : ";
}
}
event.getPlayer().sendMessage(ChatColor.AQUA + MinigameUtils.getLang("minigame.info.score") + sc);
}
String playerCount = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.playerCount") + " " + ChatColor.GRAY;
String players = ChatColor.AQUA + MinigameUtils.getLang("minigame.info.players.msg") + " ";
if (mgm.hasPlayers()) {
playerCount += mgm.getPlayers().size();
if (mgm.getType() != MinigameType.SINGLEPLAYER) {
playerCount += "/" + mgm.getMaxPlayers();
}
List<String> plyList = new ArrayList<String>();
for (MinigamePlayer pl : mgm.getPlayers()) {
plyList.add(pl.getName());
}
players += MinigameUtils.listToString(plyList);
} else {
playerCount += "0";
if (mgm.getType() != MinigameType.SINGLEPLAYER) {
playerCount += "/" + mgm.getMaxPlayers();
}
players += ChatColor.GRAY + MinigameUtils.getLang("minigame.info.players.none");
}
event.getPlayer().sendMessage(playerCount);
event.getPlayer().sendMessage(players);
}
} else if (mgm == null) {
event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noMinigame"));
} else if (mgm.getUsePermissions()) {
event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.formStr("minigame.error.noPermission", "minigame.join." + mgm.getName(false).toLowerCase()));
}
}
}
}
}
ItemStack item = event.getItem();
if (item != null && MinigameUtils.isMinigameTool(item) && ply.getPlayer().hasPermission("minigame.tool")) {
MinigameTool tool = new MinigameTool(item);
event.setCancelled(true);
if (event.getPlayer().isSneaking() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
tool.openMenu(ply);
event.setCancelled(true);
} else if (event.getClickedBlock() != null && (event.getClickedBlock().getType() == Material.WALL_SIGN || event.getClickedBlock().getType() == Material.SIGN_POST)) {
Sign sign = (Sign) event.getClickedBlock().getState();
if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("[Minigame]") && ChatColor.stripColor(sign.getLine(1)).equalsIgnoreCase("Join")) {
Minigame minigame = mdata.getMinigame(sign.getLine(2));
tool.setMinigame(minigame);
ply.sendMessage("Tools Minigame has been set to " + minigame, null);
event.setCancelled(true);
}
} else if (tool.getMode() != null && tool.getMinigame() != null) {
Minigame mg = tool.getMinigame();
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
tool.getMode().onRightClick(ply, mg, TeamsModule.getMinigameModule(mg).getTeam(tool.getTeam()), event);
} else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
tool.getMode().onLeftClick(ply, mg, TeamsModule.getMinigameModule(mg).getTeam(tool.getTeam()), event);
}
} else if (tool.getMinigame() == null) {
ply.sendMessage("Please select a minigame. Click on the join sign, or /mg tool minigame <minigame>", null);
} else if (tool.getMode() == null) {
ply.sendMessage("Please select a tool mode. Shift + Right click", null);
}
}
//Spectator disables:
if (ply.isInMinigame() && pdata.getMinigamePlayer(event.getPlayer()).getMinigame().isSpectator(pdata.getMinigamePlayer(event.getPlayer()))) {
event.setCancelled(true);
}
}
Aggregations