我正在尝试制作一个允许你让任何玩家无懈可击的命令 - 也就是神模式.
到目前为止这是我的代码(虽然它是所有的样板)
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if(event.getEntity() instaceof Player) {
if(godModed.containsKey(event.getPlayer())) {
//This is where I need the code to go - something to cancel the damage.
}
}
}
Run Code Online (Sandbox Code Playgroud)
godModed是一个HashMap godModed包含目前所有人的所有玩家.当他们关闭godmode时,他们将从地图中删除.
命令本身工作正常 - 我现在让它向触发它的玩家发送消息,并且如果它们尚未打开,我还将它添加到godModed.但是,我无法弄清楚如何真正防止对玩家的伤害.我想完全阻止它,而不仅仅是事后医治它们; 虽然后者可能会起作用,但如果其他模式onEntityDamage试图触发一个不应该遇到的模仿玩家不应该遇到的事情,它也可能导致不可预见的后果.
在我的小node.js应用程序中,使用express,我想记录所有传入的请求,所以我最终得到了这个:
var bodyParser = require('body-parser');
module.exports = function(app) {
app.set("port", 50001);
app.set("json spaces", 2);
app.use(bodyParser.json());
app.use(function (error, req, res, next) {
app.logger.info("received from "+req.get("X-Forwarded-For")+" : "+req.method+" "+req.originalUrl+" (Authorization: "+req.get("Authorization")+")");
//does not work if json is malformed
//app.logger.info("content :"+JSON.stringify(req.body));
if (error /*instanceof SyntaxError*/) {
res.status(400);
app.logger.error(error);
res.json({ error:{msg: error.message}});
} else {
next();
}
});
app.use(app.auth.initialize());
};
Run Code Online (Sandbox Code Playgroud)
不幸的是,我只是app.logger.info在出现错误时通过线路获取日志(在我的情况下,正文中的格式错误的JSON字符串).我在这里错过了什么?
在C中,将结构声明为是否存在任何有效差异
typedef struct {...} Foo;
Run Code Online (Sandbox Code Playgroud)
和
struct Foo {...};
Run Code Online (Sandbox Code Playgroud)
我知道第二个要求你使用前缀struct,但是在编写或执行程序时我会注意到这两个定义之间有什么区别?用enums怎么样?
public static void main(String[] args) {
int n = factorial(30);
int x = 0;
while (x <= 30) {
System.out.println(x + " " + n);
x = x + 1;
}
public static int factorial (int n) {
if (n == 0) {
return 1;
} else {
return n * factorial (n-1);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试打印出这样的东西:
0 1
1 1
2 2
3 6
4 24
...etc, up to 30 (30!)
Run Code Online (Sandbox Code Playgroud)
我得到的是这样的:
0 (30!)
1 (30!)
...etc, up to …Run Code Online (Sandbox Code Playgroud) 我正在阅读《使用Node和Express进行Web开发》一书,遇到了麻烦。
我被指示将以下内容放入我的应用程序文件,但它似乎body-parser已被弃用,将无法使用。如何获得相同的功能?
这是我当前的代码:
app.use(require('body-parser')());
app.get('/newsletter', function(req, res){
// we will learn about CSRF later...for now, we just
// provide a dummy value
res.render('newsletter', { csrf: 'CSRF token goes here' });
});
app.post('/process', function(req, res){
console.log('Form (from querystring): ' + req.query.form);
console.log('CSRF token (from hidden form field): ' + req.body._csrf);
console.log('Name (from visible form field): ' + req.body.name);
console.log('Email (from visible form field): ' + req.body.email); res.redirect(303, '/thank-you');
});
Run Code Online (Sandbox Code Playgroud) 例如,请使用以下代码段:
class Foo;
class Something {
Foo *thing;
};
typedef std::vector<Something> Foo;
Run Code Online (Sandbox Code Playgroud)
这不会编译,因为Foo在typedef命中时它已经是一个类型.但是,我认为它显示了我的用例; 我有周期依赖,需要一个来实现另一个,但(目前)其中一个是typedef'd.我不想写类似的东西
class Foo {
std::vector<Something> inside;
}
Run Code Online (Sandbox Code Playgroud)
因为那时我需要记住inside每一个my_foo.inside.some_method().我也想避免写一个包装器std::vector<Something>,因为它是很多样板.
我如何转发声明我用一个类型定义的类型typedef?或者,如何在不使用上述解决方案的情况下解决我的周期性依赖问题?有可能吗?
请注意,我不会问"如何typedef使用尚未声明的类型".我问"如何使用它typedef来定义先前声明的类型".
我测试了各种数组连接技术,不是因为它对我的代码实际上很重要,而只是作为一个旁边,看看我们现在在哪里.正如预期的那样,新的ES 2015传播运营商concat()在Javascript阵列上被旧方法击败了相当大的差距.
然而,当我比较这两个时,让我感到惊讶的是:
var a = b = c = [1,2,3,4,5];
// SLOWER (V8 and Edge, very slightly faster in Firefox)
console.time('t1');
for (i = 0; i < 1000000; i++) {
Array.prototype.concat(a, b, c);
};
console.timeEnd('t1')
// FASTER (V8 and Edge, very slightly slower in Firefox)
console.time('t2');
for (i = 0; i < 1000000; i++) {
[].concat(a, b, c);
};
console.timeEnd('t2')Run Code Online (Sandbox Code Playgroud)
我在最新的node.js,Chrome和Edge浏览器上测试并运行了多次,然后再进行下一次.使用V8(node.js,Chrome),结果甚至更大,但即使对于Edge,第一个选项总是很明显 - 在V8上显着 - 比第二个选项慢.在Firefox中,结果反转但几乎相等,所以让我们将问题限制在另外两个浏览器引擎(V8和Chakra).
所以我只是出于好奇而要求,因为我根本没有预见到这一点,
1)除了性能之外,连接这些数组的两种方法之间是否存在实际差异?
2)为什么AFAICS创建一个对象(数组)的速度比另一个(初始数组)慢?
编辑:我知道方法是相同的,这就是为什么我测试了对原型上方法的直接访问,而不是创建一个(未使用的)数组对象来访问它.我也知道它依赖于浏览器,这是a)为什么我测试了两个基于V8的系统(Chrome和node.js)和Microsoft Edge浏览器,以及b)为什么我包含了上面的可运行测试用例.
顺便说一句,这个问题在发布之后仅在 …
I've looked through the NCurses function list, and I can't seem to find a function that returns the characters already printed on the screen. Is there an accessible value for the char stored in each character cell? If not, is there a similar function in the Windows terminal?
我想用它来用a不同的字符或新的属性替换屏幕上某个值(例如:所有的)的所有字符。
我正在使用Spring Boot.
我在类路径之外的外部文件中声明了属性.
我将其添加到我的一个XML文件中:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>file:///d:/etc/services/pushExecuterService/pushExecuterServices.properties</value>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
但是,我仍然收到此错误:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'configuration.serviceId' in string value "${configuration.serviceId}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
Run Code Online (Sandbox Code Playgroud)
我PropertiesLoaderSupport在这个方法中在类中添加了一个断点:
public void setLocations(Resource... locations) {
this.locations = locations;
}
Run Code Online (Sandbox Code Playgroud)
我注意到这个方法多次调用,其中一个我注意到填充的位置参数:
URL [file:/d:/etc/services/pushExecuterService/pushExecuterServices.properties]
Run Code Online (Sandbox Code Playgroud)
但是,我仍然收到此错误.
我仔细检查了我的项目,我没有任何额外的PropertyPlaceholderConfigurer bean(没有检查外部依赖项)
我用硬编码运行我的应用程序我在spring-boot日志中可以看到xml中的params:
2015-01-05 18:56:52.902 INFO 7016 --- [ main]
o.s.b.f.c.PropertyPlaceholderConfigurer: Loading properties file from
URL [file:/d:/etc/services/pushExecuterService/pushExecuterServices.properties]`
Run Code Online (Sandbox Code Playgroud)所以我不确定发生了什么.任何线索?
谢谢.
我正在尝试创建一个从容器类型中选择随机元素的方法,比如std::vector.以前,我用这个:
std::string pick_random(std::vector<std::string> c) {
int r = std::rand() % ids.size() + 1;
auto it = c.begin();
std::advance(it, r);
return *it;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,这很好.这并不是说这是很好,只是它似乎是.
我很快就要为另一个容器做同样的事情,所以我尝试使用模板模板参数来使方法通用:
template <template<typename element_t> container_t>
element_t pick_random(container_t from) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
但是,这会引发错误:
element_t does not name a type
Run Code Online (Sandbox Code Playgroud)
我认为我的意图很清楚,但重申一下:我正在尝试获取列表的元素类型.我可以有一个单独的模板参数,但它无法正确推断出类型.我尝试了各种不同的版本,但都没有.