Compare commits

...

10 Commits

Author SHA1 Message Date
Len 433329be36 Add EssentiaListener.java to listen and interact with Essentia events. 2024-05-26 11:46:27 +02:00
Len 9a560cd8c6 Build changes 2024-05-26 11:33:20 +02:00
Len 92664eb636 Fix some issues with ore generators 2024-05-10 22:03:38 +02:00
Len 18cb07f34e Add KickFromBungeeCommand 2024-04-26 09:50:03 +02:00
Len b2eab51b72 Rework listeners and add EntityListener. 2024-04-23 10:54:56 +02:00
Len 88c3ee39ec Add support for IslandTrust and IslandUnTrust. 2024-04-23 10:44:11 +02:00
Len 72daaca943 Fix exp not being dropped for generated ores. 2024-04-23 09:09:30 +02:00
destro174 c081eb24ff
Ore gen v2 (#16)
* Fix typo in island gui

* Add glow for challenges that are completed.

* Enhance ore generators to generate the ore when the block is broken.

* Fix worlds not unloading.

* Fix generating ore for obsidian.
2024-04-21 18:47:40 +02:00
destro174 94b3abb0f5
Ore generators V2 (#15)
* Fix typo in island gui

* Add glow for challenges that are completed.

* Enhance ore generators to generate the ore when the block is broken.
2024-04-20 15:00:35 +02:00
Len 09525f0be1 Add challenges node to IslandGUI.java 2024-04-12 22:02:49 +02:00
24 changed files with 504 additions and 241 deletions

View File

@ -16,14 +16,7 @@ publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
repositories{
maven {
name = "maven"
url = uri("https://repo.destro.xyz/snapshots")
credentials(PasswordCredentials::class)
artifactId = "${project.name}-$version.jar"
}
}
}

View File

@ -23,6 +23,18 @@ subprojects {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
publishing {
configure<PublishingExtension> {
repositories {
maven {
name = "maven"
url = uri("https://repo.destro.xyz/snapshots/")
credentials(PasswordCredentials::class)
}
}
}
}
}
dependencies {
@ -56,24 +68,6 @@ tasks {
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
configure<PublishingExtension> {
repositories {
maven {
name = "maven"
url = uri("https://repo.destro.xyz/snapshots/")
credentials(PasswordCredentials::class)
}
}
}
}
dependencies {
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
}

View File

@ -9,6 +9,8 @@ dependencies {
isChanging = true
}
compileOnly("com.alttd.essentia:Essentia-api-Build-6.jar:Build-6")
compileOnly("org.projectlombok:lombok:1.18.24")
annotationProcessor("org.projectlombok:lombok:1.18.24")
@ -51,5 +53,9 @@ bukkit {
description = "${rootProject.name} admin command."
permission = "${rootProject.name}.command.admin"
}
register("kickfrombungee") {
description = "${rootProject.name} admin command."
}
}
}

View File

@ -2,6 +2,7 @@ package com.alttd.cometskyblock;
import com.alttd.cometskyblock.challenges.ChallengeHandler;
import com.alttd.cometskyblock.challenges.ChallengeLoader;
import com.alttd.cometskyblock.commands.KickFromBungeeCommand;
import com.alttd.cometskyblock.commands.admin.SkyBlockCommand;
import com.alttd.cometskyblock.commands.challenges.ChallengeCommand;
import com.alttd.cometskyblock.commands.island.IslandCommand;
@ -10,10 +11,8 @@ import com.alttd.cometskyblock.gui.GUIListener;
import com.alttd.cometskyblock.island.IslandData;
import com.alttd.cometskyblock.island.oregenerator.GeneratorHandler;
import com.alttd.cometskyblock.island.oregenerator.GeneratorLoader;
import com.alttd.cometskyblock.listeners.BedListener;
import com.alttd.cometskyblock.listeners.CobbestoneGeneratorListener;
import com.alttd.cometskyblock.listeners.PlayerJoinListener;
import com.alttd.cometskyblock.listeners.PlayerListener;
import com.alttd.cometskyblock.listeners.*;
;
import com.alttd.cometskyblock.managers.IslandManager;
import com.alttd.cometskyblock.worldgenerator.MasterWorldGenerator;
import lombok.Getter;
@ -102,15 +101,21 @@ public class CometSkyBlockPlugin extends JavaPlugin implements CometSkyBlockAPI
getCommand("island").setExecutor(new IslandCommand(this));
getCommand("challenges").setExecutor(new ChallengeCommand(this));
getCommand("skyblock").setExecutor( new SkyBlockCommand(this));
getCommand("kickfrombungee").setExecutor( new KickFromBungeeCommand());
}
public void loadEventListeners() {
final PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new PlayerJoinListener(this), this);
pm.registerEvents(new BedListener(this), this);
pm.registerEvents(new CobbestoneGeneratorListener(this), this);
pm.registerEvents(new GUIListener(this), this);
pm.registerEvents(new PlayerListener(this), this);
// final PluginManager pm = getServer().getPluginManager();
// pm.registerEvents(new BedListener(this), this);
// pm.registerEvents(new cobblestoneGeneratorListener(this), this);
// pm.registerEvents(new GUIListener(this), this);
// pm.registerEvents(new PlayerListener(this), this);
new BedListener(this);
new cobblestoneGeneratorListener(this);
new GUIListener(this);
new PlayerListener(this);
new EntityListener(this);
new EssentiaListener(this);
}
}

