Add some listeners
This commit is contained in:
parent
36642c2b0a
commit
3c2763d53c
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.alttd.cometskyblock.listeners;
|
||||||
|
|
||||||
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
|
import com.alttd.cometskyblock.island.Island;
|
||||||
|
import com.destroystokyo.paper.MaterialTags;
|
||||||
|
import org.bukkit.GameRule;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
private final CometSkyBlockPlugin plugin;
|
||||||
|
public BedListener(CometSkyBlockPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBedPlace(BlockPlaceEvent event) {
|
||||||
|
if (!MaterialTags.BEDS.isTagged(event.getBlockPlaced())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
World world = player.getWorld();
|
||||||
|
Island island = plugin.getIslandManager().getIsland(world);
|
||||||
|
if (island == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!island.canBuild(player.getUniqueId())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
world.setGameRule(GameRule.DO_INSOMNIA, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
package com.alttd.cometskyblock.listeners;
|
package com.alttd.cometskyblock.listeners;
|
||||||
|
|
||||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
import com.alttd.cometskyblock.worldgenerator.IslandGenerator;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
@ -20,14 +14,6 @@ public class PlayerJoinListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoinEvent(PlayerJoinEvent playerJoinEvent) {
|
public void onPlayerJoinEvent(PlayerJoinEvent playerJoinEvent) {
|
||||||
Player player = playerJoinEvent.getPlayer();
|
|
||||||
String island = "Island";
|
|
||||||
World world = Bukkit.getWorld(island);
|
|
||||||
if (world == null) {
|
|
||||||
new IslandGenerator(plugin).create(island);
|
|
||||||
}
|
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
|
||||||
player.setFlying(true);
|
|
||||||
player.teleportAsync(new Location(world, 0, 256, 0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user