use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class SpawnFeature method enable.
@Override
public void enable() {
map = getPhase().getFeature(MapFeature.class).getMap();
for (Marker marker : map.getMarkers(spawnMarker)) {
spawns.add(marker.getLoc());
}
if (spawns.size() == 0) {
log.warning("Could not find any spawns on map " + map.getInfo().getDisplayName() + "(" + map.getInfo().getWorldName() + ")");
getPhase().getGame().abortGame();
return;
}
if (isInitialSpawn) {
for (User user : getPhase().getGame().getPlayers()) {
user.getPlayer().teleportAsync(getSpawn(user.getPlayer().getUniqueId()));
}
}
}
use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class SignPlaceholders method init.
public void init() {
registerPlaceholders();
// search for already loaded signs
Bukkit.getWorlds().stream().flatMap(w -> Arrays.stream(w.getLoadedChunks())).flatMap(s -> Arrays.stream(s.getTileEntities())).filter(s -> s instanceof Sign).map(s -> (Sign) s).forEach(s -> lastSeenSigns.put(s.getLocation(), s));
// modify update packets
protocolManager.addPacketListener(new PacketAdapter(voxelGamesLib, PacketType.Play.Server.TILE_ENTITY_DATA) {
@Override
public void onPacketSending(@Nonnull PacketEvent event) {
int action = event.getPacket().getIntegers().read(0);
// 9 = set sign text action
if (action != 9) {
return;
}
NbtCompound data = (NbtCompound) event.getPacket().getNbtModifier().read(0);
// read data
Component[] lines = new Component[4];
String[] rawLines = new String[4];
for (int i = 0; i < lines.length; i++) {
lines[i] = ComponentSerializers.JSON.deserialize(data.getString("Text" + (i + 1)));
rawLines[i] = ChatUtil.toPlainText(lines[i]);
}
// sometimes its a double, sometimes its an int...
double x;
double y;
double z;
try {
x = data.getDouble("x");
y = data.getDouble("y");
z = data.getDouble("z");
} catch (ClassCastException ex) {
x = data.getInteger("x");
y = data.getInteger("y");
z = data.getInteger("z");
}
Location loc = new Location(event.getPlayer().getWorld(), x, y, z);
if (event.getPlayer().getLocation().distanceSquared(loc) > 200 * 200) {
return;
}
if (!(rawLines[0].equals("") && rawLines[1].equals("") && rawLines[2].equals("") && rawLines[3].equals(""))) {
Block b = loc.getBlock();
if (!(b.getState() instanceof Sign)) {
return;
}
Sign sign = (Sign) b.getState();
lastSeenSigns.put(loc, sign);
}
Optional<User> user = userHandler.getUser(event.getPlayer().getUniqueId());
if (!user.isPresent()) {
return;
}
// call sign placeholders
modifySign(user.get(), loc, rawLines, lines);
// modify packet
for (int i = 0; i < lines.length; i++) {
data.put("Text" + (i + 1), ComponentSerializers.JSON.serialize(lines[i]));
}
}
});
// update task
new BukkitRunnable() {
@Override
public void run() {
lastSeenSigns.forEach((loc, sign) -> sign.update());
}
}.runTaskTimer(voxelGamesLib, 20, 20);
}
use of com.voxelgameslib.voxelgameslib.components.user.User 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.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class EditMode method gui.
@Subcommand("gui")
@CommandPermission("%admin")
public void gui(@Nonnull User sender) {
if (editMode.contains(sender.getUuid())) {
// TODO implement paginated invs
InventoryMenuBuilder builder = new InventoryMenuBuilder().withSize(9).withTitle(Lang.legacy(LangKey.INV_MARKER));
for (int i = 0; i < mapHandler.getMarkerDefinitions().size(); i++) {
MarkerDefinition markerDefinition = mapHandler.getMarkerDefinitions().get(i);
ItemStack is = new ItemBuilder(Material.PLAYER_HEAD).name(markerDefinition.getPrefix()).meta(itemMeta -> {
char prefix = markerDefinition.getPrefix().toUpperCase().charAt(0);
Skin skin = textureHandler.getSkin(prefix + "").orElseThrow(() -> new VoxelGameLibException("Unknown skull " + prefix));
SkullMeta meta = ((SkullMeta) itemMeta);
meta.setPlayerProfile(textureHandler.getPlayerProfile(skin));
Objects.requireNonNull(meta.getPlayerProfile()).setName(markerDefinition.getPrefix());
meta.setOwner(markerDefinition.getPrefix());
}).build();
builder.withItem(i, is, (player, clickType, itemStack) -> sender.getPlayer().performCommand("editmode skull " + itemStack.getItemMeta().getDisplayName()), ClickType.LEFT);
}
builder.show(sender.getPlayer());
} else {
Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED);
}
}
use of com.voxelgameslib.voxelgameslib.components.user.User 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() + ")"));
user.setLeaving(true);
gameHandler.getGames(event.getPlayer().getUniqueId(), true).forEach((game -> game.leave(user, false)));
}
Aggregations