Add portal limiter - simply disallow certain worlds

This commit is contained in:
Norbi Peti 2019-09-22 00:54:27 +02:00
parent 648518d5b6
commit 226dbc8c77
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 42 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package buttondevteam.presents;
import buttondevteam.lib.architecture.Component;
import buttondevteam.presents.components.chunkarchive.ChunkArchiveComponent;
import buttondevteam.presents.components.magic.MagicComponent;
import buttondevteam.presents.components.portals.PortalLimitComponent;
import buttondevteam.presents.components.research.ResearchComponent;
import buttondevteam.presents.components.research.dictionary.DictionaryComponent;
import buttondevteam.presents.components.spawn.SpawnComponent;
@ -31,6 +32,7 @@ public class ButtonPresents extends JavaPlugin{
getLogger().warning("ChunkArchive compatibility error, not registering it.");
}
Component.registerComponent(this, new TownyFactionsComponent());
Component.registerComponent(this, new PortalLimitComponent());
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");
}

View file

@ -0,0 +1,40 @@
package buttondevteam.presents.components.portals;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.presents.ButtonPresents;
import com.google.common.collect.Lists;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import java.util.List;
public class PortalLimitComponent extends Component<ButtonPresents> implements Listener {
@Override
protected void enable() {
registerListener(this);
}
@Override
protected void disable() {
}
private ConfigData<List<String>> worlds() {
return getConfig().getData("worlds", Lists.newArrayList("v1", "v2", "v3"));
}
@EventHandler(ignoreCancelled = true)
public void onPortalEnter(PlayerPortalEvent event) {
if (worlds().get().contains(event.getFrom().getWorld().getName()))
event.setCancelled(true);
}
@EventHandler(ignoreCancelled = true)
public void onPortalEnter(EntityPortalEvent event) {
if (worlds().get().contains(event.getFrom().getWorld().getName()))
event.setCancelled(true);
}
}