1.14 support, fixes #105
4 changed files with 36 additions and 26 deletions
|
@ -39,7 +39,7 @@
|
|||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.TownyAdvanced:Towny:0.94.0.9" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.milkbowl:VaultAPI:master-af0353b1d7-1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.bukkit:bukkit:1.13.1-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot:1.12.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.webbukkit:Dynmap-Towny:master-0.60-g924051d-7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.webbukkit:Dynmap:v2.5" level="project" />
|
||||
|
@ -50,5 +50,6 @@
|
|||
<orderEntry type="library" name="Maven: org.anjocaido:EssentialsGroupManager:2.10.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
|
||||
</component>
|
||||
</module>
|
23
pom.xml
23
pom.xml
|
@ -212,12 +212,14 @@
|
|||
<version>master-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
|
@ -247,7 +249,14 @@
|
|||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<artifactId>ButtonChat</artifactId>
|
||||
<organization>
|
||||
<name>TBMCPlugins</name>
|
||||
|
|
|
@ -4,20 +4,22 @@ import buttondevteam.chat.ChatProcessing;
|
|||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import com.palmergames.bukkit.towny.TownyLogger;
|
||||
import lombok.val;
|
||||
import org.apache.log4j.Appender;
|
||||
import org.apache.log4j.AppenderSkeleton;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TownyAnnouncer {
|
||||
private static final Pattern LOG_TYPE_PATTERN = Pattern.compile("\\[(\\w+) (?:Msg|Message)](?: (\\w+):)?");
|
||||
private static final Handler HANDLER = new Handler() {
|
||||
private static final Appender HANDLER = new AppenderSkeleton() {
|
||||
@Override
|
||||
public void publish(LogRecord logRecord) {
|
||||
public void append(LoggingEvent logRecord) {
|
||||
if (logRecord.getMessage() == null) return;
|
||||
val m = LOG_TYPE_PATTERN.matcher(logRecord.getMessage());
|
||||
String message = logRecord.getMessage().toString();
|
||||
val m = LOG_TYPE_PATTERN.matcher(message);
|
||||
if (!m.find()) return;
|
||||
String groupID = m.group(2); //The group ID is correctly cased
|
||||
switch (String.valueOf(m.group(1))) { //valueOf: Handles null
|
||||
|
@ -25,30 +27,30 @@ public class TownyAnnouncer {
|
|||
if (townChannel == null) return;
|
||||
TBMCChatAPI.SendSystemMessage(townChannel,
|
||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID),
|
||||
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
|
||||
message, target, ChatProcessing.MCORIGIN);
|
||||
break;
|
||||
case "Nation":
|
||||
if (nationChannel == null) return;
|
||||
TBMCChatAPI.SendSystemMessage(nationChannel,
|
||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID),
|
||||
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
|
||||
message, target, ChatProcessing.MCORIGIN);
|
||||
break;
|
||||
case "Global":
|
||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
|
||||
Channel.RecipientTestResult.ALL,
|
||||
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
|
||||
message, target, ChatProcessing.MCORIGIN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
public void close() throws SecurityException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
|
||||
public boolean requiresLayout() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -60,7 +62,7 @@ public class TownyAnnouncer {
|
|||
target = TBMCSystemChatEvent.BroadcastTarget.add("towny");
|
||||
TownyAnnouncer.townChannel = townChannel;
|
||||
TownyAnnouncer.nationChannel = nationChannel;
|
||||
TownyLogger.log.addHandler(HANDLER);
|
||||
LogManager.getLogger("com.palmergames.bukkit.towny").addAppender(HANDLER);
|
||||
}
|
||||
|
||||
public static void setdown() {
|
||||
|
@ -68,6 +70,6 @@ public class TownyAnnouncer {
|
|||
target = null;
|
||||
TownyAnnouncer.townChannel = null;
|
||||
TownyAnnouncer.nationChannel = null;
|
||||
TownyLogger.log.removeHandler(HANDLER);
|
||||
LogManager.getLogger("com.palmergames.bukkit.towny").removeAppender(HANDLER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,12 @@ import buttondevteam.core.component.channel.Channel;
|
|||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -34,7 +32,7 @@ public class TownyComponent extends Component<PluginMain> {
|
|||
|
||||
@Override
|
||||
protected void enable() {
|
||||
TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse();
|
||||
TU = TownyUniverse.getInstance();
|
||||
Towns = TU.getTownsMap().values().stream().map(Town::getName).collect(Collectors.toCollection(ArrayList::new)); // Creates a snapshot of towns, new towns will be added when needed
|
||||
Nations = TU.getNationsMap().values().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations
|
||||
TBMCChatAPI.RegisterChatChannel(
|
||||
|
|
Loading…
Reference in a new issue