本文整理汇总了Java中com.sk89q.worldguard.protection.flags.Flag类的典型用法代码示例。如果您正苦于以下问题:Java Flag类的具体用法?Java Flag怎么用?Java Flag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Flag类属于com.sk89q.worldguard.protection.flags包,在下文中一共展示了Flag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
protected String[] get(Event event) {
World world = (World) this.world.getSingle(event);
if (world == null) {
for (RegionManager a : WGBukkit.getPlugin().getRegionContainer().getLoaded()) {
for (Entry<String, ProtectedRegion> b : a.getRegions().entrySet()) {
if (b.getKey().equals(region.getSingle(event))) {
world = Bukkit.getWorld(a.getName());
break;
}
}
}
}
RegionManager rm = WGBukkit.getRegionManager(world);
ProtectedRegion pregion = rm.getRegion(region.getSingle(event));
List<String> rfl = new ArrayList<String>();
for (Entry<Flag<?>, Object> ra : pregion.getFlags().entrySet()) {
rfl.add(ra.getKey().getName());
}
String[] s = new String[rfl.size()];
return (String[]) rfl.toArray(s);
}
示例2: getFlags
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
public Map<Flag<?>, Object> getFlags(String player) {
Map<Flag<?>, Object> flags = new TreeMap<>(new WorldGuardManager.FlagComparator());
for (Flag<?> df : DefaultFlag.flagsList) {
for (String key : fc.getConfigurationSection("ps-default.flags").getKeys(false)) {
if (df.getName().toString().equalsIgnoreCase(key)) {
if (fc.getString("ps-default.flags.".concat(key)).equalsIgnoreCase("deny")) {
flags.put(df, StateFlag.State.DENY);
} else if (fc.getString("ps-default.flags.".concat(key)).equalsIgnoreCase("allow")) {
flags.put(df, StateFlag.State.ALLOW);
} else {
flags.put(df, (Object) fc.getString("ps-default.flags.".concat(key)).replace("%player%", player));
}
}
}
}
return flags;
}
示例3: setFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
public static <T> void setFlag(ProtectedRegion region, Flag<T> flag, String value) throws CommandException, InvalidFlagFormat {
CommandContext ccontext = new CommandContext("rg "+value, valueFlags);
region.setFlag(flag, flag.parseInput(WGBukkit.getPlugin(), Bukkit.getConsoleSender(), ccontext.getRemainingString(0)));
if (ccontext.hasFlag('g')) {
String group = ccontext.getFlag('g');
RegionGroupFlag groupFlag = flag.getRegionGroupFlag();
if (groupFlag == null) {
return;
}
RegionGroup groupValue = groupFlag.parseInput(WGBukkit.getPlugin(), Bukkit.getConsoleSender(), group);
if (groupValue == groupFlag.getDefault()) {
region.setFlag(groupFlag, null);
} else {
region.setFlag(groupFlag, groupValue);
}
}
}
示例4: run
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
@Override
public void run() throws Exception {
if(!Config.REGION_WORLDGUARD.getBoolean()) {
LoggerUtils.info("Skipping WorldGuardFlag Injector. Disabled in config");
return;
}
plugin.getRegionManager().createWorldGuardFlag();
FieldAccessor<Flag[]> defaultFlagFlagListField = Reflections.getField(DefaultFlag.class, "flagsList", Flag[].class);
defaultFlagFlagListField.setNotFinal();
Flag[] array = defaultFlagFlagListField.get(null);
List<Flag> list = new ArrayList<>();
Collections.addAll(list, array);
list.add((StateFlag) RegionManager.WORLDGUARD_FLAG);
defaultFlagFlagListField.set(list.toArray(new Flag[list.size()]));
LoggerUtils.info("Successfully injected WorldGuard Flag");
}
示例5: registerFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
/**
* registers the mob-protect flag
*
* @author xize
* @param flag - the flag or StateFlag to be injected/added in worldguard
* @throws Exception when something failed
*/
public void registerFlag(Flag<?> flag) throws Exception {
Field f1 = DefaultFlag.class.getDeclaredField("flagsList");
Field f2 = Field.class.getDeclaredField("modifiers");
f2.setAccessible(true);
f2.setInt(f1, f1.getModifiers() &~Modifier.FINAL);
f1.setAccessible(true);
Flag<?>[] flags = DefaultFlag.getFlags();
List<Flag<?>> flaglist = Arrays.asList(flags);
if(!flaglist.contains(flag)) {
Flag<?>[] newflags = Arrays.copyOf(flags, flags.length+1);
newflags[newflags.length-1] = flag;
f1.set(null, newflags);
}
f1.setAccessible(false);
f2.setAccessible(false);
reloadWG();
ManCo.log(LogType.INFO, "flag registered for worldguard: " + flag.getName());
}
示例6: unregisterFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
/**
* unregisters the mob-protect flag
*
* @author xize
* @param flag - the flag or StateFlag to be injected/removed in worldguard
* @throws Exception when something failed
*/
public void unregisterFlag(Flag<?> flag) throws Exception {
Field f1 = DefaultFlag.class.getDeclaredField("flagsList");
Field f2 = Field.class.getDeclaredField("modifiers");
f2.setAccessible(true);
f2.setInt(f1, f1.getModifiers() &~Modifier.FINAL);
f1.setAccessible(true);
Flag<?>[] flags = DefaultFlag.getFlags();
List<Flag<?>> flaglist = Arrays.asList(flags);
if(flaglist.contains(flag)) {
flaglist.remove(flag);
Flag<?>[] newflags = flaglist.toArray(new Flag<?>[flaglist.size()]);
f1.set(null, newflags);
}
f1.setAccessible(false);
f2.setAccessible(false);
reloadWG();
ManCo.log(LogType.INFO, "flag unregistered for worldguard: " + flag.getName());
}
示例7: registerFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
private void registerFlag(Flag<?> flag) throws Exception {
Field f1 = DefaultFlag.class.getDeclaredField("flagsList");
Field f2 = Field.class.getDeclaredField("modifiers");
f2.setAccessible(true);
f2.setInt(f1, f1.getModifiers() &~Modifier.FINAL);
f1.setAccessible(true);
Flag<?>[] flags = DefaultFlag.getFlags();
List<Flag<?>> flaglist = Arrays.asList(flags);
if(!flaglist.contains(flag)) {
Flag<?>[] newflags = Arrays.copyOf(flags, flags.length+1);
newflags[newflags.length-1] = flag;
f1.set(null, newflags);
}
f1.setAccessible(false);
f2.setAccessible(false);
}
示例8: unregisterFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
private void unregisterFlag(Flag<?> flag) throws Exception {
Field f1 = DefaultFlag.class.getDeclaredField("flagsList");
Field f2 = Field.class.getDeclaredField("modifiers");
f2.setAccessible(true);
f2.setInt(f1, f1.getModifiers() &~Modifier.FINAL);
f1.setAccessible(true);
Flag<?>[] flags = DefaultFlag.getFlags();
List<Flag<?>> flaglist = Arrays.asList(flags);
if(flaglist.contains(flag)) {
flaglist.remove(flag);
Flag<?>[] newflags = flaglist.toArray(new Flag<?>[flaglist.size()]);
f1.set(null, newflags);
}
f1.setAccessible(false);
f2.setAccessible(false);
}
示例9: injectWorldGuardFlags
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
private static void injectWorldGuardFlags(Flag<?>... flags) throws Exception {
Flag<?>[] flagsList = DefaultFlag.flagsList;
Field flagsListField = DefaultFlag.class.getField("flagsList");
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(flagsListField, flagsListField.getModifiers() & ~Modifier.FINAL);
Flag<?>[] newFlagsList = new Flag<?>[flagsList.length + flags.length];
System.arraycopy(flagsList, 0, newFlagsList, 0, flagsList.length);
System.arraycopy(flags, 0, newFlagsList, flagsList.length, flags.length);
flagsListField.set(null, newFlagsList);
}
示例10: setFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void setFlag(final ProtectedRegion pr, final World world,
final Flag flag, final String value) {
/*
StateFlag.State state = null;
switch (value.toLowerCase()) {
case "allow":
pr.setFlag(flag, state = StateFlag.State.ALLOW);
break;
case "deny":
pr.setFlag(flag, state = StateFlag.State.DENY);
break;
default:
pr.setFlag(flag, value);
}
*/
// As WG API sucks I will implement this function using
// WG plugin commands. I hope to fix this one of those days...
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
Bukkit.dispatchCommand(plugin.getConsole(),
"region flag -w " + world.getName() + " "
+ pr.getId() + " " + flag.getName() + " " + value);
}
}, 2);
}
示例11: setFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void setFlag(Player player, Flag flag, String value) {
PSBlocks psb = getPs(player.getLocation());
if (psb == null) {
player.sendMessage(ChatColor.RED + plugin.i18n.getText("not_in_ps_area"));
return;
}
if (!validatePlayerPermission(player, psb)) {
return;
}
if (value == null) {
psb.region.setFlag(flag, null);
return;
}
switch (value.toLowerCase()) {
case "allow":
psb.region.setFlag(flag, StateFlag.State.ALLOW);
break;
case "deny":
psb.region.setFlag(flag, StateFlag.State.DENY);
break;
default:
switch (flag.getName().toLowerCase()) {
case "farewell":
case "greeting":
psb.region.setFlag(flag, value);
default:
return;
}
}
}
示例12: checkWorldGuardValidity
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
/**
* Checks WorldGuard validity if possible
*
* @param selection region selection
* @return true if valid
*/
private boolean checkWorldGuardValidity(RegionSelection selection) {
if(!plugin.getDependencyManager().isEnabled(Dependency.WORLDGUARD)) {
return true;
}
WorldGuardPlugin worldGuard = plugin.getDependencyManager().get(Dependency.WORLDGUARD, WorldGuardPlugin.class);
Area selectionArea = new Area(new Rectangle(
selection.getCorner(selection.getCorner(0).getBlockX() < selection.getCorner(1).getBlockX() ? 0 : 1).getBlockX(),
selection.getCorner(selection.getCorner(0).getBlockZ() < selection.getCorner(1).getBlockZ() ? 0 : 1).getBlockZ(),
selection.getWidth(),
selection.getLength())
);
for(ProtectedRegion region : worldGuard.getRegionManager(selection.getWorld()).getRegions().values()) {
if(region.getFlag((Flag) RegionManager.WORLDGUARD_FLAG) == StateFlag.State.ALLOW) {
continue;
}
Area regionArea = RegionUtils.toArea(region);
regionArea.intersect(selectionArea);
if(!regionArea.isEmpty()) {
return false;
}
}
return true;
}
示例13: setupHook
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
@Override
public void setupHook() {
plugin = (WorldGuardPlugin) Bukkit.getPluginManager().getPlugin("WorldGuard");
flag = new StateFlag("allowspells", true);
Flag<?>[] flags = new Flag<?>[DefaultFlag.flagsList.length + 1];
System.arraycopy(DefaultFlag.flagsList, 0, flags, 0, DefaultFlag.flagsList.length);
flags[DefaultFlag.flagsList.length] = flag;
ReflectionUtils.setStaticFinalField(DefaultFlag.class, flags, "flagsList");
}
示例14: setFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
/**
* Set a WorldGuard region flag.
* @param region The WorldGuard region to set
* @param flag The flag to set
* @param value The value to set the flag to
* @param <V> They type of flag to set
* @throws InvalidFlagFormat When the value of the flag is wrong
*/
private <V> void setFlag(ProtectedRegion region, Flag<V> flag, String value) throws InvalidFlagFormat {
V current = region.getFlag(flag);
V next = plugin.getWorldGuardHandler().parseFlagInput(flag, value);
if(!Objects.equals(current, next)) {
region.setFlag(flag, next);
}
}
示例15: setFlag
import com.sk89q.worldguard.protection.flags.Flag; //导入依赖的package包/类
private <V> void setFlag(Target t, ProtectedRegion region,
Flag<V> flag, CommandSender sender, String value)
throws InvalidFlagFormat {
try {
region.setFlag(flag, flag.parseInput(FlagContext.create().setSender(sender).setInput(value).build()));
} catch (NoClassDefFoundError ex) {
// probably WorldGuard 3.1.2 or earlier
region.setFlag(flag, flag.unmarshal(ReflectionUtils.invokeMethod(flag, "parseInput", WorldGuardPlugin.inst(), sender, value)));
}
}