Compare commits

..
Author SHA1 Message Date
benwoo1110 a4e87b13d2 Use final fields where needed. 2020-12-15 11:26:59 +08:00
32 changed files with 239 additions and 114 deletions

No files matched your search

+10 -12
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>4.2.3-SNAPSHOT</version>
<name>Multiverse-Core</name>
<description>World Management Plugin</description>
<properties>
@@ -22,6 +22,10 @@
<id>onarandombox</id>
<url>http://repo.onarandombox.com/content/groups/public</url>
</repository>
<repository>
<id>spigot</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
@@ -275,10 +279,10 @@
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- SerializationConfig Dependency -->
<dependency>
@@ -307,12 +311,6 @@
<artifactId>CommandHandler</artifactId>
<version>11</version>
</dependency>
<!-- End of CommandHandler Dependency -->
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>buscript</artifactId>
@@ -321,7 +319,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.8</version>
<version>1.7</version>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
@@ -20,20 +20,28 @@ import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
import me.main__.util.SerializationConfig.ChangeDeniedException;
import me.main__.util.SerializationConfig.NoSuchPropertyException;
import me.main__.util.SerializationConfig.VirtualProperty;
import net.minidev.json.JSONObject;
import org.bukkit.*;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
import org.json.simple.JSONObject;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
/**
* The implementation of a Multiverse handled world.
@@ -128,9 +128,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private static final int PROTOCOL = 24;
// TODO: Investigate if this one is really needed to be static.
// Doubt it. -- FernFerret
private static Map<String, String> teleportQueue = new HashMap<String, String>();
private static final Map<String, String> teleportQueue = new HashMap<String, String>();
private AnchorManager anchorManager = new AnchorManager(this);
private final AnchorManager anchorManager = new AnchorManager(this);
// TODO please let's make this non-static
private volatile MultiverseCoreConfiguration config;
@@ -383,6 +383,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
pm.registerEvents(this.entityListener, this);
pm.registerEvents(this.weatherListener, this);
pm.registerEvents(this.portalListener, this);
Logging.info(ChatColor.GREEN + "We are aware of the warning about the deprecated event. There is no alternative that allows us to do what we need to do and performance impact is negligible. It is safe to ignore.");
pm.registerEvents(this.worldListener, this);
pm.registerEvents(new MVMapListener(this), this);
}
@@ -20,7 +20,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
* Creates a clone of a world.
*/
public class CloneCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public CloneCommand(MultiverseCore plugin) {
super(plugin);
@@ -19,6 +19,7 @@ import java.util.Map;
* Allows you to set Global MV Variables.
*/
public class ConfigCommand extends MultiverseCommand {
public ConfigCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Configuration");
@@ -24,7 +24,7 @@ import java.util.List;
* Returns detailed information on the Players where abouts.
*/
public class CoordCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public CoordCommand(MultiverseCore plugin) {
super(plugin);
@@ -26,7 +26,7 @@ import java.util.List;
* Creates a new world and loads it.
*/
public class CreateCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public CreateCommand(MultiverseCore plugin) {
super(plugin);
@@ -30,7 +30,7 @@ import java.util.List;
* Returns detailed information about a world.
*/
public class InfoCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public InfoCommand(MultiverseCore plugin) {
super(plugin);
@@ -115,7 +115,6 @@ public class InfoCommand extends MultiverseCommand {
FancyColorScheme colors = new FancyColorScheme(ChatColor.AQUA, ChatColor.AQUA, ChatColor.GOLD, ChatColor.WHITE);
message.add(new FancyHeader("General Info", colors));
message.add(new FancyMessage("World Name: ", world.getName(), colors));
message.add(new FancyMessage("World UID: ", world.getCBWorld().getUID().toString(), colors));
message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors));
message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors));
message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors));
@@ -152,7 +151,6 @@ public class InfoCommand extends MultiverseCommand {
message = new ArrayList<FancyText>();
message.add(new FancyHeader("More World Settings", colors));
message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors));
message.add(new FancyMessage("Generator: ", world.getGenerator(), colors));
message.add(new FancyMessage("Structures: ", world.getCBWorld().canGenerateStructures() + "", colors));
message.add(new FancyMessage("Weather: ", world.isWeatherEnabled() + "", colors));
message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors));
@@ -25,7 +25,7 @@ import java.util.List;
* Used to modify various aspects of worlds.
*/
public class ModifyAddCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public ModifyAddCommand(MultiverseCore plugin) {
super(plugin);
@@ -22,7 +22,7 @@ import java.util.List;
* Removes all values from a world-property.
*/
public class ModifyClearCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public ModifyClearCommand(MultiverseCore plugin) {
super(plugin);
@@ -22,7 +22,7 @@ import java.util.List;
* Removes values from a world-property.
*/
public class ModifyRemoveCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public ModifyRemoveCommand(MultiverseCore plugin) {
super(plugin);
@@ -23,7 +23,7 @@ import java.util.List;
* Used to set world-properties.
*/
public class ModifySetCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public ModifySetCommand(MultiverseCore plugin) {
super(plugin);
@@ -24,7 +24,7 @@ import java.util.List;
* Removes a type of mob from a world.
*/
public class PurgeCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public PurgeCommand(MultiverseCore plugin) {
super(plugin);
@@ -34,7 +34,7 @@ import java.util.logging.Level;
* Used to teleport players.
*/
public class TeleportCommand extends MultiverseCommand {
private SafeTTeleporter playerTeleporter;
private final SafeTTeleporter playerTeleporter;
public TeleportCommand(MultiverseCore plugin) {
super(plugin);
@@ -23,8 +23,7 @@ import java.util.List;
* States who is in what world.
*/
public class WhoCommand extends MultiverseCommand {
private MVWorldManager worldManager;
private final MVWorldManager worldManager;
public WhoCommand(MultiverseCore plugin) {
super(plugin);
@@ -16,7 +16,7 @@ import java.util.List;
* Called when the Multiverse-config should be reloaded.
*/
public class MVConfigReloadEvent extends Event {
private List<String> configsLoaded;
private final List<String> configsLoaded;
public MVConfigReloadEvent(List<String> configsLoaded) {
this.configsLoaded = configsLoaded;
@@ -17,8 +17,8 @@ import org.bukkit.event.HandlerList;
* This event is thrown when a portal is touched.
*/
public class MVPlayerTouchedPortalEvent extends Event implements Cancellable {
private Player p;
private Location l;
private final Player p;
private final Location l;
private boolean isCancelled;
private boolean canUse = true;
@@ -16,10 +16,9 @@ import org.bukkit.event.HandlerList;
* Called when a player is respawning.
*/
public class MVRespawnEvent extends Event {
private Player player;
private final Player player;
private final String respawnMethod;
private Location location;
private String respawnMethod;
public MVRespawnEvent(Location spawningAt, Player p, String respawnMethod) {
this.player = p;
@@ -21,10 +21,10 @@ import org.bukkit.event.HandlerList;
* Event that gets called when a player use the /mvtp command.
*/
public class MVTeleportEvent extends Event implements Cancellable {
private Player teleportee;
private CommandSender teleporter;
private MVDestination dest;
private boolean useSafeTeleport;
private final Player teleportee;
private final CommandSender teleporter;
private final MVDestination dest;
private final boolean useSafeTeleport;
private boolean isCancelled;
public MVTeleportEvent(MVDestination dest, Player teleportee, CommandSender teleporter, boolean safeTeleport) {
@@ -24,11 +24,11 @@ import org.bukkit.event.HandlerList;
* @param <T> The type of the property that was set.
*/
public class MVWorldPropertyChangeEvent<T> extends Event implements Cancellable {
private MultiverseWorld world;
private CommandSender changer;
private boolean isCancelled = false;
private String name;
private final MultiverseWorld world;
private final CommandSender changer;
private final String name;
private T value;
private boolean isCancelled = false;
public MVWorldPropertyChangeEvent(MultiverseWorld world, CommandSender changer, String name, T value) {
this.world = world;
@@ -28,8 +28,8 @@ import java.util.logging.Level;
* Multiverse's Entity {@link Listener}.
*/
public class MVEntityListener implements Listener {
private MultiverseCore plugin;
private MVWorldManager worldManager;
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
public MVEntityListener(MultiverseCore plugin) {
this.plugin = plugin;
@@ -305,7 +305,15 @@ public class MVPlayerListener implements Listener {
+ "' because enforceaccess is off.");
}
if (!plugin.getMVConfig().isUsingDefaultPortalSearch()) {
event.setSearchRadius(this.plugin.getMVConfig().getPortalSearchRadius());
try {
Class.forName("org.bukkit.TravelAgent");
if (event.getPortalTravelAgent() != null) {
event.getPortalTravelAgent().setSearchRadius(plugin.getMVConfig().getPortalSearchRadius());
}
} catch (ClassNotFoundException ignore) {
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName());
}
}
}
@@ -12,7 +12,6 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.Material;
import org.bukkit.PortalType;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
@@ -27,55 +26,38 @@ import java.util.logging.Level;
*/
public class MVPortalListener implements Listener {
private MultiverseCore plugin;
private final MultiverseCore plugin;
public MVPortalListener(MultiverseCore core) {
this.plugin = core;
}
/**
* This is called when a portal is formed.
* @param event The event where a portal was create or formed due to a world link
* This is called when an entity creates a portal.
*
* @param event The event where an entity created a portal.
*/
@EventHandler
public void entityPortalCreate(EntityCreatePortalEvent event) {
if (event.isCancelled() || event.getBlocks().size() == 0) {
return;
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getEntity().getWorld());
// We have to do it like this due to a bug in 1.1-R3
if (world != null && !world.getAllowedPortals().isPortalAllowed(event.getPortalType())) {
event.setCancelled(true);
}
}
/**
* This is called when a portal is created as the result of another world being linked.
* @param event The event where a portal was formed due to a world link
*/
@EventHandler(ignoreCancelled = true)
public void portalForm(PortalCreateEvent event) {
Logging.fine("Attempting to create portal at '%s' with reason: %s", event.getWorld().getName(), event.getReason());
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld());
if (world == null) {
Logging.fine("World '%s' is not managed by Multiverse! Ignoring at PortalCreateEvent.", event.getWorld().getName());
return;
}
PortalType targetType;
switch (event.getReason()) {
case FIRE:
// Ensure portal by flint and steel actually creates nether
boolean isNether = false;
for (BlockState block : event.getBlocks()) {
if (block.getType() == Material.NETHER_PORTAL) {
isNether = true;
break;
}
}
if (!isNether) {
return;
}
targetType = PortalType.NETHER;
break;
case NETHER_PAIR:
targetType = PortalType.NETHER;
break;
case END_PLATFORM:
targetType = PortalType.ENDER;
break;
default:
Logging.fine("Portal created is not NETHER or ENDER type. Ignoring...");
return;
}
if (!world.getAllowedPortals().isPortalAllowed(targetType)) {
Logging.fine("Cancelling creation of %s portal because portalForm disallows.", targetType);
if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.NETHER)) {
Logging.fine("Cancelling creation of nether portal because portalForm disallows.");
event.setCancelled(true);
}
}
@@ -90,21 +72,15 @@ public class MVPortalListener implements Listener {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
if (event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) {
if (event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) {
return;
}
if (event.getItem() == null || event.getItem().getType() != Material.ENDER_EYE) {
return;
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getPlayer().getWorld());
if (world == null) {
Logging.fine("World '%s' is not managed by Multiverse! Ignoring at PlayerInteractEvent.", event.getPlayer().getWorld().getName());
return;
}
if (!world.getAllowedPortals().isPortalAllowed(PortalType.ENDER)) {
Logging.fine("Cancelling creation of ENDER portal because portalForm disallows.");
if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.ENDER)) {
Logging.fine("Cancelling creation of ender portal because portalForm disallows.");
event.setCancelled(true);
}
}
@@ -18,7 +18,7 @@ import org.bukkit.event.weather.WeatherChangeEvent;
* Multiverse's Weather {@link Listener}.
*/
public class MVWeatherListener implements Listener {
private MultiverseCore plugin;
private final MultiverseCore plugin;
public MVWeatherListener(MultiverseCore plugin) {
this.plugin = plugin;
@@ -14,7 +14,7 @@ import org.bukkit.event.world.WorldInitEvent;
public class MVWorldInitListener implements Listener {
MultiverseCore plugin;
private final MultiverseCore plugin;
public MVWorldInitListener(MultiverseCore plugin) {
this.plugin = plugin;
@@ -20,8 +20,8 @@ import org.bukkit.event.world.WorldUnloadEvent;
* Multiverse's World {@link Listener}.
*/
public class MVWorldListener implements Listener {
private MultiverseCore plugin;
private MVWorldManager worldManager;
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
public MVWorldListener(MultiverseCore plugin) {
this.plugin = plugin;
@@ -0,0 +1,111 @@
package com.onarandombox.MultiverseCore.utils;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.destination.CannonDestination;
import org.bukkit.Location;
import org.bukkit.TravelAgent;
import org.bukkit.event.player.PlayerPortalEvent;
public class BukkitTravelAgent implements TravelAgent {
private final MVTravelAgent agent;
public BukkitTravelAgent(MVTravelAgent agent) {
this.agent = agent;
}
/**
* {@inheritDoc}
*/
@Override
public BukkitTravelAgent setSearchRadius(int radius) {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int getSearchRadius() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public BukkitTravelAgent setCreationRadius(int radius) {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int getCreationRadius() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean getCanCreatePortal() {
return false;
}
/**
* {@inheritDoc}
*/
@Override
public void setCanCreatePortal(boolean create) {
}
/**
* {@inheritDoc}
*/
@Override
public Location findOrCreate(Location location) {
return this.getSafeLocation();
}
/**
* {@inheritDoc}
*/
@Override
public Location findPortal(Location location) {
return this.getSafeLocation();
}
/**
* {@inheritDoc}
*/
@Override
public boolean createPortal(Location location) {
return false;
}
private Location getSafeLocation() {
// At this time, these can never use the velocity.
if (agent.destination instanceof CannonDestination) {
Logging.fine("Using Stock TP method. This cannon will have 0 velocity");
}
SafeTTeleporter teleporter = agent.core.getSafeTTeleporter();
Location newLoc = agent.destination.getLocation(agent.player);
if (agent.destination.useSafeTeleporter()) {
newLoc = teleporter.getSafeLocation(agent.player, agent.destination);
}
if (newLoc == null) {
return agent.player.getLocation();
}
return newLoc;
}
public void setPortalEventTravelAgent(PlayerPortalEvent event) {
event.setPortalTravelAgent(this);
event.useTravelAgent(true);
}
}
@@ -0,0 +1,27 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.utils;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import org.bukkit.entity.Player;
/**
* The Multiverse TravelAgent.
*/
public class MVTravelAgent {
protected MVDestination destination;
protected MultiverseCore core;
protected Player player;
public MVTravelAgent(MultiverseCore multiverseCore, MVDestination d, Player p) {
this.destination = d;
this.core = multiverseCore;
this.player = p;
}
}
@@ -1,8 +1,8 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.util.Map;
@@ -1,8 +1,8 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.util.HashMap;
@@ -1,9 +1,8 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.util.Map;
@@ -1,9 +1,9 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.util.HashMap;