Skip to content

Commit

Permalink
Version 1.1.0
Browse files Browse the repository at this point in the history
Changes:
- Added bStats.
- Added a config option "disable-group-teleporting" that prevents all players standing on a beacon from teleporting at the same time when it was activated, and instead only teleports the player choosing the destination, when enabled.
- Added config reload command (/waypoints reload). This adds the permission BeaconWaypoints.reload which is enabled for operators by default.
- Changed the icon for the "Options for this waypoint" button from a comparator to the icon of the waypoint being interacted with.
- Added an update checker that notifies the console and operators of an update to the plugin.

Bug Fixes:
- A waypoint was not deleted if the beacon was removed with the setblock or fill commands. Changing or deleting blocks using WorldEdit still does not remove the waypoint.
- BeaconWaypoints could conflict with other plugins and make players take fall damage when landing on the destination beacon.
  • Loading branch information
BuildTools committed Feb 21, 2022
1 parent b732e2a commit 5596cf3
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 58 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

Developed and tested for version 1.18.1

This plugin uses bStats.

## Features
- Create public or private waypoints at beacons
- Configurable icon chooser for waypoints


## Commands
- /waypoint <name> <public | private> - Create a public or private waypoint for the beacon the player is standing on
- /waypoints reload - Reloads the config


## Demo
Expand All @@ -25,6 +28,7 @@ Note: Teleportation between beacons requires the beacon to have no blocks inside

## Permissions
- BeaconWaypoints.waypoint: Allows players to create waypoints
- BeaconWaypoints.reload: Allows players to reload the config


## Configuration
Expand All @@ -34,9 +38,24 @@ Note: Teleportation between beacons requires the beacon to have no blocks inside
- private-waypoint-menu-rows: The number of rows the private waypoint selection menu will show per page, not including the row for page navigation (default: 2, range: 1-5)
- instant-teleport: Activate teleportation as soon as the destination is chosen without a warmup animation (default: false)
- disable-animations: Disable the particle animations when teleporting through a beacon (default: false)
- disable-group-teleporting: By default, beacons teleport anyone standing on top of them. If you want to limit the teleportation to only the player who chooses the destination, set this to true. (default: false)
- allowed-worlds: List of worlds that allow waypoints based on folder name (default: world, world_nether, world_the_end)
- waypoint-icons: List of items that can be used for waypoint icons, the order given here is the same order that will be in the icon picker menu (default includes 111 items)


### [Issue Tracker](https://github.com/dawson-vilamaa/BeaconWaypoints/issues) - Please report bugs here
### Contact me on Discord: energy_sync#9851

## Changelog

# 1.1.0
Changes:
- Added bStats.
- Added a config option "disable-group-teleporting" that prevents all players standing on a beacon from teleporting at the same time when it was activated, and instead only teleports the player choosing the destination, when enabled.
- Added config reload command (/waypoints reload). This adds the permission BeaconWaypoints.reload which is enabled for operators by default.
- Changed the icon for the "Options for this waypoint" button from a comparator to the icon of the waypoint being interacted with.
- Added an update checker that notifies the console and operators of an update to the plugin.

Bug Fixes:
- A waypoint was not deleted if the beacon was removed with the setblock or fill commands. Changing or deleting blocks using WorldEdit still does not remove the waypoint.
- BeaconWaypoints could conflict with other plugins and make players take fall damage when landing on the destination beacon.
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Changes:
- Added bStats.
- Added a config option "disable-group-teleporting" that prevents all players standing on a beacon from teleporting at the same time when it was activated, and instead only teleports the player choosing the destination, when enabled.
- Added config reload command (/waypoints reload). This adds the permission BeaconWaypoints.reload which is enabled for operators by default.
- Changed the icon for the "Options for this waypoint" button from a comparator to the icon of the waypoint being interacted with.
- Added an update checker that notifies the console and operators of an update to the plugin.

