Skip to content

Commit

Permalink
Protect the world from visitors.
Browse files Browse the repository at this point in the history
#28 more flexible protection.
  • Loading branch information
SilverCory committed Sep 5, 2016
1 parent 369b3d1 commit 07007f0
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -293,6 +295,22 @@ public void onPlayerQuit( PlayerQuitEvent event ) {

}

/**
* Handle world protection.
*
* @param event The interaction event.
*/
@EventHandler( ignoreCancelled = true, priority = EventPriority.HIGH )
public void onInteractEvent( PlayerInteractEvent event ) {

if ( event.getPlayer().getGameMode() == GameMode.ADVENTURE ) {
event.setUseItemInHand( Event.Result.DENY );
event.setUseInteractedBlock( Event.Result.DENY );
event.setCancelled( true );
}

}

public void playerLeftWorld( @NonNull World world ) {

List<Player> worldPlayers = WorldDimension.getPlayersAllDimensions( world );
Expand Down

0 comments on commit 07007f0

Please sign in to comment.