Skip to content

Commit

Permalink
Merge branch 'TownyAdvanced:master' into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
CorruptedGreed authored Apr 13, 2024
2 parents e77d912 + 7c99c0b commit daf89ea
Show file tree
Hide file tree
Showing 71 changed files with 2,073 additions and 480 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compile-on-push.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Compile
on:
push:
branches: [master]
branches-ignore: [l10n_master]
pull_request:
branches-ignore: [l10n_master]
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Run Tests
on:
push:
branches: [master]
branches-ignore: [l10n_master]
pull_request:
branches-ignore: [l10n_master]
jobs:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ___

<table>
<tr><th> Minecraft Version</th><th>Towny Version</th></tr>
<tr align=center><td> MC 1.20.* </td><td rowspan=5> Use <a href=https://github.com/TownyAdvanced/Towny/releases/tag/0.100.1.0>0.100.1.0</a> or the <a href=https://github.com/TownyAdvanced/Towny/releases>the Latest Pre-Release.</a></td>
<tr align=center><td> MC 1.20.* </td><td rowspan=5> Use <a href=https://github.com/TownyAdvanced/Towny/releases/tag/0.100.2.0>0.100.2.0</a> or the <a href=https://github.com/TownyAdvanced/Towny/releases>the Latest Pre-Release.</a></td>
<tr align=center><td> MC 1.19.* </td>
<tr align=center><td> MC 1.18.* </td>
<tr align=center><td> MC 1.17.* </td>
Expand Down
10 changes: 5 additions & 5 deletions Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.100.1.24</version>
<version>0.100.2.2</version>

