Skip to content

Documentation #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;

/**
* This class is for Plotsquared v4 support and is called "PlotSquaredWhatTheHellSupport" because it is legacy and
* Plotsquared v4 is no longer supported by the IntellectualSites team. Take sure to update Plotsquared, FAWE and
* your minecraft version to prevent not fixed issues and exploits.
* This class creates a new third party Plotsquared flag for enabling / disabling antiredstone detection on a plot.
* It also gets the accurate version of Plotsquared and checks if the location of the redstone clock is on a plot.
*/

public final class PlotSquaredWhatTheHellSupport extends AbstractPlotsquaredSupport {

private static final PlotAPI PLOT_API = new PlotAPI();
Expand All @@ -17,6 +25,12 @@ public void init() {
PLOT_API.addFlag(new RedstoneClockFlag());
}

/**
* Checks if the location of the redstone clock is in a plot
* @param location the location of the redstone clock
* @return true if the location is inside a plot and has the redstoneclockflag enabled,
* false if it is not inside a plot and has the redstoneclockflag disabled
*/
@Override
public boolean isAllowedPlot(@NotNull Location location) {
var plot = BukkitUtil.getPlot(location);
Expand All @@ -33,6 +47,11 @@ public boolean isAllowedPlot(@NotNull Location location) {
return false;
}

/** This method is deprecated and checks the Plotsquared version to garantee matching support
*
* @return the plotsquared version of the Plotsquared plugin, if it is enabled, if not, return unknown
*/

@Override
@SuppressWarnings("deprecation")
public String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.github.intellectualsites.plotsquared.plot.flag.BooleanFlag;
public final class RedstoneClockFlag extends BooleanFlag {

/**
* Inherits the flag name
*/
public RedstoneClockFlag() {
super(PlotSquaredWhatTheHellSupport.FLAG_STRING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,31 @@
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

/**
* Plotsquared legacy is no longer supported by the IntellectualSites team. Take sure to update Plotsquared, FAWE and
* your minecraft version to prevent not fixed issues and exploits.
* This class creates a new third party Plotsquared flag for enabling / disabling antiredstone detection on a plot.
* It also gets the accurate version of Plotsquared and checks if the location of the redstone clock is on a plot.
*/
public final class PlotSquaredLegacySupport extends AbstractPlotsquaredSupport {

/**
* initialize a new flag with the default boolean value false; this flag disables ARC-R detection on default,
* you have to enable this flag though the plotsquared flag command
*/
@Override
public void init() {
GlobalFlagContainer.getInstance().addFlag(new RedstoneClockFlag(false));
}

/**
* Checks if the location of the redstone clock is in a plotarea ("plot")
* @param location the location of the redstone clock
* @return true if the location is inside a plotarea and has the redstoneclockflag enabled,
* false if it is not inside a plotarea and has the redstoneclockflag disabled
*
*/

@Override
public boolean isAllowedPlot(@NotNull Location location) {
var plotArea = PlotSquared.get().getPlotAreaManager().getPlotArea(BukkitUtil.adapt(location));
Expand All @@ -27,6 +46,10 @@ public boolean isAllowedPlot(@NotNull Location location) {
return false;
}

/**
* Get the version of the Plotsquared plugin
* @return String the version of the plugin or unknown if the plugin does not exist or is not enabled
*/
@Override
@SuppressWarnings("deprecation")
public String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

/**
* The implementation of WorldGuardSupport class but in legacy, looking for Worldguard in an enabled state
* and in addition check if the worldguard region(s) is/are allowed
* to register a redstone-clock flag which is default disabled.
* Also check if the redstone-clock flag can be applied to overlapping worldguard region(s)
*/
public final class WorldGuardLegacySupport extends AbstractWorldGuardSupport {

private static final StateFlag REDSTONECLOCK_FLAG = new StateFlag("redstone-clock", false);
Expand All @@ -35,7 +41,12 @@ private static WorldGuardPlugin loadPlugin() {
if (plugin instanceof WorldGuardPlugin wgp) return wgp;
return null;
}

/**
* The actual check if the worldguard regions are allowed to add a redstone-clock flag, considering
* overlapping regions
* @param location the location of the redstone-clock
* @return the boolean result whether the region is allowed or not
*/
@Override
public boolean isRegionAllowed(@NotNull Location location) {
boolean result = false;
Expand Down Expand Up @@ -71,7 +82,10 @@ private ApplicableRegionSet getRegion(RegionManager regionManager, Location loc)
Vector vector = new Vector(loc.getX(), loc.getY(), loc.getZ());
return regionManager.getApplicableRegions(vector);
}

/**
* Searches for enabled Worldguard
* @return undefined if Worldguard was not found or is not enabled
*/
@Override
@SuppressWarnings("deprecation")
public String getVersion() {
Expand All @@ -82,6 +96,11 @@ public String getVersion() {
}
}

/**
* This method tries to register a redstone-clock flag. If the user have a different plugin providing a flag
* with the same name, an exception is thrown with a matching message
* @return boolean flagloaded = true if the flag was able to load, if not return false
*/
@Override
public boolean registerFlag() {
boolean flagLoaded = false;
Expand All @@ -92,7 +111,7 @@ public boolean registerFlag() {
registry.register(REDSTONECLOCK_FLAG);
flagLoaded = true;
} catch (FlagConflictException e) {
Bukkit.getLogger().severe("A plugin already use the flag redstoneclock. WorldGuard flag support will not work");
Bukkit.getLogger().severe("A plugin already uses the flag redstoneclock. WorldGuard flag support will not work");
}
}
return flagLoaded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

/**
* The implementation of WorldGuardSupport class, looking for Worldguard in an enabled state
* and in addition check if the worldguard region(s) is/are allowed
* to register a redstone-clock flag which is default disabled.
* Also check if the redstone-clock flag can be applied to overlapping worldguard region(s)
*/
public final class WorldGuardModernSupport extends AbstractWorldGuardSupport {

private static final WorldGuardPlugin WORLD_GUARD_PLUGIN = loadPlugin();
Expand All @@ -30,6 +36,12 @@ public WorldGuardModernSupport(@NotNull Plugin plugin) {
super(plugin);
}

/**
* The actual check if the worldguard regions are allowed to add a redstone-clock flag, considering
* overlapping regions
* @param location the location of the redstone-clock
* @return the boolean result whether the region is allowed or not
*/
@Override
public boolean isRegionAllowed(@NotNull Location location) {
boolean result = false;
Expand All @@ -47,6 +59,10 @@ public boolean isRegionAllowed(@NotNull Location location) {
return result;
}

/**
* Searches for enabled Worldguard
* @return null if Worldguard was not found or is not enabled
*/
private static WorldGuardPlugin loadPlugin() {

Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
Expand Down Expand Up @@ -76,6 +92,10 @@ private RegionManager getRegionManager(World world) {
return wgPlatform.getRegionContainer().get(worldEditWorld);
}

/**
* Checks the Worldguard version if Worldguard is enabled
* @return the version as a String
*/
@Override
@SuppressWarnings("deprecation")
public String getVersion() {
Expand All @@ -86,6 +106,11 @@ public String getVersion() {
}
}

/**
* This method tries to register a redstone-clock flag. If the user have a different plugin providing a flag
* with the same name, an exception is thrown with a matching message
* @return boolean flagloaded = true if the flag was able to load, if not return false
*/
@Override
public boolean registerFlag() {
boolean flagLoaded = false;
Expand All @@ -94,7 +119,7 @@ public boolean registerFlag() {
registry.register(REDSTONECLOCK_FLAG);
flagLoaded = true;
} catch (FlagConflictException e) {
Bukkit.getLogger().severe("A plugin already use the flag redstone-clock. WorldGuard flag support will not work");
Bukkit.getLogger().severe("A plugin already uses the flag redstone-clock. WorldGuard flag support will not work");
}
return flagLoaded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

/**
* The abstract Worldguard Support class which implements the WorldguardSupport interface to get Plugin and Version
* The configpath is always the same for the ignored regions, used to check if redstone clocks are in not ignored regions
*/
public abstract non-sealed class AbstractWorldGuardSupport implements WorldGuardSupport {

protected final @NotNull Plugin plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;

/**
* The interface for Worldguard Support
*/
public sealed interface WorldGuardSupport permits AbstractWorldGuardSupport {

boolean isRegionAllowed(@NotNull Location location);

// This is not used yet, but is going to be used for statistics
String getVersion();

boolean registerFlag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@

public final class AntiRedstoneClockRemastered extends JavaPlugin {
private CheckTPS tps;

private RedstoneClockService redstoneClockService;
private WorldGuardSupport worldGuardSupport;

private PlotsquaredSupport plotsquaredSupport;

private Metrics metrics;
Expand All @@ -35,15 +33,14 @@ public final class AntiRedstoneClockRemastered extends JavaPlugin {
public void onLoad() {
saveDefaultConfig();
reloadConfig();

enableWorldGuardSupport();
enableWorldGuardSupport(); //Worldguard needs to enable flags before the worlds are loaded
}



@Override
public void onEnable() {
enablePlotsquaredSupport();
enablePlotsquaredSupport(); //Plotsquared can enable flags after the worlds are loaded
enableTPSChecker();
enableRedstoneClockService();
enableBStatsSupport();
Expand Down Expand Up @@ -83,8 +80,10 @@ private void enableWorldGuardSupport() {
@SuppressWarnings("deprecation")
int wgVersion = Integer.parseInt(plugin.getDescription().getVersion().split("\\.")[0]);
if (wgVersion > 6) {
getLogger().warning("Thanks for keeping Worldguard up-to date <3");
this.worldGuardSupport = new WorldGuardModernSupport(this);
} else {
getLogger().warning("You use a legacy version of Worldguard");
this.worldGuardSupport = new WorldGuardLegacySupport(this);
}

Expand Down Expand Up @@ -142,6 +141,10 @@ private void enableTPSChecker() {
this.tps.startCheck();
}

/**
* This plugin captures its own tps from the server to be independent for older versions
* @return CheckTPS Object
*/
private void enableBStatsSupport() {
this.metrics = new Metrics(this, 19085);
this.metrics.addCustomChart(new SimplePie("worldguard", this::bstatsWorldGuardVersion));
Expand Down Expand Up @@ -183,17 +186,27 @@ public CheckTPS getTps() {
return tps;
}

/**
* A getter method
* @return RedstoneClockService Object
*/
public RedstoneClockService getRedstoneClockService() {
return redstoneClockService;
}

/**
* A getter method
* @return WorldGuardSupport Object
*/
public WorldGuardSupport getWorldGuardSupport() {
return worldGuardSupport;
}

/**
* A getter method
* @return PlotsquaredSupport Object
*/
public PlotsquaredSupport getPlotsquaredSupport() {
return plotsquaredSupport;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockRedstoneEvent;

/**
* The ComparatorListener is for all events that needs to be considered
* when having a redstone comparator block in a redstone clock / as a redstone clock for this plugin
*/
public final class ComparatorListener implements Listener {
private final Material comparatorMaterial;
private final AntiRedstoneClockRemastered antiRedstoneClockRemastered;

/**
* A setter method for the ComparatorListener
* @param comparatorMaterial is the bukkit Material of the Comparator
* @param antiRedstoneClockRemastered is another main class
*/
public ComparatorListener(Material comparatorMaterial, AntiRedstoneClockRemastered antiRedstoneClockRemastered) {
this.comparatorMaterial = comparatorMaterial;
this.antiRedstoneClockRemastered = antiRedstoneClockRemastered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockRedstoneEvent;

/**
* The ObserverListener is for all events that needs to be considered
* when having a redstone observer block in a redstone clock / as a redstone clock for this plugin
*/
public final class ObserverListener implements Listener {
private final Material material;
private final AntiRedstoneClockRemastered antiRedstoneClockRemastered;

/**
* A setter method for the ObserverListener
* @param antiRedstoneClockRemastered is another main class
*/
public ObserverListener(AntiRedstoneClockRemastered antiRedstoneClockRemastered) {
this.material = Material.OBSERVER;
this.antiRedstoneClockRemastered = antiRedstoneClockRemastered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockRedstoneEvent;

/**
* The PistonListener is for all events that needs to be considered
* when having a redstone piston block in a redstone clock / as a redstone clock for this plugin
*/
public final class PistonListener implements Listener {
private final AntiRedstoneClockRemastered antiRedstoneClockRemastered;

/**
* A setter method for the PistonListener
* @param antiRedstoneClockRemastered is another main class
*/
public PistonListener(AntiRedstoneClockRemastered antiRedstoneClockRemastered) {
this.antiRedstoneClockRemastered = antiRedstoneClockRemastered;
}
Expand Down
Loading