Skip to content

Commit

Permalink
Add access/deny permissions for worlds.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Dec 12, 2023
1 parent 301d3cc commit dacdad0
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 170 deletions.
2 changes: 2 additions & 0 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import me.lokka30.phantomworlds.listeners.player.PlayerDeathListener;
import me.lokka30.phantomworlds.listeners.player.PlayerJoinListener;
import me.lokka30.phantomworlds.listeners.player.PlayerPortalListener;
import me.lokka30.phantomworlds.listeners.player.PlayerTeleportListener;
import me.lokka30.phantomworlds.listeners.world.WorldInitListener;
import me.lokka30.phantomworlds.managers.FileManager;
import me.lokka30.phantomworlds.managers.WorldManager;
Expand Down Expand Up @@ -249,6 +250,7 @@ void registerListeners() {
getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerPortalListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerTeleportListener(this), this);

getServer().getPluginManager().registerEvents(new WorldInitListener(this), this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void backup(BukkitCommandActor actor, @Optional final World world) {
@Subcommand({"create", "+", "new"})
@CommandPermission("phantomworlds.command.phantomworlds.create")
@Description("command.phantomworlds.help.create")
public void create(BukkitCommandActor actor) {
public void create(BukkitCommandActor actor, final String name) {
//todo: port create command
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import me.lokka30.phantomworlds.PhantomWorlds;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import revxrsal.commands.process.ValueResolver;
Expand All @@ -35,8 +34,6 @@ public class AliasWorldResolver implements ValueResolver<World> {
public World resolve(@NotNull ValueResolverContext context) throws Throwable {
final String value = context.arguments().pop();

final String name = PhantomWorlds.worldManager().aliases.getOrDefault(value, value);

return Bukkit.getWorld(name);
return PhantomWorlds.worldManager().findWorld(value);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import revxrsal.commands.command.CommandActor;
import revxrsal.commands.command.ExecutableCommand;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onChangeWorld(PlayerChangedWorldEvent event) {
}

final String cfgPath = "worlds-to-load." + event.getPlayer().getWorld().getName();
if(PhantomWorlds.instance().data.getConfig().contains(cfgPath + ".gameMode")) {
if(PhantomWorlds.instance().data.getConfig().contains(cfgPath + ".gameMode") && !event.getPlayer().hasPermission("phantomworlds.world.bypass.gamemode")) {
final GameMode mode = GameMode.valueOf(PhantomWorlds.instance().data.getConfig().getString(cfgPath + ".gameMode"));
event.getPlayer().setGameMode(mode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package me.lokka30.phantomworlds.listeners.player;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import me.lokka30.phantomworlds.PhantomWorlds;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent;

/**
* PlayerTeleportEvent
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class PlayerTeleportListener implements Listener {

final PhantomWorlds plugin;

public PlayerTeleportListener(PhantomWorlds plugin) {
this.plugin = plugin;
}

@EventHandler
public void onPortal(PlayerTeleportEvent event) {
if(event.getTo() == null || event.getTo().getWorld() == null || event.getFrom().getWorld() == null) {
return;
}

if(event.getFrom().getWorld().getUID().equals(event.getTo().getWorld().getUID())) {
return;
}

final String cfgPath = "worlds-to-load." + event.getTo().getWorld().getName();

if(PhantomWorlds.instance().data.getConfig().getBoolean(cfgPath + ".whitelist", false)
&& !event.getPlayer().hasPermission("phantomworlds.world.access." + event.getPlayer().getWorld())) {
event.setCancelled(true);
return;
}

if(event.getPlayer().hasPermission("phantomworlds.world.deny." + event.getPlayer().getWorld())) {
event.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.WorldType;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static me.lokka30.phantomworlds.misc.Utils.zipFolder;
Expand Down Expand Up @@ -161,6 +159,12 @@ public PhantomWorld getPhantomWorldFromData(final String name) {
return world;
}

@Nullable
public World findWorld(final String name) {

return Bukkit.getWorld(aliases.getOrDefault(name, name));
}

public boolean backupWorld(final String world) {
return backupWorld(world, new File(PhantomWorlds.instance().getDataFolder(), PhantomWorlds.BACKUP_FOLDER));
}
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/me/lokka30/phantomworlds/managers/WorldRule.java

This file was deleted.

0 comments on commit dacdad0

Please sign in to comment.