Bug Fixes:
- A waypoint was not deleted if the beacon was removed with the setblock or fill commands. Changing or deleting blocks using WorldEdit still does not remove the waypoint.
- BeaconWaypoints could conflict with other plugins and make players take fall damage when landing on the destination beacon.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.dawsonvilamaa</groupId>
<artifactId>BeaconWaypoints</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.Waypoint;
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.WaypointCoord;
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.WaypointPlayer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -24,7 +25,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
Player player = (Player) sender;
String cleanCmd = cmd.getName().toLowerCase();

if (cleanCmd.equals("waypoint") || cleanCmd.equals("wp")) {
if (cleanCmd.equals("waypoint") || cleanCmd.equals("wp") || cleanCmd.equals("waypoints")) {
//reload
if (args.length >= 1 && args[0].equalsIgnoreCase("reload")) {
if (player.hasPermission("BeaconWaypoints.reload")) {
Main.plugin.reloadConfig();
player.sendMessage(ChatColor.GREEN + "BeaconWaypoints config reloaded!");
}
else
player.sendMessage(ChatColor.RED + "You don't have permission to use that command");
return true;
}

//create waypoint
if (args.length < 2)
return false;
if (!(args[args.length - 1].equalsIgnoreCase("public") || args[args.length - 1].equalsIgnoreCase("private")))
Expand Down
37 changes: 17 additions & 20 deletions src/main/java/com/github/dawsonvilamaa/beaconwaypoint/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.WaypointCoord;
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.WaypointManager;
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.WaypointPlayer;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
Expand Down Expand Up @@ -34,17 +35,18 @@ public class Main extends JavaPlugin {
@Override
public void run() {
saveData();
Main.plugin.saveDefaultConfig();
}
};

@Override
public void onEnable() {
plugin = this;
this.saveDefaultConfig();
waypointManager = new WaypointManager();
menuManager = new MenuManager();

//bStats
Metrics metrics = new Metrics(this, 14276);

//register commands
BWCommandExecutor commandExecutor = new BWCommandExecutor(this);
Objects.requireNonNull(getCommand("waypoint")).setExecutor(commandExecutor);
Expand All @@ -64,6 +66,17 @@ public void onEnable() {

loadData();
autoSave.runTaskTimer(plugin, 6000, 6000);

//update checker
new UpdateChecker(this, 99866).getVersion(version -> {
if (!this.getDescription().getVersion().equals(version))
this.getLogger().info("\n=======================================================================\n"
+ ChatColor.AQUA + "A new version of Beacon Waypoints is available!\n"
+ ChatColor.YELLOW + "Current version: " + Main.plugin.getDescription().getVersion()
+ "\nUpdated version: " + version
+ ChatColor.WHITE + "\nDownload link: " + ChatColor.UNDERLINE + "https://www.spigotmc.org/resources/beaconwaypoints.99866\n"
+ ChatColor.RESET + "=======================================================================");
});
}

@Override
Expand All @@ -73,6 +86,8 @@ public void onDisable() {
}

public void loadData() {
this.reloadConfig();

//read data from public file
JSONParser parser = new JSONParser();
try {
Expand Down Expand Up @@ -176,22 +191,4 @@ public void saveData() {
}
}
}

/**
* Returns a waypoint from a waypoint coordinate, public or private, or null if it doesn't exist
* @param coord
* @return waypoint
*/
public Waypoint getWaypoint(WaypointCoord coord) {
Waypoint waypoint = waypointManager.getPublicWaypoints().get(coord);

if (waypoint == null) {
for (WaypointPlayer waypointPlayer : waypointManager.getWaypointPlayers().values()) {
waypoint = waypointPlayer.getWaypoints().get(coord);
if (waypoint != null) break;
}
}

return waypoint;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.dawsonvilamaa.beaconwaypoint;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Consumer;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;

public class UpdateChecker {
private final JavaPlugin plugin;
private final int resourceId;

public UpdateChecker(JavaPlugin plugin, int resourceId) {
this.plugin = plugin;
this.resourceId = resourceId;
}

public void getVersion(final Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
if (scanner.hasNext())
consumer.accept(scanner.next());
} catch (IOException exception) {
plugin.getLogger().info("Unable to check for updates: " + exception.getMessage());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ else if (numRows > 5)
if (Main.waypointManager.getPublicWaypoint(coord) == null)
player.sendMessage(ChatColor.RED + "That waypoint doesn't exist!");
else if (publicWaypoint.getBeaconStatus() == 0)
player.sendMessage(ChatColor.RED + "The destination beacon is not able to be traveled to. It either does not have a pyramid underneath it, or something is obstructing the beam.");
else Waypoint.teleport(waypoint, publicWaypoint);
player.sendMessage(ChatColor.RED + "The destination beacon is not able to be traveled to. It either is not constructed correctly, or something is obstructing the beam.");
else Waypoint.teleport(waypoint, publicWaypoint, Main.plugin.getConfig().getBoolean("disable-group-teleporting") ? player : null);
});
if (publicWaypoint.getOwnerUUID().equals(player.getUniqueId())) {
waypointButton.setOnRightClick(e -> {
Expand All @@ -125,7 +125,7 @@ else if (publicWaypoint.getBeaconStatus() == 0)
//options button for this waypoint
Waypoint thisWaypoint = Main.waypointManager.getPublicWaypoint(waypoint.getCoord());
if (thisWaypoint != null) {
InventoryGUIButton optionsButton = new InventoryGUIButton(gui.getGUI(), "Options for this public waypoint", null, Material.COMPARATOR);
InventoryGUIButton optionsButton = new InventoryGUIButton(gui.getGUI(), "Options for this public waypoint", null, thisWaypoint.getIcon());
optionsButton.setOnClick(e -> {
waypointOptionsMenu(player, thisWaypoint, waypoint, gui.getGUI(), true);
});
Expand All @@ -152,8 +152,8 @@ else if (numRows > 5)
if (Main.waypointManager.getPrivateWaypoint(player.getUniqueId(), coord) == null)
player.sendMessage(ChatColor.RED + "That waypoint doesn't exist!");
else if (privateWaypoint.getBeaconStatus() == 0)
player.sendMessage(ChatColor.RED + "The destination beacon is not able to be traveled to. It either does not have a pyramid underneath it, or something is obstructing the beam.");
else Waypoint.teleport(waypoint, privateWaypoint);
player.sendMessage(ChatColor.RED + "The destination beacon is not able to be traveled to. It either is not constructed correctly, or something is obstructing the beam.");
else Waypoint.teleport(waypoint, privateWaypoint, Main.plugin.getConfig().getBoolean("disable-group-teleporting") ? player : null);
});
if (privateWaypoint.getOwnerUUID().equals(player.getUniqueId())) {
waypointButton.setOnRightClick(e -> {
Expand All @@ -169,7 +169,7 @@ else if (privateWaypoint.getBeaconStatus() == 0)
//options button for this waypoint
Waypoint thisWaypoint = Main.waypointManager.getPrivateWaypoint(player.getUniqueId(), waypoint.getCoord());
if (thisWaypoint != null) {
InventoryGUIButton optionsButton = new InventoryGUIButton(gui.getGUI(), "Options for this private waypoint", null, Material.COMPARATOR);
InventoryGUIButton optionsButton = new InventoryGUIButton(gui.getGUI(), "Options for this private waypoint", null, thisWaypoint.getIcon());
optionsButton.setOnClick(e -> {
waypointOptionsMenu(player, thisWaypoint, waypoint, gui.getGUI(), false);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.github.dawsonvilamaa.beaconwaypoint.listeners;

import com.github.dawsonvilamaa.beaconwaypoint.Main;
import com.github.dawsonvilamaa.beaconwaypoint.UpdateChecker;
import com.github.dawsonvilamaa.beaconwaypoint.gui.GUIs;
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.Waypoint;
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.WaypointCoord;
import com.github.dawsonvilamaa.beaconwaypoint.waypoints.WaypointPlayer;
import net.minecraft.network.chat.ChatMessageType;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.PacketPlayOutChat;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
Expand All @@ -35,6 +39,19 @@ public void onPlayerJoin(PlayerJoinEvent e) {
//add if not in map
if (waypointPlayer == null)
Main.waypointManager.addPlayer(e.getPlayer().getUniqueId());

//if player is op, check for updates
if (e.getPlayer().isOp()) {
new UpdateChecker(Main.plugin, 99866).getVersion(version -> {
if (!Main.plugin.getDescription().getVersion().equals(version)) {
e.getPlayer().sendMessage("========================================\n" + ChatColor.AQUA + "A new version of Beacon Waypoints is available!\n" + ChatColor.YELLOW + "Current version: " + Main.plugin.getDescription().getVersion() + "\nUpdated version: " + version);
String json = "[{\"text\":\"§b§nClick here to download\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.spigotmc.org/resources/beaconwaypoints.99866/\"}}]";
PacketPlayOutChat packet = new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(json), ChatMessageType.a, e.getPlayer().getUniqueId());
((CraftPlayer)e.getPlayer()).getHandle().b.a(packet);
e.getPlayer().sendMessage("========================================");
}
});
}
}

//add new non-activated waypoint when one is placed, and make the player who placed it the owner
Expand Down Expand Up @@ -78,6 +95,32 @@ public void onBlockBreak(BlockBreakEvent e) {
}
}

//deletes waypoints if they are removed with fill or setblock commands
@EventHandler
public void onBlockPhysics(BlockPhysicsEvent e) {
if (e.getSourceBlock().getType() == Material.AIR) {
WaypointCoord waypointCoord = new WaypointCoord(e.getBlock().getLocation());

//remove public waypoint
Waypoint publicWaypoint = Main.waypointManager.getPublicWaypoint(waypointCoord);
if (publicWaypoint != null) {
Main.waypointManager.removePublicWaypoint(waypointCoord);
}

//remove private waypoint
for (WaypointPlayer waypointPlayer : Main.waypointManager.getWaypointPlayers().values()) {
Waypoint privateWaypoint = Main.waypointManager.getPrivateWaypoint(waypointPlayer.getUUID(), waypointCoord);
if (privateWaypoint != null)
Main.waypointManager.removePrivateWaypoint(waypointPlayer.getUUID(), waypointCoord);
}

//remove inactive waypoint
Waypoint inactiveWaypoint = Main.waypointManager.getInactiveWaypoint(waypointCoord);
if (inactiveWaypoint != null)
Main.waypointManager.removeInactiveWaypoint(waypointCoord);
}
}

//when player opens a beacon
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Expand All @@ -91,7 +134,7 @@ public void onPlayerInteract(PlayerInteractEvent e) {
int beaconStatus = waypoint.getBeaconStatus();
if (beaconStatus != 0)
GUIs.beaconMenu(e.getPlayer(), waypoint);
else e.getPlayer().sendMessage(ChatColor.RED + "Unable to teleport with this beacon. It either does not have a pyramid underneath it, or something is obstructing the beam.");
else e.getPlayer().sendMessage(ChatColor.RED + "The destination beacon is not able to be traveled to. It either is not constructed correctly, or something is obstructing the beam.");
}
}
}
Expand All @@ -116,4 +159,14 @@ public void onEat(PlayerItemConsumeEvent e) {
e.setCancelled(true);
}
}

//disable damage to player when teleporting
@EventHandler
public void onDamage(EntityDamageEvent e) {
if (e.getEntity().getType() == EntityType.PLAYER && e.getCause() == EntityDamageEvent.DamageCause.FALL) {
WaypointPlayer waypointPlayer = Main.waypointManager.getPlayer(e.getEntity().getUniqueId());
if (waypointPlayer != null && waypointPlayer.isTeleporting())
e.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- delete waypoint if beacon is removed via command rather than manually breaking (done but doesn't work for worldedit)
- add config option to change whether beacon teleports all entities standing on it or just that player (done)
- add bStats (done)
- disable player fall damage when falling on destination beacon (event) (done)
- plugin reload command (/waypoint reload) (done)
- change current beacon settings button to waypoint's icon (done)
- add update notification for console and when op joins the server (done)
Loading

0 comments on commit 5596cf3

Please sign in to comment.