use of com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot in project buildinggame by stefvanschie.
the class CommandManager method onSetBounds.
/**
* Called whenever a player wants to set the boundary of a plot
*
* @param player the player
* @param arena the arena
* @param id the plot id to set the boundary of
* @since 5.8.0
*/
@Subcommand("setbounds")
@Description("Set the boundary of a plot (inclusive)")
@CommandPermission("bg.setbounds")
@CommandCompletion("@arenas @nothing")
public void onSetBounds(Player player, Arena arena, int id) {
final var plot = arena.getPlot(id);
if (plot == null) {
MessageManager.getInstance().send(player, ChatColor.RED + "That's not a valid plot");
return;
}
player.getInventory().setItemInMainHand(new ItemBuilder(player, Material.STICK).setDisplayName(ChatColor.LIGHT_PURPLE + "Wand").setClickEvent(new Consumer<>() {
private Location previousLocation;
@Override
public void accept(PlayerInteractEvent event) {
YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
YamlConfiguration messages = SettingsManager.getInstance().getMessages();
var player = event.getPlayer();
var action = event.getAction();
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK)
return;
if (previousLocation == null) {
previousLocation = event.getClickedBlock().getLocation();
MessageManager.getInstance().send(player, ChatColor.GREEN + "Now click on the other corner");
} else {
// second time
var location = event.getClickedBlock().getLocation();
String name = arena.getName();
int plotID = plot.getId();
World world = location.getWorld();
if (previousLocation.getWorld().equals(world)) {
arenas.set(name + '.' + plotID + ".high.world", world.getName());
arenas.set(name + '.' + plotID + ".low.world", previousLocation.getWorld().getName());
} else {
MessageManager.getInstance().send(player, ChatColor.RED + "The world has to be the same");
event.setCancelled(true);
return;
}
int highestX = Math.max(previousLocation.getBlockX(), location.getBlockX());
int lowestX = Math.min(previousLocation.getBlockX(), location.getBlockX());
int highestY = Math.max(previousLocation.getBlockY(), location.getBlockY());
int lowestY = Math.min(previousLocation.getBlockY(), location.getBlockY());
int highestZ = Math.max(previousLocation.getBlockZ(), location.getBlockZ());
int lowestZ = Math.min(previousLocation.getBlockZ(), location.getBlockZ());
// x
arenas.set(name + '.' + plotID + ".high.x", highestX);
arenas.set(name + '.' + plotID + ".low.x", lowestX);
// y
arenas.set(name + '.' + plotID + ".high.y", highestY);
arenas.set(name + '.' + plotID + ".low.y", lowestY);
// z
arenas.set(name + '.' + plotID + ".high.z", highestZ);
arenas.set(name + '.' + plotID + ".low.z", lowestZ);
SettingsManager.getInstance().save();
String worldName = world.getName();
Supplier<World> worldSupplier = () -> Bukkit.getWorld(worldName);
Region region = RegionFactory.createRegion(worldSupplier, highestX, highestY, highestZ, lowestX, lowestY, lowestZ);
plot.setBoundary(region);
messages.getStringList("commands.setbounds.success").forEach(message -> MessageManager.getInstance().send(player, message.replace("%place%", plotID + "").replace("%arena%", name)));
previousLocation = null;
player.getInventory().setItemInMainHand(null);
}
event.setCancelled(true);
}
}).build());
MessageManager.getInstance().send(player, ChatColor.GREEN + "Please click on one corner");
}
use of com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot in project buildinggame by stefvanschie.
the class CommandManager method onSpectate.
/**
* Called whenever a player wants to spectate
*
* @param player the player
* @param toSpectate the player to spectate
* @since 5.8.0
*/
@Subcommand("spectate")
@Description("Spectate a player")
@CommandPermission("bg.spectate")
public void onSpectate(Player player, Player toSpectate) {
var arena = ArenaManager.getInstance().getArena(toSpectate);
if (arena == null) {
MessageManager.getInstance().send(player, ChatColor.RED + "Arena not found");
return;
}
if (arena.getState() != GameState.BUILDING) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate right now");
return;
}
GamePlayer toSpectateGamePlayer = arena.getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).filter(gamePlayer -> gamePlayer.getPlayer().equals(toSpectate)).findAny().orElse(null);
if (toSpectateGamePlayer == null) {
MessageManager.getInstance().send(player, ChatColor.RED + "Couldn't find the player to spectate");
return;
}
if (toSpectateGamePlayer.getGamePlayerType() == GamePlayerType.SPECTATOR) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate a spectator");
return;
}
// check if the player is playing the game
if (ArenaManager.getInstance().getArena(player) != null && ArenaManager.getInstance().getArena(player).getPlot(player).getGamePlayer(player).getGamePlayerType() == GamePlayerType.PLAYER) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate while you're in game");
return;
}
// check if we are already spectating
Plot spectating = null;
for (Arena a : ArenaManager.getInstance().getArenas()) {
for (Plot plot : a.getUsedPlots()) {
for (GamePlayer gamePlayer : plot.getSpectators()) {
if (gamePlayer.getPlayer().equals(player)) {
spectating = plot;
break;
}
}
}
}
if (spectating != null)
spectating.removeSpectator(spectating.getGamePlayer(player));
arena.getPlot(toSpectateGamePlayer.getPlayer()).addSpectator(player, toSpectateGamePlayer);
MessageManager.getInstance().send(player, ChatColor.GREEN + "Now spectating " + toSpectateGamePlayer.getPlayer().getName() + '!');
}
use of com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot in project buildinggame by stefvanschie.
the class EntityOptionsMenu method onEntityInteract.
/**
* Called whenever a player interacts with an entity
*
* @param e the event that is called when a player interacts with an entity
* @since 5.3.0
*/
@EventHandler
public void onEntityInteract(PlayerInteractEntityEvent e) {
SettingsManager settingsManager = SettingsManager.getInstance();
if (e.getHand() != EquipmentSlot.HAND || !settingsManager.getConfig().getBoolean("mobs.options.enable")) {
return;
}
var entity = e.getRightClicked();
EntityType entityType = entity.getType();
Player player = e.getPlayer();
if (SHIFT_CLICK_TYPES.contains(entityType) && !player.isSneaking()) {
return;
}
Plot plot = null;
loop: for (var arena : ArenaManager.getInstance().getArenas()) {
for (Plot p : arena.getUsedPlots()) {
if (p.getEntities().containsKey(entity)) {
plot = p;
break loop;
}
}
}
if (plot == null || plot.getArena().getState() != GameState.BUILDING) {
return;
}
switch(entityType) {
case CHICKEN:
case COW:
case GOAT:
case OCELOT:
case SKELETON_HORSE:
case POLAR_BEAR:
case HUSK:
case ZOMBIE:
case TURTLE:
case PIGLIN:
case HOGLIN:
case STRIDER:
case ZOGLIN:
new BabyMenu(plot, entity).show(player);
break;
case DONKEY:
case MULE:
new ChestMenu(plot, (ChestedHorse) entity).show(player);
break;
case VILLAGER:
case ZOMBIE_VILLAGER:
new VillagerlikeMenu(plot, (Creature) entity).show(player);
break;
case PHANTOM:
case MAGMA_CUBE:
case SLIME:
new SizeMenu(plot, (Mob) entity).show(player);
break;
case AXOLOTL:
new AxolotlMenu(plot, (Axolotl) entity).show(player);
break;
case PIG:
new PigMenu(plot, (Pig) entity).show(player);
break;
case RABBIT:
new RabbitMenu(plot, (Rabbit) entity).show(player);
break;
case SHEEP:
new SheepMenu(plot, (Sheep) entity).show(player);
break;
case CREEPER:
new CreeperMenu(plot, (Creeper) entity).show(player);
break;
case SHULKER:
new ShulkerMenu(plot, (Shulker) entity).show(player);
break;
case HORSE:
new HorseMenu(plot, (Horse) entity).show(player);
break;
case LLAMA:
new LlamaMenu(plot, (Llama) entity).show(player);
break;
case PARROT:
new ParrotMenu(plot, (Parrot) entity).show(player);
break;
case WOLF:
new ColorMenu(plot, (Animals) entity).show(player);
break;
case SNOWMAN:
new SnowGolemMenu(plot, (Snowman) entity).show(player);
break;
case PUFFERFISH:
new PufferfishMenu(plot, (PufferFish) entity).show(player);
break;
case TROPICAL_FISH:
new TropicalFishMenu(plot, (TropicalFish) entity).show(player);
break;
case MUSHROOM_COW:
new MooshroomMenu(plot, (MushroomCow) entity).show(player);
break;
case PANDA:
new PandaMenu(plot, (Panda) entity).show(player);
break;
case CAT:
new CatMenu(plot, (Cat) entity).show(player);
break;
case FOX:
new FoxMenu(plot, (Fox) entity).show(player);
break;
case BEE:
new BeeMenu(plot, (Bee) entity).show(player);
break;
case IRON_GOLEM:
new IronGolemMenu(plot, (IronGolem) entity).show(player);
break;
default:
new RemoveMenu(plot, entity).show(player);
break;
}
e.setCancelled(true);
}
use of com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot in project buildinggame by stefvanschie.
the class PlotManager method setup.
/**
* Loads/Reloads all plots
*/
@SuppressWarnings("MethodMayBeStatic")
public void setup() {
ArenaManager.getInstance().getArenas().forEach(arena -> {
arena.getPlots().clear();
SettingsManager.getInstance().getArenas().getConfigurationSection(arena.getName()).getKeys(false).forEach(plot -> {
int id;
try {
id = Integer.parseInt(plot);
} catch (NumberFormatException e) {
return;
}
Plot p = new Plot(arena, id);
arena.addPlot(p);
if (SettingsManager.getInstance().getConfig().getBoolean("debug"))
Main.getInstance().getLogger().info("Loaded plot " + p.getId() + " in arena " + arena.getName());
});
});
}
use of com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot in project buildinggame by stefvanschie.
the class TreeGrow method onStructureGrow.
/**
* Handles trees growing
*
* @param e an event representing a structure growing
* @see StructureGrowEvent
* @since 2.1.0
*/
@EventHandler
public static void onStructureGrow(StructureGrowEvent e) {
Plot plot = null;
for (var arena : ArenaManager.getInstance().getArenas()) {
for (Plot p : arena.getPlots()) {
Region boundary = p.getBoundary();
if (boundary == null)
continue;
if (boundary.isInside(e.getLocation())) {
plot = p;
break;
}
}
}
if (plot == null)
return;
Region boundary = plot.getBoundary();
if (boundary == null)
return;
e.getBlocks().removeIf(blockState -> !boundary.isInside(blockState.getLocation()));
}
Aggregations