mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Added WaypointCreateEvent
This commit is contained in:
parent
3a2cced5d0
commit
dec22b9960
@ -23,6 +23,7 @@
|
||||
* Added Ukrainian translations
|
||||
* Added /sf backpack to restore lost backpacks
|
||||
* Added automated Unit Tests
|
||||
* Added WaypointCreateEvent
|
||||
|
||||
#### Changes
|
||||
* Little performance improvements
|
||||
|
@ -0,0 +1,113 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.events;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.gps.GPSNetwork;
|
||||
import io.github.thebusybiscuit.slimefun4.api.gps.TeleportationManager;
|
||||
|
||||
/**
|
||||
* A {@link WaypointCreateEvent} is called when a {@link Player} creates a new waypoint.
|
||||
* Either manually or through dying with an emergency transmitter.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see GPSNetwork
|
||||
* @see TeleportationManager
|
||||
*
|
||||
*/
|
||||
public class WaypointCreateEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Location location;
|
||||
private String name;
|
||||
|
||||
private final boolean deathpoint;
|
||||
private boolean cancelled;
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public WaypointCreateEvent(Player player, String name, Location location, boolean deathpoint) {
|
||||
super(player);
|
||||
|
||||
Validate.notNull(location, "Location must not be null!");
|
||||
Validate.notNull(name, "Name must not be null!");
|
||||
|
||||
this.location = location;
|
||||
this.name = name;
|
||||
this.deathpoint = deathpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the {@link Location} of the waypoint that should be created.
|
||||
*
|
||||
* @return The {@link Location} of this waypoint
|
||||
*/
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets the {@link Location} of the waypoint.
|
||||
* The {@link Location} may never be null!
|
||||
*
|
||||
* @param loc
|
||||
* The {@link Location} to set
|
||||
*/
|
||||
public void setLocation(Location loc) {
|
||||
Validate.notNull(loc, "Cannot set the Location to null!");
|
||||
this.location = loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the name of the waypoint.
|
||||
*
|
||||
* @return The name of this waypoint
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets the name of the waypoint to the given argument.
|
||||
*
|
||||
* @param name
|
||||
* The name for this waypoint
|
||||
*/
|
||||
public void setName(String name) {
|
||||
Validate.notEmpty(name, "The name of a waypoint must not be empty!");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns whether this waypoint was created by an Emergency Transmitter.
|
||||
* This should mean that our {@link Player} has died.
|
||||
*
|
||||
* @return Whether this is a deathpoint
|
||||
*/
|
||||
public boolean isDeathpoint() {
|
||||
return deathpoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
}
|
@ -17,11 +17,13 @@ import org.bukkit.World.Environment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput;
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
|
||||
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.WaypointCreateEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitter;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
@ -273,7 +275,7 @@ public class GPSNetwork {
|
||||
* @param l
|
||||
* The {@link Location} of the new waypoint
|
||||
*/
|
||||
public void addWaypoint(Player p, Location l) {
|
||||
public void createWaypoint(Player p, Location l) {
|
||||
if ((getWaypoints(p.getUniqueId()).size() + 2) > inventory.length) {
|
||||
SlimefunPlugin.getLocal().sendMessage(p, "gps.waypoint.max", true);
|
||||
return;
|
||||
@ -301,15 +303,19 @@ public class GPSNetwork {
|
||||
return;
|
||||
}
|
||||
|
||||
Config cfg = new Config(WAYPOINTS_DIRECTORY + p.getUniqueId().toString() + ".yml");
|
||||
String id = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', name)).toUpperCase(Locale.ROOT).replace(' ', '_');
|
||||
WaypointCreateEvent event = new WaypointCreateEvent(p, name, l, name.startsWith("player:death "));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
Config cfg = new Config(WAYPOINTS_DIRECTORY + p.getUniqueId().toString() + ".yml");
|
||||
String id = ChatColor.stripColor(ChatColors.color(name)).toUpperCase(Locale.ROOT).replace(' ', '_');
|
||||
|
||||
cfg.setValue(id, l);
|
||||
cfg.setValue(id + ".name", name);
|
||||
cfg.save();
|
||||
cfg.setValue(id, l);
|
||||
cfg.setValue(id + ".name", name);
|
||||
cfg.save();
|
||||
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 1F);
|
||||
SlimefunPlugin.getLocal().sendMessage(p, "gps.waypoint.added", true);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1F, 1F);
|
||||
SlimefunPlugin.getLocal().sendMessage(p, "gps.waypoint.added", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ public class GPSMarkerTool extends SimpleSlimefunItem<ItemUseHandler> implements
|
||||
|
||||
if (e.getClickedBlock().isPresent()) {
|
||||
Block b = e.getClickedBlock().get().getRelative(e.getClickedFace());
|
||||
SlimefunPlugin.getGPSNetwork().addWaypoint(e.getPlayer(), b.getLocation());
|
||||
SlimefunPlugin.getGPSNetwork().createWaypoint(e.getPlayer(), b.getLocation());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user