View File

@ -177,10 +177,9 @@ public class ChallengesGUI extends GUIInventory {
lore.add(miniMessage.deserialize("<yellow>Reward: " + StringUtil.splitMiniMessageString(
(challenge.challengeType().equals(ChallengeType.ON_PLAYER) && challengeCount != 0) ?
challenge.repeatRewardText() : challenge.rewardText())));
// TODO -- Add glow for challenges that are completed
// if (challengeCount > 0 || challenge.repeatRewards() != null && !challenge.repeatRewards().isEmpty()) {
// meta.addEnchant(Enchantment.MENDING, 1, true);
// }
if (challengeCount > 0) {
meta.addEnchant(Enchantment.MENDING, 1, true);
}
meta.addItemFlags(ItemFlag.values());
meta.lore(lore);

View File

@ -0,0 +1,49 @@
package com.alttd.cometskyblock.commands;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class KickFromBungeeCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.hasPermission("utility.kickfrombungee")) {
if (!(args.length == 0)) {
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
String reason = join(args, ' ' , 1, args.length);
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("KickPlayer");
out.writeUTF(target.getName());
out.writeUTF(ChatColor.translateAlternateColorCodes('&', reason));
target.sendPluginMessage(CometSkyBlockPlugin.instance(), "BungeeCord", out.toByteArray());
}
}
}
return true;
}
public static String join(final String[] array, final char delimiter, final int startIndex, final int endIndex) {
if (array == null) {
return null;
}
if (endIndex - startIndex <= 0) {
return "";
}
final StringBuilder stringBuilder = new StringBuilder(array.length * 5 + array.length - 1);
for (int i = startIndex; i < endIndex; i++) {
stringBuilder
.append(array[i])
.append(delimiter);
}
return stringBuilder.substring(0, stringBuilder.length() - 1);
}
}

View File

@ -27,6 +27,8 @@ public class IslandCommand extends PlayerSubCommand {
registerSubCommand(new IslandKick(plugin)); // TODO -- Add IslandKickCommand
registerSubCommand(new IslandSetOwner(plugin));
registerSubCommand(new IslandVisit(plugin));
registerSubCommand(new IslandTrust(plugin));
registerSubCommand(new IslandUnTrust(plugin));
}
@Override

View File

@ -0,0 +1,55 @@
package com.alttd.cometskyblock.commands.island;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.commands.PlayerSubCommand;
import com.alttd.cometskyblock.configuration.MessageConfiguration;
import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer;
import com.alttd.cometskyblock.request.InviteRequest;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
public class IslandTrust extends PlayerSubCommand {
public IslandTrust(CometSkyBlockPlugin plugin) {
super(plugin, "trust");
}
@Override
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
MessageConfiguration.Commands.Island.Trust trust = plugin.messagesConfiguration().get().commands().island().trust();
if (islandPlayer.islandId() == 0) {
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().noIsland());
return true;
}
if (args.length < 1) {
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().commandUsage());
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (player == target) {
player.sendRichMessage(trust.trustSelf());
return true;
}
if (target == null) {
player.sendRichMessage(trust.targetOffline());
return true;
}
Island island = Island.getIsland(islandPlayer.islandUUID());
UUID uuid = target.getUniqueId();
if (island.members().contains(uuid)) {
player.sendRichMessage(trust.targetIsMember());
return true;
}
if (island.trustList().contains(uuid)) {
player.sendRichMessage(trust.targetIsTrusted());
return true;
}
island.trust(uuid);
return true;
}
}

View File

