use of com.voxelgameslib.voxelgameslib.exception.UserException in project VoxelGamesLibv2 by VoxelGamesLib.
the class SignButtons method signInteract.
@EventHandler
public void signInteract(@Nonnull PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock() == null) {
return;
}
// is block a sign?
if (event.getClickedBlock().getState() instanceof Sign) {
User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException("Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
Sign sign = (Sign) event.getClickedBlock().getState();
for (int i = 0; i < sign.getLines().length; i++) {
String line = sign.getLines()[i];
for (String key : getButtons().keySet()) {
if (line.contains("[" + key + "]")) {
// TODO implement perm check
getButtons().get(key).execute(user, event.getClickedBlock());
}
}
}
}
}
use of com.voxelgameslib.voxelgameslib.exception.UserException in project VoxelGamesLibv2 by VoxelGamesLib.
the class SignListener method signBreakEvent.
@EventHandler
public void signBreakEvent(@Nonnull BlockBreakEvent event) {
// is block a sign?
if (event.getBlock().getState() instanceof Sign) {
User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException("Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
Sign sign = (Sign) event.getBlock().getState();
for (int i = 0; i < sign.getLines().length; i++) {
String line = sign.getLines()[i];
for (String key : signHandler.getSignPlaceholders().getPlaceHolders().keySet()) {
if (line.contains("%" + key + "%")) {
// has user permission for that?
if (user.hasPermission(placeHolderSignBreak)) {
Lang.msg(user, LangKey.SIGNS_BREAK_SUCCESS, key);
event.getBlock().setType(Material.AIR);
return;
} else {
event.setCancelled(true);
Lang.msg(user, LangKey.SIGNS_BREAK_NO_PERM, key, placeHolderSignBreak.getRole().getName());
return;
}
}
}
for (String key : signHandler.getSignButtons().getButtons().keySet()) {
if (line.contains("%" + key + "%")) {
// has user permission for that?
if (user.hasPermission(buttonSignBreak)) {
Lang.msg(user, LangKey.SIGNS_BREAK_SUCCESS, key);
event.getBlock().setType(Material.AIR);
return;
} else {
event.setCancelled(true);
Lang.msg(user, LangKey.SIGNS_BREAK_NO_PERM, key, buttonSignBreak.getRole().getName());
return;
}
}
}
}
}
}
use of com.voxelgameslib.voxelgameslib.exception.UserException in project VoxelGamesLibv2 by VoxelGamesLib.
the class GameListener method onLeave.
@EventHandler
public void onLeave(@Nonnull PlayerQuitEvent event) {
User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException("Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
gameHandler.getGames(event.getPlayer().getUniqueId(), true).forEach((game -> game.leave(user)));
}
Aggregations