Skip to content

Commit

Permalink
Fix compatibility with hardcore mode on lower versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Mar 1, 2024
1 parent 35fbeb8 commit 494523e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
Expand Down Expand Up @@ -58,4 +59,22 @@ default List<String> potionEffectSuggestions() {
default PotionEffectType findType(final String effectType) {
return PotionEffectType.getByKey(NamespacedKey.fromString(effectType));
}

/**
* Used to check if world is hardcore or not.
* @param world The world to check.
* @return True if hardcore, otherwise false.
*/
default boolean hardcore(final World world) {
return world.isHardcore();
}

/**
* Used to apply the hardcore value to the world.
* @param world The world to apply to.
* @param hardcore Hardcore value to set for the world.
*/
default void applyHardcore(World world, final boolean hardcore) {
world.setHardcore(hardcore);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import me.lokka30.phantomworlds.comatibility.VersionCompatibility;
import org.bukkit.World;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
Expand Down Expand Up @@ -64,4 +65,27 @@ public List<String> potionEffectSuggestions() {
public PotionEffectType findType(String effectType) {
return PotionEffectType.getByName(effectType);
}

/**
* Used to check if world is hardcore or not.
*
* @param world The world to check.
*
* @return True if hardcore, otherwise false.
*/
@Override
public boolean hardcore(World world) {
return false;
}

/**
* Used to apply the hardcore value to the world.
*
* @param world The world to apply to.
* @param hardcore Hardcore value to set for the world.
*/
@Override
public void applyHardcore(World world, boolean hardcore) {
//do nothing, not applicable to these versions.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void onCommand(final CommandSender sender, final World world) {

final PhantomWorld pworld = new PhantomWorld(
world.getName(), world.getEnvironment(), world.canGenerateStructures(), null,
null, world.isHardcore(), world.getSeed(), world.getWorldType(), world.getAllowMonsters(),
null, PhantomWorlds.compatibility().hardcore(world), world.getSeed(), world.getWorldType(), world.getAllowMonsters(),
world.getAllowAnimals(), world.getKeepSpawnInMemory(), world.getPVP(), world.getDifficulty(), GameMode.SURVIVAL
);
pworld.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void onPortal(PlayerTeleportEvent event) {
event.setCancelled(true);
}

if(!event.getPlayer().isOp() && event.getPlayer().hasPermission("phantomworlds.world.deny." + event.getTo().getWorld().getName())) {
/*if(!event.getPlayer().isOp() && event.getPlayer().hasPermission("phantomworlds.world.deny." + event.getTo().getWorld().getName())) {
event.setCancelled(true);
}
}*/

if(plugin.worldManager.tpAwaiting.containsKey(event.getPlayer().getUniqueId())) {
if(event.isCancelled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public void create() {
world.setKeepSpawnInMemory(keepSpawnInMemory);
world.setPVP(allowPvP);
world.setDifficulty(difficulty);

PhantomWorlds.compatibility().applyHardcore(world, hardcore);
}

public void save() {
Expand Down

0 comments on commit 494523e

Please sign in to comment.