Merge branch 'development' into 'master'

2.2.1

See merge request Songoda/songodaupdater!16
This commit is contained in:
Jacob Scott 2019-10-10 01:05:59 +00:00
commit b1c4b8d84e
46 changed files with 2445 additions and 168 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "SongodaCore"
path: "/builds/$CI_PROJECT_PATH"
version: "2.1.10"
version: "2.2.1"
build:
stage: build

View File

@ -183,6 +183,7 @@
<scope>compile</scope>
</dependency>
<!-- End NMS -->
<!-- Start Plugin Hooks -->
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
@ -231,6 +232,49 @@
<version>4.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<version>1.9.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bgsoftware</groupId>
<artifactId>WildStacker</artifactId>
<version>2-9-0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>uk.antiperson</groupId>
<artifactId>stackmob</artifactId>
<version>4-0-2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gamingmesh</groupId>
<artifactId>jobs</artifactId>
<version>4.13.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.nossr50</groupId>
<artifactId>mcmmo</artifactId>
<version>2.1.50</version>
<scope>provided</scope>
</dependency>
<!-- End Plugin Hooks -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
@ -266,35 +310,5 @@
<artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<version>1.9.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bgsoftware</groupId>
<artifactId>WildStacker</artifactId>
<version>2-9-0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>uk.antiperson</groupId>
<artifactId>stackmob</artifactId>
<version>4-0-2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,7 +1,6 @@
package com.songoda.core;
import com.songoda.core.configuration.Config;
import com.songoda.core.configuration.ConfigFileConfigurationAdapter;
import com.songoda.core.locale.Locale;
import com.songoda.core.utils.Metrics;
import java.util.List;
@ -9,6 +8,7 @@ import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
/**
@ -44,11 +44,14 @@ public abstract class SongodaPlugin extends JavaPlugin {
public abstract List<Config> getExtraConfig();
@Override
public ConfigFileConfigurationAdapter getConfig() {
// todo? change prototype to FileConfiguration? This seems to cause development issues due to shading.
public FileConfiguration getConfig() {
return config.getFileConfig();
}
public Config getCoreConfig() {
return config;
}
@Override
public void reloadConfig() {
config.load();

View File

@ -9,29 +9,42 @@ import java.util.List;
public abstract class AbstractCommand {
private final boolean noConsole;
private boolean hasArgs = false;
private final CommandType _cmdType;
private final boolean _hasArgs;
private final List<String> _handledCommands = new ArrayList<>();
private final List<String> subCommand = new ArrayList<>();
protected AbstractCommand(boolean noConsole, String... command) {
this.subCommand.addAll(Arrays.asList(command));
this.noConsole = noConsole;
protected AbstractCommand(CommandType type, String... command) {
this._handledCommands.addAll(Arrays.asList(command));
this._hasArgs = false;
this._cmdType = type;
}
protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) {
this.subCommand.addAll(Arrays.asList(command));
protected AbstractCommand(CommandType type, boolean hasArgs, String... command) {
this._handledCommands.addAll(Arrays.asList(command));
this._hasArgs = hasArgs;
this._cmdType = type;
}
this.hasArgs = hasArgs;
this.noConsole = noConsole;
@Deprecated
protected AbstractCommand(boolean noConsole, String... command) {
this._handledCommands.addAll(Arrays.asList(command));
this._hasArgs = false;
this._cmdType = noConsole ? CommandType.PLAYER_ONLY : CommandType.CONSOLE_OK;
}
@Deprecated
protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) {
this._handledCommands.addAll(Arrays.asList(command));
this._hasArgs = hasArgs;
this._cmdType = noConsole ? CommandType.PLAYER_ONLY : CommandType.CONSOLE_OK;
}
public final List<String> getCommands() {
return Collections.unmodifiableList(subCommand);
return Collections.unmodifiableList(_handledCommands);
}
public final void addSubCommand(String command) {
subCommand.add(command);
_handledCommands.add(command);
}
protected abstract ReturnType runCommand(CommandSender sender, String... args);
@ -45,13 +58,14 @@ public abstract class AbstractCommand {
public abstract String getDescription();
public boolean hasArgs() {
return hasArgs;
return _hasArgs;
}
public boolean isNoConsole() {
return noConsole;
return _cmdType == CommandType.PLAYER_ONLY;
}
public static enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
public static enum ReturnType {SUCCESS, NEEDS_PLAYER, FAILURE, SYNTAX_ERROR}
public static enum CommandType {PLAYER_ONLY, CONSOLE_OK}
}

View File

@ -2,17 +2,9 @@ package com.songoda.core.commands;
import com.songoda.core.compatibility.ServerProject;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.utils.TextUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@ -21,20 +13,52 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class CommandManager implements CommandExecutor, TabCompleter {
private final JavaPlugin plugin;
private final HashMap<String, SimpleNestedCommand> commands = new HashMap<>();
private String msg_noConsole = ChatColor.RED + "You must be a player to use this command.";
private String msg_noPerms = ChatColor.RED + "You do not have permission to do that.";
private String msg_noCommand = ChatColor.GRAY + "The command you entered does not exist or is spelt incorrectly.";
private List<String> msg_syntaxError = Arrays.asList(
ChatColor.RED + "Invalid Syntax!",
ChatColor.GRAY + "The valid syntax is: " + ChatColor.GOLD + "%syntax%" + ChatColor.GRAY + "."
);
private boolean allowLooseCommands = false;
public CommandManager(JavaPlugin plugin) {
this.plugin = plugin;
}
public void setNoConsoleMessage(String msg_noConsole) {
this.msg_noConsole = msg_noConsole;
}
public void setNoPermsMessage(String msg_noPerms) {
this.msg_noPerms = msg_noPerms;
}
public void setNoCommandMessage(String msg_noCommand) {
this.msg_noCommand = msg_noCommand;
}
public void setSyntaxErrorMessage(List<String> msg_syntaxError) {
this.msg_syntaxError = msg_syntaxError;
}
public Set<String> getCommands() {
return Collections.unmodifiableSet(commands.keySet());
}
@ -62,9 +86,6 @@ public class CommandManager implements CommandExecutor, TabCompleter {
return this;
}
/**
* TODO: Test compatibility. Seems to fail in 1.8
*/
public SimpleNestedCommand registerCommandDynamically(AbstractCommand abstractCommand) {
SimpleNestedCommand nested = new SimpleNestedCommand(abstractCommand);
abstractCommand.getCommands().stream().forEach(cmd -> {
@ -96,14 +117,43 @@ public class CommandManager implements CommandExecutor, TabCompleter {
return nested;
}
public MainCommand addMainCommand(String command) {
MainCommand nested = new MainCommand(plugin, command);
commands.put(command.toLowerCase(), nested.nestedCommands);
PluginCommand pcmd = plugin.getCommand(command);
if (pcmd != null) {
pcmd.setExecutor(this);
pcmd.setTabCompleter(this);
} else {
plugin.getLogger().warning("Failed to register command: /" + command);
}
return nested;
}
public MainCommand getMainCommand(String command) {
SimpleNestedCommand nested = command == null ? null : commands.get(command.toLowerCase());
if (nested != null && nested.parent instanceof MainCommand) {
return (MainCommand) nested.parent;
}
return null;
}
public CommandManager addCommands(AbstractCommand... abstractCommands) {
for (AbstractCommand abstractCommand : abstractCommands)
for (AbstractCommand abstractCommand : abstractCommands) {
addCommand(abstractCommand);
}
return this;
}
public CommandManager setExecutor(String command) {
plugin.getCommand(command).setExecutor(this);
PluginCommand pcmd = command == null ? null : plugin.getCommand(command);
if (pcmd != null) {
pcmd.setExecutor(this);
} else {
plugin.getLogger().warning("Failed to register command: /" + command);
}
return this;
}
@ -138,21 +188,27 @@ public class CommandManager implements CommandExecutor, TabCompleter {
return true;
}
}
commandSender.sendMessage(TextUtils.formatText("&7The command you entered does not exist or is spelt incorrectly."));
commandSender.sendMessage(msg_noCommand);
return true;
}
private String getSubCommand(SimpleNestedCommand nested, String[] args) {
String cmd = args[0].toLowerCase();
if(nested.children.containsKey(cmd))
return cmd;
String match = null;
// support for two-argument subcommands
if(args.length >= 2 && nested.children.keySet().stream().anyMatch(k -> k.indexOf(' ') != -1)) {
cmd = String.join(" ", args[0], args[1]);
if(nested.children.containsKey(cmd))
if (nested.children.containsKey(cmd)) {
return cmd;
}
String match = null;
// support for mulit-argument subcommands
if (args.length >= 2 && nested.children.keySet().stream().anyMatch(k -> k.indexOf(' ') != -1)) {
for (int len = args.length; len > 1; --len) {
String cmd2 = String.join(" ", Arrays.copyOf(args, len)).toLowerCase();
if (nested.children.containsKey(cmd2)) {
return cmd2;
}
}
}
// if we don't have a subcommand, should we search for one?
if (allowLooseCommands) {
// do a "closest match"
@ -173,18 +229,21 @@ public class CommandManager implements CommandExecutor, TabCompleter {
private void processRequirements(AbstractCommand command, CommandSender sender, String[] args) {
if (!(sender instanceof Player) && command.isNoConsole()) {
sender.sendMessage("&cYou must be a player to use this command...");
sender.sendMessage(msg_noConsole);
return;
}
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
AbstractCommand.ReturnType returnType = command.runCommand(sender, args);
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
sender.sendMessage(TextUtils.formatText("&cInvalid Syntax!"));
sender.sendMessage(TextUtils.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
if (returnType == AbstractCommand.ReturnType.NEEDS_PLAYER) {
sender.sendMessage(msg_noConsole);
} else if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
for (String s : msg_syntaxError) {
sender.sendMessage(s.replace("%syntax%", command.getSyntax()));
}
}
return;
}
sender.sendMessage(TextUtils.formatText("&cYou do not have permission to do that."));
sender.sendMessage(msg_noPerms);
}
@Override
@ -228,6 +287,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
private List<String> fetchList(AbstractCommand abstractCommand, String[] args, CommandSender sender) {
List<String> list = abstractCommand.onTab(sender, args);
if (args.length != 0) {
String str = args[args.length - 1];
if (list != null && str != null && str.length() >= 1) {
try {
@ -235,6 +295,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
} catch (UnsupportedOperationException ignored) {
}
}
}
return list;
}

View File

@ -0,0 +1,117 @@
package com.songoda.core.commands;
import com.songoda.core.input.ClickableChat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class MainCommand extends AbstractCommand {
String header = null;
String description;
boolean sortHelp = false;
final String command;
final Plugin plugin;
protected final SimpleNestedCommand nestedCommands;
public MainCommand(Plugin plugin, String command) {
super(CommandType.CONSOLE_OK, command);
this.command = command;
this.plugin = plugin;
this.description = "Shows the command help page for /" + command;
this.nestedCommands = new SimpleNestedCommand(this);
}
public MainCommand setHeader(String header) {
this.header = header;
return this;
}
public MainCommand setDescription(String description) {
this.description = description;
return this;
}
public MainCommand setSortHelp(boolean sortHelp) {
this.sortHelp = sortHelp;
return this;
}
public MainCommand addSubCommand(AbstractCommand command) {
nestedCommands.addSubCommand(command);
return this;
}
public MainCommand addSubCommands(AbstractCommand... commands) {
nestedCommands.addSubCommands(commands);
return this;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
sender.sendMessage("");
if (header != null) {
sender.sendMessage(header);
} else {
sender.sendMessage(String.format("%s%s %s» %sVersion %s Created with <3 by %sSongoda",
ChatColor.AQUA.toString() + ChatColor.BOLD, plugin.getDescription().getName(),
ChatColor.DARK_GRAY.toString(), ChatColor.GRAY.toString(), plugin.getDescription().getVersion(),
ChatColor.DARK_PURPLE.toString() + ChatColor.BOLD + ChatColor.ITALIC
));
}
if (nestedCommands != null) {
ArrayList<String> commands = new ArrayList(nestedCommands.children.keySet());
if (sortHelp) {
Collections.sort(commands);
}
boolean isPlayer = sender instanceof Player;
// todo? pagation if commands.size is too large? (player-only)
sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.GREEN + getSyntax() + ChatColor.GRAY + " - " + getDescription());
for (String cmdStr : commands) {
final AbstractCommand cmd = nestedCommands.children.get(cmdStr);
if (!isPlayer) {
sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.GREEN + cmd.getSyntax() + ChatColor.GRAY + " - " + cmd.getDescription());
} else if (cmd.getPermissionNode() == null || sender.hasPermission(cmd.getPermissionNode())) {
ClickableChat msg = new ClickableChat();
final String c = "/" + command + " ";
msg.addMessage(ChatColor.DARK_GRAY + "- ")
.addPromptCommand(ChatColor.GREEN + c + cmd.getSyntax(), ChatColor.GREEN + c + cmdStr, c + cmdStr)
.addMessage(ChatColor.GRAY + " - " + cmd.getDescription());
msg.sendTo((Player) sender);
}
}
}
sender.sendMessage("");
return ReturnType.SUCCESS;
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
// don't need to worry about tab for a root command - handled by the manager
return null;
}
@Override
public String getPermissionNode() {
// permissions for a root command should be handled in the plugin.yml
return null;
}
@Override
public String getSyntax() {
return "/" + command;
}
@Override
public String getDescription() {
return description;
}
}

View File

@ -0,0 +1,192 @@
package com.songoda.core.commands;
import com.songoda.core.compatibility.EntityNamespace;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SelectorArguments {
static Pattern selectorPattern = Pattern.compile("^(@[apers])(\\[(.*?)\\])?$");
static Pattern selectorRangePattern = Pattern.compile("^([0-9]{1,9}(\\.[0-9]{1,9})?)?(\\.\\.)?([0-9]{1,9}(\\.[0-9]{1,9})?)?$");
/**
* Parse a command selector using Minecraft's selector format. <br>
* Currently only supports distance and entity type
*
* @param sender CommandBlock or Player running the command
* @param argument argument with the selector to parse
* @return SelectorArguments Object for grabbing the list of entities, or null if the selector is invalid
*/
@Nullable
public static SelectorArguments parseSelector(@NotNull CommandSender sender, @NotNull String argument) {
if (!(sender instanceof BlockCommandSender || sender instanceof Player)) {
return null;
}
Matcher m = selectorPattern.matcher(argument);
if (!m.find()) {
return null;
}
SelectorType type = SelectorType.getType(m.group(1));
if (type == null) {
return null;
}
SelectorArguments selector = new SelectorArguments(sender, type);
if (m.group(3) != null) {
selector.parseArguments(m.group(3));
}
return selector;
}
protected final CommandSender sender;
protected final SelectorType selector;
protected double rangeMin = 0, rangeMax = Double.POSITIVE_INFINITY;
protected EntityType entityType;
public SelectorArguments(CommandSender sender, SelectorType type) {
this.sender = sender;
this.selector = type;
}
private void parseArguments(String selectorArgs) {
String[] args = selectorArgs.split(",");
for (String s : args) {
if (s.contains("=")) {
String[] v = s.split("=");
if (v[0].equals("distance")) {
// 10 = d == 10
// 10..12 = d > 10 && d <= 12
// 5.. = d >= 5
// ..5 = d <= 15
Matcher distGroup = selectorRangePattern.matcher(v[1]);
if (distGroup.find()) {
if (distGroup.group(1) != null) {
rangeMin = Double.parseDouble(distGroup.group(1));
}
if (distGroup.group(3) == null) {
rangeMax = rangeMin;
} else if (distGroup.group(4) != null) {
rangeMax = Double.parseDouble(distGroup.group(4));
}
}
} else if (v[0].equals("type")) {
entityType = EntityNamespace.minecraftToBukkit(v[1]);
}
// more arguments can be parsed here (TODO)
}
}
/*
advancements Advancement earned by entity.
distance Distance to entity.
dx Entities between x and x + dx.
dy Entities between y and y + dy.
dz Entities between z and z + dz.
gamemode Players with gamemode. It can be one of the following values: adventure, creative, spectator, survival, !adventure, !creative, !spectator, !survival
level Experience level. It must be an integer value that is 0 or greater.
limit Maximum number of entities to target. It must be an integer value that is 1 or greater.
name Entity name.
nbt NBT tag.
scores Score.
sort Sort the entities. It must be one of the following values: arbitrary, furthest, nearest, random
tag Scoreboard tag.
team Entities on team.
type Entity type (target must be the specified entity type - https://www.digminecraft.com/lists/entity_list_pc.php ).
x Entity's x-coordinate position.
x_rotation Entity's x rotation (vertical rotation).
y Entity's y-coordinate position.
y_rotation Entity's y rotation (horizontal rotation).
z Entity's z-coordinate position.
target selector arguments are case-sensitive
@e[type=cow,limit=5]
*/
}
public Collection<Entity> getSelection() {
final Location location = sender instanceof Player ? ((Player) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation();
Collection<Entity> list = preSelect(location);
if (list.isEmpty()) {
return list;
}
List<Entity> list2 = filter(location, list);
if (list2.isEmpty()) {
return list2;
}
switch (selector) {
case PLAYER:
Collections.sort(list2, (o1, o2) -> (int) (o1.getLocation().distanceSquared(location) - o2.getLocation().distanceSquared(location)));
return Arrays.asList(list2.get(0));
case RANDOM_PLAYER:
Collections.shuffle(list2);
return Arrays.asList(list2.get(0));
case ALL_PLAYER:
case ALL_ENTITIES:
case SELF:
return list2;
}
return list2;
}
protected Collection<Entity> preSelect(Location location) {
switch (selector) {
case PLAYER:
case RANDOM_PLAYER:
case ALL_PLAYER:
return rangeMax == Double.POSITIVE_INFINITY
? location.getWorld().getEntitiesByClasses(Player.class)
: location.getWorld().getNearbyEntities(location, rangeMax * 2, rangeMax * 2, rangeMax * 2).stream()
.filter(e -> e instanceof Player).collect(Collectors.toSet());
case ALL_ENTITIES:
return rangeMax == Double.POSITIVE_INFINITY
? location.getWorld().getEntities()
: location.getWorld().getNearbyEntities(location, rangeMax * 2, rangeMax * 2, rangeMax * 2);
case SELF:
return sender instanceof Entity ? Arrays.asList((Entity) sender) : Collections.EMPTY_LIST;
}
return Collections.EMPTY_LIST;
}
protected List<Entity> filter(Location location, Collection<Entity> list) {
Stream<Entity> stream = list.stream()
.filter(p -> rangeMin == 0 || p.getLocation().distance(location) > rangeMin)
.filter(e -> entityType == null || e.getType() == entityType);
return stream.collect(Collectors.toList());
}
public static enum SelectorType {
PLAYER, RANDOM_PLAYER, ALL_PLAYER, ALL_ENTITIES, SELF;
public static SelectorType getType(String str) {
if (str != null) {
switch (str.toLowerCase()) {
case "@p":
return PLAYER;
case "@r":
return RANDOM_PLAYER;
case "@a":
return ALL_PLAYER;
case "@e":
return ALL_ENTITIES;
case "@s":
return SELF;
}
}
return null;
}
}
}

View File

@ -1,12 +1,12 @@
package com.songoda.core.commands;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.stream.Stream;
public class SimpleNestedCommand {
final AbstractCommand parent;
final HashMap<String, AbstractCommand> children = new HashMap();
final LinkedHashMap<String, AbstractCommand> children = new LinkedHashMap();
protected SimpleNestedCommand(AbstractCommand parent) {
this.parent = parent;

View File

@ -140,7 +140,7 @@ public enum CompatibleSound {
BLOCK_METAL_PRESSURE_PLATE_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_METAL_PRESSUREPLATE_CLICK_ON"), v("WOOD_CLICK", true)),
BLOCK_METAL_STEP(ServerVersion.V1_9, v("STEP_STONE", true)),
BLOCK_NETHER_WART_BREAK,
BLOCK_NOTE_BLOCK_BANJO(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_GUITAR", true), v(ServerVersion.V1_9, "BLOCK_NOTE_GUITAR", true), v("NOTE_BASS_GUITAR", true)),
BLOCK_NOTE_BLOCK_BANJO(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_GUITAR", true), v(ServerVersion.V1_12, "BLOCK_NOTE_GUITAR", true), v(ServerVersion.V1_9, "BLOCK_NOTE_BASS"), v("NOTE_BASS_GUITAR", true)),
BLOCK_NOTE_BLOCK_BASEDRUM(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_BASEDRUM"), v("NOTE_BASS_DRUM")),
BLOCK_NOTE_BLOCK_BASS(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_BASS"), v("NOTE_BASS")),
BLOCK_NOTE_BLOCK_BELL(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_BELL"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_PLING", true)),
@ -152,7 +152,7 @@ public enum CompatibleSound {
BLOCK_NOTE_BLOCK_GUITAR(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_GUITAR"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_BASS_GUITAR")), // This value disappeared from the API from 1.9-1.11 (returned in 12)
BLOCK_NOTE_BLOCK_HARP(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_HARP"), v("NOTE_PIANO")),
BLOCK_NOTE_BLOCK_HAT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_HAT"), v("NOTE_STICKS")),
BLOCK_NOTE_BLOCK_IRON_XYLOPHONE(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_XYLOPHONE", true), v(ServerVersion.V1_9, "BLOCK_NOTE_XYLOPHONE", true), v("NOTE_PLING", true)),
BLOCK_NOTE_BLOCK_IRON_XYLOPHONE(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_XYLOPHONE", true), v(ServerVersion.V1_12, "BLOCK_NOTE_XYLOPHONE"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)),
BLOCK_NOTE_BLOCK_PLING(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_PLING"), v("NOTE_PLING")),
BLOCK_NOTE_BLOCK_SNARE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_SNARE"), v("NOTE_SNARE_DRUM")),
BLOCK_NOTE_BLOCK_XYLOPHONE(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_XYLOPHONE"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)),
@ -173,8 +173,8 @@ public enum CompatibleSound {
BLOCK_SCAFFOLDING_HIT,
BLOCK_SCAFFOLDING_PLACE,
BLOCK_SCAFFOLDING_STEP,
BLOCK_SHULKER_BOX_CLOSE("CHEST_CLOSE"),
BLOCK_SHULKER_BOX_OPEN("CHEST_OPEN"),
BLOCK_SHULKER_BOX_CLOSE(v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_CLOSE"), v("CHEST_CLOSE")),
BLOCK_SHULKER_BOX_OPEN(v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_OPEN"), v("CHEST_OPEN")),
BLOCK_SLIME_BLOCK_BREAK(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_BREAK"), v(null, true)),
BLOCK_SLIME_BLOCK_FALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_FALL"), v(null, true)),
BLOCK_SLIME_BLOCK_HIT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_HIT"), v(null, true)),
@ -430,11 +430,11 @@ public enum CompatibleSound {
ENTITY_LIGHTNING_BOLT_THUNDER(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_LIGHTNING_THUNDER"), v("AMBIENCE_THUNDER")),
ENTITY_LINGERING_POTION_THROW,
ENTITY_LLAMA_AMBIENT,
ENTITY_LLAMA_ANGRY,
ENTITY_LLAMA_ANGRY(v(ServerVersion.V1_11, "ENTITY_HORSE_ANGRY"), v("HORSE_ANGRY")),
ENTITY_LLAMA_CHEST,
ENTITY_LLAMA_DEATH,
ENTITY_LLAMA_EAT("EAT"),
ENTITY_LLAMA_HURT,
ENTITY_LLAMA_DEATH(v(ServerVersion.V1_11, "ENTITY_HORSE_DEATH"), v("HORSE_DEATH")),
ENTITY_LLAMA_EAT(v(ServerVersion.V1_11, "ENTITY_HORSE_EAT"), v("EAT")),
ENTITY_LLAMA_HURT(v(ServerVersion.V1_11, "ENTITY_HORSE_HURT"), v("HORSE_HIT")),
ENTITY_LLAMA_SPIT,
ENTITY_LLAMA_STEP,
ENTITY_LLAMA_SWAG,

View File

@ -0,0 +1,85 @@
package com.songoda.core.compatibility;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.EntityType;
public class EntityNamespace {
static final HashMap<String, EntityType> validTypes = new HashMap();
static final HashMap<String, String> legacyToModernTypes = new HashMap() {
{
put("xporb", "experience_orb");
put("xp_orb", "experience_orb");
put("leashknot", "leash_knot");
put("smallfireball", "small_fireball");
put("thrownenderpearl", "ender_pearl");
put("eyeofendersignal", "eye_of_ender");
put("eye_of_ender_signal", "eye_of_ender");
put("thrownexpbottle", "experience_bottle");
put("xp_bottle", "experience_bottle");
put("itemframe", "item_frame");
put("witherskull", "wither_skull");
put("primedtnt", "tnt");
put("fallingsand", "falling_block");
put("fireworksrocketentity", "firework_rocket");
put("fireworks_rocket", "firework_rocket");
put("spectralarrow", "spectral_arrow");
put("tippedarrow", "arrow");
put("shulkerbullet", "shulker_bullet");
put("dragonfireball", "dragon_fireball");
put("armorstand", "armor_stand");
put("minecartcommandblock", "command_block_minecart");
put("commandblock_minecart", "command_block_minecart");
put("minecartrideable", "minecart");
put("minecartchest", "chest_minecart");
put("minecartfurnace", "furnace_minecart");
put("minecarttnt", "tnt_minecart");
put("minecarthopper", "hopper_minecart");
put("minecartmobspawner", "spawner_minecart");
put("pigzombie", "zombie_pigman");
put("cavespider", "cave_spider");
put("lavaslime", "magma_cube");
put("enderdragon", "ender_dragon");
put("witherboss", "wither");
put("mushroomcow", "mooshroom");
put("snowman", "snow_golem");
put("snowman", "snow_golem");
put("ozelot", "ocelot");
put("villagergolem", "iron_golem");
put("villager_golem", "iron_golem");
put("entityhorse", "horse");
put("endercrystal", "end_crystal");
put("ender_crystal", "end_crystal");
}
};
static {
for (EntityType t : EntityType.values()) {
if (t.getName() != null) {
validTypes.put(t.getName().toLowerCase(), t);
}
}
}
public static EntityType minecraftToBukkit(String entity) {
if (entity == null) {
return null;
}
// first try to translate natively
EntityType type = EntityType.fromName(entity);
if (type == null) {
// try legacy values
type = EntityType.fromName(legacyToModernTypes.get(entity));
// try converting modern to legacy
if (type == null && legacyToModernTypes.containsValue(entity)) {
for (Map.Entry<String, String> e : legacyToModernTypes.entrySet()) {
if (e.getValue().equals(entity) && (type = EntityType.fromName(legacyToModernTypes.get(e.getKey()))) != null) {
return type;
}
}
}
}
return type;
}
}

View File

@ -87,9 +87,8 @@ public class Config extends ConfigSection {
boolean autoremove = false;
/**
* load comments when loading the file
* TODO
*/
boolean loadComments = false;
boolean loadComments = true;
/**
* Default comment applied to config nodes
*/
@ -440,7 +439,6 @@ public class Config extends ConfigSection {
}
protected void parseComments(@NotNull String contents, @NotNull Map<?, ?> input) {
// TODO?
// if starts with a comment, load all nonbreaking comments as a header
// then load all comments and assign to the next valid node loaded
// (Only load comments that are on their own line)

View File

@ -106,12 +106,18 @@ public class ConfigSetting {
@NotNull
public CompatibleMaterial getMaterial() {
CompatibleMaterial m = getMaterial(null);
return m != null ? m : CompatibleMaterial.STONE;
String val = config.getString(key);
CompatibleMaterial mat = CompatibleMaterial.getMaterial(config.getString(key));
if (mat == null) {
System.out.println(String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
}
@Nullable
public CompatibleMaterial getMaterial(@Nullable CompatibleMaterial def) {
return mat != null ? mat : CompatibleMaterial.STONE;
}
@NotNull
public CompatibleMaterial getMaterial(@NotNull CompatibleMaterial def) {
//return config.getMaterial(key, def);
String val = config.getString(key);
CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;

View File

@ -36,7 +36,7 @@ public class PluginConfigGui extends SimplePagedGui {
this.plugin = plugin;
// collect list of plugins
configs.put(plugin.getConfig().getCoreConfig().getFile().getName(), plugin.getConfig().getCoreConfig());
configs.put(plugin.getCoreConfig().getFile().getName(), plugin.getCoreConfig());
List<Config> more = plugin.getExtraConfig();
if (more != null && !more.isEmpty()) {
for (Config cfg : more) {

View File

@ -1,13 +1,14 @@
package com.songoda.core.core;
import com.songoda.core.locale.Locale;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class LocaleModule implements PluginInfoModule {
@ -25,7 +26,7 @@ public class LocaleModule implements PluginInfoModule {
}
}
} catch (IOException e) {
e.printStackTrace();
Logger.getLogger(LocaleModule.class.getName()).log(Level.INFO, "Failed to check for locale files: " + e.getMessage());
}
}

View File

@ -5,6 +5,8 @@ import com.songoda.core.gui.methods.Clickable;
import com.songoda.core.nms.CoreNMS;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.NmsManager;
import java.util.Arrays;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
@ -22,6 +24,7 @@ public class AnvilGui extends Gui {
final Player player;
CustomAnvil anvil;
List<String> endPrompt = null;
public AnvilGui(Player player) {
this.player = player;
@ -58,6 +61,28 @@ public class AnvilGui extends Gui {
return (AnvilGui) this.setItem(2, item);
}
public AnvilGui setOutputPrompt(String str) {
endPrompt = Arrays.asList(str);
return this;
}
public AnvilGui setOutputPrompt(String ... str) {
endPrompt = Arrays.asList(str);
return this;
}
public AnvilGui setOutputPrompt(List<String> str) {
endPrompt = str;
return this;
}
void updateOutputPrompt() {
final ItemStack in;
if(endPrompt != null && (in = cellItems.get(0)) != null) {
setItem(2, GuiUtils.createButtonItem(in, endPrompt));
}
}
public ItemStack getOutput() {
return this.getItem(2);
}
@ -78,7 +103,8 @@ public class AnvilGui extends Gui {
} else if ((item = cellItems.get(1)) != null) {
inventory.setItem(1, item);
} else if (!acceptsItems) {
inventory.setItem(0, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, " ", " "));
cellItems.put(0, item = GuiUtils.createButtonItem(CompatibleMaterial.PAPER, " ", " "));
inventory.setItem(0, item);
}
if ((item = cellItems.get(2)) != null) {
inventory.setItem(2, item);
@ -95,6 +121,7 @@ public class AnvilGui extends Gui {
anvil.setCustomTitle(title);
anvil.setLevelCost(0);
inventory = anvil.getInventory();
anvil.setOnChange(this::updateOutputPrompt);
}
}
}

View File

@ -47,6 +47,11 @@ public class DoubleGui extends Gui {
allowDropItems = false;
}
public DoubleGui(Gui parent) {
super(parent);
allowDropItems = false;
}
public int getPlayerRows() {
return playerRows;
}
@ -85,6 +90,38 @@ public class DoubleGui extends Gui {
return this;
}
public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) {
final int last = invOffset(cellLast);
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
unlockedCells.put(cell, true);
}
return this;
}
public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast, boolean open) {
final int last = invOffset(cellLast);
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
unlockedCells.put(cell, open);
}
return this;
}
public DoubleGui setPlayerUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) {
final int last = invOffset(cellColLast + cellRowLast * 9);
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
unlockedCells.put(cell, true);
}
return this;
}
public DoubleGui setPlayerUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) {
final int last = invOffset(cellColLast + cellRowLast * 9);
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
unlockedCells.put(cell, open);
}
return this;
}
public DoubleGui setPlayerItem(int cell, ItemStack item) {
cellItems.put(invOffset(cell), item);
if (open && cell >= 0 && cell < 36) {

View File

@ -181,6 +181,14 @@ public class Gui {
return this;
}
@NotNull
public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) {
for (int cell = cellFirst; cell <= cellLast; ++cell) {
unlockedCells.put(cell, open);
}
return this;
}
@NotNull
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) {
final int last = cellColLast + cellRowLast * 9;
@ -190,6 +198,15 @@ public class Gui {
return this;
}
@NotNull
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) {
final int last = cellColLast + cellRowLast * 9;
for (int cell = cellColFirst + cellRowFirst * 9; cell <= last; ++cell) {
unlockedCells.put(cell, open);
}
return this;
}
@NotNull
public Gui setUnlocked(int cell, boolean open) {
unlockedCells.put(cell, open);
@ -772,8 +789,8 @@ public class Gui {
protected static String trimTitle(String title) {
if(title == null) {
return "";
} else if (title != null && title.length() > 32) {
return title.substring(0, 31);
} else if (title.length() > 32) {
return title.charAt(30) == '\u00A7' ? title.substring(0, 30) : title.substring(0, 31);
}
return title;
}

View File

@ -179,6 +179,9 @@ public class GuiManager {
for(ItemStack it : gui.inventory.getContents()) {
if(!gui.unlockedCells.getOrDefault(cell++, false) && clicked.isSimilar(it)) {
event.setCancelled(true);
if(gui instanceof AnvilGui) {
((AnvilGui) gui).anvil.update();
}
break;
}
}
@ -203,6 +206,9 @@ public class GuiManager {
player.playSound(player.getLocation(), CompatibleSound.UI_BUTTON_CLICK.getSound(), 1F, 1F);
} else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
event.setCancelled(true);
if(gui instanceof AnvilGui) {
((AnvilGui) gui).anvil.update();
}
}
}
}

View File

@ -0,0 +1,232 @@
package com.songoda.core.hooks;
import com.songoda.core.hooks.jobs.JobsHandler;
import com.songoda.core.hooks.jobs.JobsPlayerHandler;
import java.util.Collections;
import java.util.List;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class JobsHook {
static boolean canHook;
static {
try {
// if this class exists, we're good to use Jobs classes
Class.forName("com.gamingmesh.jobs.Jobs");
canHook = true;
} catch (ClassNotFoundException ex) {
}
}
public static JobsPlayerHandler getPlayer(Player player) {
if (canHook) {
return JobsPlayerHandler.loadPlayer(player);
}
return null;
}
public static boolean isEnabled() {
return canHook;
}
public static List<String> getAllJobs() {
if (canHook) {
return JobsHandler.getJobs();
}
return Collections.EMPTY_LIST;
}
public static double getBoostExp(Player player, String job) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
return jPlayer.getBoostExp(job);
}
return -1;
}
public static double getBoostMoney(Player player, String job) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
return jPlayer.getBoostMoney(job);
}
return -1;
}
public static double getBoostPoints(Player player, String job) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
return jPlayer.getBoostPoints(job);
}
return -1;
}
public static void promoteJob(Player player, String job) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.promoteJob(job);
}
}
public static void promoteJob(Player player, String job, int levels) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.promoteJob(job, levels);
}
}
public static void demoteJob(Player player, String job) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.demoteJob(job);
}
}
public static void demoteJob(Player player, String job, int levels) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.demoteJob(job, levels);
}
}
public static void joinJob(Player player, String job) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.joinJob(job);
}
}
public static void leaveAllJobs(Player player) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.leaveAllJobs();
}
}
public static void leaveJob(Player player, String job) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.leaveJob(job);
}
}
public static int getTotalLevels(Player player) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
return jPlayer.getTotalLevels();
}
return -1;
}
public static int getMaxBrewingStandsAllowed(Player player) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
return jPlayer.getMaxBrewingStandsAllowed();
}
return -1;
}
public static int getMaxFurnacesAllowed(Player player) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
return jPlayer.getMaxFurnacesAllowed();
}
return -1;
}
public static List<String> getJobs(Player player) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
return jPlayer.getJobs();
}
return Collections.EMPTY_LIST;
}
public static void eatItem(Player player, ItemStack item) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.eatItem(item);
}
}
public static void breakBlock(Player player, Block block) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.breakBlock(block);
}
}
public static void tntBreakBlock(Player player, Block block) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.tntBreakBlock(block);
}
}
public static void placeBlock(Player player, Block block) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.placeBlock(block);
}
}
public static void placeEntity(Player player, Entity block) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.placeEntity(block);
}
}
public static void breakEntity(Player player, Entity block) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.breakEntity(block);
}
}
public static void breedEntity(Player player, LivingEntity entity) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.breedEntity(entity);
}
}
public static void killEntity(Player player, LivingEntity entity) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.killEntity(entity);
}
}
public static void tameEntity(Player player, LivingEntity entity) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.tameEntity(entity);
}
}
public static void catchFish(Player player, ItemStack items) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.catchFish(items);
}
}
public static void killEntity(Player player, LivingEntity entity, Entity damageSource) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.killEntity(entity, damageSource);
}
}
public static void itemEnchanted(Player player, ItemStack resultStack) {
JobsPlayerHandler jPlayer = getPlayer(player);
if (jPlayer != null) {
jPlayer.itemEnchanted(resultStack);
}
}
}

