use of com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager 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.managers.files.SettingsManager in project buildinggame by stefvanschie.
the class Arena method setVotingPlot.
/**
* Sets the new voting plot, send messages and titles, teleports all players, gives them new vote items and changes
* their time and weather.
*
* @param votingPlot the new voting plot
* @see Plot
* @since 2.1.0
*/
public void setVotingPlot(Plot votingPlot) {
SettingsManager instance = SettingsManager.getInstance();
YamlConfiguration config = instance.getConfig();
YamlConfiguration messages = instance.getMessages();
this.votingPlot = votingPlot;
Region boundary = votingPlot.getBoundary();
Location safeLocation = boundary.getSafeLocation();
Location center = boundary.getCenter();
// https://bukkit.org/threads/lookat-and-move-functions.26768/
if (safeLocation != null) {
// Clone the loc to prevent applied changes to the input loc
safeLocation = safeLocation.clone();
// Values of change in distance (make it relative)
double dx = center.getX() - safeLocation.getX();
double dz = center.getZ() - safeLocation.getZ();
// Set yaw
if (dx != 0)
safeLocation.setYaw((dx < 0 ? ((float) (1.5 * Math.PI)) : ((float) (0.5 * Math.PI))) - (float) Math.atan(dz / dx));
else if (dz < 0)
safeLocation.setYaw((float) Math.PI);
// Set pitch
safeLocation.setPitch((float) -Math.atan((center.getY() - safeLocation.getY()) / (Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2)))));
// Set values, convert to degrees (invert the yaw since Bukkit uses a different yaw dimension format)
safeLocation.setYaw(-safeLocation.getYaw() * 180f / (float) Math.PI);
safeLocation.setPitch(safeLocation.getPitch() * 180f / (float) Math.PI);
}
for (Plot plot : getUsedPlots()) {
for (GamePlayer gamePlayer : plot.getAllGamePlayers()) {
Player player = gamePlayer.getPlayer();
if (!config.getBoolean("names-after-voting")) {
messages.getStringList("voting.message").forEach(message -> MessageManager.getInstance().send(player, message.replace("%playerplot%", votingPlot.getPlayerFormat())));
gamePlayer.addTitleAndSubtitle(messages.getString("voting.title").replace("%playerplot%", votingPlot.getPlayerFormat()), messages.getString("voting.subtitle").replace("%playerplot%", votingPlot.getPlayerFormat()));
gamePlayer.sendActionbar(messages.getString("voting.actionbar").replace("%playerplot%", votingPlot.getPlayerFormat()));
}
int blockIndex = ThreadLocalRandom.current().nextInt(votingPlot.getBoundary().getAllBlocks().size());
player.teleport(Objects.requireNonNullElseGet(safeLocation, () -> boundary.getAllBlocks().get(blockIndex).getLocation()));
// give blocks
player.getInventory().clear();
if (gamePlayer.getGamePlayerType() == GamePlayerType.PLAYER) {
config.getConfigurationSection("voting.items").getKeys(false).forEach(identifier -> {
boolean save = false;
if (!messages.contains("voting.items." + identifier + ".name")) {
messages.set("voting.items." + identifier + ".name", "Type: Null");
save = true;
}
if (!messages.contains("voting.items." + identifier + ".lore")) {
messages.set("voting.items." + identifier + ".lore", new ArrayList<String>(0));
save = true;
}
if (save)
instance.save();
Material material = SettingsManager.getInstance().getMaterial("voting.items." + identifier + ".id", Material.BARRIER);
player.getInventory().setItem(config.getInt("voting.items." + identifier + ".slot") - 1, new ItemBuilder(player, material).setDisplayName(MessageManager.translate(messages.getString("voting.items." + identifier + ".name"))).setLore(MessageManager.translate(messages.getStringList("voting.items." + identifier + ".lore"))).movable(false).setClickEvent(event -> {
int points = config.getInt("voting.items." + identifier + ".points");
votingPlot.addVote(new Vote(points, player));
event.setCancelled(true);
}).build());
});
boolean worldEditEnabled = Bukkit.getPluginManager().isPluginEnabled("WorldEdit");
if (worldEditEnabled && config.getBoolean("reports.enable")) {
player.getInventory().setItem(8, new ItemBuilder(player, Material.BOOK).setDisplayName(ChatColor.RED + "Report build").movable(false).setClickEvent(event -> {
var dateTimeFormatter = DateTimeFormatter.ofPattern("yyy-MM-dd_HH-mm-ss");
String players = getVotingPlot().getGamePlayers().stream().map(gp -> '-' + gp.getPlayer().getName()).reduce("", String::concat);
var fileName = LocalDateTime.now().format(dateTimeFormatter) + players + ".schem";
var file = new File(instance.getReportsSchematicsFolder(), fileName);
getVotingPlot().getBoundary().saveSchematic(file, () -> MessageManager.getInstance().send(event.getPlayer(), ChatColor.GREEN + "Your report has been saved."));
getVotingPlot().getGamePlayers().forEach(gp -> Report.add(new Report(gp.getPlayer(), player, ZonedDateTime.now(), file)));
}).build());
}
}
// update scoreboard and update time and weather
if (config.getBoolean("scoreboards.vote.enable"))
getVoteScoreboard(plot).show(player);
player.setPlayerTime(plot.getTime(), false);
player.setPlayerWeather(plot.isRaining() ? WeatherType.DOWNFALL : WeatherType.CLEAR);
}
}
getVotedPlots().add(votingPlot);
}
Aggregations