<licenses>
<license>
Expand Down Expand Up @@ -142,7 +142,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
<version>1.26.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -246,7 +246,7 @@
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.78.0</version>
<version>3.80.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -267,7 +267,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<version>3.13.0</version>
<configuration>
<release>8</release>
<source>${java.version}</source>
Expand Down Expand Up @@ -340,7 +340,7 @@
<plugin> <!-- Create sources.jar -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,13 @@ public enum ConfigNodes {
NWS_PLOT_MANAGEMENT_WILD_REVERT_BLOCK_WHITELIST(
"new_world_settings.plot_management.wild_revert_on_explosion_block_whitelist",
"",
"",
"# This section is applied to new worlds as default settings when new worlds are detected.",
"# The list of blocks to regenerate for block and entity explosions. (if empty all blocks will regenerate)"),
NWS_PLOT_MANAGEMENT_WILD_REVERT_BLOCKS_TO_NOT_OVERWRITE(
"new_world_settings.plot_management.wild_revert_explosions_blocks_to_not_replace",
"",
"",
"# This section is applied to new worlds as default settings when new worlds are detected.",
"# This is the list of blocks that should not be overwritten by wilderness explosion reverts. (if empty all ",
"# blocks placed into regenerating explosions will be overwritten with the original pre-explosion blocks.)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ public void onDisable() {

this.townyUniverse = null;

// Used to be required, but in the latest versions the server will cancel these tasks for us as well.
if (this.scheduler instanceof FoliaTaskScheduler foliaScheduler)
foliaScheduler.cancelTasks();

Expand Down
12 changes: 8 additions & 4 deletions Towny/src/main/java/com/palmergames/bukkit/towny/TownyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.palmergames.bukkit.towny.command.BaseCommand;
import com.palmergames.bukkit.towny.db.TownyDataSource;
import com.palmergames.bukkit.towny.event.teleport.CancelledTownyTeleportEvent.CancelledTeleportReason;
import com.palmergames.bukkit.towny.event.townblockstatus.NationZoneTownBlockStatusEvent;
import com.palmergames.bukkit.towny.exceptions.KeyAlreadyRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
Expand Down Expand Up @@ -713,10 +714,13 @@ public void requestTeleport(Player player, Location spawnLoc, int cooldown) {
}
}

public void abortTeleportRequest(Resident resident) {

TeleportWarmupTimerTask.abortTeleportRequest(resident);
}
public void abortTeleportRequest(Resident resident) {
abortTeleportRequest(resident, CancelledTeleportReason.UNKNOWN);
}

public void abortTeleportRequest(Resident resident, CancelledTeleportReason reason) {
TeleportWarmupTimerTask.abortTeleportRequest(resident, reason);
}

public void registerCustomDataField(CustomDataField<?> field) throws KeyAlreadyRegisteredException {
townyUniverse.addCustomCustomDataField(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public boolean hasTownyWorld(String worldName) {
if (worldName.isEmpty())
return false;

return worlds.containsKey(worldName);
return worlds.containsKey(worldName.toLowerCase(Locale.ROOT));
}
/*
* Towny Tree command output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1560,13 +1560,19 @@ private void nationAllyAccept(Player player, Nation nation, String[] split) thro
}
if (toAccept != null) {

// Nation has reached the max amount of allies
// Check if either nation has reached the max amount of allies
if (nation.hasReachedMaximumAllies()) {
toAccept.getReceiver().deleteReceivedInvite(toAccept);
toAccept.getSender().deleteSentInvite(toAccept);
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_ally_limit_reached"));
return;
}
if (sendernation.hasReachedMaximumAllies()) {
toAccept.getReceiver().deleteReceivedInvite(toAccept);
toAccept.getSender().deleteSentInvite(toAccept);
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_ally_limit_reached_cannot_accept", sendernation));
return;
}

try {
NationAcceptAllyRequestEvent acceptAllyRequestEvent = new NationAcceptAllyRequestEvent((Nation)toAccept.getSender(), (Nation) toAccept.getReceiver());
Expand Down Expand Up @@ -1689,6 +1695,10 @@ private void nationAddAlly(Resident resident, Nation nation, Nation targetNation
throw new TownyException("Could not add " + targetNation + " as Ally because your Player is null! This shouldn't be possible!");
if (nation.hasAlly(targetNation))
throw new TownyException(Translatable.of("msg_already_ally", targetNation));
if (nation.hasReachedMaximumAllies())
throw new TownyException(Translatable.of("msg_err_ally_limit_reached_cannot_send", targetNation));
if (targetNation.hasReachedMaximumAllies())
throw new TownyException(Translatable.of("msg_err_ally_limit_reached_cannot_send_targetNation", targetNation, targetNation));
if (!targetNation.hasEnemy(nation)) {
BukkitTools.ifCancelledThenThrow(new NationPreAddAllyEvent(nation, targetNation));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setCancelled(boolean cancel) {
*/
@Nullable
public Town getTown() {
return townblock.getTownOrNull();
return townblock == null ? null : townblock.getTownOrNull();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.palmergames.bukkit.towny.event.teleport;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import com.palmergames.bukkit.towny.object.Resident;

/**
* An event thrown by Towny when a player that was supposed to teleport to the
* /res, /town, or /nation spawn, but the action was cancelled. This can be due
* to Movement, Damage or an Unknown source (when cancelled via the TownyAPI
* class.
*
* @since 0.100.2.2
* @author LlmDl
*/
public class CancelledTownyTeleportEvent extends Event {

private static final HandlerList handlers = new HandlerList();
private final Resident resident;
private final Location location;
private final double teleportCost;
private final CancelledTeleportReason reason;

public CancelledTownyTeleportEvent(Resident resident, Location location, double teleportCost, CancelledTeleportReason reason) {
super(!Bukkit.isPrimaryThread());
this.resident = resident;
this.location = location;
this.teleportCost = teleportCost;
this.reason = reason;
}

/**
* @return Resident which is not going to teleport.
*/
public Resident getResident() {
return resident;
}

/**
* @return Location that resident was going to go to.
*/
public Location getLocation() {
return location;
}

/**
* @return the amount of money which was refunded to the player.
*/
public double getTeleportCost() {
return teleportCost;
}

/**
* @return the {@link CancelledTeleportReason} that the resident will not teleport.
* When cancelled via the TownyAPI class, this will return UNKNOWN.
*/
public CancelledTeleportReason getReason() {
return reason;
}

@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}

public enum CancelledTeleportReason {
MOVEMENT, DAMAGE, UNKNOWN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.command.TownCommand;
import com.palmergames.bukkit.towny.command.TownyCommand;
import com.palmergames.bukkit.towny.confirmations.Confirmation;
import com.palmergames.bukkit.towny.event.BedExplodeEvent;
import com.palmergames.bukkit.towny.event.ChunkNotificationEvent;
import com.palmergames.bukkit.towny.event.NewTownEvent;
Expand Down Expand Up @@ -220,7 +221,7 @@ public void onTownUnclaim(TownPreUnclaimCmdEvent event) {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTownClaim(TownClaimEvent event) {
if (TownySettings.isShowingClaimParticleEffect())
if (TownySettings.isShowingClaimParticleEffect() && event.getTownBlock().getWorldCoord().isFullyLoaded())
Towny.getPlugin().getScheduler().runAsync(() ->
CellSurface.getCellSurface(event.getTownBlock().getWorldCoord()).runClaimingParticleOverSurfaceAtPlayer(event.getResident().getPlayer()));

Expand Down Expand Up @@ -276,17 +277,33 @@ public void onResidentJoinTown(TownAddResidentEvent event) {

Town town = event.getTown();
Player player = event.getResident().getPlayer();
Town residentTown = event.getResident().getTownOrNull();
Town playerLocationTown = TownyAPI.getInstance().getTown(player.getLocation());

if (player == null || residentTown == null || residentTown.equals(town))
if (player == null || (playerLocationTown != null && playerLocationTown.equals(town)))
return;

String notAffordMsg = Translatable.of("msg_err_cant_afford_tp").forLocale(player);

try {
SpawnUtil.sendToTownySpawn(player, new String[0], town, notAffordMsg, false, false, SpawnType.TOWN);
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage(player));
double cost = town.getSpawnCost();
if (cost > 0) {
// The costed spawn will have its own Confirmation.
try {
SpawnUtil.sendToTownySpawn(player, new String[0], town, notAffordMsg, false, false, SpawnType.TOWN);
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage(player));
}
} else {
// No cost, so lets offer the new resident a choice.
Confirmation.runOnAccept(() -> {
try {
SpawnUtil.sendToTownySpawn(player, new String[0], town, notAffordMsg, false, false, SpawnType.TOWN);
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage(player));
}
})
.setTitle(Translatable.of("msg_new_resident_spawn_to_town_prompt"))
.sendTo(player);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ public void onEntityInteract(EntityInteractEvent event) {
return;
}

// Prevent protecting the wilderness from switch use.
if (TownyAPI.getInstance().isWilderness(block))
return;

// Prevent creatures triggering switch items.
if (TownySettings.isSwitchMaterial(block.getType(), block.getLocation())) {
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.palmergames.bukkit.towny.event.deathprice.PlayerPaysDeathPriceEvent;
import com.palmergames.bukkit.towny.event.deathprice.TownPaysDeathPriceEvent;
import com.palmergames.bukkit.towny.event.player.PlayerKilledPlayerEvent;
import com.palmergames.bukkit.towny.event.teleport.CancelledTownyTeleportEvent.CancelledTeleportReason;
import com.palmergames.bukkit.towny.hooks.PluginIntegrations;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void onPlayerTakesDamage(EntityDamageEvent event) {

Resident resident = TownyAPI.getInstance().getResident(player);

if (TeleportWarmupTimerTask.abortTeleportRequest(resident))
if (TeleportWarmupTimerTask.abortTeleportRequest(resident, CancelledTeleportReason.DAMAGE))
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_teleport_cancelled_damage"));}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.palmergames.bukkit.towny.event.player.PlayerExitsFromTownBorderEvent;
import com.palmergames.bukkit.towny.event.player.PlayerKeepsExperienceEvent;
import com.palmergames.bukkit.towny.event.player.PlayerKeepsInventoryEvent;
import com.palmergames.bukkit.towny.event.teleport.CancelledTownyTeleportEvent.CancelledTeleportReason;
import com.palmergames.bukkit.towny.hooks.PluginIntegrations;
import com.palmergames.bukkit.towny.object.CommandList;
import com.palmergames.bukkit.towny.object.PlayerCache;
Expand Down Expand Up @@ -736,7 +737,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
if (this.teleportWarmupTime > 0 && this.isMovementCancellingWarmup) {
final Resident resident = TownyAPI.getInstance().getResident(player);

if (resident != null && resident.hasRequestedTeleport() && !resident.isAdmin() && TeleportWarmupTimerTask.abortTeleportRequest(resident))
if (resident != null && resident.hasRequestedTeleport() && !resident.isAdmin() && TeleportWarmupTimerTask.abortTeleportRequest(resident, CancelledTeleportReason.MOVEMENT))
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_teleport_cancelled"));
}

Expand Down
Loading

0 comments on commit daf89ea

Please sign in to comment.