Skip to content

Commit

Permalink
Merge pull request #17 from ShermansWorld/feature/admin-command
Browse files Browse the repository at this point in the history
Feature/admin command merge
  • Loading branch information
NinjaMandalorian authored Apr 24, 2023
2 parents 7a8ec59 + cdbfb50 commit 62833c7
Show file tree
Hide file tree
Showing 19 changed files with 3,562 additions and 463 deletions.
50 changes: 25 additions & 25 deletions resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: AlathraWar
version: 1.3.2
api-version: 1.19
author: ShermansWorld
main: me.ShermansWorld.AlathraWar.Main
depend: [Vault, Towny, TAB]

commands:
war:
description: used to create, delete, join and leave wars
softdepend: [Vault, Towny, TAB]
usage: /war
siege:
description: used to start, end, and view sieges
softdepend: [Vault, Towny]
usage: /siege
raid:
description: used to start, end, and view raids
softdepend: [Vault, Towny]
usage: /raid
alathrawaradmin:
description: used to administrate wars and modify existing events
softdepend: [Vault, Towny, TAB]
usage: /alathrawaradmin
aliases: [awa]
name: AlathraWar
version: 1.3.2
api-version: 1.19
author: ShermansWorld
main: me.ShermansWorld.AlathraWar.Main
depend: [Vault, Towny, TAB]

commands:
war:
description: used to create, delete, join and leave wars
softdepend: [Vault, Towny, TAB]
usage: /war
siege:
description: used to start, end, and view sieges
softdepend: [Vault, Towny]
usage: /siege
raid:
description: used to start, end, and view raids
softdepend: [Vault, Towny]
usage: /raid
alathrawaradmin:
description: used to administrate wars and modify existing events
softdepend: [Vault, Towny, TAB]
usage: /alathrawaradmin
aliases: [awa]
4 changes: 4 additions & 0 deletions src/main/java/me/ShermansWorld/AlathraWar/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.ShermansWorld.AlathraWar;

import me.ShermansWorld.AlathraWar.commands.*;
import me.ShermansWorld.AlathraWar.data.TimeoutData;
import me.ShermansWorld.AlathraWar.listeners.CommandsListener;
import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredServiceProvider;
Expand Down Expand Up @@ -81,12 +82,15 @@ public void onEnable() {
initLogs();

new WarData(this);
// new TimeoutData(this);
new WarCommands(this);
new SiegeCommands(this);
new RaidCommands(this);
new AdminCommands(this);
getCommand("war").setTabCompleter(new WarTabCompletion());
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
getCommand("raid").setTabCompleter(new RaidTabCompletion());
getCommand("alathrawaradmin").setTabCompleter(new AdminTabCompletion());
getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this);
getServer().getPluginManager().registerEvents((Listener) new CommandsListener(), (Plugin) this);
getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this);
Expand Down
413 changes: 241 additions & 172 deletions src/main/java/me/ShermansWorld/AlathraWar/Raid.java

Large diffs are not rendered by default.

77 changes: 67 additions & 10 deletions src/main/java/me/ShermansWorld/AlathraWar/Siege.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.TownyAPI;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.WorldCoord;
Expand Down Expand Up @@ -94,13 +95,13 @@ public void run() {
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().isHomeBlock()
&& WorldCoord
.parseWorldCoord(
Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().getTown().equals(town)
.parseWorldCoord(
Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().getTown().equals(town)
&& !Bukkit.getPlayer(playerName).isDead()
&& (Math.abs(
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
- townSpawn.getBlockY())) < 10) {
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
- townSpawn.getBlockY())) < 10) {
attackersAreOnHomeBlock = true;
}
} catch (NotRegisteredException ex) {
Expand All @@ -112,13 +113,13 @@ public void run() {
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().isHomeBlock()
&& WorldCoord
.parseWorldCoord(
Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().getTown().equals(town)
.parseWorldCoord(
Main.getInstance().getServer().getPlayer(playerName))
.getTownBlock().getTown().equals(town)
&& !Bukkit.getPlayer(playerName).isDead()
&& (Math.abs(
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
- townSpawn.getBlockY())) < 10) {
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
- townSpawn.getBlockY())) < 10) {
defendersAreOnHomeBlock = true;
}
} catch (NotRegisteredException ex3) {
Expand Down Expand Up @@ -279,6 +280,18 @@ public void defendersWin() {
clearBeacon();
}

/**
* No winnder declared
*/
public void noWinner() {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "No money has been recovered.");
Main.warLogger
.log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
stop();
clearBeacon();
}

