mirror of
https://github.com/Freezy-Studios/BlazeSMP.git
synced 2025-04-22 01:14:03 +02:00
Added spawn preassureplatelistener
This commit is contained in:
parent
e511a3aea9
commit
fcb2ca8496
3 changed files with 79 additions and 5 deletions
|
@ -73,6 +73,7 @@ public final class BlazeSMP extends JavaPlugin {
|
|||
pm.registerEvents(new PlayerCommandBlockerListener(), this);
|
||||
pm.registerEvents(new PlayerClaimListener(), this);
|
||||
pm.registerEvents(new ChunkInventoryManager(), this);
|
||||
pm.registerEvents(new PressurePlateListener(), this);
|
||||
this.log.info("Registered EventListeners!");
|
||||
|
||||
this.log.info("Starting Timer tasks...");
|
||||
|
|
|
@ -17,18 +17,16 @@ public class PlayerChatListener implements Listener {
|
|||
Component suffix = Component.empty();
|
||||
|
||||
if (team != null) {
|
||||
team.prefix();
|
||||
prefix = team.prefix();
|
||||
team.suffix();
|
||||
suffix = team.suffix();
|
||||
}
|
||||
|
||||
Component messageComponent = event.message();
|
||||
|
||||
Component chatComponent = Component.empty()
|
||||
.append(prefix)
|
||||
.append(Component.text(player.getName()))
|
||||
.append(suffix)
|
||||
//.append(prefix)
|
||||
.append(player.teamDisplayName())
|
||||
//.append(suffix)
|
||||
.append(Component.text(": "))
|
||||
.append(messageComponent);
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package me.freezy.plugins.papermc.blazesmp.listener;
|
||||
|
||||
import me.freezy.plugins.papermc.blazesmp.BlazeSMP;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PressurePlateListener implements Listener {
|
||||
private static final Plugin plugin = JavaPlugin.getPlugin(BlazeSMP.class);
|
||||
private final Location pressurePlateLocation;
|
||||
private final Location spawnLocation;
|
||||
private final Map<UUID, BukkitRunnable> playerTasks = new HashMap<>();
|
||||
private final String teleportMessage;
|
||||
private final long teleportDelay;
|
||||
|
||||
public PressurePlateListener() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
pressurePlateLocation = new Location(
|
||||
Bukkit.getWorld(config.getString("pressure-plate.world", "world")),
|
||||
config.getDouble("pressure-plate.x", 1),
|
||||
config.getDouble("pressure-plate.y", 68),
|
||||
config.getDouble("pressure-plate.z", 0)
|
||||
);
|
||||
spawnLocation = new Location(
|
||||
Bukkit.getWorld(config.getString("spawn-location.world", "world")),
|
||||
config.getDouble("spawn-location.x", 0),
|
||||
config.getDouble("spawn-location.y", 200),
|
||||
config.getDouble("spawn-location.z", 0)
|
||||
);
|
||||
teleportMessage = config.getString("teleport-message", "§cYou need to wait 5 seconds to be teleported.");
|
||||
teleportDelay = config.getLong("teleport-delay", 100L); // Default to 5 seconds (100 ticks)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (event.getTo().getBlock().getLocation().equals(pressurePlateLocation)) {
|
||||
if (!playerTasks.containsKey(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(teleportMessage);
|
||||
BukkitRunnable task = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
event.getPlayer().teleport(spawnLocation);
|
||||
playerTasks.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
};
|
||||
task.runTaskLater(plugin, teleportDelay);
|
||||
playerTasks.put(event.getPlayer().getUniqueId(), task);
|
||||
}
|
||||
} else {
|
||||
if (playerTasks.containsKey(event.getPlayer().getUniqueId())) {
|
||||
playerTasks.get(event.getPlayer().getUniqueId()).cancel();
|
||||
playerTasks.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getBlock().getLocation().equals(pressurePlateLocation) && event.getBlock().getType() == Material.POLISHED_BLACKSTONE_PRESSURE_PLATE) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue