mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-03 23:07:55 +01:00
Pull changes from master
This commit is contained in:
commit
fa80b66ac2
@ -20,7 +20,6 @@ public class MVPlayerSession {
|
||||
private Long messageLast = 0L; // Timestamp for the Players last Alert Message.
|
||||
|
||||
private Configuration config; // Configuration file to find out Cooldown Timers.
|
||||
private int cachedHunger = 20;
|
||||
|
||||
public MVPlayerSession(Player player, Configuration config, MultiverseCore multiVerseCore) {
|
||||
this.player = player;
|
||||
@ -46,12 +45,4 @@ public class MVPlayerSession {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCachedHunger() {
|
||||
this.cachedHunger = this.player.getFoodLevel();
|
||||
}
|
||||
|
||||
public int getCachedHunger() {
|
||||
return this.cachedHunger;
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,7 @@ package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.utils.EnglishChatColor;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@ -59,6 +56,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
private boolean hunger = true;
|
||||
private Permission permission;
|
||||
private Permission exempt;
|
||||
private Difficulty difficulty;
|
||||
|
||||
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
|
||||
private boolean allowWeather;
|
||||
@ -94,6 +92,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
this.setScaling(config.getDouble("worlds." + this.name + ".scale", this.getDefaultScale(this.environment)));
|
||||
this.setRespawnToWorld(config.getString("worlds." + this.name + ".respawnworld", ""));
|
||||
this.setEnableWeather(config.getBoolean("worlds." + this.name + ".allowweather", true));
|
||||
this.setDifficulty(config.getString("worlds." + this.name + ".difficulty", "EASY"));
|
||||
|
||||
this.setAnimals(config.getBoolean("worlds." + this.name + ".animals.spawn", true));
|
||||
this.setMonsters(config.getBoolean("worlds." + this.name + ".monsters.spawn", true));
|
||||
@ -303,6 +302,8 @@ public class MVWorld implements MultiverseWorld {
|
||||
this.setMonsters(value);
|
||||
} else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) {
|
||||
this.setSpawnInMemory(value);
|
||||
} else if ((name.equalsIgnoreCase("hunger")) || (name.equalsIgnoreCase("food"))) {
|
||||
this.setHunger(value);
|
||||
} else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) {
|
||||
this.setEnableWeather(value);
|
||||
} else {
|
||||
@ -320,6 +321,9 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public boolean setVariable(String name, String value) {
|
||||
if (name.equalsIgnoreCase("diff") || name.equalsIgnoreCase("difficulty")) {
|
||||
return this.setDifficulty(value);
|
||||
}
|
||||
if (name.equalsIgnoreCase("alias")) {
|
||||
this.setAlias(value);
|
||||
return true;
|
||||
@ -643,4 +647,30 @@ public class MVWorld implements MultiverseWorld {
|
||||
public Location getSpawnLocation() {
|
||||
return this.spawnLocation;
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return this.getCBWorld().getDifficulty();
|
||||
}
|
||||
|
||||
public boolean setDifficulty(String difficulty) {
|
||||
Difficulty worlddiff = null;
|
||||
try {
|
||||
worlddiff = Difficulty.valueOf(difficulty.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
int diff = Integer.parseInt(difficulty);
|
||||
if (diff >= 0 && diff <= 3) {
|
||||
worlddiff = Difficulty.getByValue(diff);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.getCBWorld().setDifficulty(worlddiff);
|
||||
config.setProperty("worlds." + this.name + ".difficulty", worlddiff.getValue());
|
||||
saveConfig();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -229,10 +229,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Priority.Low, this); // Let plugins which specialize in (re)spawning carry more weight.
|
||||
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this); // To prepend the world name
|
||||
pm.registerEvent(Event.Type.PLAYER_PORTAL, this.playerListener, Priority.Monitor, this); // To switch gamemode
|
||||
pm.registerEvent(Event.Type.PLAYER_CHANGED_WORLD, this.playerListener, Priority.Monitor, this); // To switch gamemode
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP
|
||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning.
|
||||
pm.registerEvent(Event.Type.FOOD_LEVEL_CHANGE, this.entityListener, Priority.Normal, this);
|
||||
|
||||
pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Monitor, this);
|
||||
|
@ -125,7 +125,9 @@ public class InfoCommand extends MultiverseCommand {
|
||||
// Page 2
|
||||
message = new ArrayList<FancyText>();
|
||||
message.add(new FancyHeader("More World Settings", colors));
|
||||
message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors));
|
||||
message.add(new FancyMessage("Weather: ", world.getWeatherEnabled() + "", colors));
|
||||
message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors));
|
||||
message.add(new FancyMessage("Keep spawn in memory: ", world.getKeepSpawnInMemory() + "", colors));
|
||||
message.add(new FancyHeader("PVP Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.getPvp().toString(), colors));
|
||||
|
@ -63,10 +63,6 @@ public class MVPlayerListener extends PlayerListener {
|
||||
}
|
||||
|
||||
if (event.isBedSpawn() && this.plugin.getConfig().getBoolean("bedrespawn", true)) {
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) {
|
||||
this.handleGameMode(event.getPlayer(), event.getRespawnLocation().getWorld());
|
||||
}
|
||||
this.plugin.log(Level.FINE, "Spawning " + event.getPlayer().getName() + " at their bed");
|
||||
return;
|
||||
}
|
||||
@ -90,11 +86,6 @@ public class MVPlayerListener extends PlayerListener {
|
||||
MVRespawnEvent respawnEvent = new MVRespawnEvent(respawnLocation, event.getPlayer(), "compatability");
|
||||
this.plugin.getServer().getPluginManager().callEvent(respawnEvent);
|
||||
event.setRespawnLocation(respawnEvent.getPlayersRespawnLocation());
|
||||
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) {
|
||||
this.handleGameMode(event.getPlayer(), respawnEvent.getPlayersRespawnLocation().getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
private Location getMostAccurateRespawnLocation(World w) {
|
||||
@ -119,6 +110,14 @@ public class MVPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) {
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
this.plugin.removePlayerSession(event.getPlayer());
|
||||
@ -132,20 +131,12 @@ public class MVPlayerListener extends PlayerListener {
|
||||
MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
|
||||
MVWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
|
||||
event.setCancelled(checkWorldPermissions(fromWorld, toWorld, event.getPlayer()));
|
||||
// Dunno If I like these... @fernferret
|
||||
// if (toWorld != null && !toWorld.getHunger() && fromWorld != null && fromWorld.getHunger() && !event.isCancelled()) {
|
||||
// // If to has hunger, and from doesn't, save the hunger
|
||||
// this.plugin.getPlayerSession(event.getPlayer()).setCachedHunger();
|
||||
// }
|
||||
// else if (toWorld != null && toWorld.getHunger() && fromWorld != null && !fromWorld.getHunger() && !event.isCancelled()) {
|
||||
// // If from has hunger, and to doesn't, restore the hunger
|
||||
// event.getPlayer().setFoodLevel(this.plugin.getPlayerSession(event.getPlayer()).getCachedHunger());
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPortal(PlayerPortalEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
|
||||
if (event.isCancelled() || event.getTo() == null || event.getFrom() == null) {
|
||||
return;
|
||||
}
|
||||
MVWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
|
||||
@ -171,6 +162,9 @@ public class MVPlayerListener extends PlayerListener {
|
||||
player.sendMessage("You don't have access to go here...");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// The toworld is not handled by MV, we don't care about payments
|
||||
return false;
|
||||
}
|
||||
if (fromWorld != null) {
|
||||
if (fromWorld.getWorldBlacklist().contains(toWorld.getName())) {
|
||||
@ -178,17 +172,9 @@ public class MVPlayerListener extends PlayerListener {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (toWorld == null) {
|
||||
// The toworld is not handled by MV, we don't care about payments
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only check payments if it's a different world:
|
||||
if (!toWorld.equals(fromWorld)) {
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
if (this.plugin.getConfig().getBoolean("enforcegamemodes", true)) {
|
||||
this.handleGameMode(player, toWorld);
|
||||
}
|
||||
|
||||
// If the player does not have to pay, return now.
|
||||
if (toWorld.isExempt(player)) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user