View File

@ -0,0 +1,230 @@
package com.songoda.core.hooks;
import com.songoda.core.hooks.mcmmo.McMMOHandler;
import java.util.Collection;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public class McMMOHook {
static boolean canHook = false;
static {
try {
// if this class exists, we're good to use McMMO
Class.forName("com.gmail.nossr50.api.AbilityAPI");
canHook = true;
} catch (ClassNotFoundException ex) {
}
}
public static void addMining(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addMining(player, blocks);
}
}
public static void addExcavation(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addExcavation(player, blocks);
}
}
public static void addHerbalism(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addHerbalism(player, blocks);
}
}
public static void addWoodcutting(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addWoodcutting(player, blocks);
}
}
public static int getAcrobaticsSkill(Player player) {
return canHook ? McMMOHandler.getAcrobaticsSkill(player) : -1;
}
public static int getAlchemySkill(Player player) {
return canHook ? McMMOHandler.getAlchemySkill(player) : -1;
}
public static int getArcherySkill(Player player) {
return canHook ? McMMOHandler.getArcherySkill(player) : -1;
}
public static int getAxesSkill(Player player) {
return canHook ? McMMOHandler.getAxesSkill(player) : -1;
}
public static int getExcavationSkill(Player player) {
return canHook ? McMMOHandler.getExcavationSkill(player) : -1;
}
public static int getFishingSkill(Player player) {
return canHook ? McMMOHandler.getFishingSkill(player) : -1;
}
public static int getHerbalismSkill(Player player) {
return canHook ? McMMOHandler.getHerbalismSkill(player) : -1;
}
public static int getMiningSkill(Player player) {
return canHook ? McMMOHandler.getMiningSkill(player) : -1;
}
public static int getRepairSkill(Player player) {
return canHook ? McMMOHandler.getRepairSkill(player) : -1;
}
public static int getSmeltingSkill(Player player) {
return canHook ? McMMOHandler.getSmeltingSkill(player) : -1;
}
public static int getSwordsSkill(Player player) {
return canHook ? McMMOHandler.getSwordsSkill(player) : -1;
}
public static int getTamingSkill(Player player) {
return canHook ? McMMOHandler.getTamingSkill(player) : -1;
}
public static int getUnarmedSkill(Player player) {
return canHook ? McMMOHandler.getUnarmedSkill(player) : -1;
}
public static int getWoodcuttingSkill(Player player) {
return canHook ? McMMOHandler.getWoodcuttingSkill(player) : -1;
}
public static void addAcrobatics(Player player, int xp) {
if (canHook) {
McMMOHandler.addAcrobatics(player, xp);
}
}
public static void addAlchemy(Player player, int xp) {
if (canHook) {
McMMOHandler.addAlchemy(player, xp);
}
}
public static void addArchery(Player player, int xp) {
if (canHook) {
McMMOHandler.addArchery(player, xp);
}
}
public static void addAxes(Player player, int xp) {
if (canHook) {
McMMOHandler.addAxes(player, xp);
}
}
public static void addExcavation(Player player, int xp) {
if (canHook) {
McMMOHandler.addExcavation(player, xp);
}
}
public static void addFishing(Player player, int xp) {
if (canHook) {
McMMOHandler.addFishing(player, xp);
}
}
public static void addHerbalism(Player player, int xp) {
if (canHook) {
McMMOHandler.addHerbalism(player, xp);
}
}
public static void addMining(Player player, int xp) {
if (canHook) {
McMMOHandler.addMining(player, xp);
}
}
public static void addRepair(Player player, int xp) {
if (canHook) {
McMMOHandler.addRepair(player, xp);
}
}
public static void addSmelting(Player player, int xp) {
if (canHook) {
McMMOHandler.addSmelting(player, xp);
}
}
public static void addSwords(Player player, int xp) {
if (canHook) {
McMMOHandler.addSwords(player, xp);
}
}
public static void addTaming(Player player, int xp) {
if (canHook) {
McMMOHandler.addTaming(player, xp);
}
}
public static void addUnarmed(Player player, int xp) {
if (canHook) {
McMMOHandler.addUnarmed(player, xp);
}
}
public static void addWoodcutting(Player player, int xp) {
if (canHook) {
McMMOHandler.addWoodcutting(player, xp);
}
}
public static boolean hasHerbalismDoubleDrops(Player player) {
return canHook ? McMMOHandler.hasHerbalismDoubleDrops(player) : false;
}
public static boolean hasMiningDoubleDrops(Player player) {
return canHook ? McMMOHandler.hasMiningDoubleDrops(player) : false;
}
public static boolean hasWoodcuttingDoubleDrops(Player player) {
return canHook ? McMMOHandler.hasWoodcuttingDoubleDrops(player) : false;
}
public static boolean isUsingBerserk(Player player) {
return canHook ? McMMOHandler.isUsingBerserk(player) : false;
}
public static boolean isUsingGigaDrill(Player player) {
return canHook ? McMMOHandler.isUsingGigaDrill(player) : false;
}
public static boolean isUsingGreenTerra(Player player) {
return canHook ? McMMOHandler.isUsingGreenTerra(player) : false;
}
public static boolean isUsingSerratedStrikes(Player player) {
return canHook ? McMMOHandler.isUsingSerratedStrikes(player) : false;
}
public static boolean isUsingSkullSplitter(Player player) {
return canHook ? McMMOHandler.isUsingSkullSplitter(player) : false;
}
public static boolean isUsingSuperBreaker(Player player) {
return canHook ? McMMOHandler.isUsingSuperBreaker(player) : false;
}
public static boolean isUsingTreeFeller(Player player) {
return canHook ? McMMOHandler.isUsingTreeFeller(player) : false;
}
public static boolean isBleeding(LivingEntity victim) {
return canHook ? McMMOHandler.isBleeding(victim) : false;
}
}

