Initial Commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.alttd.blacklistfromworlds;
|
||||
|
||||
import com.alttd.blacklistfromworlds.events.LoginEvent;
|
||||
import com.alttd.blacklistfromworlds.events.TeleportEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class BlacklistFromWorlds extends JavaPlugin {
|
||||
|
||||
public static BlacklistFromWorlds instance;
|
||||
|
||||
public static BlacklistFromWorlds getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getServer().getPluginManager().registerEvents(new LoginEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new TeleportEvent(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.alttd.blacklistfromworlds.events;
|
||||
|
||||
import com.alttd.blacklistfromworlds.util.RemoveFromWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class LoginEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onLoginEvent(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("blacklistfromworld." + event.getPlayer().getWorld().getName()))
|
||||
RemoveFromWorld.teleportPlayer(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.alttd.blacklistfromworlds.events;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
public class TeleportEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onTeleport(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String name = event.getTo().getWorld().getName();
|
||||
if (player.hasPermission("blacklistfromworld." + name)) {
|
||||
player.sendMessage(MiniMessage.miniMessage()
|
||||
.deserialize("<red>You are blacklisted from <world>, cancelling teleportation...</red>",
|
||||
TemplateResolver.resolving(Template.template("world", name))));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.alttd.blacklistfromworlds.util;
|
||||
|
||||
import com.alttd.blacklistfromworlds.BlacklistFromWorlds;
|
||||
|
||||
public class Logger {
|
||||
|
||||
static private final java.util.logging.Logger logger;
|
||||
|
||||
static {
|
||||
logger = BlacklistFromWorlds.getInstance().getLogger();
|
||||
}
|
||||
|
||||
public static void info(String info, String... variables)
|
||||
{
|
||||
for (String variable : variables) {
|
||||
info = info.replaceFirst("%", variable);
|
||||
}
|
||||
logger.info(info);
|
||||
}
|
||||
|
||||
public static void warning(String warning, String... variables)
|
||||
{
|
||||
for (String variable : variables) {
|
||||
warning = warning.replaceFirst("%", variable);
|
||||
}
|
||||
logger.warning(warning);
|
||||
}
|
||||
|
||||
public static void severe(String severe, String... variables)
|
||||
{
|
||||
for (String variable : variables) {
|
||||
severe = severe.replaceFirst("%", variable);
|
||||
}
|
||||
logger.severe(severe);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.alttd.blacklistfromworlds.util;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RemoveFromWorld {
|
||||
|
||||
public static void teleportPlayer(Player player) {
|
||||
World defaultWorld = Bukkit.getWorld("world");
|
||||
if (defaultWorld != null && !player.hasPermission("blacklistfromworld.world")) {
|
||||
player.teleport(defaultWorld.getSpawnLocation());
|
||||
player.sendMessage(MiniMessage.miniMessage()
|
||||
.deserialize("<green>You were teleported out of a world you're blacklisted in!</green>"));
|
||||
Logger.info("Teleported % to %", player.getName(), defaultWorld.getSpawnLocation().toString());
|
||||
return;
|
||||
}
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
if (player.hasPermission("blacklistfromworld." + world.getName()))
|
||||
continue;
|
||||
player.teleport(world.getSpawnLocation());
|
||||
player.sendMessage(MiniMessage.miniMessage()
|
||||
.deserialize("<green>You were teleported out of a world you're blacklisted in!</green>"));
|
||||
Logger.info("Teleported % to %", player.getName(), world.getSpawnLocation().toString());
|
||||
return;
|
||||
}
|
||||
player.kick(MiniMessage.miniMessage()
|
||||
.deserialize("<red>You are blacklisted from all worlds on this server.</red>"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
name: BlacklistFromWorlds
|
||||
version: '${project.version}'
|
||||
main: com.alttd.blacklistfromworlds.BlacklistFromWorlds
|
||||
api-version: 1.18
|
||||
authors: [ Teriuihi ]
|
||||
description: Plugin to blacklist players from worlds
|
||||
Reference in New Issue
Block a user