本文整理汇总了Java中cn.nukkit.scheduler.PluginTask类的典型用法代码示例。如果您正苦于以下问题:Java PluginTask类的具体用法?Java PluginTask怎么用?Java PluginTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PluginTask类属于cn.nukkit.scheduler包,在下文中一共展示了PluginTask类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTaskTiming
import cn.nukkit.scheduler.PluginTask; //导入依赖的package包/类
public static Timing getTaskTiming(TaskHandler handler, long period) {
String repeating = " ";
if (period > 0) {
repeating += "(interval:" + period + ")";
} else {
repeating += "(Single)";
}
if (handler.getTask() instanceof PluginTask) {
String owner = ((PluginTask) handler.getTask()).getOwner().getName();
return TimingsManager.getTiming(owner, "PluginTask: " + handler.getTaskId() + repeating, schedulerSyncTimer);
} else if (!handler.isAsynchronous()) {
return TimingsManager.getTiming(DEFAULT_GROUP.name, "Task: " + handler.getTaskId() + repeating, schedulerSyncTimer);
} else {
return null;
}
}
示例2: PlaceChest
import cn.nukkit.scheduler.PluginTask; //导入依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true)
public void PlaceChest(BlockPlaceEvent event){
Block block = event.getBlock();
if(block.getId() == Block.CHEST)
this.plugin.getServer().getScheduler().scheduleDelayedTask(new PluginTask<ChestLocker>(this.plugin) {
//delay 1tick
@Override
public void onRun(int i) {
try {
if (((BlockEntityChest) block.getLevel().getBlockEntity(block)).getPair() != null) {
BlockEntityChest chestPair = ((BlockEntityChest) block.getLevel().getBlockEntity(block)).getPair();
BlockEntityChest chest = (BlockEntityChest)block.getLevel().getBlockEntity(block);
if (chestPair.namedTag.exist("Owner")) {
if(!Objects.equals(ChestLocker.getInstance().getChestOwner(chest), event.getPlayer().getName())){
block.getLevel().useBreakOn(block);
event.getPlayer().sendMessage(TextFormat.YELLOW + "[ChestLocker] 你无法在这里放置箱子,因为这个箱子所连接的另一个箱子不属于你");
}else{
ChestLocker.getInstance().CopyChestInformation(chestPair,chest);
}
}
}
}catch(Exception ignore){
//ignore
}
}
},1);
}
示例3: onEnable
import cn.nukkit.scheduler.PluginTask; //导入依赖的package包/类
@Override
public void onEnable() {
CleanerManager.addCleaner(new EntityCleaner());
getServer().getScheduler().scheduleRepeatingTask(new PluginTask<Main>(this) {
@Override
public void onRun(int currentTick) {
CleanerManager.cleanEntities();
}
}, 20 * 60 * 3);
}
示例4: onEnable
import cn.nukkit.scheduler.PluginTask; //导入依赖的package包/类
public void onEnable(){
saveDefaultConfig();
try{
SQLite3 sql = new SQLite3(new File(getDataFolder(), "auths.db").toString());
auth = new PasswordAuth(sql);
}catch(Exception e){
getLogger().info("出现错误 : 数据库连接失败" + e.getMessage());
setEnabled(false);
return;
}
getServer().generateLevel(getConfig().getString("world"));
getServer().generateLevel(getConfig().getString("target"));
getServer().loadLevel(getConfig().getString("world"));
getServer().loadLevel(getConfig().getString("target"));
level = getServer().getLevelByName(getConfig().getString("world"));
stage = getServer().getLevelByName(getConfig().getString("target"));
if(level == null || stage == null){
getLogger().info("出现错误 : 地图加载失败");
setEnabled(false);
return;
}
buttons = new Vector3[4];
Config c = new Config(
new File(getDataFolder(), "buttons.yml"),
Config.YAML, new LinkedHashMap<String,Object>(){{
put("login_button","0,0,0");
put("info_button", "0,0,0");
put("invisible_button", "0,0,0");
put("jump_button", "0,0,0");
}});
String[] s = ((String) c.get("login_button")).split(",");
buttons[LOGIN_BUTTON] = new Vector3(Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]));
s = ((String) c.get("info_button")).split(",");
buttons[GET_INFO] = new Vector3(Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]));
s = ((String) c.get("invisible_button")).split(",");
buttons[EGG_INVISIBLE] = new Vector3(Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]));
s = ((String) c.get("jump_button")).split(",");
buttons[EGG_JUMP] = new Vector3(Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]));
getServer().getPluginManager().registerEvents(this, this);
getServer().getScheduler().scheduleRepeatingTask(new PluginTask<Login>(this){
public void onRun(int currentTick) {
getOwner().tick();
}
}, 15);
getServer().getCommandMap().register("LevelLogin" ,new LCommand(this));
getServer().getCommandMap().register("LevelLogin", new RemoveCommand(this));
tips = new HashMap<>();
times = new HashMap<String, Integer>();
currentButton = -1;
preloginlisteners = new ArrayList<PreLoginListener>();
loginlisteners = new ArrayList<LoginListener>();
getLogger().info("加载成功");
}