View File

@ -1,8 +1,14 @@
package com.songoda.core.hooks;
import com.songoda.core.hooks.worldguard.WorldGuardFlagHandler;
import com.songoda.core.hooks.worldguard.WorldGuardRegionHandler;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class WorldGuardHook {
@ -24,7 +30,7 @@ public class WorldGuardHook {
* @param flag name of the flag to set
* @param state default value of the flag
*/
public static void addHook(String flag, boolean state) {
public static void addHook(@NotNull String flag, boolean state) {
if(canHook) {
WorldGuardFlagHandler.addHook(flag, state);
}
@ -47,7 +53,8 @@ public class WorldGuardHook {
* @param flag ALLOW/DENY flag to check
* @return flag state, or null if undefined
*/
public static Boolean getBooleanFlag(Location l, String flag) {
@Nullable
public static Boolean getBooleanFlag(@NotNull Location l, @NotNull String flag) {
return canHook ? WorldGuardFlagHandler.getBooleanFlag(l, flag) : null;
}
@ -58,7 +65,66 @@ public class WorldGuardHook {
* @param flag ALLOW/DENY flag to check
* @return flag state, or null if undefined
*/
public static Boolean getBooleanFlag(Chunk c, String flag) {
@Nullable
public static Boolean getBooleanFlag(@NotNull Chunk c, @NotNull String flag) {
return canHook ? WorldGuardFlagHandler.getBooleanFlag(c, flag) : null;
}
/**
* Check to see if the pvp flag is set and is set to ALLOW
*
* @param loc Location to check
* @return false if the pvp flag is not set for this region, or is set to DENY
*/
public static boolean isPvpAllowed(@NotNull Location loc) {
return canHook ? Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "pvp"), Boolean.TRUE) : false;
}
/**
* Check to see if the block-break flag is set and is set to ALLOW
*
* @param loc Location to check
* @return false if the block-break flag is not set for this region, or is set to DENY
*/
public boolean isBreakAllowed(@NotNull Location loc) {
return canHook ? Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "block-break"), Boolean.TRUE) : false;
}
/**
* Check to see if the other-explosion flag is set and is set to ALLOW
*
* @param loc Location to check
* @return false if the other-explosion flag is not set for this region, or is set to DENY
*/
public boolean isExplosionsAllowed(@NotNull Location loc) {
return canHook ? Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "other-explosion"), Boolean.TRUE) : false;
}
/**
* Check to see if the mob-spawning flag is set and is set to ALLOW
*
* @param loc Location to check
* @return false if the mob-spawning flag is not set for this region, or is set to DENY
*/
public boolean isMobSpawningAllowed(@NotNull Location loc) {
return canHook ? Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "mob-spawning"), Boolean.TRUE) : false;
}
/**
* @param loc Location to check
* @return A list of regions that contain this location.
*/
@NotNull
public static List<String> getRegionNames(@NotNull Location loc) {
return canHook ? WorldGuardRegionHandler.getRegionNames(loc) : Collections.EMPTY_LIST;
}
/**
* @param c Chunk to check
* @return A list of regions that contain any part of this chunk.
*/
@NotNull
public static List<String> getRegionNames(@NotNull Chunk c) {
return canHook ? WorldGuardRegionHandler.getRegionNames(c) : Collections.EMPTY_LIST;
}
}