@ -0,0 +1,42 @@
package com.alttd.cometskyblock.commands.island;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.commands.PlayerSubCommand;
import com.alttd.cometskyblock.configuration.MessageConfiguration;
import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
public class IslandUnTrust extends PlayerSubCommand {
public IslandUnTrust(CometSkyBlockPlugin plugin) {
super(plugin, "untrust");
}
@Override
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
MessageConfiguration.Commands.Island.Trust trust = plugin.messagesConfiguration().get().commands().island().trust();
if (islandPlayer.islandId() == 0) {
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().noIsland());
return true;
}
if (args.length < 1) {
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().commandUsage());
return true;
}
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
Island island = Island.getIsland(islandPlayer.islandUUID());
UUID uuid = target.getUniqueId();
if (!island.trustList().contains(uuid)) {
player.sendRichMessage(trust.targetIsNotTrusted());
return true;
}
island.untrust(uuid);
return true;
}
}

View File

@ -149,6 +149,16 @@ public class MessageConfiguration implements Configuration {
String targetNotAMember = "<red><target> must be a member of your island.";
}
Trust trust = new Trust();
@ConfigSerializable @Getter
public static class Trust {
String trustSelf = "<red>You can not trust yourself to this island.";
String targetOffline = "<red><target> not found, is the player online?";
String targetIsMember = "<red><target> is already a member on this island.";
String targetIsTrusted = "<red><target> is already trusted on this island.";
String targetIsNotTrusted = "<red><target> is not trusted on this island.";
}
Visit visit = new Visit();
@ConfigSerializable @Getter
public static class Visit {

View File

@ -1,6 +1,7 @@
package com.alttd.cometskyblock.gui;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.listeners.EventListener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -12,12 +13,13 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
/**
* Basically a handler to redirect events to our GUI implementations
*/
public class GUIListener implements Listener {
public class GUIListener extends EventListener {
protected final CometSkyBlockPlugin plugin;
public GUIListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
this.register(this.plugin);
}
@EventHandler

View File

@ -163,8 +163,8 @@ public class Island extends YamlConfiguration {
return s == null || s.isEmpty() ? NILL_UUID : UUID.fromString(s);
}
public boolean canBuild(UUID uuid) {
return owner().equals(uuid) || members().contains(uuid);
public boolean canInteract(UUID uuid) {
return owner().equals(uuid) || members().contains(uuid) || trustList().contains(uuid);
}
public void addMember(UUID uuid) {
@ -269,4 +269,30 @@ public class Island extends YamlConfiguration {
}
return contains("generator-level." + generatorTier.toString().toLowerCase(), true);
}
public List<UUID> trustList() {
List<String> trustList = getStringList("island.trust-list");
return trustList.stream()
.map(this::stringToUUID)
.collect(Collectors.toList());
}
public void trustList(List<UUID> trusList) {
set("island.trust-list", trusList.stream()
.map(uuid -> uuid == null ? "null" : uuid.toString())
.collect(Collectors.toList()));
save();
}
public void trust(UUID uuid) {
List<UUID> list = trustList();
list.add(uuid);
trustList(list);
}
public void untrust(UUID uuid) {
List<UUID> list = trustList();
list.remove(uuid);
trustList(list);
}
}

View File

@ -1,5 +1,6 @@
package com.alttd.cometskyblock.island.gui;
import com.alttd.cometskyblock.challenges.ChallengesGUI;
import com.alttd.cometskyblock.gui.GUIInventory;
import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer;
@ -42,6 +43,10 @@ public class IslandGUI extends GUIInventory {
player.closeInventory();
new SettingsGUI(island).open(player);
}));
addButton(13, createMenuButton(Material.BOOKSHELF, "Challenges", new ArrayList<>(), event -> {
player.closeInventory();
new ChallengesGUI(island).open(player);
}));
addButton(16, createMenuButton(Material.PLAYER_HEAD, "Island Members!", new ArrayList<>(), event -> {
player.closeInventory();

View File

@ -26,13 +26,14 @@ public class GeneratorHandler {
return generatorLevels.getInt(tier);
}
public Material generateOre(Island island, boolean cobblestone, int depth) {
boolean deepslate = depth <= 16 && cobblestone;
Material ore = rollGenerator(island, cobblestone);
public Material generateOre(Island island, Material material) {
boolean deepslate = material == Material.DEEPSLATE;
Material ore = rollGenerator(island, material);
return deepslate ? deepslateVariant(ore) : ore;
}
private Material rollGenerator(Island island, boolean cobblestone) {
private Material rollGenerator(Island island, Material material) {
boolean cobblestone = material == Material.STONE || material == Material.COBBLESTONE || material == Material.DEEPSLATE;
double random = Math.random() * 100;
double checkedChance = 0;
@ -52,12 +53,15 @@ public class GeneratorHandler {
}
}
return cobblestone ? Material.COBBLESTONE : Material.BASALT;
return material;
}
public Material deepslateVariant(Material material) {
switch (material) {
case COBBLESTONE -> {
return Material.COBBLED_DEEPSLATE;
}
case STONE -> {
return Material.DEEPSLATE;
}
case COAL_ORE -> {

View File

@ -15,11 +15,12 @@ import org.bukkit.event.block.BlockPlaceEvent;
* By default Gamerule DO_INSOMNIA is disabled, the moment an island member sleeps this gamerule will be enabled.
* Still debating if this should only be enabled for those that have slept
*/
public class BedListener implements Listener {
public class BedListener extends EventListener {
private final CometSkyBlockPlugin plugin;
public BedListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
this.register(this.plugin);
}
@EventHandler(ignoreCancelled = true)
@ -28,23 +29,10 @@ public class BedListener implements Listener {
return;
}
Player player = event.getPlayer();
if(!canInteract(event, player))
return;
World world = player.getWorld();
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId());
if (!world.getUID().equals(islandPlayer.islandUUID())) {
event.setCancelled(true);
return;
}
Island island = Island.getIsland(world.getUID());
if (island == null) {
return;
}
if (!island.canBuild(player.getUniqueId())) {
event.setCancelled(true);
return;
}
world.setGameRule(GameRule.DO_INSOMNIA, true);
}

View File

@ -1,71 +0,0 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.island.Island;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent;
import java.util.concurrent.TimeUnit;
public class CobbestoneGeneratorListener implements Listener {
private final CometSkyBlockPlugin plugin;
// public static Cache<Location, Long> generatorCache = CacheBuilder.newBuilder()
// .maximumSize(1000)
// .expireAfterAccess(10, TimeUnit.MINUTES)
// .build();
public CobbestoneGeneratorListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
}
@EventHandler
public void onBockForm(BlockFormEvent blockFormEvent) {
Block block = blockFormEvent.getNewState().getBlock();
Island island = Island.getIsland(block.getWorld().getUID());
if (island.worldName() == null || island.worldName().isEmpty()) // Worlds not generated by us will have this as null or empty
return;
Material formedMaterial = blockFormEvent.getNewState().getType();
boolean cobblestone;
switch (formedMaterial) {
case COBBLESTONE -> cobblestone = true;
case BASALT -> cobblestone = false;
default -> {
return;
}
}
Material generatedMaterial = plugin.generatorHandler().generateOre(island, cobblestone, blockFormEvent.getBlock().getLocation().getBlockY());
blockFormEvent.getNewState().setType(generatedMaterial);
// TODO - set to infested variants - turn them into ore when breaking them?
// if infested block -> rollgenerator -> block::breaknaturally?
}
// @EventHandler
// public void cobblestoneGeneratorDrops(BlockBreakEvent event) {
// // TODO - multiply drops from cobble gen?
// Block block = event.getBlock();
// if (block.getType().equals(Material.COBBLESTONE)) {
// if (relativeEqualsMaterial(block, Material.LAVA)) { // any other way to detect if they are from cobble gen
// // set some data during blockform event?
// if (relativeEqualsMaterial(block, Material.WATER)) {
//
// }
// }
// }
// }
boolean relativeEqualsMaterial(Block block, Material material) {
return block.getRelative(BlockFace.NORTH).getType().equals(material)
|| block.getRelative(BlockFace.EAST).getType().equals(material)
|| block.getRelative(BlockFace.SOUTH).getType().equals(material)
|| block.getRelative(BlockFace.WEST).getType().equals(material);
}
}

View File

@ -0,0 +1,24 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
public class EntityListener extends EventListener {
private final CometSkyBlockPlugin plugin;
public EntityListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
this.register(this.plugin);
}
@EventHandler(ignoreCancelled = true)
public void onEntityTargetPlayer(EntityTargetLivingEntityEvent event) {
if (!(event.getTarget() instanceof Player player))
return;
if(!canInteract(event, player))
return;
}
}

View File

@ -0,0 +1,41 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.essentia.events.PlayerSetHomeEvent;
import com.alttd.essentia.events.PlayerTeleportBackEvent;
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
public class EssentiaListener extends EventListener {
private final CometSkyBlockPlugin plugin;
public EssentiaListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
this.register(this.plugin);
}
@EventHandler(ignoreCancelled = true)
public void onPlayerSetHome(PlayerSetHomeEvent event) {
Player player = event.getPlayer();
if (!canInteract(event, player)) {
player.sendRichMessage("<red>You can not set a home here.");
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleportBack(PlayerTeleportBackEvent event) {
Player player = event.getPlayer();
if (!canInteract(event, player)) {
player.sendRichMessage("<red>You can not teleport back to this location.");
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleportHome(PlayerTeleportHomeEvent event) {
Player player = event.getPlayer();
if (!canInteract(event, player)) {
player.sendRichMessage("<red>You can not teleport to this home.");
}
}
}

View File

@ -0,0 +1,58 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class EventListener implements Listener {
protected boolean isRegistered = false;
public void register(JavaPlugin instance) {
Bukkit.getServer().getPluginManager().registerEvents(this, instance);
isRegistered = true;
}
public void unregister() {
HandlerList.unregisterAll(this);
isRegistered = false;
}
boolean canInteract(Cancellable event, Player player) {
World world = player.getWorld();
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId());
if (world.getUID().equals(Bukkit.getWorlds().get(0).getUID()))
return false;
// if (!world.getUID().equals(islandPlayer.islandUUID())) {
// return cancelEvent(event);
// }
Island island = Island.getIsland(world.getUID());
if (island == null) {
return cancelEvent(event);
}
// Worlds not generated by CometSkyblock will have this as null or empty
// We do not care about these worlds - yet
if (island.worldName() == null || island.worldName().isEmpty()) {
return true;
}
if (!island.canInteract(player.getUniqueId())) {
return cancelEvent(event);
}
return true;
}
boolean cancelEvent(Cancellable event) {
event.setCancelled(true);
return false;
}
}

View File

@ -1,43 +0,0 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.events.IslandPlayerJoinEvent;
import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerJoinListener implements Listener {
private final CometSkyBlockPlugin plugin;
public PlayerJoinListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
}
@EventHandler(ignoreCancelled = true)
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (!player.hasPlayedBefore())
return;
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId());
if (islandPlayer.islandId() == 0) {
return;
}
Bukkit.getServer().getPluginManager().callEvent(new IslandPlayerJoinEvent(islandPlayer.toRecord()));
if (!player.getWorld().getUID().equals(islandPlayer.islandUUID()))
return;
Island island = Island.getIsland(islandPlayer.islandUUID());
if (island == null) {
return;
}
island.teleport(player, player.getLocation());
}
}

View File

@ -1,34 +0,0 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.events.IslandPlayerJoinEvent;
import com.alttd.cometskyblock.events.IslandPlayerLeaveEvent;
import com.alttd.cometskyblock.island.IslandPlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerLeaveListener implements Listener {
private final CometSkyBlockPlugin plugin;
public PlayerLeaveListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
}
@EventHandler(ignoreCancelled = true)
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (!player.hasPlayedBefore())
return;
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId());
if (islandPlayer.islandId() == 0) {
return;
}
Bukkit.getServer().getPluginManager().callEvent(new IslandPlayerLeaveEvent(islandPlayer.toRecord()));
}
}

