mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-07 07:51:41 +01:00
Moved allowObsidianScooping to WorldSettings and renamed ObsidianToLava to ObsidianScoopingListener
#432
This commit is contained in:
parent
915cd6f293
commit
708c014d14
@ -18,7 +18,7 @@ import world.bentobox.bentobox.listeners.BlockEndDragon;
|
||||
import world.bentobox.bentobox.listeners.DeathListener;
|
||||
import world.bentobox.bentobox.listeners.JoinLeaveListener;
|
||||
import world.bentobox.bentobox.listeners.NetherPortals;
|
||||
import world.bentobox.bentobox.listeners.ObsidianToLava;
|
||||
import world.bentobox.bentobox.listeners.ObsidianScoopingListener;
|
||||
import world.bentobox.bentobox.listeners.PanelListenerManager;
|
||||
import world.bentobox.bentobox.managers.AddonsManager;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
@ -193,7 +193,7 @@ public class BentoBox extends JavaPlugin {
|
||||
// Nether portals
|
||||
manager.registerEvents(new NetherPortals(this), this);
|
||||
// Obsidian to lava helper
|
||||
manager.registerEvents(new ObsidianToLava(this), this);
|
||||
manager.registerEvents(new ObsidianScoopingListener(this), this);
|
||||
// End dragon blocking
|
||||
manager.registerEvents(new BlockEndDragon(this), this);
|
||||
// Banned visitor commands
|
||||
|
@ -78,13 +78,6 @@ public class Settings implements DataObject {
|
||||
@ConfigEntry(path = "general.fakeplayers", experimental = true)
|
||||
private Set<String> fakePlayers = new HashSet<>();
|
||||
|
||||
@ConfigComment("Allow obsidian to be scooped up with an empty bucket back into lava")
|
||||
@ConfigComment("This only works if there is a single block of obsidian (no obsidian within 10 blocks)")
|
||||
@ConfigComment("Recommendation is to keep this true so that newbies don't bother you or reset their")
|
||||
@ConfigComment("island unnecessarily.")
|
||||
@ConfigEntry(path = "general.allow-obsidian-scooping")
|
||||
private boolean allowObsidianScooping = true;
|
||||
|
||||
@ConfigComment("Rank required to use a command. e.g., use the invite command. Default is owner rank is required.")
|
||||
@ConfigEntry(path = "general.rank-command", experimental = true)
|
||||
private Map<String, Integer> rankCommand = new HashMap<>();
|
||||
@ -240,14 +233,6 @@ public class Settings implements DataObject {
|
||||
this.fakePlayers = fakePlayers;
|
||||
}
|
||||
|
||||
public boolean isAllowObsidianScooping() {
|
||||
return allowObsidianScooping;
|
||||
}
|
||||
|
||||
public void setAllowObsidianScooping(boolean allowObsidianScooping) {
|
||||
this.allowObsidianScooping = allowObsidianScooping;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getRankCommand() {
|
||||
return rankCommand;
|
||||
}
|
||||
|
@ -146,6 +146,15 @@ public interface WorldSettings {
|
||||
*/
|
||||
String getWorldName();
|
||||
|
||||
/**
|
||||
* Allow obsidian to be scooped up with an empty bucket back into lava.
|
||||
* This only works if there is a single block of obsidian (no obsidian within 10 blocks).
|
||||
* Recommendation is to keep this true so that newbies don't bother you or reset their
|
||||
* island unnecessarily.
|
||||
* @return whether obsidian scooping is allowed or not.
|
||||
*/
|
||||
boolean isAllowObsidianScooping();
|
||||
|
||||
/**
|
||||
* @return the dragonSpawn
|
||||
*/
|
||||
|
@ -20,29 +20,28 @@ import world.bentobox.bentobox.api.user.User;
|
||||
/**
|
||||
* Enables changing of obsidian back into lava
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class ObsidianToLava implements Listener {
|
||||
public class ObsidianScoopingListener implements Listener {
|
||||
|
||||
private BentoBox plugin;
|
||||
|
||||
/**
|
||||
* @param plugin - plugin
|
||||
* @param plugin plugin
|
||||
*/
|
||||
public ObsidianToLava(BentoBox plugin) {
|
||||
public ObsidianScoopingListener(BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables changing of obsidian back into lava
|
||||
*
|
||||
* @param e - event
|
||||
* @param e event
|
||||
* @return false if obsidian not scooped, true if scooped
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public boolean onPlayerInteract(final PlayerInteractEvent e) {
|
||||
if (!plugin.getSettings().isAllowObsidianScooping()
|
||||
|| !plugin.getIWM().inWorld(e.getPlayer().getLocation())
|
||||
if (!plugin.getIWM().inWorld(e.getPlayer().getLocation())
|
||||
|| !plugin.getIWM().isAllowObsidianScooping(e.getPlayer().getWorld())
|
||||
|| !e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)
|
||||
|| !e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
|
||||
|| !(e.getItem() != null && e.getItem().getType().equals(Material.BUCKET))
|
@ -251,6 +251,13 @@ public class IslandWorldManager {
|
||||
return gameModes.get(Util.getWorld(world)).getWorldSettings().getWorldName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether obsidian scooping is allowed or not.
|
||||
*/
|
||||
public boolean isAllowObsidianScooping(World world) {
|
||||
return gameModes.get(Util.getWorld(world)).getWorldSettings().isAllowObsidianScooping();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the endGenerate
|
||||
*/
|
||||
|
@ -40,14 +40,14 @@ import world.bentobox.bentobox.managers.LocalesManager;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({PlayerEvent.class, PlayerInteractEvent.class})
|
||||
public class ObsidianToLavaTest {
|
||||
public class ObsidianScoopingListenerTest {
|
||||
|
||||
private static World world;
|
||||
|
||||
@Test
|
||||
public void testObsidianToLava() {
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
assertNotNull(new ObsidianToLava(plugin));
|
||||
assertNotNull(new ObsidianScoopingListener(plugin));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -75,14 +75,7 @@ public class ObsidianToLavaTest {
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
|
||||
// Create new object
|
||||
ObsidianToLava listener = new ObsidianToLava(plugin);
|
||||
|
||||
// Mock settings
|
||||
Settings settings = mock(Settings.class);
|
||||
when(plugin.getSettings()).thenReturn(settings);
|
||||
when(settings.isAllowObsidianScooping()).thenReturn(false);
|
||||
// Allow scooping
|
||||
when(settings.isAllowObsidianScooping()).thenReturn(true);
|
||||
ObsidianScoopingListener listener = new ObsidianScoopingListener(plugin);
|
||||
|
||||
// Mock player
|
||||
Player who = mock(Player.class);
|
||||
@ -103,6 +96,7 @@ public class ObsidianToLavaTest {
|
||||
when(iwm.getIslandWorld(Mockito.any())).thenReturn(world);
|
||||
when(iwm.getNetherWorld(Mockito.any())).thenReturn(world);
|
||||
when(iwm.getEndWorld(Mockito.any())).thenReturn(world);
|
||||
when(iwm.isAllowObsidianScooping(Mockito.any())).thenReturn(true); // Allow scooping
|
||||
|
||||
// Mock up IslandsManager
|
||||
IslandsManager im = mock(IslandsManager.class);
|
||||
@ -205,7 +199,7 @@ public class ObsidianToLavaTest {
|
||||
Block airBlock = mock(Block.class);
|
||||
when(airBlock.getType()).thenReturn(Material.AIR);
|
||||
|
||||
ObsidianToLava listener = new ObsidianToLava(plugin);
|
||||
ObsidianScoopingListener listener = new ObsidianScoopingListener(plugin);
|
||||
PlayerInteractEvent event = new PlayerInteractEvent(who, action, item, clickedBlock, BlockFace.EAST);
|
||||
if (!action.equals(Action.RIGHT_CLICK_BLOCK) || !item.getType().equals(Material.BUCKET) || !clickedBlock.getType().equals(Material.OBSIDIAN)) {
|
||||
assertFalse(listener.onPlayerInteract(event));
|
Loading…
Reference in New Issue
Block a user