View File

@ -1,15 +1,15 @@
package com.songoda.core.hooks.economies;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
public class PlayerPointsEconomy extends Economy {
private final PlayerPoints playerPoints;
public PlayerPointsEconomy() {
this.playerPoints = (PlayerPoints) Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints");
public PlayerPointsEconomy(Plugin plugin) {
this.playerPoints = (PlayerPoints) plugin;
}
private int convertAmount(double amount) {

View File

@ -0,0 +1,12 @@
package com.songoda.core.hooks.jobs;
import com.gamingmesh.jobs.Jobs;
import java.util.List;
import java.util.stream.Collectors;
public class JobsHandler {
public static List<String> getJobs() {
return Jobs.getJobs().stream().map(j -> j.getName()).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,182 @@
package com.songoda.core.hooks.jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.BlockActionInfo;
import com.gamingmesh.jobs.actions.CustomKillInfo;
import com.gamingmesh.jobs.actions.EnchantActionInfo;
import com.gamingmesh.jobs.actions.EntityActionInfo;
import com.gamingmesh.jobs.actions.ItemActionInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class JobsPlayerHandler {
protected final JobsPlayer jPlayer;
protected JobsPlayerHandler(JobsPlayer jPlayer) {
this.jPlayer = jPlayer;
}
public static JobsPlayerHandler loadPlayer(Player player) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
return jPlayer != null ? new JobsPlayerHandler(jPlayer) : null;
}
public double getBoostExp(String job) {
return jPlayer.getBoost(job, CurrencyType.EXP);
}
public double getBoostMoney(String job) {
return jPlayer.getBoost(job, CurrencyType.MONEY);
}
public double getBoostPoints(String job) {
return jPlayer.getBoost(job, CurrencyType.POINTS);
}
public void promoteJob(String jobName) {
Job job = Jobs.getJob(jobName);
if (job != null) {
jPlayer.promoteJob(job, 1);
}
}
public void promoteJob(String jobName, int levels) {
Job job = Jobs.getJob(jobName);
if (job != null) {
jPlayer.promoteJob(job, levels);
}
}
public void demoteJob(String jobName) {
Job job = Jobs.getJob(jobName);
if (job != null) {
jPlayer.demoteJob(job, 1);
}
}
public void demoteJob(String jobName, int levels) {
Job job = Jobs.getJob(jobName);
if (job != null) {
jPlayer.demoteJob(job, levels);
}
}
public void joinJob(String jobName) {
Job job = Jobs.getJob(jobName);
if (job != null) {
jPlayer.joinJob(job);
}
}
public void leaveAllJobs() {
jPlayer.leaveAllJobs();
}
public void leaveJob(String jobName) {
Job job = Jobs.getJob(jobName);
if (job != null) {
jPlayer.leaveJob(job);
}
}
public int getTotalLevels() {
return jPlayer.getTotalLevels();
}
public int getMaxBrewingStandsAllowed() {
return jPlayer.getMaxBrewingStandsAllowed();
}
public int getMaxFurnacesAllowed() {
return jPlayer.getMaxFurnacesAllowed();
}
public List<String> getJobs() {
return jPlayer.getJobProgression().stream().map(p -> p.getJob().getName()).collect(Collectors.toList());
}
public void eatItem(ItemStack item) {
Jobs.action(jPlayer, new ItemActionInfo(item, ActionType.EAT));
}
public void breakBlock(Block block) {
Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.BREAK), block);
}
public void tntBreakBlock(Block block) {
Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.TNTBREAK), block);
}
public void placeBlock(Block block) {
Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.PLACE), block);
}
public void placeEntity(Entity block) {
Jobs.action(jPlayer, new EntityActionInfo(block, ActionType.PLACE));
}
public void breakEntity(Entity block) {
Jobs.action(jPlayer, new EntityActionInfo(block, ActionType.BREAK));
}
public void breedEntity(LivingEntity entity) {
Jobs.action(jPlayer, new EntityActionInfo(entity, ActionType.BREED));
}
public void killEntity(LivingEntity entity) {
killEntity(entity, jPlayer.getPlayer());
}
public void tameEntity(LivingEntity entity) {
Jobs.action(jPlayer, new EntityActionInfo((Entity) entity, ActionType.TAME));
}
public void catchFish(ItemStack items) {
Jobs.action(jPlayer, new ItemActionInfo(items, ActionType.FISH));
}
public void killEntity(LivingEntity entity, Entity damageSource) {
Jobs.action(jPlayer, new EntityActionInfo(entity, ActionType.KILL), damageSource, entity);
if (entity instanceof Player && !entity.hasMetadata("NPC")) {
JobsPlayer jVictim = Jobs.getPlayerManager().getJobsPlayer((Player) entity);
if (jVictim == null) {
return;
}
List<JobProgression> jobs = jVictim.getJobProgression();
if (jobs == null) {
return;
}
for (JobProgression job : jobs) {
Jobs.action(jPlayer, new CustomKillInfo(job.getJob().getName(), ActionType.CUSTOMKILL), damageSource, entity);
}
}
}
public void itemEnchanted(ItemStack resultStack) {
Map<Enchantment, Integer> enchants = resultStack.getEnchantments();
for (Map.Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
CMIEnchantment e;
String enchantName;
Integer level2;
Enchantment enchant = oneEnchant.getKey();
if (enchant == null || (enchantName = (e = CMIEnchantment.get(enchant)) == null ? null : e.toString()) == null || (level2 = oneEnchant.getValue()) == null) {
continue;
}
Jobs.action(jPlayer, new EnchantActionInfo(enchantName, level2, ActionType.ENCHANT));
}
}
}

