Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lRENyaaa committed Mar 16, 2024
2 parents 31fa49e + fcb2da7 commit db060ee
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 181 deletions.
13 changes: 13 additions & 0 deletions src/com/bekvon/bukkit/residence/Residence.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.bekvon.bukkit.residence.api.ResidenceApi;
import com.bekvon.bukkit.residence.api.ResidenceInterface;
import com.bekvon.bukkit.residence.api.ResidencePlayerInterface;
import com.bekvon.bukkit.residence.bigDoors.BigDoorsManager;
import com.bekvon.bukkit.residence.chat.ChatManager;
import com.bekvon.bukkit.residence.commands.padd;
import com.bekvon.bukkit.residence.containers.Flags;
Expand Down Expand Up @@ -218,6 +219,7 @@ public class Residence extends JavaPlugin {
protected CMITask autosaveBukkitId = null;

private boolean SlimeFun = false;
private boolean BigDoors = false;
private boolean lwc = false;
Metrics metrics = null;

Expand Down Expand Up @@ -563,6 +565,17 @@ public void onEnable() {
}
}

BigDoors = Bukkit.getPluginManager().getPlugin("BigDoors") != null;

if (BigDoors) {
try {
BigDoorsManager.register(this);
} catch (Throwable e) {
BigDoors = false;
e.printStackTrace();
}
}

this.getConfigManager().copyOverTranslations();

parseHelpEntries();
Expand Down
24 changes: 24 additions & 0 deletions src/com/bekvon/bukkit/residence/bigDoors/BigDoorsDef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bekvon.bukkit.residence.bigDoors;

import nl.pim16aap2.bigDoors.compatibility.IProtectionCompat;
import nl.pim16aap2.bigDoors.compatibility.IProtectionCompatDefinition;

public class BigDoorsDef implements IProtectionCompatDefinition {

private final String name;

public BigDoorsDef(String name) {
this.name = name;
}

@Override
public Class<? extends IProtectionCompat> getClass(String arg0) {
return null;
}

@Override
public String getName() {
return name;
}

}
53 changes: 53 additions & 0 deletions src/com/bekvon/bukkit/residence/bigDoors/BigDoorsManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.bekvon.bukkit.residence.bigDoors;

import java.lang.reflect.Method;

import com.bekvon.bukkit.residence.Residence;

import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
import net.Zrips.CMILib.Version.Schedulers.CMITask;
import nl.pim16aap2.bigDoors.BigDoors;
import nl.pim16aap2.bigDoors.compatibility.IProtectionCompat;
import nl.pim16aap2.bigDoors.compatibility.ProtectionCompatManager;

public class BigDoorsManager {

// Fail safe to avoid infinite checks
private final static int TRIES = 3;
private static int times = 0;
private static CMITask task = null;

public static void register(Residence residence) {
task = CMIScheduler.scheduleSyncRepeatingTask(() -> {
++times;
if (times >= TRIES) {
residence.consoleMessage("&cFailed to initialize BigDoors support");
task.cancel();
}

ProtectionCompatManager manager = BigDoors.get().getProtectionCompatManager();

// Wait for protectionManager to load (loaded on first server tick)
if (manager != null) {
try {

manager.registerProtectionCompatDefinition(new BigDoorsDef("Residence") {
@Override
public Class<? extends IProtectionCompat> getClass(String version) {
return BigDoorsModule.class;
}
});

Method method = manager.getClass().getDeclaredMethod("addProtectionCompat", IProtectionCompat.class);
method.setAccessible(true);
method.invoke(manager, new BigDoorsModule());

residence.consoleMessage("Enabled compatability with BigDoors plugin");
task.cancel();
} catch (Throwable e) {
e.printStackTrace();
}
}
}, 20, 20);
}
}
49 changes: 49 additions & 0 deletions src/com/bekvon/bukkit/residence/bigDoors/BigDoorsModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.bekvon.bukkit.residence.bigDoors;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import com.bekvon.bukkit.residence.listeners.ResidenceBlockListener;
import com.bekvon.bukkit.residence.protection.CuboidArea;

import nl.pim16aap2.bigDoors.compatibility.IProtectionCompat;

public class BigDoorsModule implements IProtectionCompat {

@Override
public boolean canBreakBlock(Player player, Location loc) {
return ResidenceBlockListener.canBreakBlock(player, loc, false);
}

@Override
public boolean canBreakBlocksBetweenLocs(Player player, Location loc1, Location loc2) {

CuboidArea area = new CuboidArea(loc1, loc2);

Vector min = area.getLowVector();
Vector max = area.getHighVector();

for (int xPos = min.getBlockX(); xPos <= max.getBlockX(); xPos++) {
for (int yPos = min.getBlockY(); yPos <= max.getBlockY(); yPos++) {
for (int zPos = min.getBlockZ(); zPos <= max.getBlockZ(); zPos++) {
if (!ResidenceBlockListener.canBreakBlock(player, new Location(loc1.getWorld(), xPos, yPos, zPos), false)) {
return false;
}
}
}
}

return true;
}

@Override
public String getName() {
return "Residence";
}

@Override
public boolean success() {
return true;
}
}
68 changes: 44 additions & 24 deletions src/com/bekvon/bukkit/residence/commands/auto.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import net.Zrips.CMILib.Container.CMIWorld;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.RawMessages.RawMessage;