View File

@ -1,13 +1,14 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.events.IslandPlayerJoinEvent;
import com.alttd.cometskyblock.events.IslandPlayerLeaveEvent;
import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
@ -16,17 +17,15 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
public class PlayerListener implements Listener {
public class PlayerListener extends EventListener {
private final CometSkyBlockPlugin plugin;
public PlayerListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
this.register(this.plugin);
}
@EventHandler(ignoreCancelled = true)
@ -95,36 +94,39 @@ public class PlayerListener implements Listener {
// }
// }
boolean canInteract(Cancellable event, Player player) {
World world = player.getWorld();
@EventHandler(ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (!player.hasPlayedBefore())
return;
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId());
if (world.getUID().equals(Bukkit.getWorlds().get(0).getUID()))
return false;
if (!world.getUID().equals(islandPlayer.islandUUID())) {
return cancelEvent(event);
if (islandPlayer.islandId() == 0) {
return;
}
Bukkit.getServer().getPluginManager().callEvent(new IslandPlayerJoinEvent(islandPlayer.toRecord()));
if (!player.getWorld().getUID().equals(islandPlayer.islandUUID()))
return;
Island island = Island.getIsland(world.getUID());
Island island = Island.getIsland(islandPlayer.islandUUID());
if (island == null) {
return cancelEvent(event);
return;
}
// Worlds not generated by CometSkyblock will have this as null or empty
// We do not care about these worlds - yet
if (island.worldName() == null || island.worldName().isEmpty()) {
return true;
}
if (!island.canBuild(player.getUniqueId())) {
return cancelEvent(event);
}
return true;
island.teleport(player, player.getLocation());
}
boolean cancelEvent(Cancellable event) {
event.setCancelled(true);
return false;
@EventHandler(ignoreCancelled = true)
public void onPlayerLeave(PlayerQuitEvent event) {
Player player = event.getPlayer();
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId());
if (islandPlayer.islandId() == 0) {
return;
}
Bukkit.getServer().getPluginManager().callEvent(new IslandPlayerLeaveEvent(islandPlayer.toRecord()));
}
}

View File

@ -0,0 +1,104 @@
package com.alttd.cometskyblock.listeners;
import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.island.Island;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.*;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class cobblestoneGeneratorListener extends EventListener {
public static final @NotNull String GENERATOR_METADATA_KEY = "comet:oregenerator";
private final CometSkyBlockPlugin plugin;
public cobblestoneGeneratorListener(CometSkyBlockPlugin plugin) {
this.plugin = plugin;
this.register(this.plugin);
}
@EventHandler(ignoreCancelled = true)
public void onBockForm(BlockFormEvent blockFormEvent) {
Block block = blockFormEvent.getBlock();
if (!isFromGenerator(blockFormEvent.getNewState().getType()))
return;
Island island = Island.getIsland(block.getWorld().getUID());
if (island.worldName() == null || island.worldName().isEmpty()) // Worlds not generated by us will have this as null or empty
return;
BlockState blockState = blockFormEvent.getNewState();
blockState.setMetadata(GENERATOR_METADATA_KEY, new CometMeta());
if (blockFormEvent.getNewState().getType() == Material.COBBLESTONE && block.getLocation().getBlockY() <= 16)
blockFormEvent.getNewState().setType(Material.DEEPSLATE);
}
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if(!block.hasMetadata(GENERATOR_METADATA_KEY))
return;
if (!isFromGenerator(block.getType()))
return;
Island island = Island.getIsland(block.getWorld().getUID());
Material generatedMaterial = plugin.generatorHandler().generateOre(island, block.getType());
block.setType(generatedMaterial);
event.setExpToDrop(block.getExpDrop(event.getPlayer().getInventory().getItemInMainHand()));
}
@EventHandler(ignoreCancelled = true)
public void onBlockDropItem(BlockDropItemEvent event) {
Block block = event.getBlock();
if(!block.hasMetadata(GENERATOR_METADATA_KEY)) {
return;
}
// At This point we can inject bonus items
block.removeMetadata(GENERATOR_METADATA_KEY, plugin);
for (Item item : event.getItems()) {
item.setFireInvulnerableTicks(100);
}
}
// @EventHandler(ignoreCancelled = true)
// public void onBlockPistonExtend(BlockPistonExtendEvent event) {
// cleanPistonBlocks(event.getBlocks());
// }
//
// @EventHandler(ignoreCancelled = true)
// public void onBlockPistonRetract(BlockPistonRetractEvent event) {
// cleanPistonBlocks(event.getBlocks());
// }
//
// private void cleanPistonBlocks(List<Block> blocks) {
// for (Block block : blocks) {
// if(block.hasMetadata(GENERATOR_METADATA_KEY)) {
// block.removeMetadata(GENERATOR_METADATA_KEY, plugin);
// }
// }
// }
private boolean isFromGenerator(Material material) {
return switch (material) {
case STONE, COBBLESTONE, DEEPSLATE, BASALT -> true;
default -> false;
};
}
public class CometMeta extends FixedMetadataValue {
public CometMeta() {
super(plugin, true);
}
}
}

View File

@ -86,6 +86,7 @@ public class MasterWorldGenerator {
return;
}
newIsland.setDifficulty(Difficulty.NORMAL);
newIsland.setKeepSpawnInMemory(false);
newIsland.setGameRule(GameRule.DO_INSOMNIA, false);
// TODO Load a schematic into this world?
// Currently random islands are generated by CometIslandGenerator()
@ -119,6 +120,7 @@ public class MasterWorldGenerator {
return null;
}
newIsland.setKeepSpawnInMemory(false);
newIsland.setDifficulty(Difficulty.NORMAL); // TODO - island options to set difficulty
return newIsland;
}