View File

@ -0,0 +1,514 @@
package com.songoda.core.hooks.mcmmo;
import com.gmail.nossr50.api.AbilityAPI;
import com.gmail.nossr50.api.ExperienceAPI;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.random.RandomChanceUtil;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType;
import com.songoda.core.compatibility.ServerVersion;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public class McMMOHandler {
static boolean mcmmo_v2 = false;
static boolean legacy_v13 = false;
static boolean legacy_v12 = false;
static boolean legacy_v8 = false;
static Class mcmmo_SkillType;
static Method mcmmo_SkillType_valueOf;
static Method mcmmo_SkillType_getDoubleDropsDisabled;
static Object mcmmo_ExperienceConfig_instance;
static Method mcmmo_ExperienceConfig_getXp;
static Method mcmmo_McMMOPlayer_getSkillLevel;
static Class mcmmo_PerksUtils;
static Method mcmmo_PerksUtils_handleLuckyPerks;
static Class mcmmo_SecondaryAbility;
static Method mcmmo_SecondaryAbility_valueOf;
static Method mcmmo_Permissions_secondaryAbilityEnabled;
static Method mcmmo_SkillUtils_activationSuccessful;
static {
try {
Class.forName("com.gmail.nossr50.datatypes.skills.PrimarySkillType");
mcmmo_v2 = true;
} catch (ClassNotFoundException ex) {
try {
mcmmo_SkillType = Class.forName("com.gmail.nossr50.datatypes.skills.SkillType");
mcmmo_SkillType_valueOf = mcmmo_SkillType.getDeclaredMethod("valueOf", String.class);
mcmmo_SkillType_getDoubleDropsDisabled = mcmmo_SkillType.getDeclaredMethod("getDoubleDropsDisabled");
mcmmo_ExperienceConfig_instance = ExperienceConfig.getInstance();
mcmmo_McMMOPlayer_getSkillLevel = com.gmail.nossr50.datatypes.player.McMMOPlayer.class.getDeclaredMethod("getSkillLevel", mcmmo_SkillType);
mcmmo_PerksUtils = Class.forName("com.gmail.nossr50.util.skills.PerksUtils");
mcmmo_PerksUtils_handleLuckyPerks = mcmmo_PerksUtils.getDeclaredMethod("handleLuckyPerks", Player.class, mcmmo_SkillType);
mcmmo_SecondaryAbility = Class.forName("com.gmail.nossr50.datatypes.skills.SecondaryAbility");
mcmmo_SecondaryAbility_valueOf = mcmmo_SecondaryAbility.getDeclaredMethod("valueOf", String.class);
mcmmo_Permissions_secondaryAbilityEnabled = com.gmail.nossr50.util.Permissions.class.getDeclaredMethod("secondaryAbilityEnabled", Player.class, mcmmo_SecondaryAbility);
mcmmo_SkillUtils_activationSuccessful = com.gmail.nossr50.util.skills.SkillUtils.class.getDeclaredMethod("activationSuccessful", mcmmo_SecondaryAbility, Player.class, int.class, int.class);
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.block.data.BlockData.class);
legacy_v13 = true;
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.material.MaterialData.class);
legacy_v12 = true;
} else {
mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.Material.class);
legacy_v8 = true;
}
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to register McMMO Legacy Hook", ex1);
}
}
}
public static void addMining(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "mining");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.MINING);
}
public static void addExcavation(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "excavation");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.EXCAVATION);
}
public static void addHerbalism(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "herbalism");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.HERBALISM);
}
public static void addWoodcutting(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "woodcutting");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.WOODCUTTING);
}
public static int getAcrobaticsSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "acrobatics");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ACROBATICS);
}
public static int getAlchemySkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "alchemy");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ALCHEMY);
}
public static int getArcherySkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "archery");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ARCHERY);
}
public static int getAxesSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "axes");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.AXES);
}
public static int getExcavationSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "excavation");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.EXCAVATION);
}
public static int getFishingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "fishing");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.FISHING);
}
public static int getHerbalismSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "herbalism");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.HERBALISM);
}
public static int getMiningSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "mining");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.MINING);
}
public static int getRepairSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "repair");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.REPAIR);
}
public static int getSmeltingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "smelting");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SMELTING);
}
public static int getSwordsSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "swords");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SWORDS);
}
public static int getTamingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "taming");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.TAMING);
}
public static int getUnarmedSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "unarmed");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.UNARMED);
}
public static int getWoodcuttingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "woodcutting");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.WOODCUTTING);
}
public static void addAcrobatics(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "acrobatics", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ACROBATICS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addAlchemy(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "alchemy", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ALCHEMY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addArchery(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "archery", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ARCHERY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addAxes(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "axes", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.AXES, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addExcavation(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "excavation", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.EXCAVATION, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addFishing(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "fishing", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.FISHING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addHerbalism(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "herbalism", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.HERBALISM, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addMining(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "mining", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.MINING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addRepair(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "repair", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.REPAIR, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addSmelting(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "smelting", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SMELTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addSwords(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "swords", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SWORDS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addTaming(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "taming", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.TAMING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addUnarmed(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "unarmed", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.UNARMED, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addWoodcutting(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "woodcutting", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.WOODCUTTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static boolean hasHerbalismDoubleDrops(Player player) {
if (legacy_v13 || legacy_v12 || legacy_v8) {
return hasBlockDoubleLegacy(player, "herbalism");
}
if (PrimarySkillType.HERBALISM.getDoubleDropsDisabled()) {
return false;
}
return Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_DOUBLE_DROPS)
&& RankUtils.hasReachedRank(1, player, SubSkillType.HERBALISM_DOUBLE_DROPS)
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_DOUBLE_DROPS, player);
}
public static boolean hasMiningDoubleDrops(Player player) {
if (legacy_v13 || legacy_v12 || legacy_v8) {
return hasBlockDoubleLegacy(player, "mining");
}
if (PrimarySkillType.MINING.getDoubleDropsDisabled()) {
return false;
}
return Permissions.isSubSkillEnabled(player, SubSkillType.MINING_DOUBLE_DROPS)
&& RankUtils.hasReachedRank(1, player, SubSkillType.MINING_DOUBLE_DROPS)
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.MINING_DOUBLE_DROPS, player);
}
public static boolean hasWoodcuttingDoubleDrops(Player player) {
if (legacy_v13 || legacy_v12 || legacy_v8) {
return hasBlockDoubleLegacy(player, "woodcutting");
}
if (PrimarySkillType.WOODCUTTING.getDoubleDropsDisabled()) {
return false;
}
return Permissions.isSubSkillEnabled(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER)
&& RankUtils.hasReachedRank(1, player, SubSkillType.WOODCUTTING_HARVEST_LUMBER)
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.WOODCUTTING_HARVEST_LUMBER, player);
}
public static boolean isUsingBerserk(Player player) {
return AbilityAPI.berserkEnabled(player);
}
public static boolean isUsingGigaDrill(Player player) {
return AbilityAPI.gigaDrillBreakerEnabled(player);
}
public static boolean isUsingGreenTerra(Player player) {
return AbilityAPI.greenTerraEnabled(player);
}
public static boolean isUsingSerratedStrikes(Player player) {
return AbilityAPI.serratedStrikesEnabled(player);
}
public static boolean isUsingSkullSplitter(Player player) {
return AbilityAPI.skullSplitterEnabled(player);
}
public static boolean isUsingSuperBreaker(Player player) {
return AbilityAPI.superBreakerEnabled(player);
}
public static boolean isUsingTreeFeller(Player player) {
return AbilityAPI.treeFellerEnabled(player);
}
public static boolean isBleeding(LivingEntity victim) {
return AbilityAPI.isBleeding(victim);
}
/**
* woodcutting, mining, herbalism
*/
protected static boolean hasBlockDoubleLegacy(Player player, String skill) {
if (player.hasMetadata("mcMMO: Player Data")) {
try {
Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase());
if ((boolean) mcmmo_SkillType_getDoubleDropsDisabled.invoke(skillType)) {
return false;
}
int skillLevel = (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType);
int activationChance = (int) mcmmo_PerksUtils_handleLuckyPerks.invoke(null, player, skillType);
Object secondaryDouble = mcmmo_SecondaryAbility_valueOf.invoke(null, skill.toUpperCase() + "_DOUBLE_DROPS");
if (!((boolean) mcmmo_Permissions_secondaryAbilityEnabled.invoke(null, player, secondaryDouble))) {
return false;
}
return (boolean) mcmmo_SkillUtils_activationSuccessful.invoke(null, secondaryDouble, player, skillLevel, activationChance);
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1);
}
}
return false;
}
protected static void addBlockSkillLegacy(Player player, Collection<Block> blocks, String skill) {
try {
Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase());
int xp = 0;
for (Block block : blocks) {
xp += (int) mcmmo_ExperienceConfig_getXp.invoke(mcmmo_ExperienceConfig_instance, skillType, legacy_getBlock(block));
}
ExperienceAPI.addXP(player, skill, xp);
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1);
}
}
protected static Object legacy_getBlock(Block block) {
if (legacy_v13) {
return block.getBlockData();
} else if (legacy_v12) {
return block.getState().getData();
} else {
return block.getType();
}
}
protected static int getSkillLegacy(Player player, String skill) {
if (player.hasMetadata("mcMMO: Player Data")) {
try {
Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase());
return (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType);
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1);
}
}
return 0;
}
}

View File

@ -1,6 +1,7 @@
package com.songoda.core.hooks.stackers;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import uk.antiperson.stackmob.api.EntityManager;
@ -72,4 +73,10 @@ public class StackMob extends Stacker {
StackedEntity stackedEntity = plugin.getStackedEntity(entity);
stackedEntity.setSize(stackedEntity.getSize() + amount);
}
@Override
public int minimumEntityStack(EntityType type) {
return 0;
}
}

View File

@ -1,6 +1,7 @@
package com.songoda.core.hooks.stackers;
import com.songoda.core.hooks.Hook;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
@ -29,4 +30,7 @@ public abstract class Stacker implements Hook {
}
public abstract void add(LivingEntity entity, int amount);
public abstract int minimumEntityStack(EntityType type);
}

View File

@ -3,8 +3,10 @@ package com.songoda.core.hooks.stackers;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.utils.Methods;
import java.lang.reflect.Method;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.Plugin;
public class UltimateStacker extends Stacker {
@ -80,4 +82,9 @@ public class UltimateStacker extends Stacker {
public void add(LivingEntity entity, int amount) {
plugin.getEntityStackManager().getStack(entity).addAmount(amount);
}
@Override
public int minimumEntityStack(EntityType type) {
return ((Plugin) plugin).getConfig().getInt("Entities.Min Stack Amount");
}
}

View File

@ -2,11 +2,19 @@ package com.songoda.core.hooks.stackers;
import com.bgsoftware.wildstacker.api.WildStackerAPI;
import com.bgsoftware.wildstacker.api.objects.StackedEntity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.Plugin;
public class WildStacker extends Stacker {
final Plugin plugin;
public WildStacker(Plugin plugin) {
this.plugin = plugin;
}
@Override
public String getName() {
return "WildStacker";
@ -58,4 +66,14 @@ public class WildStacker extends Stacker {
StackedEntity stackedEntity = WildStackerAPI.getStackedEntity(entity);
stackedEntity.setStackAmount(stackedEntity.getStackAmount() + amount, true);
}
@Override
public int minimumEntityStack(EntityType type) {
int min = plugin.getConfig().getInt("entities.minimum-limits." + type.name(), -1);
if (min == -1) {
min = plugin.getConfig().getInt("entities.minimum-limits.all", -1);
}
return min == -1 ? 0 : min;
}
}

View File

@ -10,7 +10,6 @@ import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@ -31,7 +30,7 @@ import org.bukkit.Location;
*/
public class WorldGuardFlagHandler {
static Boolean wgPlugin = null;
static boolean wgPlugin;
static Object worldGuardPlugin;
static boolean wg_v7 = false;
static boolean legacy_v60 = false;
@ -40,15 +39,8 @@ public class WorldGuardFlagHandler {
static boolean hooksInstalled = false;
static Map<String, Object> flags = new HashMap();
/**
* Attempt to register a worldGuard flag (ALLOW/DENY) <br />
* Note: This must be called before WorldGuard loads, or it will fail.
*
* @param flag name of the flag to set
* @param state default value of the flag
*/
public static void addHook(String flag, boolean state) {
if (wgPlugin == null && (wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) {
static {
if ((wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) {
// a number of flags were introduced in 7.x that aren't in 5 or 6
try {
// if this class exists, we're on 7.x
@ -77,6 +69,16 @@ public class WorldGuardFlagHandler {
}
}
}
}
/**
* Attempt to register a worldGuard flag (ALLOW/DENY) <br />
* Note: This must be called before WorldGuard loads, or it will fail.
*
* @param flag name of the flag to set
* @param state default value of the flag
*/
public static void addHook(String flag, boolean state) {
if (!wgPlugin) {
return;
}
@ -135,12 +137,14 @@ public class WorldGuardFlagHandler {
// and put the new list into place
setStaticField(flagField, flagsNew);
if (legacy_v62) { // SimpleFlagRegistry is NOT in 6.0
if (legacy_v62) { // SimpleFlagRegistry is NOT in 6.0 or 6.1
// register this flag in the registry
Object flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry");
Class simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry");
Method registerSimpleFlagRegistry = simpleFlagRegistryClazz.getDeclaredMethod("register", Flag.class);
registerSimpleFlagRegistry.invoke(flagRegistry, wgFlag);
if(legacy_simpleFlagRegistryClazz == null) {
legacy_worldGuardPlugin_flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry");
legacy_simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry");
legacy_simpleFlagRegistry_get = legacy_simpleFlagRegistryClazz.getDeclaredMethod("get", String.class);
}
legacy_simpleFlagRegistryClazz.getDeclaredMethod("register", Flag.class).invoke(legacy_worldGuardPlugin_flagRegistry, wgFlag);
}
// all good!
@ -168,37 +172,67 @@ public class WorldGuardFlagHandler {
}
public static boolean isEnabled() {
return wgPlugin != null && wgPlugin;
return wgPlugin;
}
public static Object getFlag(String flag) {
Object flagObj = flags.get(flag);
// load a flag if we don't know it
if (flagObj == null) {
if (wg_v7) {
flags.put(flag, flagObj = WorldGuard.getInstance().getFlagRegistry().get(flag));
} else if (legacy_v62) {
try {
if (legacy_simpleFlagRegistryClazz == null) {
legacy_worldGuardPlugin_flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry");
legacy_simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry");
legacy_simpleFlagRegistry_get = legacy_simpleFlagRegistryClazz.getDeclaredMethod("get", String.class);
}
flags.put(flag, flagObj = legacy_simpleFlagRegistry_get.invoke(legacy_worldGuardPlugin_flagRegistry, flag));
} catch (Exception ex) {
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex);
}
} else if (!legacy_loadedFlags && (legacy_v60 || legacy_v5)) {
try {
Class defaultFlagClazz = Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag");
Field flagField = defaultFlagClazz.getField("flagsList");
Flag<?>[] flagsOld = (Flag<?>[]) flagField.get(null);
Stream.of(flagsOld).forEach(f -> flags.put(f.getName(), f));
flagObj = flags.get(flag);
} catch (Exception ex) {
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex);
}
legacy_loadedFlags = true;
}
}
return flagObj;
}
/**
* Checks this location to see what this flag is set to
*
* @param l location to check
* @param loc location to check
* @param flag ALLOW/DENY flag to check
* @return flag state, or null if undefined
*/
public static Boolean getBooleanFlag(Location l, String flag) {
if (wgPlugin == null || !wgPlugin) {
public static Boolean getBooleanFlag(Location loc, String flag) {
if (!wgPlugin) {
return null;
}
Object flagObj = flags.get(flag);
Object flagObj = getFlag(flag);
// There's a different way to get this in the old version
if (legacy_v62 || legacy_v60 || legacy_v5) {
return flagObj == null ? null : getBooleanFlagLegacy(l, flagObj);
}
// for convinience, we can load a flag if we don't know it
if (flagObj == null) {
flags.put(flag, flagObj = WorldGuard.getInstance().getFlagRegistry().get(flag));
return flagObj == null ? null : getBooleanFlagLegacy(loc, flagObj);
}
// so, what's up?
if (flagObj instanceof StateFlag) {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(l);
return query.testState(loc, (RegionAssociable) null, (StateFlag) flagObj);
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
//return query.testState(BukkitAdapter.adapt(loc), (RegionAssociable) null, (StateFlag) flagObj);
State result = query.getApplicableRegions(BukkitAdapter.adapt(loc)).queryState(null, (StateFlag) flagObj);
return result != null ? result == State.ALLOW : null;
}
return null;
}
@ -211,20 +245,15 @@ public class WorldGuardFlagHandler {
* @return flag state, or null if undefined
*/
public static Boolean getBooleanFlag(Chunk c, String flag) {
if (wgPlugin == null || !wgPlugin) {
if (!wgPlugin) {
return null;
}
Object flagObj = flags.get(flag);
Object flagObj = getFlag(flag);
// There's a different way to get this in the old version
if (legacy_v62 || legacy_v60 || legacy_v5) {
return flagObj == null ? null : getBooleanFlagLegacy(c, flagObj);
}
// for convinience, we can load a flag if we don't know it
if (flagObj == null) {
flags.put(flag, flagObj = WorldGuard.getInstance().getFlagRegistry().get(flag));
}
// so, what's up?
if (flagObj instanceof StateFlag) {
RegionManager worldManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(c.getWorld()));
@ -254,6 +283,10 @@ public class WorldGuardFlagHandler {
static Class legacy_VectorClazz;
static Constructor legacy_newVectorClazz;
static Method legacy_getApplicableRegions_Vector = null;
static Class legacy_simpleFlagRegistryClazz = null; // only used for 6.2
static Method legacy_simpleFlagRegistry_get = null; // only used for 6.2
static Object legacy_worldGuardPlugin_flagRegistry = null; // only used for 6.2
static boolean legacy_loadedFlags = false;
private static Boolean getBooleanFlagLegacy(Location l, Object flag) {
try {
@ -294,7 +327,7 @@ public class WorldGuardFlagHandler {
// also doesn't have a "queryState" function
//getFlag(T flag)
if (legacy5_applicableRegionSet_getFlag == null) {
legacy5_applicableRegionSet_getFlag = Class.forName("com.sk89q.worldguard.protection.ApplicableRegionSet").getMethod("getFlag", Object.class);
legacy5_applicableRegionSet_getFlag = Class.forName("com.sk89q.worldguard.protection.ApplicableRegionSet").getMethod("getFlag", Flag.class);
}
result = (State) legacy5_applicableRegionSet_getFlag.invoke(set, flag);
}

View File

@ -0,0 +1,248 @@
package com.songoda.core.hooks.worldguard;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
public class WorldGuardRegionHandler {
static boolean wgPlugin;
static Object worldGuardPlugin;
static boolean wg_v7 = false;
static boolean legacy_v60 = false;
static boolean legacy_v62 = false;
static boolean legacy_v5 = false;
static Method legacy_getRegionManager = null;
static Method legacy_getApplicableRegions_Region = null;
static Method legacy_getApplicableRegions_Location = null;
static Constructor legacy_newProtectedCuboidRegion;
static Class legacy_blockVectorClazz;
static Constructor legacy_newblockVector;
static Class legacy_VectorClazz;
static Constructor legacy_newVectorClazz;
static Method legacy_getApplicableRegions_Vector = null;
static void init() {
if ((wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) {
// a number of flags were introduced in 7.x that aren't in 5 or 6
try {
// if this class exists, we're on 7.x
Class.forName("com.sk89q.worldguard.protection.flags.WeatherTypeFlag");
wg_v7 = true;
} catch (ClassNotFoundException ex) {
try {
// if this class exists, we're on 6.2
Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry");
legacy_v62 = true;
} catch (ClassNotFoundException ex2) {
try {
// if this class exists, we're on 6.0
Class.forName("com.sk89q.worldguard.protection.flags.BuildFlag");
legacy_v60 = true;
} catch (ClassNotFoundException ex3) {
try {
// if this class exists, we're on 5.x
Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag");
legacy_v5 = true;
} catch (ClassNotFoundException ex4) {
// ¯\_()_/¯
wgPlugin = false;
}
}
}
}
}
if (wgPlugin && (legacy_v62 || legacy_v60 || legacy_v5)) {
try {
// cache reflection methods
if (legacy_getRegionManager == null) {
legacy_getRegionManager = worldGuardPlugin.getClass()
.getDeclaredMethod("getRegionManager", org.bukkit.World.class);
legacy_getApplicableRegions_Region = RegionManager.class.getDeclaredMethod("getApplicableRegions",
Class.forName("com.sk89q.worldguard.protection.regions.ProtectedRegion"));
legacy_getApplicableRegions_Location = RegionManager.class.getDeclaredMethod("getApplicableRegions",
Location.class);
legacy_blockVectorClazz = Class.forName("com.sk89q.worldedit.BlockVector");
legacy_newblockVector = legacy_blockVectorClazz.getConstructor(int.class, int.class, int.class);
legacy_newProtectedCuboidRegion = Class.forName("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion")
.getConstructor(String.class, legacy_blockVectorClazz, legacy_blockVectorClazz);
legacy_VectorClazz = Class.forName("com.sk89q.worldedit.Vector");
legacy_newVectorClazz = legacy_VectorClazz.getConstructor(int.class, int.class, int.class);
legacy_getApplicableRegions_Vector = RegionManager.class.getDeclaredMethod("getApplicableRegions", legacy_VectorClazz);
}
} catch (Exception ex) {
//Bukkit.getServer().getLogger().log(Level.WARNING, "Failed to set legacy WorldGuard Flags", ex);
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not load WorldGuard methods for " + (legacy_v62 ? "6.2" : (legacy_v60 ? "6.0" : "5")));
wgPlugin = false;
}
}
}
public static List<String> getRegionNames(Chunk c) {
if (worldGuardPlugin == null) {
init();
}
if (!wgPlugin || c == null) {
return Collections.EMPTY_LIST;
} else if (legacy_v62 || legacy_v60 || legacy_v5) {
return getRegionNamesLegacy(c);
}
RegionManager worldManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(c.getWorld()));
if (worldManager == null) {
return Collections.EMPTY_LIST;
}
ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("__TEST__",
BlockVector3.at(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4),
BlockVector3.at((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15));
ApplicableRegionSet set = worldManager.getApplicableRegions(chunkRegion);
List<String> regions = new ArrayList<>();
List<String> parentNames = new ArrayList<>();
for (ProtectedRegion region : set) {
String id = region.getId();
regions.add(id);
ProtectedRegion parent = region.getParent();
while (parent != null) {
parentNames.add(parent.getId());
parent = parent.getParent();
}
}
regions.removeAll(parentNames);
return regions;
}
private static List<String> getRegionNamesLegacy(Chunk c) {
try {
// grab the applicable manager for this world
Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, c.getWorld());
if (worldManager == null) {
return null;
}
// Create a legacy ProtectedCuboidRegion
Object chunkRegion = legacy_newProtectedCuboidRegion.newInstance("__TEST__",
legacy_newblockVector.newInstance(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4),
legacy_newblockVector.newInstance((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15));
// now look for any intersecting regions
// ApplicableRegionSet's prototype is different from v5 to v6, but they're both Iterable
Iterable<ProtectedRegion> set = (Iterable<ProtectedRegion>) legacy_getApplicableRegions_Region.invoke(worldManager, chunkRegion);
List<String> regions = new ArrayList<>();
List<String> parentNames = new ArrayList<>();
for (ProtectedRegion region : set) {
String id = region.getId();
regions.add(id);
ProtectedRegion parent = region.getParent();
while (parent != null) {
parentNames.add(parent.getId());
parent = parent.getParent();
}
}
regions.removeAll(parentNames);
return regions;
} catch (Exception ex) {
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab regions from WorldGuard", ex);
}
return Collections.EMPTY_LIST;
}
public static List<String> getRegionNames(Location loc) {
if (worldGuardPlugin == null) {
init();
}
if (!wgPlugin || loc == null) {
return Collections.EMPTY_LIST;
} else if (legacy_v62 || legacy_v60 || legacy_v5) {
return getRegionNamesLegacy(loc);
}
RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
if (regionManager == null) {
return Collections.EMPTY_LIST;
}
List<String> regions = new ArrayList<>();
List<String> parentNames = new ArrayList<>();
ApplicableRegionSet set = regionManager.getApplicableRegions(BukkitAdapter.asBlockVector(loc));
for (ProtectedRegion region : set) {
String id = region.getId();
regions.add(id);
ProtectedRegion parent = region.getParent();
while (parent != null) {
parentNames.add(parent.getId());
parent = parent.getParent();
}
}
regions.removeAll(parentNames);
return regions;
}
private static List<String> getRegionNamesLegacy(Location loc) {
try {
// grab the applicable manager for this world
Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, loc.getWorld());
if (worldManager == null) {
return Collections.EMPTY_LIST;
}
// create a vector object
Object vec = legacy_newVectorClazz.newInstance(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
// now look for any intersecting regions
// ApplicableRegionSet's prototype is different from v5 to v6, but they're both Iterable
Iterable<ProtectedRegion> set = (Iterable<ProtectedRegion>) legacy_getApplicableRegions_Vector.invoke(worldManager, legacy_VectorClazz.cast(vec));
List<String> regions = new ArrayList<>();
List<String> parentNames = new ArrayList<>();
for (ProtectedRegion region : set) {
String id = region.getId();
regions.add(id);
ProtectedRegion parent = region.getParent();
while (parent != null) {
parentNames.add(parent.getId());
parent = parent.getParent();
}
}
regions.removeAll(parentNames);
return regions;
} catch (Exception ex) {
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab regions from WorldGuard", ex);
}
return Collections.EMPTY_LIST;
}
}

View File

@ -119,7 +119,7 @@ public class Message {
*/
public Message processPlaceholder(String placeholder, Object replacement) {
final String place = Matcher.quoteReplacement(placeholder);
this.message = message.replaceAll("%" + place + "%|\\{" + place +"\\}", Matcher.quoteReplacement(replacement.toString()));
this.message = message.replaceAll("%" + place + "%|\\{" + place +"\\}", replacement == null ? "" : Matcher.quoteReplacement(replacement.toString()));
return this;
}

View File

@ -442,7 +442,7 @@ public class BlockUtils {
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS ? 3 : 7)) {
try {
legacySetBlockData.invoke(block, (byte) block.getData() + 1);
legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
} catch (Exception ex) {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
}

View File

@ -1,5 +1,6 @@
package com.songoda.core.nms;
import com.songoda.core.nms.methods.AnvilTextChange;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -25,6 +26,8 @@ public interface CustomAnvil {
public void setRenameText(String text);
public void setOnChange(AnvilTextChange handler);
public ItemStack getLeftInput();
public ItemStack getRightInput();
@ -43,4 +46,9 @@ public interface CustomAnvil {
* Open this anvil for the provided player
*/
public void open();
/**
* Force a redraw of the output
*/
public void update();
}

View File

@ -0,0 +1,6 @@
package com.songoda.core.nms.methods;
public interface AnvilTextChange {
void onChange();
}

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_10_R1;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -24,7 +25,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -94,6 +95,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
try {
@ -110,6 +116,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_11_R1;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -24,6 +25,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -93,6 +95,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
try {
@ -109,6 +116,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_12_R1;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -24,6 +25,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -81,6 +83,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
return this.renameText;
@ -96,6 +103,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
return title;
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public void setCustomTitle(String title) {
this.title = title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_13_R1;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -24,6 +25,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -82,6 +84,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
d();
}
@Override
public String getRenameText() {
return this.renameText;
@ -92,6 +99,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_13_R2;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -24,6 +25,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -82,6 +84,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
d();
}
@Override
public String getRenameText() {
return this.renameText;
@ -92,6 +99,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_14_R1;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.logging.Level;
@ -29,6 +30,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String customTitle = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -131,6 +133,12 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.levelCost.set(cost);
}
}
textChange.onChange();
}
@Override
public void update() {
e();
}
@Override
@ -143,6 +151,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return customTitle;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_8_R1;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -23,6 +24,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -91,6 +93,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
try {
@ -107,6 +114,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_8_R2;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -23,6 +24,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -91,6 +93,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
try {
@ -107,6 +114,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_8_R3;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -23,6 +24,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -91,6 +93,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
try {
@ -107,6 +114,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_9_R1;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -24,6 +25,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -93,6 +95,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
try {
@ -109,6 +116,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;

View File

@ -1,6 +1,7 @@
package com.songoda.core.nms.v1_9_R2;
import com.songoda.core.nms.CustomAnvil;
import com.songoda.core.nms.methods.AnvilTextChange;
import java.lang.reflect.Field;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -24,6 +25,7 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
private String title = "Repairing";
private int cost = -1;
private boolean canUse = true;
private AnvilTextChange textChange = null;
// used for setting custom inventory
static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result
@ -93,6 +95,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
}
}
@Override
public void update() {
e();
}
@Override
public String getRenameText() {
try {
@ -109,6 +116,11 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil {
this.a(text);
}
@Override
public void setOnChange(AnvilTextChange handler) {
textChange = handler;
}
@Override
public String getCustomTitle() {
return title;