public class auto implements cmd {
Expand All @@ -43,7 +44,7 @@ public Boolean perform(Residence plugin, CommandSender sender, String[] args, bo
} catch (Exception | Error e) {

}

if (args.length > 0 && length == -1)
resName = args[0];
else
Expand Down Expand Up @@ -110,31 +111,50 @@ public Boolean perform(Residence plugin, CommandSender sender, String[] args, bo

Selection selection = plugin.getSelectionManager().getSelection(player);

double ratioX = getRatio(selection.getBaseArea().getXSize(), selection.getBaseArea().getYSize(), selection.getBaseArea().getZSize());
double ratioY = getRatio(selection.getBaseArea().getYSize(), selection.getBaseArea().getXSize(), selection.getBaseArea().getZSize());
double ratioZ = getRatio(selection.getBaseArea().getZSize(), selection.getBaseArea().getXSize(), selection.getBaseArea().getZSize());

String maxSide = "";
String minSide = "";

double maxRatio = 0;

if (ratioX > maxRatio) {
maxSide = "Z";
minSide = "X";
maxRatio = ratioX;
}
if (plugin.getConfigManager().isSelectionIgnoreY()) {

if (ratioZ > maxRatio) {
maxSide = "X";
minSide = "Z";
maxRatio = ratioZ;
}
double ratioX = getRatio(selection.getBaseArea().getXSize(), selection.getBaseArea().getXSize(), selection.getBaseArea().getZSize());
double ratioZ = getRatio(selection.getBaseArea().getZSize(), selection.getBaseArea().getXSize(), selection.getBaseArea().getXSize());

if (ratioX > maxRatio) {
maxSide = "Z";
minSide = "X";
maxRatio = ratioX;
}

if (ratioZ > maxRatio) {
maxSide = "X";
minSide = "Z";
maxRatio = ratioZ;
}

if (ratioY > maxRatio) {
maxSide = "X";
minSide = "Y";
maxRatio = ratioY;
} else {

double ratioX = getRatio(selection.getBaseArea().getXSize(), selection.getBaseArea().getYSize(), selection.getBaseArea().getZSize());
double ratioY = getRatio(selection.getBaseArea().getYSize(), selection.getBaseArea().getZSize(), selection.getBaseArea().getXSize());
double ratioZ = getRatio(selection.getBaseArea().getZSize(), selection.getBaseArea().getYSize(), selection.getBaseArea().getXSize());

if (ratioX > maxRatio) {
maxSide = "Z";
minSide = "X";
maxRatio = ratioX;
}

if (ratioZ > maxRatio) {
maxSide = "X";
minSide = "Z";
maxRatio = ratioZ;
}

if (ratioY > maxRatio) {
maxSide = "X";
minSide = "Y";
maxRatio = ratioY;
}
}

if (maxRatio > plugin.getConfigManager().getARCRatioValue()) {
Expand Down Expand Up @@ -164,7 +184,7 @@ private double getRatio(int v1, int v2, int v3) {
return ratio;
}

private static int getMax(int max) {
private static int getMax(int max) {
if (!Residence.getInstance().getConfigManager().isARCSizeEnabled())
return max;
int arcmin = Residence.getInstance().getConfigManager().getARCSizeMin();
Expand Down Expand Up @@ -318,7 +338,7 @@ public static boolean resize(Residence plugin, Player player, CuboidArea cuboid,

if (!Residence.getInstance().getEconomyManager().canAfford(player, cost)) {
plugin.msg(player, lm.Economy_NotEnoughMoney);
return false;
return false;
}
}

Expand Down Expand Up @@ -374,10 +394,10 @@ public static boolean optimizedResize(Residence plugin, Player player, CuboidAre
int maxX = getMax(groupMaxX);
int maxY = getMax(group.getMaxY());
int maxZ = getMax(groupMaxZ);

if (maxX > max && max > 0)
maxX = max;
if (maxY > max && max > 0)
if (!Residence.getInstance().getConfigManager().isSelectionIgnoreY() && maxY > max && max > 0)
maxY = max;
if (maxZ > max && max > 0)
maxZ = max;
Expand Down
2 changes: 1 addition & 1 deletion src/com/bekvon/bukkit/residence/commands/create.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Boolean perform(Residence plugin, CommandSender sender, String[] args, bo
if (plugin.getWorldEditTool() == plugin.getConfigManager().getSelectionTool()) {
plugin.getSelectionManager().worldEdit(player);
}
}
}

if (plugin.getSelectionManager().hasPlacedBoth(player)) {

Expand Down
1 change: 1 addition & 0 deletions src/com/bekvon/bukkit/residence/commands/expand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.bekvon.bukkit.residence.protection.CuboidArea;

import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Logs.CMIDebug;

public class expand implements cmd {

Expand Down
5 changes: 2 additions & 3 deletions src/com/bekvon/bukkit/residence/commands/select.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Logs.CMIDebug;

import com.bekvon.bukkit.residence.LocaleManager;
import com.bekvon.bukkit.residence.Residence;
import com.bekvon.bukkit.residence.containers.CommandAnnotation;
Expand All @@ -23,6 +20,8 @@
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.CuboidArea;

import net.Zrips.CMILib.FileHandler.ConfigReader;

public class select implements cmd {

@Override
Expand Down
Loading

0 comments on commit db060ee

Please sign in to comment.