Renaming placed containers [closed] - bukkit

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm just wondering is there a way to give or rename a container like chest that is already on ground?
I mean not using NMS. But the spigot API to edit the names?

There is no API for it but it is possible with NMS. I made this method some time ago, it allows you to name any tile entity.
You give it a normal bukkit block and name that will be applied to the block. Name can have § coloring char.
With this code you can make version using reflections if you want to avoid NMS and CB imports.
import net.minecraft.server.v1_8_R1.INamableTileEntity;
import net.minecraft.server.v1_8_R1.TileEntity;
import net.minecraft.server.v1_8_R1.TileEntityBrewingStand;
import net.minecraft.server.v1_8_R1.TileEntityChest;
import net.minecraft.server.v1_8_R1.TileEntityCommand;
import net.minecraft.server.v1_8_R1.TileEntityDispenser;
import net.minecraft.server.v1_8_R1.TileEntityEnchantTable;
import net.minecraft.server.v1_8_R1.TileEntityFurnace;
import net.minecraft.server.v1_8_R1.TileEntityHopper;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
public static void setName(String name, Block block) {
final CraftWorld world = (CraftWorld) block.getWorld();
final TileEntity nmsTileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (nmsTileEntity instanceof INamableTileEntity) {
if (nmsTileEntity instanceof TileEntityChest) {
((TileEntityChest) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityFurnace) {
((TileEntityFurnace) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityDispenser) {
((TileEntityDispenser) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityHopper) {
((TileEntityHopper) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityBrewingStand) {
((TileEntityBrewingStand) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityEnchantTable) {
((TileEntityEnchantTable) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityCommand) {
((TileEntityCommand) nmsTileEntity).getCommandBlock().setName(name);
}
nmsTileEntity.update();
}
}

Related

Select only inline code blocks [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I need to select every inline code blocks (not multilane)
Here is text https://regex101.com/r/8e7nPL/7
Example of inline blocks that I need to extract: f.call();, yield(), Fiber
this could help you:
function test(text) {
var re = /`([^`\n]+)`/g;
let match;
while(match = re.exec(text)) {
console.log('match', match);
}
}
test(
`
Пример создания файбера и передача ему в качестве аргумента вызываемой функции:
\`\`\`
auto f = new Fiber(&foo);
\`\`\`
\`f.call();\` вызов файбера
\`Fiber.yield();\` метод \`yield()\` класса \`Fiber\` вызывающий преостановку выполнение текущей функции
Пример:
\`\`\`
import std.stdio;
import core.thread;
void main()
{
auto f = new Fiber(&foo);
f.call(); // Prints Hello
f.call(); // Prints World
}
void foo()
{
writeln("Hello");
Fiber.yield();
writeln("World");
}
\`\`\`
Результат:
\`\`\`
> app.exe
Hello
World\`
`
)

checking database from webservice netbeans

sorry if my question confusing cause this is the first time i make a question. if there is something that i can do to make it clearer, just tell me so i can improve the way i'm asking.
currently i'm trying to make web service from netbeans that can check some data from database. Because i'm newbie so i followed tutorial from
http://programmerguru.com/webservice-tutorial/how-to-create-java-webservice-in-netbeans/ to make the web service.
but when i trying to check the database with my usual way with mybattis, it keep in give me java.lang.nulpointerexception. when i try to debug it, it give me "variable information not available, source compiled without -g option" and throw me to InvocationTargetException.java
public InvocationTargetException(Throwable target) {
super((Throwable)null); // Disallow initCause
this.target = target;
}
here is the code for the web service
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bismillah.berkah;
import com.bismillah.berkah.dao.DummyDao;
import com.bismillah.berkah.daoImpl.DummyDaoImpl;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
/**
*
* #author Ari
*/
#WebService(serviceName = "Check4Update")
public class Check4Update {
public DummyDaoImpl ddi;
/**
* This is a sample web service operation
*
* #param InTerminalNumber
* #return
*/
#WebMethod(operationName = "CheckUpdate")
public String hello(#WebParam(name = "InTerminalNumber") String InTerminalNumber) {
String OutError = "";
String OutMessage = "";
if (InTerminalNumber == null) {
return "InTerminalNumber can't be null";
} else {
Map mapdao = new HashMap<String, Object>();
Map map = new HashMap<String, Object>();
map.put("InTerminalNumber", InTerminalNumber);
mapdao = ddi.check4UpdatePatch(map);
OutError = (String) mapdao.get("OutError");
OutMessage = (String) mapdao.get("OutMessage");
return "Error : " + OutError + ", with message : " + OutMessage;
}
}
public void setDdi(DummyDaoImpl ddi) {
this.ddi = ddi;
}
}
and here is the code mybattis impl
package com.bismillah.berkah.daoImpl;
import com.bismillah.berkah.Check4Update;
import com.bismillah.berkah.config.MyBatisConnectionFactory;
import com.bismillah.berkah.dao.*;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
/**
*
* #author Ari
*/
public class DummyDaoImpl
{
private SqlSessionFactory sqlSessionFactory;
public DummyDaoImpl()
{
sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
}
public Map check4UpdatePatch(Map map)
{
Check4Update c4u = new Check4Update();
c4u.setDdi(this);
SqlSession session = sqlSessionFactory.openSession();
try
{
session.selectOne("dummy.check4UpdatePatch", map);
} catch (Exception ex)
{
ex.toString();
} finally
{
session.close();
}
return map;
}
}
could you tell me how to fix it? so i can get the data? by the way i always get thrown at my web service, here exactly
mapdao = ddi.check4UpdatePatch(map);
once again sorry if my question confusing cause this is the first time i make a question. if there is something that i can do to make it clearer, just tell me so i can improve the way i'm asking.
sorry already found the problem, it is cause wrong configuration on mybatis.
i haven't change my string resource on MyBatisConnectionFactory, also the one at xml file.
maybe that's why i always get java lang nul.
actually when i trying to fix this, i make some interface class too, but still not working until i find my problem. if anyone have some problem like me maybe you can fix it with adding some interface so the impl will override the interface.

Parser JSON ON QT [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Is it possible to use an operator || in json like this :
{
"ven":{
"source":"logicCtrl" ,
"msg":"radio_volume" || "radio-mute", || "radio3",
"type":"int"
}
}
i can after get data by parsing data in C++ side like this :
QFile jsonFile("VenParser.json");
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "problème d'overture du fichier, exit";
}
QByteArray jsonData = jsonFile.readAll();
QJsonParseError *err = new QJsonParseError();
QJsonDocument doc = QJsonDocument::fromJson(jsonData, err);
if (err->error != 0)
qDebug() << err->errorString();
Venparser myparser;
if (doc.isNull())
{
qDebug() << "Document invalide";
}
else if (doc.isObject())
{
//recuperer l'object json
QJsonObject jObject = doc.object();
//convertir l'object json to variantmap
QVariantMap mainMap = jObject.toVariantMap();
// variant map
QVariantMap Map = mainMap["ven"].toMap();
myparser.source = Map["source"].toString();
myparser.msg = Map["msg"].toString();
myparser.type = Map["type"].toString();
header.H file : i define my struct
struct Venparser {
QString source;
QString msg;
QString type;
My problem is that i don't want a list in my "msg" but something like this :
when i call myparser.msg , then it will check just the value i need in msg and return it.
"msg":"radio_volume" || "radio-mute", || "radio3",
Thanks,
Your example with the || token is not a valid JSON. You can read more about its format here. However, if I understand you correctly, you can easily use JSON arrays for your task.
JSON:
{
"ven": {
"source": "logicCtrl",
"msg": ["radio_volume", "radio-mute", "radio3"],
"type": "int"
}
}
C++:
You can access the msg array using the toStringList() method. Also, you can use QVariantList and toList() respectively if you fill your array with data different from strings.
QStringList messages = Map["msg"].toStringList();
Now the messages variable contains "radio_volume", "radio-mute" and "radio3" values so you can extract the required string any way you need using your code.
If you still need to parse your exact example (which is technically not a valid JSON as I said before), you will have to go with writing your own parser, which is a bit wide topic for the answer.

C++ json deserializer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
We can C++ project and we need to (de) serialize objects from and into json.
In C# we are using JSON.NET. We simple call:
string json = JsonConvert.SerializeObject(product);
var myNewObject = JsonConvert.DeserializeObject<MyClass>(json);
Very simple and useful.
Does anybody know about free C++ library, which can be used in the same simple way like in C#?
We are using JsonCpp, but it does not support it.
Thanks very much
Regards
C++ does not support reflection so you necessarily have to write your own serialize and deserialize functions for each object.
I'm using https://github.com/nlohmann/json in a C++ websocket server talking to a html/javascript client. The websocket framework is https://github.com/zaphoyd/websocketpp. So sending the json structure 'matches' from the server goes like
msg->set_payload(matches.dump());
m_server.send(hdl, msg);
And like wise from the client
var m = "la_liga";
var msg = {
"type": "request",
"data": m
}
msg = JSON.stringify(msg);
ws.send(msg);
When I receive json on the server I parse it and then a try-catch
void on_message(connection_hdl hdl, server::message_ptr msg) {
connection_ptr con = m_server.get_con_from_hdl(hdl);
nlohmann::json jdata;
std::string payload = msg->get_payload();
try {
jdata.clear();
jdata = nlohmann::json::parse(payload);
if (jdata["type"] == "update") {
<do something with this json structure>
}
} catch (const std::exception& e) {
msg->set_payload("Unable to parse json");
m_server.send(hdl, msg);
std::cerr << "Unable to parse json: " << e.what() << std::endl;
}
}
And likewise on the client
ws.onmessage = function (e) {
var receivedMsg = JSON.parse(e.data);
if (receivedMsg.type == "table") {
<sort and display updated table standing>
}
}
Websocketpp requires boost libraries.
I wrote this serializer/deserializer for c++ since I couldn't find any non boost serializer that fit my needs:
Pakal Persist
It supports both json and xml and polymorphics objets as well.

Glass Throwing Error

I have some questions regarding my block of code. I've tried running it in Netbeans and it doesn't seem to like this block of code on Google Glass. I compiled it using Eclipse and it seems to compile correctly as well.
package com.openglassquartz.helloglass;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
public class OnlineRetrieval {
boolean activeGame;
public boolean checkGame() { //Method for which to check if there is a current game going on.
try {
URL url = new URL("http://danielchan.me/league/active.txt");
Scanner s = new Scanner(url.openStream()); //All errors point to this line of code??
int temporary_Reading = s.nextInt();
if(temporary_Reading == 1) {
return activeGame = true;
} else {
return activeGame = false;
}
} catch(IOException ex) {
ex.printStackTrace();
}
return activeGame;
}
}
From the LaunchService Class.
OnlineRetrieval OR = new OnlineRetrieval();
boolean temp_Check = OR.checkGame();
01-14 16:38:32.187: E/AndroidRuntime(18639): at com.openglassquartz.helloglass.OnlineRetrieval.checkGame(OnlineRetrieval.java:20)
01-14 16:38:32.187: E/AndroidRuntime(18639): at com.openglassquartz.helloglass.CardLaunchService.onStartCommand(CardLaunchService.java:77)
How can I fix this? It seems to work on Netbeans when I tried outputting it but not in Google Glass.
Two things to look at (it looks like your stack trace is cut off in your post):
Did you add the android.permission.INTERNET permission to your application's manifest?
Is this code being called in the main UI thread? Network operations must be executed in a background thread – you may want to look at the AsyncTask class as a way of handling this.