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.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" 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" 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" 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-Towny:master-0.60-g924051d-7" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.github.webbukkit:Dynmap:v2.5" 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" 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: junit:junit:4.12" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" 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>
|
</component>
|
||||||
</module>
|
</module>
|
11
pom.xml
11
pom.xml
|
@ -212,12 +212,14 @@
|
||||||
<version>master-SNAPSHOT</version>
|
<version>master-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.16.16</version>
|
<version>1.18.10</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
|
@ -247,6 +249,13 @@
|
||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<artifactId>ButtonChat</artifactId>
|
<artifactId>ButtonChat</artifactId>
|
||||||
<organization>
|
<organization>
|
||||||
|
|
|
@ -4,20 +4,22 @@ import buttondevteam.chat.ChatProcessing;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import com.palmergames.bukkit.towny.TownyLogger;
|
|
||||||
import lombok.val;
|
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;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TownyAnnouncer {
|
public class TownyAnnouncer {
|
||||||
private static final Pattern LOG_TYPE_PATTERN = Pattern.compile("\\[(\\w+) (?:Msg|Message)](?: (\\w+):)?");
|
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
|
@Override
|
||||||
public void publish(LogRecord logRecord) {
|
public void append(LoggingEvent logRecord) {
|
||||||
if (logRecord.getMessage() == null) return;
|
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;
|
if (!m.find()) return;
|
||||||
String groupID = m.group(2); //The group ID is correctly cased
|
String groupID = m.group(2); //The group ID is correctly cased
|
||||||
switch (String.valueOf(m.group(1))) { //valueOf: Handles null
|
switch (String.valueOf(m.group(1))) { //valueOf: Handles null
|
||||||
|
@ -25,31 +27,31 @@ public class TownyAnnouncer {
|
||||||
if (townChannel == null) return;
|
if (townChannel == null) return;
|
||||||
TBMCChatAPI.SendSystemMessage(townChannel,
|
TBMCChatAPI.SendSystemMessage(townChannel,
|
||||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID),
|
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID),
|
||||||
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
|
message, target, ChatProcessing.MCORIGIN);
|
||||||
break;
|
break;
|
||||||
case "Nation":
|
case "Nation":
|
||||||
if (nationChannel == null) return;
|
if (nationChannel == null) return;
|
||||||
TBMCChatAPI.SendSystemMessage(nationChannel,
|
TBMCChatAPI.SendSystemMessage(nationChannel,
|
||||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID),
|
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID),
|
||||||
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
|
message, target, ChatProcessing.MCORIGIN);
|
||||||
break;
|
break;
|
||||||
case "Global":
|
case "Global":
|
||||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
|
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
|
||||||
Channel.RecipientTestResult.ALL,
|
Channel.RecipientTestResult.ALL,
|
||||||
logRecord.getMessage(), target, ChatProcessing.MCORIGIN);
|
message, target, ChatProcessing.MCORIGIN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws SecurityException {
|
public void close() throws SecurityException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresLayout() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static TBMCSystemChatEvent.BroadcastTarget target;
|
private static TBMCSystemChatEvent.BroadcastTarget target;
|
||||||
|
@ -60,7 +62,7 @@ public class TownyAnnouncer {
|
||||||
target = TBMCSystemChatEvent.BroadcastTarget.add("towny");
|
target = TBMCSystemChatEvent.BroadcastTarget.add("towny");
|
||||||
TownyAnnouncer.townChannel = townChannel;
|
TownyAnnouncer.townChannel = townChannel;
|
||||||
TownyAnnouncer.nationChannel = nationChannel;
|
TownyAnnouncer.nationChannel = nationChannel;
|
||||||
TownyLogger.log.addHandler(HANDLER);
|
LogManager.getLogger("com.palmergames.bukkit.towny").addAppender(HANDLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setdown() {
|
public static void setdown() {
|
||||||
|
@ -68,6 +70,6 @@ public class TownyAnnouncer {
|
||||||
target = null;
|
target = null;
|
||||||
TownyAnnouncer.townChannel = null;
|
TownyAnnouncer.townChannel = null;
|
||||||
TownyAnnouncer.nationChannel = 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.architecture.Component;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
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.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -34,7 +32,7 @@ public class TownyComponent extends Component<PluginMain> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enable() {
|
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
|
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
|
Nations = TU.getNationsMap().values().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations
|
||||||
TBMCChatAPI.RegisterChatChannel(
|
TBMCChatAPI.RegisterChatChannel(
|
||||||
|
|
Loading…
Reference in a new issue