Skip to content

Commit

Permalink
Merge branch 'retromcorg:main' into feature-1
Browse files Browse the repository at this point in the history
  • Loading branch information
zavdav authored Jan 12, 2025
2 parents 077f560 + 09715dd commit a6cc0d8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# JVillage
An alterative for Towny in Beta 1.7.3
An alternative for Towny in Beta 1.7.3
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.johnymuffin.beta.fundamentals.api.FundamentalsAPI;
import com.johnymuffin.jvillage.beta.JVillage;
import com.johnymuffin.jvillage.beta.commands.JVBaseCommand;
import com.johnymuffin.jvillage.beta.models.VCords;
import com.johnymuffin.jvillage.beta.models.Village;
import com.johnymuffin.jvillage.beta.models.chunk.ChunkClaimSettings;
import com.johnymuffin.jvillage.beta.models.chunk.VClaim;
import com.johnymuffin.jvillage.beta.player.VPlayer;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
Expand All @@ -14,6 +17,8 @@

import java.util.logging.Level;

import static com.johnymuffin.jvillage.beta.JVUtility.cordsInChunk;

public class JDeleteCommand extends JVBaseCommand implements CommandExecutor {

public JDeleteCommand(JVillage plugin) {
Expand Down Expand Up @@ -58,17 +63,28 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}

// Refund the player the balance
double townBalance = village.getBalance();
double refundAmount = village.getBalance();

// Refund the player the cost of the claims
VCords spawnCords = village.getTownSpawn();

for (VClaim vClaim : plugin.getVillageClaimsArray(village)) {
ChunkClaimSettings chunkClaimSettings = village.getChunkClaimSettings(vClaim);

if (!cordsInChunk(spawnCords, vClaim)) {
refundAmount += chunkClaimSettings.getPrice();
}
}

if (townBalance > 0 && plugin.isFundamentalsEnabled()) {
EconomyAPI.EconomyResult result = FundamentalsAPI.getEconomy().additionBalance(player.getUniqueId(), townBalance);
if (refundAmount > 0 && plugin.isFundamentalsEnabled()) {
EconomyAPI.EconomyResult result = FundamentalsAPI.getEconomy().additionBalance(player.getUniqueId(), refundAmount);
String message;
switch (result) {
case successful:
this.plugin.logger(Level.INFO, "Successfully refunded $" + townBalance + " to " + player.getName() + " for deleting village " + village.getTownName());
this.plugin.logger(Level.INFO, "Successfully refunded $" + refundAmount + " to " + player.getName() + " for deleting village " + village.getTownName());
break;
default:
this.plugin.logger(Level.WARNING, "Failed to refund $" + townBalance + " to " + player.getName() + " for deleting village " + village.getTownName());
this.plugin.logger(Level.WARNING, "Failed to refund $" + refundAmount + " to " + player.getName() + " for deleting village " + village.getTownName());
message = language.getMessage("generic_error");
commandSender.sendMessage(message);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.johnymuffin.jvillage.beta.JVillage;
import com.johnymuffin.jvillage.beta.models.Village;
import com.johnymuffin.jvillage.beta.player.VPlayer;
import com.johnymuffin.jvillage.beta.models.chunk.VChunk;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
Expand All @@ -29,7 +30,7 @@ public JVPlayerAlterListener(JVillage plugin) {
//Lowest priority so that other plugins can cancel this event
@EventHandler(ignoreCancelled = true, priority = Event.Priority.Lowest)
public void onBlockPlaceEvent(final BlockPlaceEvent event) {
if (isAuthorizedToAlter(event.getPlayer())) {
if (isAuthorizedToAlter(event.getPlayer(), event.getBlock())) {
return;
}

Expand All @@ -43,7 +44,7 @@ public void onBlockPlaceEvent(final BlockPlaceEvent event) {
//Lowest priority so that other plugins can cancel this event
@EventHandler(ignoreCancelled = true, priority = Event.Priority.Lowest)
public void onBlockBreakEvent(final BlockBreakEvent event) {
if (isAuthorizedToAlter(event.getPlayer())) {
if (isAuthorizedToAlter(event.getPlayer(), event.getBlock())) {
return;
}

Expand All @@ -60,7 +61,7 @@ public void onBlockIgniteEvent(final BlockIgniteEvent event) {
return;
}

if (isAuthorizedToAlter(event.getPlayer())) {
if (isAuthorizedToAlter(event.getPlayer(), event.getBlock())) {
return;
}

Expand All @@ -79,7 +80,7 @@ public void onPaintingPlace(final PaintingPlaceEvent event) {

Player player = event.getPlayer();

if (isAuthorizedToAlter(player)) {
if (isAuthorizedToAlter(player, event.getBlock())) {
return;
}

Expand All @@ -103,7 +104,7 @@ public void onPaintingDestruction(final PaintingBreakEvent preEvent) {

Player player = (Player) event.getRemover();

if (isAuthorizedToAlter(player)) {
if (isAuthorizedToAlter(player, event.getPainting().getLocation().getBlock())) {
return;
}

Expand All @@ -119,7 +120,7 @@ public void onPlayerBucketEmptyEvent(PlayerBucketEmptyEvent event) {
return;
}

if (isAuthorizedToAlter(event.getPlayer())) {
if (isAuthorizedToAlter(event.getPlayer(), event.getBlockClicked())) {
return;
}

Expand All @@ -130,12 +131,12 @@ public void onPlayerBucketEmptyEvent(PlayerBucketEmptyEvent event) {
}

@EventHandler(ignoreCancelled = true, priority = Event.Priority.Lowest)
public void onPlayerBucketEmptyEvent(PlayerBucketFillEvent event) {
public void onPlayerBucketFillEvent(PlayerBucketFillEvent event) {
if (event.isCancelled()) {
return;
}

if (isAuthorizedToAlter(event.getPlayer())) {
if (isAuthorizedToAlter(event.getPlayer(), event.getBlockClicked())) {
return;
}

Expand All @@ -147,21 +148,16 @@ public void onPlayerBucketEmptyEvent(PlayerBucketFillEvent event) {


//Method utilized to determine if a player is authorized to alter a block based on their permissions and the village they are in
private boolean isAuthorizedToAlter(Player player) {
private boolean isAuthorizedToAlter(Player player, Block block) {
if (isAuthorized(player, "jvillage.admin.bypass")) {
return true;
}

VPlayer vPlayer = plugin.getPlayerMap().getPlayer(player.getUniqueId());
if (!vPlayer.isLocatedInVillage()) {
return true;
VChunk vChunk = new VChunk(block.getLocation());
if(plugin.isClaimed(vChunk)){
Village village = plugin.getVillageAtLocation(vChunk);
return village.canPlayerAlter(player);
}
Village locatedVillage = vPlayer.getCurrentlyLocatedIn();
if (locatedVillage.canPlayerAlter(player)) {
return true;
}

return false;
return true;
}

}

0 comments on commit a6cc0d8

Please sign in to comment.