Skip to content

Commit

Permalink
Event variables set in contructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
LlmDl committed Oct 31, 2021
1 parent cb5766f commit 1fef904
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,8 @@ public static void startSiege(Block bannerBlock,
//Save to DB
SiegeController.saveSiege(siege);

Nation nation = siege.getSiegeType().equals(SiegeType.REVOLT) ? TownOccupationController.getTownOccupier(targetTown) : (Nation)siege.getAttackingNationIfPossibleElseTown();
//Call event
Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent(
siege,
siege.getSiegeType().getName(),
siege.getTown(),
nation,
townOfSiegeStarter,
bannerBlock));
Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent(siege, townOfSiegeStarter));
}

private static void sendGlobalSiegeStartMessage(Siege siege) {
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ public class SiegeEndEvent extends Event {
private final String defenderName;
private final String besiegedTownName;

public SiegeEndEvent(Siege siege,
String siegeType,
String siegeWinner,
String attackerName,
String defenderName,
String besiegedTownName) {
public SiegeEndEvent(Siege siege) {
super(!Bukkit.getServer().isPrimaryThread());
this.siege = siege;
this.siegeType = siegeType;
this.siegeWinner = siegeWinner;
this.attackerName = attackerName;
this.defenderName = defenderName;
this.besiegedTownName = besiegedTownName;
this.siegeType = siege.getSiegeType().getName();
this.siegeWinner = siege.getSiegeWinner().name();
this.attackerName = siege.getAttackerName();
this.defenderName = siege.getDefenderName();
this.besiegedTownName = siege.getTown().getName();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gmail.goosius.siegewar.events;

import com.gmail.goosius.siegewar.enums.SiegeType;
import com.gmail.goosius.siegewar.objects.Siege;
import com.gmail.goosius.siegewar.TownOccupationController;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.block.Block;
Expand All @@ -18,19 +20,13 @@ public class SiegeWarStartEvent extends Event {
private final Block flag;
private final Town targetTown;

public SiegeWarStartEvent(
Siege siege,
String siegeType,
Town targetTown,
Nation nation,
Town townOfSiegeStarter,
Block flag) {
public SiegeWarStartEvent(Siege siege, Town townOfSiegeStarter) {
this.siege = siege;
this.siegeType = siegeType;
this.targetTown = targetTown;
this.siegeType = siege.getSiegeType().getName();
this.targetTown = siege.getTown();
this.townOfSiegeStarter = townOfSiegeStarter;
this.nation = nation;
this.flag = flag;
this.nation = siege.getSiegeType().equals(SiegeType.REVOLT) ? TownOccupationController.getTownOccupier(targetTown) : (Nation)siege.getAttackingNationIfPossibleElseTown();
this.flag = siege.getFlagLocation().getBlock();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public static void setCommonSiegeCompletionValues(Siege siege,
SiegeController.saveSiege(siege);

//Fire SiegeEnded event
Bukkit.getPluginManager().callEvent(new SiegeEndEvent(
siege,
siege.getSiegeType().getName(),
siege.getSiegeWinner().name(),
siege.getAttackerName(),
siege.getDefenderName(),
siege.getTown().getName()));
Bukkit.getPluginManager().callEvent(new SiegeEndEvent(siege));
}
}

0 comments on commit 1fef904

Please sign in to comment.