public void createBeacon() {
try {
World world = town.getWorld();
Expand Down Expand Up @@ -396,6 +409,14 @@ public void setTown(final Town town) {
this.town = town;
}

public OfflinePlayer getSiegeOwner() {
return siegeLeader;
}

public void setSiegeOwner(OfflinePlayer siegeOwner) {
this.siegeLeader = siegeOwner;
}

/** Gets attacker name string */
public String getAttackers() {
if (side1AreAttackers) {
Expand All @@ -422,6 +443,38 @@ public int getDefenderPoints() {
return this.defenderPoints;
}

public int getMaxSiegeTicks() {
return maxSiegeTicks;
}

public void setSiegeTicks(int siegeTicks) {
this.siegeTicks = siegeTicks;
}

public TownBlock getHomeBlock() {
return homeBlock;
}

public void setHomeBlock(TownBlock homeBlock) {
this.homeBlock = homeBlock;
}

public Location getTownSpawn() {
return townSpawn;
}

public void setTownSpawn(Location townSpawn) {
this.townSpawn = townSpawn;
}

public void setAttackerPoints(int points) {
this.attackerPoints = points;
}

public void setDefenderPoints(int points) {
this.defenderPoints = points;
}

public boolean getSide1AreAttackers() {
return this.side1AreAttackers;
}
Expand Down Expand Up @@ -457,4 +510,8 @@ public OfflinePlayer getSiegeLeader() {
public void save() {
SiegeData.saveSiege(this);
}

public String getName() {
return this.getWar().getName() + "-" + this.getTown();
}
}
64 changes: 56 additions & 8 deletions src/main/java/me/ShermansWorld/AlathraWar/War.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package me.ShermansWorld.AlathraWar;

import java.io.File;
import java.util.ArrayList;

import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;

import me.ShermansWorld.AlathraWar.data.DataManager;
import me.ShermansWorld.AlathraWar.data.WarData;

public class War {
Expand All @@ -22,7 +24,8 @@ public class War {
// References
private ArrayList<Siege> sieges = new ArrayList<Siege>();
private ArrayList<Raid> raids = new ArrayList<Raid>();
private int lastRaidTime = 0;
private int lastRaidTimeSide1 = 0;
private int lastRaidTimeSide2 = 0;

/**
* War Constructor
Expand Down Expand Up @@ -83,8 +86,10 @@ public void addTown(final String town, String side) {
* @param nation - Nation to surrender
*/
public void surrenderNation(Nation nation) {
for (Town town : nation.getTowns()) {
surrenderTown(town.getName());
if(nation != null) {
for (Town town : nation.getTowns()) {
surrenderTown(town.getName());
}
}
}

Expand All @@ -98,6 +103,24 @@ public void surrenderTown(String town) {
surrenderedTowns.add(town);
}

/**
* unsurrender town, perfidy time
* @param nation - Nation to unsurrender
*/
public void unSurrenderNation(Nation nation) {
for (Town town : nation.getTowns()) {
unSurrenderTown(town.getName());
}
}

/**
* unsurrender town, perfidy time
* @param town - Town to unsurrender
*/
public void unSurrenderTown(String town) {
surrenderedTowns.remove(town);
}

/**
* Gets side of town
* -1 - Surrendered
Expand Down Expand Up @@ -125,7 +148,7 @@ public int getSide(String string) {
public int getSide(Town town) {
return getSide(town.getName());
}

public String getName() {
return this.name;
}
Expand Down Expand Up @@ -158,6 +181,9 @@ public ArrayList<String> getSurrenderedTowns() {
return surrenderedTowns;
}

public void setSurrenderedTowns(ArrayList<String> towns) {
surrenderedTowns = towns;
}

public ArrayList<Siege> getSieges() {
return sieges;
Expand All @@ -175,6 +201,20 @@ public void addRaid(Raid raid) {
raids.add(raid);
}

public void setName(String name) {
DataManager.deleteFile("wars" + File.separator + this.getName() + ".yml");
this.name = name;
this.save();
}

public void setSide1(String side1) {
this.side1 = side1;
}

public void setSide2(String side2) {
this.side2 = side2;
}

/**
* Saves the war into .yml file folders.
*/
Expand Down Expand Up @@ -209,11 +249,19 @@ private static ArrayList<String> townListToPlayers(ArrayList<String> townList) {
return returnList;
}

public void setLastRaidTime(int lastRaidTime) {
this.lastRaidTime = lastRaidTime;
public void setLastRaidTimeSide1(int lastRaidTime) {
this.lastRaidTimeSide1 = lastRaidTime;
}

public int getLastRaidTimeSide1() {
return this.lastRaidTimeSide1;
}

public void setLastRaidTimeSide2(int lastRaidTime) {
this.lastRaidTimeSide2 = lastRaidTime;
}

public int getLastRaidTime() {
return this.lastRaidTime;
public int getLastRaidTimeSide2() {
return this.lastRaidTimeSide2;
}
}
Loading

0 comments on commit 62833c7

Please sign in to comment.